tabBar.vue 3.9 KB

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