Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-20 19:09:21 +08:00

fix: 修复上一个 commit 带来的 tag 显示顺序问题

This commit is contained in:
pany 2024-11-08 20:23:56 +08:00
parent 13a53cc994
commit 6f2fbf4a90
2 changed files with 6 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { getCurrentInstance, onMounted, ref, watch } from "vue"
import { getCurrentInstance, ref, watch } from "vue"
import { type RouteLocationNormalizedLoaded, type RouteRecordRaw, RouterLink, useRoute, useRouter } from "vue-router"
import { type TagView, useTagsViewStore } from "@/store/modules/tags-view"
import { usePermissionStore } from "@/store/modules/permission"
@ -65,7 +65,7 @@ const initTags = () => {
affixTags = filterAffixTags(permissionStore.routes)
for (const tag of affixTags) {
// name
tag.name && tagsViewStore.addVisitedView(tag, true)
tag.name && tagsViewStore.addVisitedView(tag)
}
}
@ -153,14 +153,12 @@ watch(visible, (value) => {
value ? document.body.addEventListener("click", closeMenu) : document.body.removeEventListener("click", closeMenu)
})
initTags()
/** 监听路由变化 */
listenerRouteChange((route) => {
addTags(route)
}, true)
onMounted(() => {
initTags()
})
</script>
<template>

View File

@ -18,7 +18,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
})
//#region add
const addVisitedView = (view: TagView, isUnshift: boolean = false) => {
const addVisitedView = (view: TagView) => {
// 检查是否已经存在相同的 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
isUnshift ? visitedViews.value.unshift({ ...view }) : visitedViews.value.push({ ...view })
visitedViews.value.push({ ...view })
}
}