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