index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <!-- 底部导航 -->
  3. <view v-if="showTabBar">
  4. <view class="fixed-lb w-full pb-safe z-999" :style="[bgColor]">
  5. <view class="page-footer-wrapper">
  6. <view class="page-footer" :class="{
  7. 'page-footer2': newData.navStyleConfig.tabVal == 1,
  8. 'page-footer3': newData.navStyleConfig.tabVal == 2,
  9. }" id="target" :style="[componentStyle]">
  10. <view class="foot-item flex-1 flex-col flex-center h-96 relative" v-for="(item,index) in newData.menuList" :key="index" @click="goRouter(item)">
  11. <template v-if="item.link.split('?')[0] == activeRouter">
  12. <image v-if="newData.navStyleConfig.tabVal != 1" :src="item.imgList[0]"></image>
  13. <view v-if="newData.navStyleConfig.tabVal != 2" class="txt active" :style="[txtActiveColor]">{{item.name}}</view>
  14. </template>
  15. <template v-else>
  16. <image v-if="newData.navStyleConfig.tabVal != 1" :src="item.imgList[1]"></image>
  17. <view v-if="newData.navStyleConfig.tabVal != 2" class="txt" :style="[txtColor]">{{item.name}}</view>
  18. </template>
  19. <uni-badge v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum>0" class="uni-badge-left-margin" :text="cartNum" absolute="rightTop">
  20. </uni-badge>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view :style="{ height: `${footerHeight}px` }"></view>
  26. <view class="safe-area-inset-bottom"></view>
  27. </view>
  28. </template>
  29. <script>
  30. import {mapState,mapGetters} from "vuex"
  31. import {getNavigation} from '@/api/public.js'
  32. import {getCartCounts} from '@/api/order.js';
  33. import {getDiyVersion} from '@/api/api.js';
  34. export default {
  35. name: 'pageFooter',
  36. props: {},
  37. computed: {
  38. ...mapGetters(['isLogin', 'cartNum']),
  39. txtActiveColor() {
  40. let styleObject = {};
  41. if (this.newData.toneConfig && this.newData.toneConfig.tabVal) {
  42. styleObject['color'] = this.newData.activeTxtColor.color[0].item;
  43. }
  44. return styleObject;
  45. },
  46. txtColor() {
  47. let styleObject = {};
  48. if (this.newData.toneConfig && this.newData.toneConfig.tabVal) {
  49. styleObject['color'] = this.newData.txtColor.color[0].item;
  50. }
  51. return styleObject;
  52. },
  53. bgColor() {
  54. let styleObject = {};
  55. if (!this.newData.name) {
  56. return styleObject;
  57. }
  58. if (!this.newData.navConfig.tabVal) {
  59. styleObject['background'] = this.newData.bgColor.color[0].item;
  60. }
  61. return styleObject;
  62. },
  63. componentStyle() {
  64. let styleObject = {};
  65. let borderRadius = ``;
  66. if (!this.newData.name) {
  67. return styleObject;
  68. }
  69. if (this.newData.navConfig.tabVal) {
  70. borderRadius = `${this.newData.fillet.val * 2}rpx`;
  71. if (this.newData.fillet.type) {
  72. borderRadius =
  73. `${this.newData.fillet.valList[0].val * 2}rpx ${this.newData.fillet.valList[1].val * 2}rpx ${this.newData.fillet.valList[3].val * 2}rpx ${this.newData.fillet.valList[2].val * 2}rpx`;
  74. }
  75. styleObject['right'] = `${this.newData.prConfig.val * 2}rpx`;
  76. styleObject['bottom'] = `${this.newData.mbConfig.val * 2}rpx`;
  77. styleObject['left'] = `${this.newData.prConfig.val * 2}rpx`;
  78. styleObject['padding-top'] = `${this.newData.topConfig.val * 2}rpx`;
  79. styleObject['padding-bottom'] = `${this.newData.bottomConfig.val * 2}rpx`;
  80. styleObject['border-radius'] = borderRadius;
  81. styleObject['background'] = this.newData.bgColor2.color[0].item;
  82. } else {
  83. styleObject['padding-top'] = `${this.newData.topConfig.val * 2}rpx`;
  84. styleObject['padding-bottom'] = `${this.newData.bottomConfig.val * 2}rpx`;
  85. styleObject['background'] = this.newData.bgColor.color[0].item;
  86. }
  87. return styleObject;
  88. },
  89. },
  90. // watch: {
  91. // 'newData.menuList'(newValue, oldValue) {
  92. // this.$nextTick(() => {
  93. // const query = uni.createSelectorQuery().in(this);
  94. // query.select("#target").boundingClientRect(({
  95. // height
  96. // }) => {
  97. // this.footerHeight = height;
  98. // }).exec();
  99. // });
  100. // }
  101. // },
  102. created() {
  103. let routes = getCurrentPages(); //获取当前打开过的页面路由数组
  104. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  105. this.activeRouter = '/' + curRoute
  106. },
  107. mounted() {
  108. this.navigationInfo();
  109. if (this.isLogin) {
  110. this.getCartNum()
  111. }
  112. },
  113. data() {
  114. return {
  115. newData: {},
  116. activeRouter: '',
  117. showTabBar: false,
  118. footerHeight: 0
  119. }
  120. },
  121. methods: {
  122. setNavigationInfo(data) {
  123. this.newData = data;
  124. this.showTabBar = data.effectConfig.tabVal;
  125. let pdHeight = data.topConfig.val + data.bottomConfig.val;
  126. this.$emit('newDataStatus', data.effectConfig.tabVal,pdHeight)
  127. if (data.effectConfig.tabVal) {
  128. uni.hideTabBar()
  129. } else {
  130. uni.showTabBar()
  131. }
  132. },
  133. getNavigationInfo() {
  134. getNavigation().then(res => {
  135. uni.setStorageSync('diyVersionNav', res.data);
  136. this.setNavigationInfo(res.data);
  137. })
  138. },
  139. navigationInfo() {
  140. let footerNavigation = uni.getStorageSync('footerNavigation');
  141. if (footerNavigation) {
  142. getDiyVersion(0).then(res => {
  143. let diyVersion = uni.getStorageSync('diyVersionNav');
  144. if ((res.data.version + '0') === diyVersion) {
  145. this.setNavigationInfo(footerNavigation);
  146. } else {
  147. uni.setStorageSync('diyVersionNav', (res.data.version + '0'));
  148. this.getNavigationInfo();
  149. }
  150. });
  151. } else {
  152. this.getNavigationInfo();
  153. }
  154. },
  155. goRouter(item) {
  156. var pages = getCurrentPages();
  157. var page = (pages[pages.length - 1]).$page.fullPath;
  158. if (item.link == page) return
  159. if (item.link == '/pages/short_video/appSwiper/index' || item.link == '/pages/short_video/nvueSwiper/index') {
  160. //#ifdef APP
  161. item.link = '/pages/short_video/appSwiper/index'
  162. //#endif
  163. //#ifndef APP
  164. item.link = '/pages/short_video/nvueSwiper/index'
  165. //#endif
  166. }
  167. uni.switchTab({
  168. url: item.link,
  169. fail(err) {
  170. uni.redirectTo({
  171. url: item.link
  172. })
  173. }
  174. })
  175. },
  176. getCartNum: function() {
  177. getCartCounts().then(res => {
  178. this.$store.commit('indexData/setCartNum', res.data.count + '')
  179. }).catch(err=>{
  180. console.log(err.msg);
  181. })
  182. },
  183. }
  184. }
  185. </script>
  186. <style scoped lang="scss">
  187. .safe-area-inset-bottom {
  188. height: 0;
  189. height: constant(safe-area-inset-bottom);
  190. height: env(safe-area-inset-bottom);
  191. }
  192. .page-footer-wrapper {
  193. position: relative;
  194. }
  195. .page-footer {
  196. position: absolute;
  197. right: 0;
  198. bottom: 0;
  199. left: 0;
  200. display: flex;
  201. .foot-item image {
  202. display: block;
  203. height: 40rpx;
  204. width: 40rpx;
  205. margin: 0 auto;
  206. }
  207. .foot-item .txt {
  208. margin-top: 4rpx;
  209. font-size: 20rpx;
  210. line-height: 28rpx;
  211. color: #333333;
  212. &.active {
  213. color: var(--view-theme);
  214. }
  215. }
  216. }
  217. .page-footer2 .foot-item .txt {
  218. margin-top: 0;
  219. font-size: 32rpx;
  220. line-height: 44rpx;
  221. color: #333333;
  222. &.active {
  223. color: var(--view-theme);
  224. }
  225. }
  226. .page-footer2.float .foot-item::before,
  227. .page-footer3.float .foot-item::before {
  228. content: "";
  229. position: absolute;
  230. top: 50%;
  231. left: 0;
  232. width: 2rpx;
  233. height: 32rpx;
  234. background: #CCCCCC;
  235. transform: translateY(-50%);
  236. }
  237. .page-footer2.float .foot-item:first-child::before,
  238. .page-footer3.float .foot-item:first-child::before {
  239. display: none;
  240. }
  241. </style>