Header.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <header class="top-header-box" :class="{init:isHome===true&&scrollState===false}">
  3. <div class="top-header">
  4. <div class="header-logo">
  5. <img src="../assets/img/mainlogo.png" alt="FX66" v-show="isHome===true&&scrollState===false">
  6. <img src="../assets/img/logo2.png" alt="FX66" v-show="!(isHome===true&&scrollState===false)">
  7. </div>
  8. <ul class="header-line">
  9. <li :class="{active:$route.path=='/home'}" @click="golink('/home')"><span>首页</span></li>
  10. <li :class="{active:$route.path=='/applyAgent'}" @click="golink('/applyAgent')">
  11. <span>申请经纪商</span>
  12. <i class="badge">HOT</i>
  13. </li>
  14. </ul>
  15. <div class="userMsg" v-show="userstate">
  16. <div class="item">
  17. <i class="iconfont icon-user"></i>
  18. <span>{{username}}</span>
  19. </div>
  20. <div class="item" @click="quit()">
  21. <i class="iconfont icon-tuichu"></i>
  22. <span>退出</span>
  23. </div>
  24. </div>
  25. <div class="userMsg" v-show="!userstate&&isHome===false">
  26. <div class="item">
  27. <span @click="golink('/home')">登录</span>
  28. </div>
  29. <div class="item">
  30. <span @click="golink('/home')">注册</span>
  31. </div>
  32. </div>
  33. </div>
  34. </header>
  35. </template>
  36. <script>
  37. import {getcookie,setcookie,deletecookie,loginOut} from '../assets/js/common.js'
  38. import bus from "../assets/js/bus.js"
  39. export default{
  40. data(){
  41. return{
  42. isHome:false,
  43. scrollState:false,
  44. userstate:false,
  45. username:""
  46. }
  47. },
  48. mounted(){
  49. this.$nextTick(()=>{
  50. if (this.$route.path=="/home") {
  51. this.isHome=true;
  52. };
  53. window.addEventListener("scroll",this.headerchange);
  54. this.currentPath=this.$route.path;
  55. let token = getcookie("token");//登录记号
  56. //此处负责刚进入页面时,进行获取用户名
  57. if (token) {
  58. this.userstate=true;
  59. this.username = getcookie("username");
  60. }else{
  61. this.userstate=false;
  62. }
  63. //此处负责登录时,刷新用户名
  64. var that = this;
  65. bus.$on("reUsername",function(){
  66. that.userstate=true;
  67. that.username=getcookie("username");
  68. })
  69. });
  70. },
  71. methods:{
  72. headerchange(){
  73. if (document.documentElement.scrollTop>0) {
  74. this.scrollState=true;
  75. }else{
  76. this.scrollState=false;
  77. }
  78. },
  79. golink(address){
  80. let token=getcookie('token');
  81. //如果已经登录允许跳转
  82. if (token) {
  83. //this.$router访问路由器,调用push方法完成路由跳转
  84. this.$router.push({path:address});
  85. }else{
  86. if (address=='/applyAgent') {
  87. //$notify是ele自带的一个全局方法,实现提示框的效果
  88. this.$notify({
  89. title:'提示',
  90. message:'请先登录',
  91. type:'warning',
  92. duration:'2000'
  93. });
  94. }
  95. else{
  96. //完成经纪商页面跳到首页
  97. this.$router.push({path:address});
  98. }
  99. }
  100. },
  101. quit(){
  102. loginOut(this)
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .top-header-box{
  109. position: fixed;
  110. background-color: #fff;
  111. width: 100%;
  112. z-index: 100;
  113. overflow: hidden;
  114. .top-header{
  115. width: 1200px;
  116. margin: 0 auto;
  117. text-align: left;
  118. .header-logo{
  119. width: 98px;
  120. float: left;
  121. height: 75px;
  122. display: flex;
  123. align-items: center;
  124. margin-right: 55px;
  125. img{
  126. width: 100%;
  127. }
  128. }
  129. .header-line{
  130. font-size: 14px;
  131. li{
  132. float: left;
  133. height: 75px;
  134. width: 118px;
  135. line-height: 75px;
  136. text-align: center;
  137. position: relative;
  138. color: #333;
  139. cursor: pointer;
  140. &.active{
  141. background-color: var(--text-color-active);
  142. color: #fff;
  143. }
  144. i{
  145. position: absolute;
  146. top: 8px;
  147. right: 0;
  148. width: 38px;
  149. height: 18px;
  150. line-height: 18px;
  151. background-color: #ff4e00;
  152. border-radius: 2px;
  153. font-size: 12px;
  154. color: #fff;
  155. &::after{
  156. content: '';
  157. width: 0;
  158. height: 0;
  159. position: absolute;
  160. z-index: -1;
  161. border-top: 14px solid #ff4e00;
  162. border-left: 5px solid transparent;
  163. border-right: 5px solid transparent;
  164. bottom: 0;
  165. left: 30%;
  166. margin-bottom: -8px;
  167. transform: rotateZ(30deg);
  168. }
  169. }
  170. }
  171. }
  172. .userMsg{
  173. float: right;
  174. line-height: 72px;
  175. color: #333;
  176. .item{
  177. float: left;
  178. font-size: 14px;
  179. cursor: pointer;
  180. &:nth-child(2){
  181. margin-left: 30px;
  182. }
  183. }
  184. }
  185. }
  186. &.init{
  187. background-color: rgba(0,0,0,.2);
  188. .header-line{
  189. li{
  190. color: #fff;
  191. &.active{
  192. background-color: #fff;
  193. color: var(--text-color-active);
  194. }
  195. }
  196. }
  197. .userMsg{
  198. color: #fff;
  199. }
  200. }
  201. }
  202. </style>