index.vue 6.6 KB

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