index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view v-if="newData">
  3. <view class="page-footer" id="target">
  4. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index" @click="goRouter(item)"
  5. :style="{'background-color':newData.bgColor.color[0].item}">
  6. <block v-if="item.link == activityTab">
  7. <image :src="item.imgList[0]" class="active"></image>
  8. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{$t(item.name)}}</view>
  9. </block>
  10. <block v-else>
  11. <image :src="item.imgList[1]"></image>
  12. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{$t(item.name)}}</view>
  13. </block>
  14. <div class="count-num" v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum>0">
  15. {{cartNum > 99 ? '99+' : cartNum}}
  16. </div>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. mapState,
  24. mapGetters
  25. } from "vuex"
  26. import {
  27. getNavigation
  28. } from '@/api/public.js'
  29. import {
  30. getCartCounts,
  31. } from '@/api/order.js';
  32. export default {
  33. name: 'pageFooter',
  34. props: {
  35. status: {
  36. type: Number | String,
  37. default: 1
  38. },
  39. countNum: {
  40. type: Number | String,
  41. default: 0
  42. },
  43. },
  44. data() {
  45. return {
  46. newData: undefined,
  47. footHeight: 0,
  48. isShow: false // 弹出动画
  49. }
  50. },
  51. computed: {
  52. ...mapState({
  53. configData: state => state.app.pageFooter,
  54. }),
  55. },
  56. computed: mapGetters(['isLogin', 'cartNum', 'activityTab']),
  57. watch: {
  58. activityTab: {
  59. handler(nVal, oVal) {
  60. console.log(nVal, 'nval')
  61. },
  62. deep: true
  63. },
  64. configData: {
  65. handler(nVal, oVal) {
  66. let self = this
  67. const query = uni.createSelectorQuery().in(this);
  68. this.newData = nVal
  69. this.$nextTick(() => {
  70. query.select('#target').boundingClientRect(data => {
  71. uni.$emit('footHeight', data.height)
  72. if (data) {
  73. self.footHeight = data.height + 50
  74. }
  75. }).exec();
  76. })
  77. },
  78. deep: true
  79. },
  80. },
  81. created() {
  82. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  83. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  84. this.$store.commit('ACTIVITYTAB', '/' + curRoute);
  85. },
  86. mounted() {
  87. getNavigation().then(res => {
  88. uni.setStorageSync('pageFoot', res.data)
  89. this.$store.commit('FOOT_UPLOAD', res.data)
  90. this.newData = res.data
  91. })
  92. let that = this
  93. uni.hideTabBar()
  94. this.newData = this.$store.state.app.pageFooter
  95. if (this.isLogin) {
  96. this.getCartNum()
  97. }
  98. },
  99. methods: {
  100. goRouter(item) {
  101. var pages = getCurrentPages();
  102. var page = pages[pages.length - 1].route;
  103. this.$store.commit('ACTIVITYTAB', item.link);
  104. if (item.link == '/' + page) return
  105. uni.switchTab({
  106. url: item.link,
  107. fail(err) {
  108. uni.redirectTo({
  109. url: item.link
  110. })
  111. }
  112. })
  113. },
  114. getCartNum: function() {
  115. let that = this;
  116. getCartCounts().then(res => {
  117. that.cartCount = res.data.count;
  118. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  119. });
  120. },
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .page-footer {
  126. position: fixed;
  127. left: 0;
  128. bottom: 0;
  129. z-index: 999;
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-around;
  133. flex-wrap: nowrap;
  134. width: 100%;
  135. height: 98rpx;
  136. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  137. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  138. box-sizing: border-box;
  139. // border-top: solid 1rpx #F3F3F3;
  140. backdrop-filter: blur(10px);
  141. background-color: #fff;
  142. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  143. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  144. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  145. // transform: translate3d(0, 100%, 0);
  146. // transition: all .3s cubic-bezier(.25, .5, .5, .9);
  147. .foot-item {
  148. display: flex;
  149. width: max-content;
  150. align-items: center;
  151. justify-content: center;
  152. flex-direction: column;
  153. position: relative;
  154. width: 100%;
  155. height: 100%;
  156. .count-num {
  157. position: absolute;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. width: 40rpx;
  162. height: 40rpx;
  163. top: 0rpx;
  164. right: calc(50% - 55rpx);
  165. color: #fff;
  166. font-size: 20rpx;
  167. background-color: #FD502F;
  168. border-radius: 50%;
  169. padding: 4rpx;
  170. }
  171. .active {
  172. animation: mymove 1s 1;
  173. }
  174. @keyframes mymove {
  175. 0% {
  176. transform: scale(1);
  177. /*开始为原始大小*/
  178. }
  179. 10% {
  180. transform: scale(0.8);
  181. }
  182. 30% {
  183. transform: scale(1.1);
  184. /*放大1.1倍*/
  185. }
  186. 50% {
  187. transform: scale(0.9);
  188. /*放大1.1倍*/
  189. }
  190. 70% {
  191. transform: scale(1.05);
  192. }
  193. 90% {
  194. transform: scale(1);
  195. }
  196. }
  197. }
  198. .foot-item image {
  199. height: 50rpx;
  200. width: 50rpx;
  201. text-align: center;
  202. margin: 0 auto;
  203. }
  204. .foot-item .txt {
  205. font-size: 24rpx;
  206. }
  207. }
  208. </style>