mirror of https://gitee.com/xiaonuobase/snowy
【底座】路由参数保持
parent
f88765a34c
commit
68eed708be
|
@ -70,6 +70,7 @@
|
|||
import routerUtil from '@/utils/routerUtil'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { watch, ref, computed, nextTick, onMounted } from 'vue'
|
||||
import { useMenuStore } from '@/store/menu'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
@ -83,6 +84,7 @@
|
|||
const contextMenuTarget = ref(null)
|
||||
const contextMenuVisible = ref(false)
|
||||
const currentContextMenuTabIndex = ref(0)
|
||||
const menuStore = useMenuStore()
|
||||
|
||||
const viewTags = computed(() => {
|
||||
return vStore.viewTags
|
||||
|
@ -100,7 +102,6 @@
|
|||
})
|
||||
watch(route, (to) => {
|
||||
addViewTags(to)
|
||||
activeKey.value = to.fullPath
|
||||
})
|
||||
watch(layoutTagsOpen, () => {
|
||||
// closeOtherCacheTabs()
|
||||
|
@ -113,7 +114,8 @@
|
|||
})
|
||||
// 增加tag
|
||||
const addViewTags = (to) => {
|
||||
activeKey.value = to.fullPath
|
||||
const viewTag = viewTags.value.find((tag) => tag.path === to.path)
|
||||
activeKey.value = viewTag ? viewTag.fullPath : to.fullPath
|
||||
if (to.name && !to.meta.fullpage) {
|
||||
vStore.pushViewTags(to)
|
||||
kStore.pushKeepLive(to.name)
|
||||
|
@ -123,7 +125,6 @@
|
|||
vStore.removeViewTags(firstTag)
|
||||
}
|
||||
}
|
||||
|
||||
// 查找树
|
||||
const treeFind = (tree, func) => {
|
||||
for (const data of tree) {
|
||||
|
|
|
@ -598,7 +598,9 @@
|
|||
onSelectTag.value = true
|
||||
const pathLength = obj.keyPath.length
|
||||
const path = obj.keyPath[pathLength - 1]
|
||||
router.push({ path })
|
||||
const viewTags = viewTagsStore().viewTags
|
||||
const viewTag = viewTags.find((item) => item.path === path)
|
||||
router.push(viewTag ? viewTag.fullPath : path)
|
||||
// 设置选中
|
||||
selectedKeys.value = obj.selectedKeys
|
||||
}
|
||||
|
|
|
@ -9,10 +9,23 @@
|
|||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
import { defineStore } from 'pinia'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
export const viewTagsStore = defineStore('viewTags', () => {
|
||||
// 定义state
|
||||
const viewTags = ref([])
|
||||
const router = useRouter()
|
||||
// 监听路由变化
|
||||
watch(
|
||||
() => router.currentRoute.value,
|
||||
(newRoute) => {
|
||||
const viewTag = viewTags.value.find((item) => item.path === newRoute.path)
|
||||
if (viewTag) {
|
||||
Object.assign(viewTag, newRoute)
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 定义action
|
||||
const pushViewTags = (route) => {
|
||||
|
@ -22,12 +35,7 @@ export const viewTagsStore = defineStore('viewTags', () => {
|
|||
viewTags.value.push(route)
|
||||
}
|
||||
if (target) {
|
||||
viewTags.value.forEach((item, index) => {
|
||||
if (item.path === route.path) {
|
||||
viewTags.value[index] = { ...route, ...item }
|
||||
// Object.assign(item, route)
|
||||
}
|
||||
})
|
||||
updateViewTags(route)
|
||||
}
|
||||
}
|
||||
const removeViewTags = (route) => {
|
||||
|
@ -39,9 +47,8 @@ export const viewTagsStore = defineStore('viewTags', () => {
|
|||
}
|
||||
const updateViewTags = (route) => {
|
||||
viewTags.value.forEach((item, index) => {
|
||||
if (item.path === route.path) {
|
||||
if (item.fullPath === route.fullPath) {
|
||||
viewTags.value[index] = { ...route, ...item }
|
||||
// Object.assign(item, route)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -56,12 +63,7 @@ export const viewTagsStore = defineStore('viewTags', () => {
|
|||
viewTags.value.splice(index, 1)
|
||||
} else {
|
||||
// 路由存在,更新
|
||||
viewTags.value = viewTags.value.map((item) => {
|
||||
if (item.path === target.path) {
|
||||
return { ...item, meta: target.meta }
|
||||
}
|
||||
return item
|
||||
})
|
||||
updateViewTags(target)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue