2020-11-18 22:41:59 +08:00
|
|
|
/**
|
|
|
|
|
* Application configuration
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-28 20:19:10 +08:00
|
|
|
import type { ProjectConfig } from '/@/types/config';
|
2020-10-20 21:06:12 +08:00
|
|
|
import type { App } from 'vue';
|
2020-09-28 20:19:10 +08:00
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
|
|
|
|
|
import { ThemeModeEnum } from '/@/enums/appEnum';
|
|
|
|
|
import { PROJ_CFG_KEY } from '/@/enums/cacheEnum';
|
|
|
|
|
|
|
|
|
|
import projectSetting from '/@/settings/projectSetting';
|
|
|
|
|
import { getLocal } from '/@/utils/helper/persistent';
|
|
|
|
|
import { isUnDef, isNull } from '/@/utils/is';
|
2020-11-11 22:13:59 +08:00
|
|
|
import {
|
|
|
|
|
updateGrayMode,
|
|
|
|
|
updateColorWeak,
|
|
|
|
|
updateHeaderBgColor,
|
|
|
|
|
updateSidebarBgColor,
|
|
|
|
|
} from '/@/setup/theme';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
|
|
|
|
import { appStore } from '/@/store/modules/app';
|
|
|
|
|
|
2020-11-18 22:41:59 +08:00
|
|
|
// Used to share global app instances
|
2020-10-20 21:06:12 +08:00
|
|
|
let app: App;
|
2020-11-18 22:41:59 +08:00
|
|
|
|
2020-10-20 21:06:12 +08:00
|
|
|
export function setApp(_app: App): void {
|
|
|
|
|
app = _app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getApp(): App {
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 22:41:59 +08:00
|
|
|
// TODO Theme switching
|
2020-09-28 20:19:10 +08:00
|
|
|
export function useThemeMode(mode: ThemeModeEnum) {
|
|
|
|
|
const modeRef = ref(mode);
|
|
|
|
|
const html = document.documentElement;
|
|
|
|
|
const clsList = html.classList;
|
|
|
|
|
|
|
|
|
|
const change = () => {
|
|
|
|
|
clsList.contains(mode) ? clsList.remove(mode) : clsList.add(mode);
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
runChangeThemeMode: change,
|
|
|
|
|
mode: computed(() => modeRef.value),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
let projCfg: ProjectConfig = getLocal(PROJ_CFG_KEY) as ProjectConfig;
|
|
|
|
|
if (!projCfg) {
|
|
|
|
|
projCfg = projectSetting;
|
|
|
|
|
}
|
2020-11-11 22:13:59 +08:00
|
|
|
const { colorWeak, grayMode, headerBgColor, menuBgColor } = projCfg;
|
2020-09-28 20:19:10 +08:00
|
|
|
try {
|
|
|
|
|
// if (
|
|
|
|
|
// themeColor !== primaryColor &&
|
|
|
|
|
// themeColor &&
|
|
|
|
|
// process.env.VUE_APP_USE_THEME_REPLACER !== 'TRUE'
|
|
|
|
|
// ) {
|
|
|
|
|
// updateTheme(themeColor);
|
|
|
|
|
// }
|
2020-11-11 22:13:59 +08:00
|
|
|
headerBgColor && updateHeaderBgColor(headerBgColor);
|
|
|
|
|
menuBgColor && updateSidebarBgColor(menuBgColor);
|
2020-09-28 20:19:10 +08:00
|
|
|
grayMode && updateGrayMode(grayMode);
|
|
|
|
|
colorWeak && updateColorWeak(colorWeak);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
appStore.commitProjectConfigState(projCfg);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 22:41:59 +08:00
|
|
|
// antdv Config Provider
|
|
|
|
|
export function getConfigProvider() {
|
2020-09-28 20:19:10 +08:00
|
|
|
function transformCellText({ text }: { text: string }) {
|
|
|
|
|
if (isNull(text) || isUnDef(text)) {
|
|
|
|
|
return ' - ';
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
transformCellText,
|
|
|
|
|
};
|
|
|
|
|
}
|