Skip to content

Commit

Permalink
fix(multi-window): close invalid & tabs active invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
hminghe committed Jul 19, 2022
1 parent 01750a8 commit 1c95f51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/LayoutTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function onCloseWindow(fullPath: string) {
<el-tabs
type="card"
closable
:model-value="multiWindowStore.currentWindow?.fullPath"
:model-value="multiWindowStore.currentWindow?.fullPath || 'null'"
:before-leave="fullPath => onSwitchWindow(fullPath.toString())"
@tab-remove="fullPath => onCloseWindow(fullPath.toString())"
>
Expand Down
18 changes: 11 additions & 7 deletions src/components/multi-window/useMultiWindowStore.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 1c95f51

Please sign in to comment.