tabBar.vue 3.4 KB

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