index.vue 7.5 KB

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