Skip to content

Commit

Permalink
perf(projects): perf theme store
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 16, 2023
1 parent 26714e9 commit b0d95f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
68 changes: 34 additions & 34 deletions src/store/modules/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
themeStore.$reset();
}

/**
* theme colors
*/
const themeColors = computed(() => {
const { themeColor, otherColor, isInfoFollowPrimary } = settings.value;
const colors: App.Theme.ThemeColor = {
primary: themeColor,
...otherColor,
info: isInfoFollowPrimary ? themeColor : otherColor.info
};
return colors;
});

/**
* dark mode
*/
const darkMode = computed(() => {
if (settings.value.themeScheme === 'auto') {
return osTheme.value === 'dark';
}

return settings.value.themeScheme === 'dark';
});

/**
* antd theme
*/
const antdTheme = computed(() => getAntdTheme(themeColors.value, darkMode.value));

/**
* settings json
* @description it is for copy settings
Expand Down Expand Up @@ -56,22 +85,6 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
setThemeScheme(nextThemeScheme);
}

/**
* dark mode
*/
const darkMode = computed(() => {
if (settings.value.themeScheme === 'auto') {
return osTheme.value === 'dark';
}

return settings.value.themeScheme === 'dark';
});

/**
* antd theme
*/
const antdTheme = computed(() => getAntdTheme(settings.value.themeColor, settings.value.otherColor, darkMode.value));

/**
* set theme layout
* @param mode theme layout mode
Expand All @@ -80,19 +93,6 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
settings.value.layout.mode = mode;
}

/**
* theme colors
*/
const themeColors = computed(() => {
const { themeColor, otherColor, isInfoFollowPrimary } = settings.value;
const colors: App.Theme.ThemeColor = {
primary: themeColor,
...otherColor,
info: isInfoFollowPrimary ? themeColor : otherColor.info
};
return colors;
});

/**
* update theme colors
* @param key theme color key
Expand Down Expand Up @@ -163,11 +163,11 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
resetStore,
settingsJson,
darkMode,
setThemeScheme,
toggleThemeScheme,
antdTheme,
setThemeLayout,
themeColors,
updateThemeColors
antdTheme,
toggleThemeScheme,
setThemeScheme,
updateThemeColors,
setThemeLayout
};
});
6 changes: 3 additions & 3 deletions src/store/modules/theme/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ export function toggleCssDarkMode(darkMode = false) {
/**
* get antd theme
*/
export function getAntdTheme(themeColor: string, otherColor: App.Theme.OtherColor, isDark: boolean) {
export function getAntdTheme(colors: App.Theme.ThemeColor, isDark: boolean) {
const { defaultAlgorithm, darkAlgorithm } = antdTheme;

const { info, success, warning, error } = otherColor;
const { primary, info, success, warning, error } = colors;

const theme: ConfigProviderProps['theme'] = {
token: {
colorPrimary: themeColor,
colorPrimary: primary,
colorInfo: info,
colorSuccess: success,
colorWarning: warning,
Expand Down

0 comments on commit b0d95f1

Please sign in to comment.