index.vue 5.5 KB

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