From a1dfc1313e0bf9647c7d3a4046d62cf242177276 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期四, 13 三月 2025 16:34:29 +0800 Subject: [PATCH] fix: 二期需求 --- apps/taro/.eslintrc-auto-import.json | 3 + apps/taro/src/subpackages/order/order/InnerPage.vue | 4 +- apps/taro/src/pages/mine/index.vue | 2 apps/taro/src/components/Policy/Policy.vue | 2 apps/taro/src/hooks/router.ts | 26 ++++++++----- apps/taro/config/index.js | 16 +++++++- apps/taro/auto-imports.d.ts | 1 apps/taro/src/utils/page.ts | 32 ++++++++++++++++ 8 files changed, 69 insertions(+), 17 deletions(-) diff --git a/apps/taro/.eslintrc-auto-import.json b/apps/taro/.eslintrc-auto-import.json index ed6afec..449db43 100644 --- a/apps/taro/.eslintrc-auto-import.json +++ b/apps/taro/.eslintrc-auto-import.json @@ -89,6 +89,7 @@ "useTemplateRef": true, "DirectiveBinding": true, "MaybeRef": true, - "MaybeRefOrGetter": true + "MaybeRefOrGetter": true, + "RouteHelper": true } } diff --git a/apps/taro/auto-imports.d.ts b/apps/taro/auto-imports.d.ts index 45a0ef1..4518d58 100644 --- a/apps/taro/auto-imports.d.ts +++ b/apps/taro/auto-imports.d.ts @@ -6,6 +6,7 @@ export {} declare global { const EffectScope: typeof import('vue')['EffectScope'] + const RouteHelper: typeof import('@/utils')['RouteHelper'] const RouterPath: typeof import('@/constants')['RouterPath'] const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate'] const computed: typeof import('vue')['computed'] diff --git a/apps/taro/config/index.js b/apps/taro/config/index.js index 6ded296..78c8ec0 100644 --- a/apps/taro/config/index.js +++ b/apps/taro/config/index.js @@ -116,7 +116,13 @@ chain.plugin('unplugin-auto-import').use( AutoImport({ - imports: ['vue', 'pinia', 'vue-router', { '@/constants': ['RouterPath'] }], + imports: [ + 'vue', + 'pinia', + 'vue-router', + { '@/constants': ['RouterPath'] }, + { '@/utils': ['RouteHelper'] }, + ], eslintrc: { enabled: true, // Default `false` filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json` @@ -230,7 +236,13 @@ webpackChain(chain, webpack) { chain.plugin('unplugin-auto-import').use( AutoImport({ - imports: ['vue', 'pinia', 'vue-router', { '@/constants': ['RouterPath'] }], + imports: [ + 'vue', + 'pinia', + 'vue-router', + { '@/constants': ['RouterPath'] }, + { '@/utils': ['RouteHelper'] }, + ], eslintrc: { enabled: true, // Default `false` filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json` diff --git a/apps/taro/src/components/Policy/Policy.vue b/apps/taro/src/components/Policy/Policy.vue index ccb7947..4590a88 100644 --- a/apps/taro/src/components/Policy/Policy.vue +++ b/apps/taro/src/components/Policy/Policy.vue @@ -38,7 +38,7 @@ }); function goPolicy() { - Taro.navigateTo({ + RouteHelper.navigateTo({ url: RouterPath.userPolicy, }); } diff --git a/apps/taro/src/hooks/router.ts b/apps/taro/src/hooks/router.ts index d571b8f..01639bb 100644 --- a/apps/taro/src/hooks/router.ts +++ b/apps/taro/src/hooks/router.ts @@ -5,6 +5,7 @@ import { isInAlipay } from '@/utils/env'; import { useLifeRechargeContext } from '@life-payment/core-vue'; import { getRouterPath } from '@life-payment/utils'; +import { pathAddExtraParam } from '@/utils'; export function useSwitchTab() { const systemStore = useSystemStore(); @@ -54,21 +55,26 @@ const router = Taro.useRouter(); const channelId = router.params?.channelId ?? ''; - console.log('router.params: ', router); + console.log('router: params', router, blLifeRecharge.accountModel.channlesNum); Taro.useDidShow(() => { + console.log('latestRoute.value: ', latestRoute.value); const isTabbarPage = Object.values(TabBarPageRouterForCheck).some((x) => latestRoute.value.toLowerCase().includes(x.toLowerCase()) ); - // if (blLifeRecharge.accountModel.channlesNum && !channelId) { - // Taro.reLaunch({ - // // url: `${getRouterPath(router.path)}?channelId=${blLifeRecharge.accountModel.channlesNum}`, - // url: `${router.path}&channelId=${blLifeRecharge.accountModel.channlesNum}`, - // success() { - // appStore.setLatestRoute(''); - // }, - // }); - // } + const currentIsTabbarPage = Object.values(TabBarPageRouterForCheck).some((x) => + getRouterPath(router.path).toLowerCase().includes(x.toLowerCase()) + ); + console.log('currentIsTabbarPage: ', currentIsTabbarPage); + if (currentIsTabbarPage && blLifeRecharge.accountModel.channlesNum && !channelId) { + Taro.reLaunch({ + url: pathAddExtraParam(router.path, { channelId: blLifeRecharge.accountModel.channlesNum }), + success() { + appStore.setLatestRoute(''); + }, + }); + return; + } if (isTabbarPage && isInAlipay) { Taro.reLaunch({ url: router.path, diff --git a/apps/taro/src/pages/mine/index.vue b/apps/taro/src/pages/mine/index.vue index 6ed70bb..df65482 100644 --- a/apps/taro/src/pages/mine/index.vue +++ b/apps/taro/src/pages/mine/index.vue @@ -56,7 +56,7 @@ } function goPage(routeName: string) { - Taro.navigateTo({ + RouteHelper.navigateTo({ url: routeName, }); } diff --git a/apps/taro/src/subpackages/order/order/InnerPage.vue b/apps/taro/src/subpackages/order/order/InnerPage.vue index 971f795..62835f4 100644 --- a/apps/taro/src/subpackages/order/order/InnerPage.vue +++ b/apps/taro/src/subpackages/order/order/InnerPage.vue @@ -23,7 +23,7 @@ const orderType = ref('1'); function goApplyRefund(id: string) { - Taro.navigateTo({ + RouteHelper.navigateTo({ url: `${RouterPath.orderApplyRefund}?id=${id}`, // events: { // submitApplyRefund: function () {}, @@ -31,7 +31,7 @@ }); } function goRefundDetail(orderNo: string) { - Taro.navigateTo({ + RouteHelper.navigateTo({ url: `${RouterPath.orderRefundResult}?orderNo=${orderNo}`, }); } diff --git a/apps/taro/src/utils/page.ts b/apps/taro/src/utils/page.ts index 8670a6f..1652ec0 100644 --- a/apps/taro/src/utils/page.ts +++ b/apps/taro/src/utils/page.ts @@ -1,6 +1,8 @@ import { TabBarPageRouter } from '@/constants'; import Taro from '@tarojs/taro'; import { useSystemStoreWithOut } from '@/stores/modules/system'; +import { query2object, object2query } from '@life-payment/utils'; +import { blLifeRecharge } from './blLifeRecharge'; export function goBack(delta = 1) { const pages = Taro.getCurrentPages(); @@ -23,3 +25,33 @@ url: TabBarPageRouter['Home'], }); } + +export function pathAddExtraParam(path: string, object: Record<string, string | number>) { + console.log('path: ', path, object); + const pathList = path.split('?'); + if (pathList.length > 1) { + const query = query2object(pathList[1]); + for (const key in object) { + query[key] = object[key] as any; + } + return `${pathList[0]}?${object2query(query)}`; + } else { + return `${pathList[0]}?${object2query(object)}`; + } +} + +export class RouteHelper { + static switchTab(option: Taro.switchTab.Option) { + return Taro.switchTab({ + ...option, + url: pathAddExtraParam(option.url, { channelId: blLifeRecharge.accountModel.channlesNum }), + }); + } + + static navigateTo(option: Taro.navigateTo.Option) { + Taro.navigateTo({ + ...option, + url: pathAddExtraParam(option.url, { channelId: blLifeRecharge.accountModel.channlesNum }), + }); + } +} -- Gitblit v1.9.1