index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view>
  3. <view :style="{height:footHeight+'px'}"></view>
  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 == 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' && $store.state.indexData.cartNum && $store.state.indexData.cartNum>0">
  17. {{$store.state.indexData.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. noTop: {
  39. type: Boolean,
  40. default: true
  41. },
  42. status: {
  43. type: Number | String,
  44. default: 1
  45. },
  46. countNum: {
  47. type: Number | String,
  48. default: 0
  49. },
  50. },
  51. computed: {
  52. ...mapState({
  53. configData: state => state.app.pageFooter
  54. })
  55. },
  56. computed: mapGetters(['isLogin', 'cartNum']),
  57. watch: {
  58. configData: {
  59. handler(nVal, oVal) {
  60. let self = this
  61. const query = uni.createSelectorQuery().in(this);
  62. this.newData = nVal
  63. this.$nextTick(() => {
  64. query.select('#target').boundingClientRect(data => {
  65. uni.$emit('footHeight', data.height)
  66. if (data) {
  67. self.footHeight = data.height + 50
  68. }
  69. }).exec();
  70. })
  71. },
  72. deep: true
  73. },
  74. cartNum(a, b) {
  75. this.$store.commit('indexData/setCartNum', a + '')
  76. if (a > 0) {
  77. uni.setTabBarBadge({
  78. index: Number(uni.getStorageSync('FOOTER_ADDCART')),
  79. text: a + ''
  80. })
  81. } else {
  82. wx.hideTabBarRedDot({
  83. index: Number(uni.getStorageSync('FOOTER_ADDCART'))
  84. })
  85. }
  86. }
  87. },
  88. created() {
  89. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  90. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  91. this.activeRouter = '/' + curRoute
  92. },
  93. onShow() {
  94. uni.request({
  95. url:'api/mock/navigation',
  96. success:res=>{
  97. this.newData = res.data
  98. uni.setStorageSync('pageFoot', newData)
  99. this.$store.commit('FOOT_UPLOAD', newData)
  100. if (this.newData.status && this.newData.status.status) {
  101. uni.hideTabBar()
  102. } else {
  103. uni.showTabBar()
  104. }
  105. }
  106. })
  107. // getNavigation().then(res => {
  108. // uni.setStorageSync('pageFoot', res.data)
  109. // this.$store.commit('FOOT_UPLOAD', res.data)
  110. // this.newData = res.data
  111. // if (this.newData.status && this.newData.status.status) {
  112. // uni.hideTabBar()
  113. // } else {
  114. // uni.showTabBar()
  115. // }
  116. // })
  117. },
  118. mounted() {
  119. let that = this
  120. this.newData = this.$store.state.app.pageFooter
  121. if (this.newData.status && this.newData.status.status) {
  122. uni.hideTabBar()
  123. } else {
  124. uni.showTabBar()
  125. }
  126. console.log(this.newData)
  127. if (this.isLogin) {
  128. this.getCartNum()
  129. }
  130. },
  131. data() {
  132. return {
  133. newData: {},
  134. activeRouter: '/',
  135. footHeight: 0
  136. }
  137. },
  138. methods: {
  139. goRouter(item) {
  140. var pages = getCurrentPages();
  141. if (pages.length) {
  142. var page = (pages[pages.length - 1]).$page.fullPath;
  143. } else {
  144. page = ''
  145. }
  146. if (item.link == page) return
  147. uni.switchTab({
  148. url: item.link,
  149. fail(err) {
  150. uni.redirectTo({
  151. url: item.link
  152. })
  153. }
  154. })
  155. },
  156. getCartNum: function() {
  157. let that = this;
  158. getCartCounts().then(res => {
  159. that.cartCount = res.data.count;
  160. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  161. });
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .page-footer {
  168. position: fixed;
  169. bottom: 0;
  170. z-index: 30;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-around;
  174. width: 100%;
  175. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  176. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  177. box-sizing: border-box;
  178. border-top: solid 1rpx #F3F3F3;
  179. background-color: #fff;
  180. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  181. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  182. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  183. .foot-item {
  184. display: flex;
  185. width: max-content;
  186. align-items: center;
  187. justify-content: center;
  188. flex-direction: column;
  189. position: relative;
  190. .count-num {
  191. position: absolute;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. width: 40rpx;
  196. height: 40rpx;
  197. top: 0rpx;
  198. right: -15rpx;
  199. color: #fff;
  200. font-size: 20rpx;
  201. background-color: #FD502F;
  202. border-radius: 50%;
  203. padding: 4rpx;
  204. }
  205. }
  206. .foot-item image {
  207. height: 50rpx;
  208. width: 50rpx;
  209. text-align: center;
  210. margin: 0 auto;
  211. }
  212. .foot-item .txt {
  213. font-size: 24rpx;
  214. &.active {}
  215. }
  216. }
  217. </style>