添加持久化标签页开关功能

This commit is contained in:
RuoYi
2026-03-22 23:12:36 +08:00
parent f8bf7a26b3
commit 943cb1815d
5 changed files with 76 additions and 3 deletions

View File

@@ -63,6 +63,13 @@
</span>
</div>
<div class="drawer-item">
<span>持久化标签页</span>
<span class="comp-style">
<el-switch v-model="settingsStore.tagsViewPersist" :disabled="!settingsStore.tagsView" @change="tagsViewPersistChange" class="drawer-switch" />
</span>
</div>
<div class="drawer-item">
<span>显示页签图标</span>
<span class="comp-style">
@@ -120,6 +127,7 @@ const showSettings = ref(false)
const navType = ref(settingsStore.navType)
const theme = ref(settingsStore.theme)
const sideTheme = ref(settingsStore.sideTheme)
const tagsViewPersist = ref(settingsStore.tagsViewPersist)
const storeSettings = computed(() => settingsStore)
const predefineColors = ref(["#409EFF", "#ff4500", "#ff8c00", "#ffd700", "#90ee90", "#00ced1", "#1e90ff", "#c71585"])
@@ -128,6 +136,11 @@ function dynamicTitleChange() {
useSettingsStore().setTitle(useSettingsStore().title)
}
function tagsViewPersistChange(val) {
settingsStore.tagsViewPersist = val
tagsViewPersist.value = val
}
function themeChange(val) {
settingsStore.theme = val
handleThemeStyle(val)
@@ -164,10 +177,14 @@ watch(() => navType, val => {
function saveSetting() {
proxy.$modal.loading("正在保存到本地,请稍候...")
if (!tagsViewPersist.value) {
proxy.$cache.local.remove('tags-view-visited')
}
let layoutSetting = {
"navType": storeSettings.value.navType,
"tagsView": storeSettings.value.tagsView,
"tagsIcon": storeSettings.value.tagsIcon,
"tagsViewPersist": storeSettings.value.tagsViewPersist,
"fixedHeader": storeSettings.value.fixedHeader,
"sidebarLogo": storeSettings.value.sidebarLogo,
"dynamicTitle": storeSettings.value.dynamicTitle,
@@ -180,6 +197,7 @@ function saveSetting() {
}
function resetSetting() {
proxy.$cache.local.remove('tags-view-visited')
proxy.$modal.loading("正在清除设置缓存并刷新,请稍候...")
localStorage.removeItem("layout-setting")
setTimeout("window.location.reload()", 1000)

View File

@@ -117,6 +117,7 @@ const visitedViews = computed(() => useTagsViewStore().visitedViews)
const routes = computed(() => usePermissionStore().routes)
const theme = computed(() => useSettingsStore().theme)
const tagsIcon = computed(() => useSettingsStore().tagsIcon)
const tagsViewPersist = computed(() => useSettingsStore().tagsViewPersist)
// 下拉菜单针对当前激活的 tag
const selectedDropdownTag = computed(() => visitedViews.value.find(v => isActive(v)) || {})
@@ -207,11 +208,14 @@ function filterAffixTags(routes, basePath = '') {
}
function initTags() {
if (tagsViewPersist) {
useTagsViewStore().loadPersistedViews()
}
const res = filterAffixTags(routes.value)
affixTags.value = res
for (const tag of res) {
if (tag.name) {
useTagsViewStore().addVisitedView(tag)
useTagsViewStore().addAffixView(tag)
}
}
}