From 1c95f51526c80e2f5fba6aef72f1fa06fb8a2042 Mon Sep 17 00:00:00 2001 From: hminghe Date: Tue, 19 Jul 2022 22:00:59 +0800 Subject: [PATCH] fix(multi-window): close invalid & tabs active invalid --- src/components/LayoutTabs.vue | 2 +- .../multi-window/useMultiWindowStore.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/LayoutTabs.vue b/src/components/LayoutTabs.vue index 818839c..eaf787d 100644 --- a/src/components/LayoutTabs.vue +++ b/src/components/LayoutTabs.vue @@ -106,7 +106,7 @@ function onCloseWindow(fullPath: string) { diff --git a/src/components/multi-window/useMultiWindowStore.ts b/src/components/multi-window/useMultiWindowStore.ts index 26b27af..756cd3b 100644 --- a/src/components/multi-window/useMultiWindowStore.ts +++ b/src/components/multi-window/useMultiWindowStore.ts @@ -1,4 +1,4 @@ -import { useTitle } from '@vueuse/core' +import { useTitle, watchOnce } from '@vueuse/core' import { acceptHMRUpdate, defineStore } from 'pinia' import { ElScrollbar } from 'element-plus' import { type Component, computed, defineComponent, h, markRaw, reactive } from 'vue' @@ -120,7 +120,7 @@ export const useMultiWindowStore = defineStore('multiWindow', () => { refreshKey: 1, refreshCallback: [], componentName: route.name as string, - baseComponent: markRaw(matched[matched.length - 1].components.default), + baseComponent: markRaw(matched[matched.length - 1].components!.default), close(command = 'self') { if (command === 'self') { closeWindow(key) @@ -156,13 +156,17 @@ export const useMultiWindowStore = defineStore('multiWindow', () => { function closeWindow(windowOrKey: Window | string) { if (hasCurrentWindow(windowOrKey)) { - router.back() - } + watchOnce(() => route.fullPath, () => { + closeWindow(windowOrKey) + }) - const index = findWindowIndex(windowOrKey) + router.back() + } else { + const index = findWindowIndex(windowOrKey) - if (index > -1) { - windows.splice(index, 1) + if (index > -1) { + windows.splice(index, 1) + } } }