index.vue 5.1 KB

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