mirror of
https://gitee.com/honghuangdc/soybean-admin-element-plus.git
synced 2025-12-30 02:12:26 +00:00
feat(projects): 🔥 optimize tabs cache cleaning strategy. fixed [#165]
This commit is contained in:
@@ -55,10 +55,4 @@ export const themePageAnimationModeRecord: Record<UnionKey.ThemePageAnimateMode,
|
|||||||
|
|
||||||
export const themePageAnimationModeOptions = transformRecordToOption(themePageAnimationModeRecord);
|
export const themePageAnimationModeOptions = transformRecordToOption(themePageAnimationModeRecord);
|
||||||
|
|
||||||
export const resetCacheStrategyRecord: Record<UnionKey.ResetCacheStrategy, App.I18n.I18nKey> = {
|
|
||||||
close: 'theme.resetCacheStrategy.close',
|
|
||||||
refresh: 'theme.resetCacheStrategy.refresh'
|
|
||||||
};
|
|
||||||
export const resetCacheStrategyOptions = transformRecordToOption(resetCacheStrategyRecord);
|
|
||||||
|
|
||||||
export const DARK_CLASS = 'dark';
|
export const DARK_CLASS = 'dark';
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import {
|
import { themePageAnimationModeOptions, themeScrollModeOptions, themeTabModeOptions } from '@/constants/app';
|
||||||
resetCacheStrategyOptions,
|
|
||||||
themePageAnimationModeOptions,
|
|
||||||
themeScrollModeOptions,
|
|
||||||
themeTabModeOptions
|
|
||||||
} from '@/constants/app';
|
|
||||||
import { useThemeStore } from '@/store/modules/theme';
|
import { useThemeStore } from '@/store/modules/theme';
|
||||||
import { translateOptions } from '@/utils/common';
|
import { translateOptions } from '@/utils/common';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
@@ -25,16 +20,6 @@ const isWrapperScrollMode = computed(() => themeStore.layout.scrollMode === 'wra
|
|||||||
<template>
|
<template>
|
||||||
<ElDivider>{{ $t('theme.pageFunTitle') }}</ElDivider>
|
<ElDivider>{{ $t('theme.pageFunTitle') }}</ElDivider>
|
||||||
<TransitionGroup tag="div" name="setting-list" class="flex-col-stretch gap-12px">
|
<TransitionGroup tag="div" name="setting-list" class="flex-col-stretch gap-12px">
|
||||||
<SettingItem key="1" :label="$t('theme.resetCacheStrategy.title')">
|
|
||||||
<ElSelect v-model="themeStore.resetCacheStrategy" size="small" class="w-120px">
|
|
||||||
<ElOption
|
|
||||||
v-for="{ label, value } in translateOptions(resetCacheStrategyOptions)"
|
|
||||||
:key="value"
|
|
||||||
:label="label"
|
|
||||||
:value="value"
|
|
||||||
/>
|
|
||||||
</ElSelect>
|
|
||||||
</SettingItem>
|
|
||||||
<SettingItem key="1" :label="$t('theme.scrollMode.title')">
|
<SettingItem key="1" :label="$t('theme.scrollMode.title')">
|
||||||
<ElSelect v-model="themeStore.layout.scrollMode" size="small" class="w-120px">
|
<ElSelect v-model="themeStore.layout.scrollMode" size="small" class="w-120px">
|
||||||
<ElOption
|
<ElOption
|
||||||
|
|||||||
@@ -148,11 +148,6 @@ const local: App.I18n.Schema = {
|
|||||||
},
|
},
|
||||||
themeDrawerTitle: 'Theme Configuration',
|
themeDrawerTitle: 'Theme Configuration',
|
||||||
pageFunTitle: 'Page Function',
|
pageFunTitle: 'Page Function',
|
||||||
resetCacheStrategy: {
|
|
||||||
title: 'Reset Cache Strategy',
|
|
||||||
close: 'Close Page',
|
|
||||||
refresh: 'Refresh Page'
|
|
||||||
},
|
|
||||||
configOperation: {
|
configOperation: {
|
||||||
copyConfig: 'Copy Config',
|
copyConfig: 'Copy Config',
|
||||||
copySuccessMsg: 'Copy Success, Please replace the variable "themeSettings" in "src/theme/settings.ts"',
|
copySuccessMsg: 'Copy Success, Please replace the variable "themeSettings" in "src/theme/settings.ts"',
|
||||||
|
|||||||
@@ -148,11 +148,6 @@ const local: App.I18n.Schema = {
|
|||||||
},
|
},
|
||||||
themeDrawerTitle: '主题配置',
|
themeDrawerTitle: '主题配置',
|
||||||
pageFunTitle: '页面功能',
|
pageFunTitle: '页面功能',
|
||||||
resetCacheStrategy: {
|
|
||||||
title: '重置缓存策略',
|
|
||||||
close: '关闭页面',
|
|
||||||
refresh: '刷新页面'
|
|
||||||
},
|
|
||||||
configOperation: {
|
configOperation: {
|
||||||
copyConfig: '复制配置',
|
copyConfig: '复制配置',
|
||||||
copySuccessMsg: '复制成功,请替换 src/theme/settings.ts 中的变量 themeSettings',
|
copySuccessMsg: '复制成功,请替换 src/theme/settings.ts 中的变量 themeSettings',
|
||||||
|
|||||||
@@ -46,10 +46,6 @@ export const useAppStore = defineStore(SetupStoreId.App, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setReloadFlag(true);
|
setReloadFlag(true);
|
||||||
|
|
||||||
if (themeStore.resetCacheStrategy === 'refresh') {
|
|
||||||
routeStore.resetRouteCache();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const locale = ref<App.I18n.LangType>(localStg.get('lang') || 'zh-CN');
|
const locale = ref<App.I18n.LangType>(localStg.get('lang') || 'zh-CN');
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
const removeTabIndex = tabs.value.findIndex(tab => tab.id === tabId);
|
const removeTabIndex = tabs.value.findIndex(tab => tab.id === tabId);
|
||||||
if (removeTabIndex === -1) return;
|
if (removeTabIndex === -1) return;
|
||||||
|
|
||||||
const removedTabRouteKey = tabs.value[removeTabIndex].routeKey;
|
|
||||||
const isRemoveActiveTab = activeTabId.value === tabId;
|
const isRemoveActiveTab = activeTabId.value === tabId;
|
||||||
|
|
||||||
// if remove the last tab, then switch to the second last tab
|
// if remove the last tab, then switch to the second last tab
|
||||||
@@ -111,11 +110,6 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
if (isRemoveActiveTab && nextTab) {
|
if (isRemoveActiveTab && nextTab) {
|
||||||
await switchRouteByTab(nextTab);
|
await switchRouteByTab(nextTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset route cache if cache strategy is close
|
|
||||||
if (themeStore.resetCacheStrategy === 'close') {
|
|
||||||
routeStore.resetRouteCache(removedTabRouteKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** remove active tab */
|
/** remove active tab */
|
||||||
@@ -147,12 +141,6 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
const tabsToRemove = tabs.value.filter(tab => !remainTabIds.includes(tab.id));
|
const tabsToRemove = tabs.value.filter(tab => !remainTabIds.includes(tab.id));
|
||||||
const routeKeysToReset: RouteKey[] = [];
|
const routeKeysToReset: RouteKey[] = [];
|
||||||
|
|
||||||
if (themeStore.resetCacheStrategy === 'close') {
|
|
||||||
for (const tab of tabsToRemove) {
|
|
||||||
routeKeysToReset.push(tab.routeKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removedTabsIds = tabsToRemove.map(tab => tab.id);
|
const removedTabsIds = tabsToRemove.map(tab => tab.id);
|
||||||
|
|
||||||
// If no tabs are actually being removed based on excludes and fixed tabs, exit
|
// If no tabs are actually being removed based on excludes and fixed tabs, exit
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export const themeSettings: App.Theme.ThemeSetting = {
|
|||||||
error: '#f5222d'
|
error: '#f5222d'
|
||||||
},
|
},
|
||||||
isInfoFollowPrimary: true,
|
isInfoFollowPrimary: true,
|
||||||
resetCacheStrategy: 'close',
|
|
||||||
layout: {
|
layout: {
|
||||||
mode: 'vertical',
|
mode: 'vertical',
|
||||||
scrollMode: 'content',
|
scrollMode: 'content',
|
||||||
|
|||||||
3
src/typings/app.d.ts
vendored
3
src/typings/app.d.ts
vendored
@@ -20,8 +20,6 @@ declare namespace App {
|
|||||||
otherColor: OtherColor;
|
otherColor: OtherColor;
|
||||||
/** Whether info color is followed by the primary color */
|
/** Whether info color is followed by the primary color */
|
||||||
isInfoFollowPrimary: boolean;
|
isInfoFollowPrimary: boolean;
|
||||||
/** Reset cache strategy */
|
|
||||||
resetCacheStrategy: UnionKey.ResetCacheStrategy;
|
|
||||||
/** Layout */
|
/** Layout */
|
||||||
layout: {
|
layout: {
|
||||||
/** Layout mode */
|
/** Layout mode */
|
||||||
@@ -409,7 +407,6 @@ declare namespace App {
|
|||||||
};
|
};
|
||||||
themeDrawerTitle: string;
|
themeDrawerTitle: string;
|
||||||
pageFunTitle: string;
|
pageFunTitle: string;
|
||||||
resetCacheStrategy: { title: string } & Record<UnionKey.ResetCacheStrategy, string>;
|
|
||||||
configOperation: {
|
configOperation: {
|
||||||
copyConfig: string;
|
copyConfig: string;
|
||||||
copySuccessMsg: string;
|
copySuccessMsg: string;
|
||||||
|
|||||||
8
src/typings/union-key.d.ts
vendored
8
src/typings/union-key.d.ts
vendored
@@ -14,14 +14,6 @@ declare namespace UnionKey {
|
|||||||
/** Theme scheme */
|
/** Theme scheme */
|
||||||
type ThemeScheme = 'light' | 'dark' | 'auto';
|
type ThemeScheme = 'light' | 'dark' | 'auto';
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset cache strategy
|
|
||||||
*
|
|
||||||
* - close: re-cache when close page
|
|
||||||
* - refresh: re-cache when refresh page
|
|
||||||
*/
|
|
||||||
type ResetCacheStrategy = 'close' | 'refresh';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The layout mode
|
* The layout mode
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user