You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.3 KiB

3 months ago
  1. <template>
  2. <!-- 底部导航 -->
  3. <view :data-theme="theme">
  4. <view v-if="obj.isCustom==1">
  5. <view class="page-footer" id="target">
  6. <view class="foot-item" v-for="(item,index) in obj.bottomNavigationList" :key="index"
  7. @click="goRouter(item)">
  8. <block v-if="item.link.split('?')[0] == activeRouter">
  9. <image :src="item.checked"></image>
  10. <view class="txt">{{item.name}}</view>
  11. </block>
  12. <block v-else>
  13. <image :src="item.unchecked"></image>
  14. <view class="unchecked">{{item.name}}</view>
  15. </block>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. let app = getApp();
  23. import {
  24. getBottomNavigationApi
  25. } from '@/api/api.js'
  26. export default {
  27. props: {
  28. arr: {
  29. type: Array,
  30. default: () => []
  31. },
  32. },
  33. data() {
  34. return {
  35. theme: app.globalData.theme,
  36. obj: {},
  37. activeRouter: ''
  38. }
  39. },
  40. created() {
  41. let routes = getCurrentPages(); //获取当前打开过的页面路由数组
  42. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  43. this.activeRouter = '/' + curRoute;
  44. },
  45. mounted() {
  46. this.getInit()
  47. },
  48. methods: {
  49. getInit() {
  50. getBottomNavigationApi().then((res) => {
  51. this.obj = res.data
  52. this.$store.commit('BottomNavigationIsCustom', this.obj.isCustom == 1 ? true : false);
  53. if (this.obj.isCustom == 1) {
  54. uni.hideTabBar()
  55. } else {
  56. uni.showTabBar()
  57. }
  58. })
  59. },
  60. goRouter(item) {
  61. var pages = getCurrentPages();
  62. var page = (pages[pages.length - 1]).$page.fullPath;
  63. if (item.link == page) return
  64. if (['/pages/index/index', '/pages/goods_cate/goods_cate',
  65. '/pages/order_addcart/order_addcart', '/pages/user/index'
  66. ].indexOf(item.link) > -1) {
  67. uni.switchTab({
  68. url: item.link,
  69. fail(err) {
  70. uni.redirectTo({
  71. url: item.link
  72. })
  73. }
  74. })
  75. } else {
  76. uni.navigateTo({
  77. url: item.link
  78. })
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .unchecked {
  86. color: #333;
  87. font-size: 24rpx;
  88. }
  89. .page-footer {
  90. position: fixed;
  91. bottom: 0;
  92. z-index: 666;
  93. display: flex;
  94. align-items: center;
  95. justify-content: space-around;
  96. width: 100%;
  97. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  98. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  99. box-sizing: border-box;
  100. border-top: solid 1rpx #F3F3F3;
  101. background-color: #fff;
  102. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  103. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  104. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  105. .foot-item {
  106. display: flex;
  107. width: max-content;
  108. align-items: center;
  109. justify-content: center;
  110. flex-direction: column;
  111. position: relative;
  112. .count-num {
  113. position: absolute;
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. width: 40rpx;
  118. height: 40rpx;
  119. top: 0rpx;
  120. right: -15rpx;
  121. color: #fff;
  122. font-size: 20rpx;
  123. background-color: #FD502F;
  124. border-radius: 50%;
  125. padding: 4rpx;
  126. }
  127. }
  128. .foot-item image {
  129. height: 50rpx;
  130. width: 50rpx;
  131. text-align: center;
  132. margin: 0 auto;
  133. }
  134. .txtchecked {
  135. font-size: 24rpx;
  136. }
  137. .foot-item .txt {
  138. font-size: 24rpx;
  139. @include main-color(theme);
  140. }
  141. }
  142. </style>