index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. <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. // key:'chat'
  105. // },
  106. {
  107. "pagePath": "/pages/classify",
  108. "iconPath": "/static/images/tabbar/work.png",
  109. "selectedIconPath": "/static/images/tabbar/work_.png",
  110. "text": "订单",
  111. key:'order'
  112. },
  113. {
  114. "pagePath": "/pages/mine",
  115. "iconPath": "/static/images/tabbar/mine.png",
  116. "selectedIconPath": "/static/images/tabbar/mine_.png",
  117. "text": "我的",
  118. key:'mine'
  119. }
  120. ]
  121. }
  122. },
  123. //uniapp子组件不支持应用生命周期,所以只能用vue生命周期
  124. created() {
  125. },
  126. methods: {
  127. //进入tabble页
  128. goPages(page) {
  129. console.log('page,index',page);
  130. uni.switchTab({
  131. url: page.pagePath
  132. })
  133. },
  134. },
  135. }
  136. </script>
  137. <style lang="scss">
  138. .tab_bar {
  139. width: 100vw;
  140. height: 160rpx;
  141. position: fixed;
  142. bottom: 0rpx;
  143. /* 模糊大小就是靠的blur这个函数中的数值大小 */
  144. // backdrop-filter: blur(10px);
  145. // border-radius: 60rpx;
  146. background-color: #fff;
  147. .tabbarBox {
  148. display: flex;
  149. margin-top: 20rpx;
  150. justify-content: space-evenly;
  151. .handleBox {
  152. width: 20vw;
  153. height: 110rpx;
  154. .menuBox {
  155. padding: 0rpx 20rpx;
  156. width: 120rpx;
  157. height: 98%;
  158. text-align: center;
  159. .img {
  160. width: 50rpx;
  161. height: 50rpx;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. .Text {
  168. font-size: 24rpx;
  169. font-weight: 900;
  170. }
  171. .TextColor {
  172. @extend .Text;
  173. color: #d81e06;
  174. }
  175. </style>