top.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="top">
  3. <view class="left">
  4. <image src="../static/logo.png" mode="widthFix" class="img"></image>
  5. <view class="nav">
  6. <text class="text" @click="clickIndex" :class="type=='index'?'navactive':''">首页</text>
  7. <text class="text" @click="toProduct" :class="type=='product'?'navactive':''">产品介绍</text>
  8. <text class="text" @click="toAboutUs" :class="type=='aboutUs'?'navactive':''">关于我们</text>
  9. </view>
  10. </view>
  11. <view class="right-content" v-if='hasLogin'>
  12. <view class="phone" @click="phoneClick">
  13. <image :src="userInfo.avatarUrl" class="img"></image>
  14. <view class="">
  15. {{userInfo.phone}}
  16. </view>
  17. </view>
  18. <view class="out-view" v-if="isSHowUser">
  19. <view class="text" @click="userClick">
  20. 个人中心
  21. </view>
  22. <view class="text" @click="logOut">
  23. 退出
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. mapState
  32. } from 'vuex';
  33. export default {
  34. name: 'top',
  35. emits: ['click'],
  36. props: {
  37. type: {
  38. type: String,
  39. default: ''
  40. },
  41. },
  42. data() {
  43. return {
  44. isSHowPhone: true,
  45. isSHowUser: false,
  46. }
  47. },
  48. watch: {
  49. title(newVal) {
  50. if (uni.report && newVal !== '') {
  51. uni.report('title', newVal)
  52. }
  53. }
  54. },
  55. computed: {
  56. ...mapState(['hasLogin', 'userInfo']),
  57. },
  58. methods: {
  59. logOut() {
  60. uni.clearStorageSync();
  61. var that = this
  62. this.$store.commit('logout')
  63. uni.navigateTo({
  64. url: `/pages/index/index`
  65. })
  66. },
  67. phoneClick() {
  68. this.isSHowUser = !this.isSHowUser
  69. },
  70. onClick() {
  71. this.$emit('click')
  72. },
  73. clickIndex() {
  74. uni.navigateTo({
  75. url: "/pages/index/index"
  76. })
  77. },
  78. userClick() {
  79. uni.navigateTo({
  80. url: "/pages/index/user"
  81. })
  82. },
  83. toProduct() {
  84. uni.navigateTo({
  85. url: "/pages/index/product"
  86. })
  87. },
  88. toAboutUs() {
  89. uni.navigateTo({
  90. url: "/pages/index/aboutUs"
  91. })
  92. },
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. .navactive {
  98. color: #2F54EF !important;
  99. }
  100. .img {
  101. width: 200rpx;
  102. }
  103. .right-content {
  104. position: relative;
  105. .phone {
  106. display: flex;
  107. align-items: center;
  108. position: relative;
  109. cursor: pointer;
  110. }
  111. .img {
  112. width: 64rpx;
  113. height: 64rpx;
  114. border-radius: 50%;
  115. margin-right: 10px;
  116. }
  117. .out-view {
  118. position: absolute;
  119. bottom: -80px;
  120. left: 45px;
  121. z-index: 2;
  122. width: 182rpx;
  123. height: 148rpx;
  124. background: #FFFFFF;
  125. box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.1);
  126. border-radius: 12px;
  127. display: flex;
  128. flex-direction: column;
  129. justify-content: center;
  130. align-items: center;
  131. .text {
  132. font-size: 28rpx;
  133. font-weight: 400;
  134. color: #333333;
  135. line-height: 20px;
  136. cursor: pointer;
  137. }
  138. }
  139. }
  140. .top {
  141. display: flex;
  142. align-items: center;
  143. background: white;
  144. justify-content: space-between;
  145. padding: 66rpx 10%;
  146. min-width: 1200px;
  147. box-sizing: border-box;
  148. .left {
  149. display: flex;
  150. .nav {
  151. margin-left: 200rpx;
  152. }
  153. }
  154. // color: white;
  155. // background: black
  156. }
  157. .title {
  158. margin: 0 40rpx;
  159. }
  160. .nav {
  161. display: flex;
  162. align-items: center;
  163. .text {
  164. font-size: 16px;
  165. color: #65676B;
  166. margin-right: 200rpx;
  167. }
  168. }
  169. </style>