header.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="top-header-box" :class="{init:isIndex===true&&scrollState===false}">
  3. <div class="top-header">
  4. <div class="logo">
  5. <img v-show="isIndex===true&&scrollState===false" src="../assets/img/mainLogo.png" alt="">
  6. <img v-show="!(isIndex===true&&scrollState===false)" src="../assets/img/logo2.png" alt="">
  7. </div>
  8. <ul class="nav-line">
  9. <li v-for="item in navlist" @click="golink(item.link)" :class="{active:item.link==currentPath}">
  10. <span>{{item.name}}</span>
  11. <i class="badge" v-if="item.badge==true">HOT</i>
  12. </li>
  13. </ul>
  14. <div class="userMsg" v-show="showstate===1">
  15. <div class="item" @click="golink('/usercenter')">
  16. <i class="iconfont icon-user"></i>
  17. <span >{{username}}</span>
  18. </div>
  19. <div class="item" @click="quit">
  20. <i class="iconfont icon-tuichu"></i>
  21. <span>退出</span>
  22. </div>
  23. </div>
  24. <div class="userMsg" v-show="showstate===0&&isIndex===false">
  25. <div class="item">
  26. <span @click="golink('/index')">登录</span>
  27. </div>
  28. <div class="item">
  29. <span @click="golink('/index')">注册</span>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import {ajax,getUserData,delatecookie,getcookie} from "../assets/js/common.js"
  37. import bus from "../assets/js/bus.js"
  38. export default{
  39. data(){
  40. return{
  41. navlist:[
  42. {
  43. name:"首页",
  44. link:"/index",
  45. },
  46. {
  47. name:"申请代理",
  48. link:"/apply",
  49. badge:true,
  50. },
  51. ],
  52. isIndex:false,
  53. scrollState:false,
  54. currentPath:"",
  55. showstate:0,
  56. username:"",
  57. }
  58. },
  59. mounted(){
  60. this.$nextTick(()=>{
  61. javascript:scrollTo(0,0);
  62. if(this.$route.path=="/index"){
  63. this.isIndex=true;
  64. }
  65. let mainword=this.$route.path.split("/")[1];
  66. this.currentPath="/"+mainword;
  67. window.addEventListener("scroll",this.menuchange);
  68. let token=getcookie("token");
  69. if(token){
  70. this.showstate=1;
  71. }
  72. else{
  73. this.showstate=0;
  74. }
  75. bus.$on("login",()=>{
  76. this.showstate=1;
  77. this.username=getcookie("username");
  78. });
  79. this.username=getcookie("username");
  80. })
  81. },
  82. methods:{
  83. menuchange(){
  84. if(document.documentElement.scrollTop>0){
  85. this.scrollState=true;
  86. }
  87. else{
  88. this.scrollState=false;
  89. }
  90. },
  91. quit(){
  92. ajax(this,this.extendApi.loginout,"",(data)=>{
  93. if(data.code==200||data.code==-2){
  94. this.$notify({
  95. title: '提示',
  96. message: '退出成功',
  97. type: 'success',
  98. duration:'1500'
  99. });
  100. delatecookie();
  101. this.$router.push({path:"/index"});
  102. this.showstate=0;
  103. bus.$emit("goout");
  104. }
  105. },"GET");
  106. },
  107. golink(val){
  108. let token=getcookie('token');
  109. if(token){
  110. this.$router.push({path:val});
  111. }
  112. else{
  113. if(val=='/apply'||val=='/myassets'){
  114. this.$notify({
  115. title: '提示',
  116. message: '请先登录',
  117. type: 'warning',
  118. duration: '2000'
  119. });
  120. }
  121. else{
  122. this.$router.push({path:val});
  123. }
  124. }
  125. },
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. .top-header-box{
  131. background-color:#fff;
  132. overflow: hidden;
  133. position: fixed;
  134. z-index: 100;
  135. width: 100%;
  136. &.init{
  137. background-color:rgba(0,0,0,0.2);
  138. .nav-line{
  139. li{
  140. color: #fff;
  141. }
  142. .active{
  143. color:#1a6fa6;
  144. background-color: #fff;
  145. }
  146. }
  147. .userMsg{
  148. color: #fff;
  149. .iconfont{
  150. color: #fff !important;
  151. }
  152. }
  153. }
  154. }
  155. .top-header{
  156. text-align: left;
  157. width: 1200px;
  158. margin: 0 auto;
  159. .logo{
  160. float: left;
  161. width: 98px;
  162. line-height: 75px;
  163. height: 75px;
  164. display: flex;
  165. align-items: center;
  166. margin-right: 55px;
  167. img{
  168. width: 100%;
  169. }
  170. }
  171. .nav-line{
  172. /*overflow: hidden;
  173. position: relative;*/
  174. li{
  175. float: left;
  176. position: relative;
  177. line-height: 75px;
  178. font-size: 14px;
  179. width: 118px;
  180. text-align: center;
  181. cursor: pointer;
  182. color: #333;
  183. }
  184. .active{
  185. color:#fff;
  186. background-color: #1a6fa6;
  187. }
  188. .badge{
  189. position: absolute;
  190. background-color: #ff4e00;
  191. color: #fff;
  192. display: block;
  193. width: 38px;
  194. height: 18px;
  195. line-height: 18px;
  196. font-size: 12px;
  197. border-radius: 2px;
  198. top: 8px;
  199. right: 0;
  200. }
  201. .badge:after{
  202. content:"";
  203. width: 0;
  204. height: 0;
  205. position: absolute;
  206. z-index:-1;
  207. bottom: 0;
  208. left: 30%;
  209. border-left:5px solid transparent;
  210. border-right:5px solid transparent;
  211. border-top:14px solid #ff4e00;
  212. margin-bottom: -8px;
  213. transform:rotate(30deg);
  214. }
  215. }
  216. .userMsg{
  217. float: right;
  218. line-height: 72px;
  219. color: #333;
  220. .item{
  221. float: left;
  222. font-size: 14px;
  223. cursor: pointer;
  224. }
  225. .item+.item{
  226. margin-left: 30px;
  227. }
  228. .iconfont{
  229. font-size: 20px;
  230. color: #999;
  231. }
  232. }
  233. }
  234. </style>