Top.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. // username:''
  34. }
  35. },
  36. computed: {
  37. logined () {
  38. return this.$store.state.logined
  39. },
  40. username () {
  41. return this.$store.state.loginedUser.username
  42. }
  43. },
  44. methods: {
  45. goApply: function (route) {
  46. if (route == 'apply') {
  47. if(this.logined){
  48. this.$router.push('/' + route)
  49. this.apply = true
  50. this.index = false
  51. this.topchange = 'toptwo'
  52. this.scrolled = true
  53. }else{
  54. this.$notify({
  55. title: '提示',
  56. message: '请先登录',
  57. type: 'warning'
  58. })
  59. }
  60. } else {
  61. this.$router.push('/' + route)
  62. this.apply = false
  63. this.index = true
  64. }
  65. },
  66. handleScroll () {
  67. if (this.$route.path == '/apply') {
  68. this.topchange = 'toptwo'
  69. this.scrolled = true
  70. } else {
  71. if (window.scrollY > 0) {
  72. this.topchange = 'toptwo'
  73. this.scrolled = true
  74. } else {
  75. this.topchange = 'topone'
  76. this.scrolled = false
  77. }
  78. }
  79. },
  80. exit: function () {
  81. this.$store.dispatch('logout')
  82. localStorage.removeItem('userInfo')
  83. this.notify('退出成功','success')
  84. },
  85. notify(mes,type) {
  86. this.$notify({
  87. title: '提示',
  88. message: mes,
  89. type: type
  90. })
  91. }
  92. },
  93. mounted () {
  94. window.addEventListener('scroll', this.handleScroll)
  95. if (this.$route.path == '/apply') {
  96. this.apply = true
  97. this.index = false
  98. this.topchange = 'toptwo'
  99. this.scrolled = true
  100. } else {
  101. this.apply = false
  102. this.index = true
  103. }
  104. },
  105. computed:{
  106. logined(){
  107. return this.$store.state.logined
  108. },
  109. username(){
  110. return this.$store.state.loginedUser.username
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .top {
  117. height: 75px;
  118. width: 100%;
  119. position: absolute;
  120. top: 0;
  121. left: 0;
  122. z-index: 100;
  123. }
  124. .topone {
  125. background-color: rgba(0, 0, 0, 0.2);
  126. color: #fff;
  127. }
  128. .toptwo {
  129. background-color: #fff;
  130. color: #000;
  131. position: fixed;
  132. top: 0;
  133. .active {
  134. color: #fff;
  135. background-color: #1a6fa6;
  136. }
  137. }
  138. .logo {
  139. float: left;
  140. width: 98px;
  141. line-height: 75px;
  142. height: 75px;
  143. margin-right: 55px;
  144. display: flex;
  145. align-items: center;
  146. }
  147. .logo > img {
  148. width: 100%;
  149. }
  150. .nav li {
  151. float: left;
  152. width: 118px;
  153. line-height: 75px;
  154. font-size: 14px;
  155. position: relative;
  156. }
  157. .nav li:hover {
  158. cursor: pointer;
  159. }
  160. .topone .active {
  161. background-color: #fff;
  162. color: #1a6fa6;;
  163. }
  164. .hot {
  165. position: absolute;
  166. background-color: #ff4e00;
  167. color: #fff;
  168. display: block;
  169. width: 38px;
  170. height: 18px;
  171. line-height: 18px;
  172. font-size: 12px;
  173. border-radius: 2px;
  174. top: 8px;
  175. right: 0;
  176. }
  177. .hot:after {
  178. content: "";
  179. width: 0;
  180. height: 0;
  181. position: absolute;
  182. z-index: -1;
  183. bottom: 0;
  184. left: 30%;
  185. border-left: 5px solid transparent;
  186. border-right: 5px solid transparent;
  187. border-top: 14px solid #ff4e00;
  188. margin-bottom: -8px;
  189. transform: rotate(30deg);
  190. }
  191. .user{
  192. li{
  193. text-align: right;
  194. width: auto;
  195. }
  196. li:nth-child(2){
  197. margin-left: 30px;
  198. }
  199. i{
  200. font-size: 20px;
  201. }
  202. }
  203. </style>