index.vue 5.2 KB

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