From 13a53cc9944a0a1c5a983bdf303e0eb198c91a1e Mon Sep 17 00:00:00 2001 From: _island <82024018+QC2168@users.noreply.github.com> Date: Fri, 8 Nov 2024 19:40:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AC=AC=E4=B8=80=E4=B8=AA=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=A1=B5=E9=9D=A2=E5=8A=A0=E8=BD=BD=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=20onActivated=20=E9=92=A9=E5=AD=90=20(#214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pany <939630029@qq.com> --- src/layouts/components/TagsView/index.vue | 11 ++++++----- src/store/modules/tags-view.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/layouts/components/TagsView/index.vue b/src/layouts/components/TagsView/index.vue index a7178d8..0e14c32 100644 --- a/src/layouts/components/TagsView/index.vue +++ b/src/layouts/components/TagsView/index.vue @@ -65,7 +65,7 @@ const initTags = () => { affixTags = filterAffixTags(permissionStore.routes) for (const tag of affixTags) { // 必须含有 name 属性 - tag.name && tagsViewStore.addVisitedView(tag) + tag.name && tagsViewStore.addVisitedView(tag, true) } } @@ -153,12 +153,13 @@ watch(visible, (value) => { value ? document.body.addEventListener("click", closeMenu) : document.body.removeEventListener("click", closeMenu) }) +/** 监听路由变化 */ +listenerRouteChange((route) => { + addTags(route) +}, true) + onMounted(() => { initTags() - /** 监听路由变化 */ - listenerRouteChange(async (route) => { - addTags(route) - }, true) }) diff --git a/src/store/modules/tags-view.ts b/src/store/modules/tags-view.ts index 51194de..db728d3 100644 --- a/src/store/modules/tags-view.ts +++ b/src/store/modules/tags-view.ts @@ -18,7 +18,7 @@ export const useTagsViewStore = defineStore("tags-view", () => { }) //#region add - const addVisitedView = (view: TagView) => { + const addVisitedView = (view: TagView, isUnshift: boolean = false) => { // 检查是否已经存在相同的 visitedView const index = visitedViews.value.findIndex((v) => v.path === view.path) if (index !== -1) { @@ -26,7 +26,7 @@ export const useTagsViewStore = defineStore("tags-view", () => { visitedViews.value[index].fullPath !== view.fullPath && (visitedViews.value[index] = { ...view }) } else { // 添加新的 visitedView - visitedViews.value.push({ ...view }) + isUnshift ? visitedViews.value.unshift({ ...view }) : visitedViews.value.push({ ...view }) } }