index.vue 4.0 KB

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