Blame view

src/setup/App.ts 2.14 KB
vben authored
1
2
3
4
/**
 * Application configuration
 */
陈文彬 authored
5
import type { ProjectConfig } from '/@/types/config';
6
import type { App } from 'vue';
陈文彬 authored
7
8
9
10
11
12
13
14
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';
15
16
17
18
19
20
import {
  updateGrayMode,
  updateColorWeak,
  updateHeaderBgColor,
  updateSidebarBgColor,
} from '/@/setup/theme';
陈文彬 authored
21
22
23

import { appStore } from '/@/store/modules/app';
vben authored
24
// Used to share global app instances
25
let app: App;
vben authored
26
27
28
29
30
31
32
33
34
export function setApp(_app: App): void {
  app = _app;
}

export function getApp(): App {
  return app;
}
vben authored
35
// TODO Theme switching
陈文彬 authored
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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),
  };
}
50
// Initial project configuration
vben authored
51
export function initAppConfigStore() {
陈文彬 authored
52
53
54
55
  let projCfg: ProjectConfig = getLocal(PROJ_CFG_KEY) as ProjectConfig;
  if (!projCfg) {
    projCfg = projectSetting;
  }
vben authored
56
57
58
59
60
61
  const {
    colorWeak,
    grayMode,
    headerSetting: { bgColor: headerBgColor },
    menuSetting: { bgColor },
  } = projCfg;
陈文彬 authored
62
63
64
65
66
67
68
69
  try {
    // if (
    //   themeColor !== primaryColor &&
    //   themeColor &&
    //   process.env.VUE_APP_USE_THEME_REPLACER !== 'TRUE'
    // ) {
    //   updateTheme(themeColor);
    // }
70
    headerBgColor && updateHeaderBgColor(headerBgColor);
vben authored
71
    bgColor && updateSidebarBgColor(bgColor);
陈文彬 authored
72
73
74
75
76
77
78
79
    grayMode && updateGrayMode(grayMode);
    colorWeak && updateColorWeak(colorWeak);
  } catch (error) {
    console.log(error);
  }
  appStore.commitProjectConfigState(projCfg);
}
vben authored
80
81
// antdv Config Provider
export function getConfigProvider() {
陈文彬 authored
82
83
84
85
86
87
88
89
90
91
  function transformCellText({ text }: { text: string }) {
    if (isNull(text) || isUnDef(text)) {
      return ' - ';
    }
    return text;
  }
  return {
    transformCellText,
  };
}