2020-11-18 22:41:59 +08:00
|
|
|
/**
|
|
|
|
|
* Application configuration
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-28 20:19:10 +08:00
|
|
|
import projectSetting from '/@/settings/projectSetting';
|
2021-02-27 23:08:12 +08:00
|
|
|
|
2021-02-03 23:52:55 +08:00
|
|
|
import { updateHeaderBgColor, updateSidebarBgColor } from '/@/logics/theme/updateBackground';
|
|
|
|
|
import { updateColorWeak } from '/@/logics/theme/updateColorWeak';
|
|
|
|
|
import { updateGrayMode } from '/@/logics/theme/updateGrayMode';
|
|
|
|
|
import { changeTheme } from '/@/logics/theme';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
|
|
|
|
import { appStore } from '/@/store/modules/app';
|
2021-02-27 23:08:12 +08:00
|
|
|
import { localeStore } from '/@/store/modules/locale';
|
|
|
|
|
|
|
|
|
|
import { getCommonStoragePrefix, getStorageShortName } from '/@/utils/env';
|
|
|
|
|
|
2021-02-03 23:52:55 +08:00
|
|
|
import { primaryColor } from '../../build/config/themeConfig';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2020-11-10 22:45:39 +08:00
|
|
|
// Initial project configuration
|
2020-11-18 22:41:59 +08:00
|
|
|
export function initAppConfigStore() {
|
2020-09-28 20:19:10 +08:00
|
|
|
try {
|
2020-11-25 21:26:10 +08:00
|
|
|
const {
|
|
|
|
|
colorWeak,
|
|
|
|
|
grayMode,
|
2021-02-03 23:52:55 +08:00
|
|
|
themeColor,
|
2020-11-25 21:26:10 +08:00
|
|
|
headerSetting: { bgColor: headerBgColor } = {},
|
|
|
|
|
menuSetting: { bgColor } = {},
|
2021-02-27 23:08:12 +08:00
|
|
|
} = projectSetting;
|
2021-02-03 23:52:55 +08:00
|
|
|
if (themeColor && themeColor !== primaryColor) {
|
|
|
|
|
changeTheme(themeColor);
|
|
|
|
|
}
|
2020-11-11 22:13:59 +08:00
|
|
|
headerBgColor && updateHeaderBgColor(headerBgColor);
|
2020-11-24 22:59:29 +08:00
|
|
|
bgColor && updateSidebarBgColor(bgColor);
|
2020-09-28 20:19:10 +08:00
|
|
|
grayMode && updateGrayMode(grayMode);
|
|
|
|
|
colorWeak && updateColorWeak(colorWeak);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
2021-02-27 23:08:12 +08:00
|
|
|
appStore.commitProjectConfigState(projectSetting);
|
|
|
|
|
localeStore.initLocale();
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
clearObsoleteStorage();
|
|
|
|
|
}, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* As the version continues to iterate, there will be more and more cache keys stored in localStorage.
|
|
|
|
|
* This method is used to delete useless keys
|
|
|
|
|
*/
|
|
|
|
|
export function clearObsoleteStorage() {
|
|
|
|
|
const commonPrefix = getCommonStoragePrefix();
|
|
|
|
|
const shortPrefix = getStorageShortName();
|
|
|
|
|
|
|
|
|
|
[localStorage, sessionStorage].forEach((item: Storage) => {
|
|
|
|
|
Object.keys(item).forEach((key) => {
|
|
|
|
|
if (key && key.startsWith(commonPrefix) && !key.startsWith(shortPrefix)) {
|
|
|
|
|
item.removeItem(key);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-09-28 20:19:10 +08:00
|
|
|
}
|