tabBar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="uni-tabbar acea-row row-around row-middle" v-if="isShow && tabbar.length && !isIframe">
  4. <view class="uni-tabbar_item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
  5. <view class="uni-tabbar_icon">
  6. <image v-if="item.link == pagePath" mode="aspectFit" :src="item.imgList[0]"></image>
  7. <image v-else mode="aspectFit" :src="item.imgList[1]"></image>
  8. </view>
  9. <view class="uni-tabbar_label" :class="{'active': item.link == pagePath}">
  10. {{$t(item.name)}}
  11. </view>
  12. </view>
  13. </view>
  14. <view class="uni-tabbar acea-row row-around row-middle" v-if="isIframe && tabbar.length">
  15. <view class="uni-tabbar_item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
  16. <view class="uni-tabbar_icon">
  17. <image v-if="item.link == pagePath" mode="aspectFit" :src="item.imgList[0]"></image>
  18. <image v-else mode="aspectFit" :src="item.imgList[1]"></image>
  19. </view>
  20. <view class="uni-tabbar_label" :class="{'active': item.link == pagePath}">
  21. {{$t(item.name)}}
  22. </view>
  23. </view>
  24. </view>
  25. <view v-if="isIframe && !tabbar.length" class="empty-img uni-tabbar acea-row row-around row-middle">{{$t(`暂无数据,请设置`)}}
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. let app = getApp();
  31. import {
  32. getDiy
  33. } from '@/api/api.js';
  34. import {
  35. goPage
  36. } from '@/libs/order.js'
  37. import colors from '@/mixins/color.js';
  38. export default {
  39. name: 'tabBar',
  40. props: {
  41. pagePath: null,
  42. dataConfig: {
  43. type: Object,
  44. default: () => {}
  45. },
  46. },
  47. watch: {
  48. dataConfig: {
  49. immediate: true,
  50. handler(nVal, oVal) {
  51. if (nVal) {
  52. this.isShow = nVal.isShow.val;
  53. }
  54. }
  55. }
  56. },
  57. mixins: [colors],
  58. data() {
  59. return {
  60. name: this.$options.name,
  61. page: '/pages/index/index',
  62. tabbar: this.$Cache.get('TAB_BAR') ? JSON.parse(this.$Cache.get('TAB_BAR')) : [],
  63. isShow: true, //true前台显示
  64. isIframe: app.globalData.isIframe //true后台显示
  65. };
  66. },
  67. mounted() {
  68. if (!this.tabbar.length) this.getDiyData()
  69. },
  70. methods: {
  71. getDiyData() {
  72. getDiy().then(res => {
  73. const {
  74. list
  75. } = res.data.tabBar.default.tabBarList;
  76. this.$Cache.set('TAB_BAR', list)
  77. this.tabbar = list;
  78. }).catch(err => {
  79. uni.showToast({
  80. title: err,
  81. icon: 'none'
  82. });
  83. });
  84. },
  85. changeTab(item) {
  86. goPage().then(res => {
  87. this.page = item.link;
  88. // 这里使用reLaunch关闭所有的页面,打开新的栏目页面
  89. uni.switchTab({
  90. url: this.page,
  91. fail: () => {
  92. uni.navigateTo({
  93. url: this.page
  94. })
  95. }
  96. });
  97. })
  98. },
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .borderShow {
  104. position: fixed;
  105. }
  106. .borderShow .uni-tabbar::after {
  107. content: ' ';
  108. position: absolute;
  109. left: 0;
  110. top: 0;
  111. width: 100%;
  112. height: 100%;
  113. border: 1px dashed #007AFF;
  114. box-sizing: border-box;
  115. }
  116. .uni-tabbar {
  117. position: fixed;
  118. bottom: 0;
  119. left: 0;
  120. z-index: 999;
  121. width: 100%;
  122. height: 98rpx;
  123. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  124. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  125. padding-bottom: calc(constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  126. padding-bottom: calc(env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  127. box-sizing: border-box;
  128. border-top: solid 1rpx #F3F3F3;
  129. background-color: #fff;
  130. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  131. display: flex;
  132. flex-wrap: nowrap;
  133. .uni-tabbar_item {
  134. width: 100%;
  135. font-size: 20rpx;
  136. text-align: center;
  137. }
  138. .uni-tabbar_icon {
  139. height: 50rpx;
  140. width: 50rpx;
  141. text-align: center;
  142. margin: 0 auto;
  143. image {
  144. width: 100%;
  145. height: 100%;
  146. }
  147. }
  148. .uni-tabbar_label {
  149. font-size: 24rpx;
  150. color: rgb(40, 40, 40);
  151. &.active {
  152. color: var(--view-theme);
  153. }
  154. }
  155. }
  156. </style>