From ac76de8c1766e63f1029367ffcc3aed914b508ab Mon Sep 17 00:00:00 2001 From: RedPig97 <1978141412@qq.com> Date: Tue, 14 May 2024 19:17:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dmodal-router?= =?UTF-8?q?=E6=89=93=E5=BC=80=E4=B8=A4=E6=AC=A1=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/modal-router-shell/modal-router-shell.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/web-app/components/modal-router-shell/modal-router-shell.tsx b/src/web-app/components/modal-router-shell/modal-router-shell.tsx index 5cc7b3b4..1e1f3e35 100644 --- a/src/web-app/components/modal-router-shell/modal-router-shell.tsx +++ b/src/web-app/components/modal-router-shell/modal-router-shell.tsx @@ -53,6 +53,9 @@ export const ModalRouterShell = defineComponent({ const openView = async (): Promise => { viewData.value = await parseRouteViewData(route, routeDepth, true); + if (isDestroyed.value) { + return; + } if (!(viewData.value.context instanceof IBizContext)) { viewData.value.context = IBizContext.create(viewData.value.context); -- Gitee From eb118d81252d3af444b4f1806d00126226c5a9be Mon Sep 17 00:00:00 2001 From: RedPig97 <1978141412@qq.com> Date: Tue, 14 May 2024 19:18:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BAmodal-router?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=A4=9A=E4=B8=AA=E8=A7=86=E5=9B=BE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modal-router-shell/modal-router-shell.tsx | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/web-app/components/modal-router-shell/modal-router-shell.tsx b/src/web-app/components/modal-router-shell/modal-router-shell.tsx index 1e1f3e35..a3fd0502 100644 --- a/src/web-app/components/modal-router-shell/modal-router-shell.tsx +++ b/src/web-app/components/modal-router-shell/modal-router-shell.tsx @@ -5,7 +5,12 @@ import { parseRouteViewData, routerCallback, } from '@ibiz-template/vue3-util'; -import { useRoute, useRouter } from 'vue-router'; +import { + useRoute, + useRouter, + onBeforeRouteUpdate, + RouteLocationNormalized, +} from 'vue-router'; import { IBizContext } from '@ibiz-template/core'; import { IModal, @@ -41,6 +46,8 @@ export const ModalRouterShell = defineComponent({ let overlay: IOverlayContainer | null = null; + const historyMap: Map = new Map(); + // 销毁视图上下文 onUnmounted(() => { isDestroyed.value = true; @@ -49,10 +56,13 @@ export const ModalRouterShell = defineComponent({ overlay = null; } destroyContext(); + historyMap.clear(); }); - const openView = async (): Promise => { - viewData.value = await parseRouteViewData(route, routeDepth, true); + const openView = async ( + to: RouteLocationNormalized = route, + ): Promise => { + viewData.value = await parseRouteViewData(to, routeDepth, true); if (isDestroyed.value) { return; } @@ -62,9 +72,9 @@ export const ModalRouterShell = defineComponent({ } // 当前模态打开的视图名称 - const appViewId = route.params.modalView as string; + const appViewId = to.params.modalView as string; // 路由参数 - const paramsStr = route.params.modalParams as string; + const paramsStr = to.params.modalParams as string; if (paramsStr) { const params = qs.parse(paramsStr, { strictNullHandling: true, @@ -120,6 +130,7 @@ export const ModalRouterShell = defineComponent({ footerHide: true, isRouteModal: true, }; + historyMap.set(router.currentRoute.value.fullPath, route); overlay = ibiz.overlay.createModal(component, undefined, opts); overlay.present(); const result = await overlay.onWillDismiss(); @@ -128,7 +139,7 @@ export const ModalRouterShell = defineComponent({ if (window.history.state?.back) { router.back(); } else { - const path = route.path; + const path = to.path; const index = path.indexOf(`/${RouteConst.ROUTE_MODAL_TAG}/`); router.replace(path.substring(0, index)); } @@ -136,9 +147,18 @@ export const ModalRouterShell = defineComponent({ router.currentRoute.value.fullPath, result || { ok: false }, ); + if (historyMap.has(router.currentRoute.value.fullPath)) { + historyMap.delete(router.currentRoute.value.fullPath); + } } }; openView(); + + onBeforeRouteUpdate((to: RouteLocationNormalized) => { + if (!historyMap.has(to.fullPath)) { + openView(to); + } + }); return {}; }, render() { -- Gitee From 4863d5281f01b308621c1cde2b2666e51b499c9a Mon Sep 17 00:00:00 2001 From: RedPig97 <1978141412@qq.com> Date: Tue, 14 May 2024 19:39:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96modal-router?= =?UTF-8?q?=E5=A4=9A=E6=A8=A1=E6=80=81=E6=97=B6=E5=9B=9E=E9=80=80=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modal-router-shell/modal-router-shell.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/web-app/components/modal-router-shell/modal-router-shell.tsx b/src/web-app/components/modal-router-shell/modal-router-shell.tsx index a3fd0502..03595a41 100644 --- a/src/web-app/components/modal-router-shell/modal-router-shell.tsx +++ b/src/web-app/components/modal-router-shell/modal-router-shell.tsx @@ -46,7 +46,7 @@ export const ModalRouterShell = defineComponent({ let overlay: IOverlayContainer | null = null; - const historyMap: Map = new Map(); + const historyMap: Map = new Map(); // 销毁视图上下文 onUnmounted(() => { @@ -130,7 +130,7 @@ export const ModalRouterShell = defineComponent({ footerHide: true, isRouteModal: true, }; - historyMap.set(router.currentRoute.value.fullPath, route); + historyMap.set(router.currentRoute.value.fullPath, overlay!); overlay = ibiz.overlay.createModal(component, undefined, opts); overlay.present(); const result = await overlay.onWillDismiss(); @@ -154,11 +154,19 @@ export const ModalRouterShell = defineComponent({ }; openView(); - onBeforeRouteUpdate((to: RouteLocationNormalized) => { - if (!historyMap.has(to.fullPath)) { - openView(to); - } - }); + onBeforeRouteUpdate( + (to: RouteLocationNormalized, from: RouteLocationNormalized) => { + if (!historyMap.has(to.fullPath)) { + openView(to); + } + if (historyMap.has(from.fullPath)) { + const fromOverlay = historyMap.get(from.fullPath); + if (fromOverlay) { + fromOverlay.dismiss(); + } + } + }, + ); return {}; }, render() { -- Gitee