index.vue 8.8 KB

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