index.vue 3.5 KB

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