index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="tab_bar">
  3. <view class="tabbarBox">
  4. <view class="handleBox" v-for="(item) in tabBarList" :key="item.key + 'tab_bar'">
  5. <view class="menuBox" @click="goPages(item)">
  6. <view class="menuIcon">
  7. <view class="message-style" v-if="item.key === 'chat' && messageCount > 0">{{ messageCount }}
  8. </view>
  9. <image v-if="item.key != selectIndex" class="img" :src="item.iconPath"></image>
  10. <image v-else class="img" :src="item.selectedIconPath"></image>
  11. </view>
  12. <view class="menuName">
  13. <text :class="item.key == selectIndex ? 'TextColor' : 'Text'">{{ item.text }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { onMounted } from 'vue';
  22. import store from '@/store'
  23. export default {
  24. props: {
  25. page: {
  26. type: String,
  27. default: "home"
  28. }
  29. },
  30. watch: {
  31. page: {
  32. handler(value) {
  33. console.log('value', value);
  34. this.selectIndex = value;
  35. },
  36. immediate: true,
  37. deep: true
  38. }
  39. },
  40. data() {
  41. return {
  42. selectIndex: null,
  43. userType: uni.getStorageSync('userType'), //读取本地存储
  44. messageCount: store.state.user.messageCount
  45. }
  46. },
  47. computed: {
  48. //获取当前页面
  49. tabBarList() {
  50. if (this.userType === 1) {
  51. return [
  52. {
  53. "pagePath": "/pages/index",
  54. "iconPath": "/static/images/tabbar/home.png",
  55. "selectedIconPath": "/static/images/tabbar/home_.png",
  56. "text": "首页",
  57. key: 'home'
  58. },
  59. {
  60. "pagePath": "/pages/mallMenu",
  61. "iconPath": "/static/images/tabbar/class.png",
  62. "selectedIconPath": "/static/images/tabbar/class_.png",
  63. "text": "分类",
  64. key: 'class'
  65. },
  66. {
  67. "pagePath": "/pages/chat",
  68. "iconPath": "/static/images/tabbar/class.png",
  69. "selectedIconPath": "/static/images/tabbar/class_.png",
  70. "text": "消息",
  71. key: 'chat'
  72. },
  73. {
  74. "pagePath": "/pages/classify",
  75. "iconPath": "/static/images/tabbar/work.png",
  76. "selectedIconPath": "/static/images/tabbar/work_.png",
  77. "text": "订单",
  78. key: 'order'
  79. },
  80. {
  81. "pagePath": "/pages/mine",
  82. "iconPath": "/static/images/tabbar/mine.png",
  83. "selectedIconPath": "/static/images/tabbar/mine_.png",
  84. "text": "我的",
  85. key: 'mine'
  86. }
  87. ]
  88. }
  89. return [
  90. {
  91. "pagePath": "/pages/index",
  92. "iconPath": "/static/images/tabbar/home.png",
  93. "selectedIconPath": "/static/images/tabbar/home_.png",
  94. "text": "首页",
  95. key: 'home'
  96. },
  97. {
  98. "pagePath": "/pages/mallMenu",
  99. "iconPath": "/static/images/tabbar/class.png",
  100. "selectedIconPath": "/static/images/tabbar/class_.png",
  101. "text": "分类",
  102. key: 'class'
  103. },
  104. // {
  105. // "pagePath": "/pages/release",
  106. // "iconPath": "/static/images/tabbar/class.png",
  107. // "selectedIconPath": "/static/images/tabbar/class_.png",
  108. // "text": "发布",
  109. // key:'release'
  110. // },
  111. {
  112. "pagePath": "/pages/chat",
  113. "iconPath": "/static/images/tabbar/class.png",
  114. "selectedIconPath": "/static/images/tabbar/class_.png",
  115. "text": "消息",
  116. key: 'chat'
  117. },
  118. {
  119. "pagePath": "/pages/classify",
  120. "iconPath": "/static/images/tabbar/work.png",
  121. "selectedIconPath": "/static/images/tabbar/work_.png",
  122. "text": "订单",
  123. key: 'order'
  124. },
  125. {
  126. "pagePath": "/pages/mine",
  127. "iconPath": "/static/images/tabbar/mine.png",
  128. "selectedIconPath": "/static/images/tabbar/mine_.png",
  129. "text": "我的",
  130. key: 'mine'
  131. }
  132. ]
  133. }
  134. },
  135. //uniapp子组件不支持应用生命周期,所以只能用vue生命周期
  136. created() {
  137. },
  138. onMounted() {
  139. },
  140. methods: {
  141. //进入tabble页
  142. goPages(page) {
  143. console.log('page,index', page);
  144. uni.switchTab({
  145. url: page.pagePath
  146. })
  147. },
  148. },
  149. }
  150. </script>
  151. <style lang="scss">
  152. .tab_bar {
  153. width: 100vw;
  154. height: 160rpx;
  155. position: fixed;
  156. bottom: 0rpx;
  157. /* 模糊大小就是靠的blur这个函数中的数值大小 */
  158. // backdrop-filter: blur(10px);
  159. // border-radius: 60rpx;
  160. background-color: #fff;
  161. .tabbarBox {
  162. display: flex;
  163. margin-top: 20rpx;
  164. justify-content: space-evenly;
  165. .handleBox {
  166. width: 20vw;
  167. height: 110rpx;
  168. .menuBox {
  169. padding: 0rpx 20rpx;
  170. width: 120rpx;
  171. height: 98%;
  172. text-align: center;
  173. .img {
  174. width: 50rpx;
  175. height: 50rpx;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. .Text {
  182. font-size: 24rpx;
  183. font-weight: 900;
  184. }
  185. .TextColor {
  186. @extend .Text;
  187. color: #d81e06;
  188. }
  189. .menuIcon {
  190. position: relative;
  191. }
  192. .message-style {
  193. background: rgba(239, 68, 68, 1);
  194. color: #fff;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. width: 20px;
  199. height: 20px;
  200. border-radius: 20px;
  201. position: absolute;
  202. right: 0;
  203. z-index: 3;
  204. }
  205. </style>