header-nav.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="header-nav" :class="{'scroll':isscroll}">
  3. <div class="nav-content">
  4. <div class="logo">
  5. <img src="../assets/img/mainLogo.png" v-show='!isscroll'>
  6. <img src="../assets/img/logo2.png" v-show='isscroll'>
  7. </div>
  8. <ul class="nav-line clearfix">
  9. <li v-on:click='cut("/")' :class="{'active':'/'==isActive}"><span>首页</span></li>
  10. <li v-on:click='cut("/apply")' :class="{'active':'/apply'==isActive}">
  11. <span>申请经纪商</span>
  12. <i class="badge">HOT</i>
  13. </li>
  14. </ul>
  15. <div class="usermsg" v-show="username!=''">
  16. <div class="item" :class="{'scroll':isscroll}">
  17. <i class="iconfont icon-user"></i>
  18. <span>{{username}}</span>
  19. </div>
  20. <div class="item" :class="{'scroll':isscroll}">
  21. <i class="iconfont icon-tuichu"></i>
  22. <span @click="quit()">退出</span>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'header-nav',
  31. data () {
  32. return {
  33. isActive:'/',
  34. isscroll:false
  35. }
  36. },
  37. props:['username'],
  38. methods:{
  39. cut(e){
  40. if (!window.localStorage.username) {
  41. alert('请先登陆')
  42. }else{
  43. this.$router.push(e)
  44. this.isActive=e
  45. }
  46. },
  47. scrollFunc(){
  48. let t = document.documentElement.scrollTop || document.body.scrollTop
  49. if (t===0&&this.$route.path=='/') {
  50. this.isscroll=false
  51. }else {
  52. this.isscroll=true
  53. }
  54. },
  55. quit(){
  56. window.localStorage.clear()
  57. this.$router.push('/')
  58. this.$emit('quit')
  59. this.isActive='/'
  60. }
  61. },
  62. mounted(){
  63. window.addEventListener('scroll',this.scrollFunc,false)
  64. this.isActive=this.$route.path
  65. },
  66. updated(){
  67. this.scrollFunc()
  68. }
  69. }
  70. </script>
  71. <!-- Add "scoped" attribute to limit CSS to this component only -->
  72. <style scoped>
  73. .header-nav{
  74. width: 100%;
  75. height: 75px;
  76. background-color: rgba(0, 0, 0, .2);
  77. position: fixed;
  78. top: 0;
  79. z-index: 999;
  80. .nav-content{
  81. width: 1200px;
  82. margin: 0 auto;
  83. height: 100%;
  84. display: flex;
  85. justify-content: space-between;
  86. .logo{
  87. height: 100%;
  88. line-height: 75px;
  89. width: 98px;
  90. float: left;
  91. margin-right: 55px;
  92. display: flex;
  93. align-items: center;
  94. img{
  95. height: 33px;
  96. }
  97. }
  98. .nav-line{
  99. flex-grow: 1;
  100. li{
  101. float: left;
  102. width: 118px;
  103. height: 75px;
  104. font-size: 14px;
  105. line-height: 75px;
  106. text-align: center;
  107. color: #fff;
  108. &.active{
  109. background: white;
  110. color: #1a6fa6;
  111. }
  112. .badge{
  113. background: #ff4e00;
  114. color: #fff;
  115. display: block;
  116. width: 38px;
  117. height: 18px;
  118. line-height: 18px;
  119. font-size: 12px;
  120. border-radius: 2px;
  121. position: absolute;
  122. top: 8px;
  123. right: 0;
  124. }
  125. .badge::after{
  126. content: '';
  127. position: absolute;
  128. width: 0;
  129. height: 0;
  130. left: 30%;
  131. bottom: 0;
  132. border-left: 5px solid transparent;
  133. border-right: 5px solid transparent;
  134. border-top: 14px solid #ff4e00;
  135. margin-bottom: -8px;
  136. transform: rotate(30deg);
  137. z-index: -1;
  138. }
  139. }
  140. li:nth-child(2){
  141. position: relative;
  142. }
  143. }
  144. .usermsg{
  145. float: right;
  146. color: white;
  147. line-height: 72px;
  148. .item{
  149. float: left;
  150. font-size: 14px;
  151. cursor: pointer;
  152. }
  153. .item:nth-child(1){
  154. margin-right: 25px;
  155. }
  156. }
  157. }
  158. }
  159. .scroll{
  160. background-color: white;
  161. color: #333;
  162. }
  163. .scroll .nav-line li.active{
  164. color: #fff!important;
  165. background-color: #1a6fa6!important;
  166. }
  167. .scroll .nav-line li{
  168. color: #333!important;
  169. }
  170. </style>