index.vue 5.2 KB

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