tabBar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. {{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. {{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. </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. });
  92. })
  93. },
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .borderShow {
  99. position: fixed;
  100. }
  101. .borderShow .uni-tabbar::after {
  102. content: ' ';
  103. position: absolute;
  104. left: 0;
  105. top: 0;
  106. width: 100%;
  107. height: 100%;
  108. border: 1px dashed #007AFF;
  109. box-sizing: border-box;
  110. }
  111. .uni-tabbar {
  112. position: fixed;
  113. bottom: 0;
  114. left: 0;
  115. z-index: 999;
  116. width: 100%;
  117. height: 98rpx;
  118. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  119. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  120. padding-bottom: calc(constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  121. padding-bottom: calc(env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  122. box-sizing: border-box;
  123. border-top: solid 1rpx #F3F3F3;
  124. background-color: #fff;
  125. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  126. display: flex;
  127. flex-wrap: nowrap;
  128. .uni-tabbar_item {
  129. width: 100%;
  130. font-size: 20rpx;
  131. text-align: center;
  132. }
  133. .uni-tabbar_icon {
  134. height: 50rpx;
  135. width: 50rpx;
  136. text-align: center;
  137. margin: 0 auto;
  138. image {
  139. width: 100%;
  140. height: 100%;
  141. }
  142. }
  143. .uni-tabbar_label {
  144. font-size: 24rpx;
  145. color: rgb(40, 40, 40);
  146. &.active {
  147. color: var(--view-theme);
  148. }
  149. }
  150. }
  151. </style>