index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. },
  61. deep: true
  62. },
  63. configData: {
  64. handler(nVal, oVal) {
  65. let self = this
  66. const query = uni.createSelectorQuery().in(this);
  67. this.newData = nVal
  68. this.$nextTick(() => {
  69. query.select('#target').boundingClientRect(data => {
  70. uni.$emit('footHeight', data.height)
  71. if (data) {
  72. self.footHeight = data.height + 50
  73. }
  74. }).exec();
  75. })
  76. },
  77. deep: true
  78. },
  79. },
  80. created() {
  81. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  82. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  83. this.$store.commit('ACTIVITYTAB', '/' + curRoute);
  84. },
  85. mounted() {
  86. getNavigation().then(res => {
  87. uni.setStorageSync('pageFoot', res.data)
  88. this.$store.commit('FOOT_UPLOAD', res.data)
  89. this.newData = res.data
  90. })
  91. let that = this
  92. uni.hideTabBar()
  93. this.newData = this.$store.state.app.pageFooter
  94. if (this.isLogin) {
  95. this.getCartNum()
  96. }
  97. },
  98. methods: {
  99. goRouter(item) {
  100. var pages = getCurrentPages();
  101. var page = pages[pages.length - 1].route;
  102. this.$store.commit('ACTIVITYTAB', item.link);
  103. if (item.link == '/' + page) return
  104. uni.switchTab({
  105. url: item.link,
  106. fail(err) {
  107. uni.redirectTo({
  108. url: item.link
  109. })
  110. }
  111. })
  112. },
  113. getCartNum: function() {
  114. let that = this;
  115. getCartCounts().then(res => {
  116. that.cartCount = res.data.count;
  117. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '...' : res.data.count)
  118. });
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .page-footer {
  125. position: fixed;
  126. left: 0;
  127. bottom: 0;
  128. z-index: 999;
  129. display: flex;
  130. align-items: center;
  131. justify-content: space-around;
  132. flex-wrap: nowrap;
  133. width: 100%;
  134. height: 98rpx;
  135. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  136. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  137. box-sizing: border-box;
  138. border-top: solid 1rpx #F3F3F3;
  139. backdrop-filter: blur(10px);
  140. background-color: #fff;
  141. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  142. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  143. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  144. // transform: translate3d(0, 100%, 0);
  145. // transition: all .3s cubic-bezier(.25, .5, .5, .9);
  146. .foot-item {
  147. display: flex;
  148. width: max-content;
  149. align-items: center;
  150. justify-content: center;
  151. flex-direction: column;
  152. position: relative;
  153. width: 100%;
  154. height: 100%;
  155. .count-num {
  156. position: absolute;
  157. display: flex;
  158. justify-content: center;
  159. align-items: center;
  160. width: 40rpx;
  161. height: 40rpx;
  162. top: 0rpx;
  163. right: calc(50% - 55rpx);
  164. color: #fff;
  165. font-size: 20rpx;
  166. background-color: #FD502F;
  167. border-radius: 50%;
  168. padding: 4rpx;
  169. }
  170. .active {
  171. animation: mymove 1s 1;
  172. }
  173. @keyframes mymove {
  174. 0% {
  175. transform: scale(1);
  176. /*开始为原始大小*/
  177. }
  178. 10% {
  179. transform: scale(0.8);
  180. }
  181. 30% {
  182. transform: scale(1.1);
  183. /*放大1.1倍*/
  184. }
  185. 50% {
  186. transform: scale(0.9);
  187. /*放大1.1倍*/
  188. }
  189. 70% {
  190. transform: scale(1.05);
  191. }
  192. 90% {
  193. transform: scale(1);
  194. }
  195. }
  196. }
  197. .foot-item image {
  198. height: 50rpx;
  199. width: 50rpx;
  200. text-align: center;
  201. margin: 0 auto;
  202. }
  203. .foot-item .txt {
  204. font-size: 24rpx;
  205. }
  206. }
  207. </style>