Top.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div :class="'top'+' '+topchange">
  3. <div class="wrap">
  4. <div class="logo">
  5. <img :src="scrolled?src2:src1" alt="" class="fl">
  6. </div>
  7. <ul class="nav fl ">
  8. <li :class="{'active':index}" @click="goApply('')">
  9. <span>首页</span></li>
  10. <li :class="{'active':apply}" @click="goApply('apply')">
  11. <span>申请经纪商</span>
  12. <i class="hot">HOT</i>
  13. </li>
  14. </ul>
  15. <ul class="fr nav user" v-show="logined">
  16. <li><i class="iconfont icon-user"></i>{{username}}</li>
  17. <li @click="exit()"><i class="iconfont icon-tuichu"></i>退出</li>
  18. </ul>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'Top',
  25. data () {
  26. return {
  27. scrolled: false,
  28. topchange: 'topone',
  29. src1: '../../static/images/mainLogo.png',
  30. src2: '../../static/images/logo2.png',
  31. index:true,
  32. apply:false
  33. }
  34. },
  35. computed:{
  36. logined(){
  37. return this.$store.state.logined
  38. },
  39. username(){
  40. return this.$store.state.loginedUser.username
  41. }
  42. },
  43. methods: {
  44. goApply: function (route) {
  45. this.$router.push('/' + route);
  46. if(route == 'apply'){
  47. this.apply = true;
  48. this.index = false;
  49. this.topchange = 'toptwo'
  50. this.scrolled = true;
  51. }
  52. else{
  53. this.apply = false;
  54. this.index = true;
  55. }
  56. },
  57. handleScroll () {
  58. if(this.$route.path == '/apply'){
  59. this.topchange = 'toptwo'
  60. this.scrolled = true
  61. }else{
  62. if (window.scrollY > 0) {
  63. this.topchange = 'toptwo'
  64. this.scrolled = true
  65. } else {
  66. this.topchange = 'topone'
  67. this.scrolled = false
  68. }
  69. }
  70. },
  71. exit:function(){
  72. this.$store.dispatch('logout')
  73. localStorage.removeItem('userInfo');
  74. }
  75. },
  76. mounted () {
  77. window.addEventListener('scroll', this.handleScroll);
  78. if(this.$route.path == '/apply'){
  79. this.apply = true;
  80. this.index = false;
  81. this.topchange = 'toptwo'
  82. this.scrolled = true
  83. }
  84. else{
  85. this.apply = false;
  86. this.index = true;
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped>
  92. .top {
  93. height: 75px;
  94. width: 100%;
  95. position: absolute;
  96. top: 0;
  97. left: 0;
  98. z-index: 100;
  99. }
  100. .topone {
  101. background-color: rgba(0, 0, 0, 0.2);
  102. color: #fff;
  103. }
  104. .toptwo {
  105. background-color: #fff;
  106. color: #000;
  107. position: fixed;
  108. top: 0;
  109. .active {
  110. color: #fff;
  111. background-color: #1a6fa6;
  112. }
  113. }
  114. .logo {
  115. float: left;
  116. width: 98px;
  117. line-height: 75px;
  118. height: 75px;
  119. margin-right: 55px;
  120. display: flex;
  121. align-items: center;
  122. }
  123. .logo > img {
  124. width: 100%;
  125. }
  126. .nav li {
  127. float: left;
  128. width: 118px;
  129. line-height: 75px;
  130. font-size: 14px;
  131. position: relative;
  132. }
  133. .nav li:hover {
  134. cursor: pointer;
  135. }
  136. .topone .active {
  137. background-color: #fff;
  138. color: #1a6fa6;;
  139. }
  140. .hot {
  141. position: absolute;
  142. background-color: #ff4e00;
  143. color: #fff;
  144. display: block;
  145. width: 38px;
  146. height: 18px;
  147. line-height: 18px;
  148. font-size: 12px;
  149. border-radius: 2px;
  150. top: 8px;
  151. right: 0;
  152. }
  153. .hot:after {
  154. content: "";
  155. width: 0;
  156. height: 0;
  157. position: absolute;
  158. z-index: -1;
  159. bottom: 0;
  160. left: 30%;
  161. border-left: 5px solid transparent;
  162. border-right: 5px solid transparent;
  163. border-top: 14px solid #ff4e00;
  164. margin-bottom: -8px;
  165. transform: rotate(30deg);
  166. }
  167. .user{
  168. li{
  169. text-align: right;
  170. width: auto;
  171. }
  172. li:nth-child(2){
  173. margin-left: 30px;
  174. }
  175. i{
  176. font-size: 20px;
  177. }
  178. }
  179. </style>