调整页面跳转后缓存问题
This commit is contained in:
parent
8cace8d278
commit
f7b2b96466
@ -12,7 +12,7 @@ import { useDesign } from '@/hooks/web/useDesign'
|
||||
import { useTemplateRefsList } from '@vueuse/core'
|
||||
import { ElScrollbar } from 'element-plus'
|
||||
import { useScrollTo } from '@/hooks/event/useScrollTo'
|
||||
|
||||
import routeParamsCache from '@/utils/routeParamsCache'
|
||||
const { getPrefixCls } = useDesign()
|
||||
|
||||
const prefixCls = getPrefixCls('tags-view')
|
||||
@ -62,6 +62,7 @@ const addTags = () => {
|
||||
|
||||
// 关闭选中的tag
|
||||
const closeSelectedTag = (view: RouteLocationNormalizedLoaded) => {
|
||||
routeParamsCache.remove(view.path);
|
||||
if (view?.meta?.affix) return
|
||||
tagsViewStore.delView(view)
|
||||
if (isActive(view)) {
|
||||
|
@ -4,6 +4,7 @@ import { getRawRoute } from '@/utils/routerHelper'
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from '../index'
|
||||
import { findIndex } from '@/utils'
|
||||
import routeParamsCache from '@/utils/routeParamsCache'
|
||||
|
||||
export interface TagsViewState {
|
||||
visitedViews: RouteLocationNormalizedLoaded[]
|
||||
@ -57,6 +58,7 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
},
|
||||
// 删除某个
|
||||
delView(view: RouteLocationNormalizedLoaded) {
|
||||
routeParamsCache.remove(view.path)
|
||||
this.delVisitedView(view)
|
||||
this.delCachedView()
|
||||
},
|
||||
@ -64,6 +66,7 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
delVisitedView(view: RouteLocationNormalizedLoaded) {
|
||||
for (const [i, v] of this.visitedViews.entries()) {
|
||||
if (v.path === view.path) {
|
||||
routeParamsCache.remove(view.path)
|
||||
this.visitedViews.splice(i, 1)
|
||||
break
|
||||
}
|
||||
@ -79,11 +82,13 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
},
|
||||
// 删除所有缓存和tag
|
||||
delAllViews() {
|
||||
routeParamsCache.clear();
|
||||
this.delAllVisitedViews()
|
||||
this.delCachedView()
|
||||
},
|
||||
// 删除所有tag
|
||||
delAllVisitedViews() {
|
||||
routeParamsCache.clear();
|
||||
// const affixTags = this.visitedViews.filter((tag) => tag.meta.affix)
|
||||
this.visitedViews = []
|
||||
},
|
||||
@ -94,6 +99,11 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
},
|
||||
// 删除其他tag
|
||||
delOthersVisitedViews(view: RouteLocationNormalizedLoaded) {
|
||||
this.visitedViews.forEach(item =>{
|
||||
if(item.path != view.path){
|
||||
routeParamsCache.remove(item.path)
|
||||
}
|
||||
})
|
||||
this.visitedViews = this.visitedViews.filter((v) => {
|
||||
return v?.meta?.affix || v.path === view.path
|
||||
})
|
||||
@ -105,6 +115,11 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
(v) => v.path === view.path
|
||||
)
|
||||
if (index > -1) {
|
||||
this.visitedViews.filter((item,i) =>{
|
||||
if(i < index && v.path !== view.path ){
|
||||
routeParamsCache.remove(item.path)
|
||||
}
|
||||
})
|
||||
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||
return v?.meta?.affix || v.path === view.path || i > index
|
||||
})
|
||||
@ -118,6 +133,11 @@ export const useTagsViewStore = defineStore('tagsView', {
|
||||
(v) => v.path === view.path
|
||||
)
|
||||
if (index > -1) {
|
||||
this.visitedViews.filter((item,i) =>{
|
||||
if(i > index && v.path !== view.path ){
|
||||
routeParamsCache.remove(item.path)
|
||||
}
|
||||
})
|
||||
this.visitedViews = this.visitedViews.filter((v, i) => {
|
||||
return v?.meta?.affix || v.path === view.path || i < index
|
||||
})
|
||||
|
@ -77,10 +77,18 @@ const routeParamsCache = {
|
||||
},
|
||||
|
||||
get(route: String) {
|
||||
console.log(route)
|
||||
const path = getCacheKey(route);
|
||||
return this.cache.get(path)?.queryParams; // 简化返回
|
||||
},
|
||||
remove(route: String) {
|
||||
const path = getCacheKey(route);
|
||||
if (this.cache.has(path)) {
|
||||
this.cache.delete(path);
|
||||
saveCache(this.cache);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
cleanExpired(expireHours = DEFAULT_EXPIRE_HOURS) {
|
||||
const now = Date.now();
|
||||
|
Loading…
Reference in New Issue
Block a user