From d3c34c36988c381f772f0a18161b34a55cee0c8b Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Sat, 30 May 2026 14:12:01 +0800 Subject: [PATCH] feat(store&bottom-nav): add package entry tab tracking logic 1. add packageEntryTab state and mutation in vuex store 2. extract and track current/previous page's matching tab entry 3. update package entry tab state via store commit instead of local variable 4. optimize tab url parsing by stripping query parameters --- components-diy/diy-bottom-nav.vue | 39 ++++++++++++++++++++++++++----- store/index.js | 4 ++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/components-diy/diy-bottom-nav.vue b/components-diy/diy-bottom-nav.vue index b64b82e..76e2ac5 100644 --- a/components-diy/diy-bottom-nav.vue +++ b/components-diy/diy-bottom-nav.vue @@ -79,8 +79,7 @@ export default { lang: uni.getStorageSync("lang"), currentRoute: '', //当前页面路径 jumpFlag: true, //是否可以跳转,防止重复点击 - cartAnimation: {}, - packageEntryTab: {} // 追踪每个分包的入口Tab { 'pages_goods': '/pages_goods/category' } + cartAnimation: {} }; }, mounted() { @@ -108,6 +107,9 @@ export default { computed: { cartChange() { return this.$store.state.cartChange; + }, + packageEntryTab() { + return this.$store.state.packageEntryTab; } }, watch: { @@ -129,7 +131,8 @@ export default { methods: { // 更新当前路由 updateCurrentRoute() { - let currentPage = getCurrentPages()[getCurrentPages().length - 1]; + let currentPages = getCurrentPages(); + let currentPage = currentPages[currentPages.length - 1]; if (currentPage && currentPage.route) { const newRoute = currentPage.route; const newRouteParts = newRoute.split('/'); @@ -137,15 +140,38 @@ export default { if (this.tabBarList && this.tabBarList.list) { const tabUrls = this.tabBarList.list .filter(item => item.link && item.link.wap_url) - .map(item => adaptSubpackageUrl(item.link.wap_url)); + .map(item => adaptSubpackageUrl(item.link.wap_url).split('?')[0]); + let currentMatchingTab = null; for (const tabUrl of tabUrls) { const tabParts = tabUrl.split('/'); if (tabParts[2] === newRouteParts[2] && tabParts[1] === newRouteParts[1]) { - this.packageEntryTab[newRouteParts[1]] = tabUrl; + currentMatchingTab = tabUrl; break; } } + + let entryTab = null; + if (currentMatchingTab) { + entryTab = currentMatchingTab; + } else { + const prevPage = currentPages[currentPages.length - 2]; + if (prevPage && prevPage.route) { + const prevRouteParts = prevPage.route.split('/'); + for (const tabUrl of tabUrls) { + const tabParts = tabUrl.split('/'); + if (tabParts[2] === prevRouteParts[2] && tabParts[1] === prevRouteParts[1]) { + entryTab = tabUrl; + break; + } + } + } + } + + if (entryTab) { + const updatedEntryTab = { ...this.packageEntryTab, [newRouteParts[1]]: entryTab }; + this.$store.commit('setPackageEntryTab', updatedEntryTab); + } } this.currentRoute = newRoute; @@ -160,7 +186,8 @@ export default { const urlParts = adaptedUrl.split('/'); if (urlParts.length >= 2 && urlParts[1]) { - this.packageEntryTab[urlParts[1]] = adaptedUrl; + const updatedEntryTab = { ...this.packageEntryTab, [urlParts[1]]: adaptedUrl }; + this.$store.commit('setPackageEntryTab', updatedEntryTab); } } diff --git a/store/index.js b/store/index.js index 55a0e07..745f2ba 100644 --- a/store/index.js +++ b/store/index.js @@ -77,6 +77,7 @@ const store = new Vuex.Store({ diyGroupPositionObj: {}, diyGroupShowModule: '', tabBarHeight: '56px', + packageEntryTab: {}, // 追踪每个分包的入口Tab { 'pages_goods': '/pages_goods/category' } mapConfig: { tencent_map_key: '', wap_is_open: 1, @@ -197,6 +198,9 @@ const store = new Vuex.Store({ setTabBarHeight(state, value) { state.tabBarHeight = value; }, + setPackageEntryTab(state, value) { + state.packageEntryTab = value; + }, setMapConfig(state, value) { state.mapConfig = value; uni.setStorageSync('mapConfig', value);