feat(layout): 实现标签页视图按用户持久化存储
- 引入用户模块以支持用户标识获取 - 修改标签页缓存键名格式为 tags-view-visited-[userId] - 在应用启动时自动加载当前用户的标签页视图 - 确保不同用户间的标签页视图数据隔离 - 保留匿名用户的支持逻辑 - 在设置重置时清理对应用户的缓存数据
This commit is contained in:
@@ -127,6 +127,7 @@
|
||||
import useAppStore from '@/store/modules/app'
|
||||
import useSettingsStore from '@/store/modules/settings'
|
||||
import usePermissionStore from '@/store/modules/permission'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import { handleThemeStyle } from '@/utils/theme'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
@@ -192,7 +193,7 @@ watch(() => navType.value, val => {
|
||||
function saveSetting() {
|
||||
proxy.$modal.loading("正在保存到本地,请稍候...")
|
||||
if (!tagsViewPersist.value) {
|
||||
proxy.$cache.local.remove('tags-view-visited')
|
||||
proxy.$cache.local.remove('tags-view-visited-' + (useUserStore().id || 'anonymous'))
|
||||
}
|
||||
let layoutSetting = {
|
||||
"topNav": storeSettings.value.topNav,
|
||||
@@ -212,7 +213,7 @@ function saveSetting() {
|
||||
}
|
||||
|
||||
function resetSetting() {
|
||||
proxy.$cache.local.remove('tags-view-visited')
|
||||
proxy.$cache.local.remove('tags-view-visited-' + (useUserStore().id || 'anonymous'))
|
||||
proxy.$modal.loading("正在清除设置缓存并刷新,请稍候...")
|
||||
localStorage.removeItem("layout-setting")
|
||||
setTimeout("window.location.reload()", 1000)
|
||||
|
||||
@@ -10,6 +10,7 @@ import useLockStore from '@/store/modules/lock'
|
||||
import useSettingsStore from '@/store/modules/settings'
|
||||
import usePermissionStore from '@/store/modules/permission'
|
||||
import useNoticeStore from '@/store/modules/notice'
|
||||
import useTagsViewStore from '@/store/modules/tagsView'
|
||||
|
||||
// 全局变量,用于控制公告弹窗只显示一次
|
||||
let hasShownNoticePopup = false
|
||||
@@ -56,6 +57,7 @@ router.beforeEach(async (to, from) => {
|
||||
}
|
||||
})
|
||||
useNoticeStore().startPolling()
|
||||
useTagsViewStore().loadPersistedViews()
|
||||
return { ...to, replace: true }
|
||||
} catch (err) {
|
||||
console.error('路由加载失败:', err)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import cache from '@/plugins/cache'
|
||||
import useSettingsStore from '@/store/modules/settings'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
|
||||
const PERSIST_KEY = 'tags-view-visited'
|
||||
function getPersistKey() {
|
||||
const userId = useUserStore().id || 'anonymous'
|
||||
return 'tags-view-visited-' + userId
|
||||
}
|
||||
|
||||
function isPersistEnabled() {
|
||||
return useSettingsStore().tagsViewPersist
|
||||
@@ -10,15 +14,15 @@ function isPersistEnabled() {
|
||||
function saveVisitedViews(views) {
|
||||
if (!isPersistEnabled()) return
|
||||
const toSave = views.filter(v => !(v.meta && v.meta.affix)).map(v => ({ path: v.path, fullPath: v.fullPath, name: v.name, title: v.title, query: v.query, meta: v.meta }))
|
||||
cache.local.setJSON(PERSIST_KEY, toSave)
|
||||
cache.local.setJSON(getPersistKey(), toSave)
|
||||
}
|
||||
|
||||
function loadVisitedViews() {
|
||||
return cache.local.getJSON(PERSIST_KEY) || []
|
||||
return cache.local.getJSON(getPersistKey()) || []
|
||||
}
|
||||
|
||||
function clearVisitedViews() {
|
||||
cache.local.remove(PERSIST_KEY)
|
||||
cache.local.remove(getPersistKey())
|
||||
}
|
||||
|
||||
const useTagsViewStore = defineStore(
|
||||
|
||||
Reference in New Issue
Block a user