Skip to content

Commit

Permalink
fix: 修复亮白主题配色,切换暗色主题后再切回亮色主题时,无法恢复之前的亮白主题配色
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Jan 2, 2024
1 parent abfc0cc commit 6c47908
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/layout/components/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ function setLayoutModel(layout: string) {
theme: layoutTheme.value.theme,
darkMode: $storage.layout?.darkMode,
sidebarStatus: $storage.layout?.sidebarStatus,
epThemeColor: $storage.layout?.epThemeColor
epThemeColor: $storage.layout?.epThemeColor,
themeColor: layoutTheme.value.theme
};
useAppStoreHook().setLayout(layout);
}
Expand Down
17 changes: 13 additions & 4 deletions src/layout/hooks/useDataThemeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ export function useDataThemeChange() {
}

/** 设置导航主题色 */
function setLayoutThemeColor(theme = getConfig().Theme ?? "default") {
function setLayoutThemeColor(
theme = getConfig().Theme ?? "light",
isClick = true
) {
layoutTheme.value.theme = theme;
toggleTheme({
scopeName: `layout-theme-${theme}`
});
// 如果非isClick,保留之前的themeColor
const storageThemeColor = $storage.layout.themeColor;
$storage.layout = {
layout: layout.value,
theme,
darkMode: dataTheme.value,
sidebarStatus: $storage.layout?.sidebarStatus,
epThemeColor: $storage.layout?.epThemeColor
epThemeColor: $storage.layout?.epThemeColor,
themeColor: isClick ? theme : storageThemeColor
};

if (theme === "default" || theme === "light") {
Expand Down Expand Up @@ -91,14 +97,17 @@ export function useDataThemeChange() {
/** 亮色、暗色整体风格切换 */
function dataThemeChange() {
if (useEpThemeStoreHook().epTheme === "light" && dataTheme.value) {
setLayoutThemeColor("default");
setLayoutThemeColor("default", false);
} else {
setLayoutThemeColor(useEpThemeStoreHook().epTheme);
setLayoutThemeColor(useEpThemeStoreHook().epTheme, false);
}

if (dataTheme.value) {
document.documentElement.classList.add("dark");
} else {
if ($storage.layout.themeColor === "light") {
setLayoutThemeColor("light", false);
}
document.documentElement.classList.remove("dark");
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/layout/hooks/useLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export function useLayout() {
if (!$storage.layout) {
$storage.layout = {
layout: $config?.Layout ?? "vertical",
theme: $config?.Theme ?? "default",
theme: $config?.Theme ?? "light",
darkMode: $config?.DarkMode ?? false,
sidebarStatus: $config?.SidebarStatus ?? true,
epThemeColor: $config?.EpThemeColor ?? "#409EFF"
epThemeColor: $config?.EpThemeColor ?? "#409EFF",
themeColor: $config?.Theme ?? "light"
};
}
/** 灰色模式、色弱模式、隐藏标签页 */
Expand Down
3 changes: 2 additions & 1 deletion src/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function setTheme(layoutModel: string) {
theme: $storage.layout?.theme,
darkMode: $storage.layout?.darkMode,
sidebarStatus: $storage.layout?.sidebarStatus,
epThemeColor: $storage.layout?.epThemeColor
epThemeColor: $storage.layout?.epThemeColor,
themeColor: $storage.layout?.themeColor
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/utils/responsive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export const injectResponsiveStorage = (app: App, config: PlatformConfigs) => {
// layout模式以及主题
layout: Storage.getData("layout", nameSpace) ?? {
layout: config.Layout ?? "vertical",
theme: config.Theme ?? "default",
theme: config.Theme ?? "light",
darkMode: config.DarkMode ?? false,
sidebarStatus: config.SidebarStatus ?? true,
epThemeColor: config.EpThemeColor ?? "#409EFF"
epThemeColor: config.EpThemeColor ?? "#409EFF",
themeColor: config.Theme ?? "light" // 主题色(对应项目配置中的主题色,与theme不同的是它不会受到亮色、暗色整体风格切换的影响,只会在手动点击主题色时改变)
},
// 项目配置-界面显示
configure: Storage.getData("configure", nameSpace) ?? {
grey: config.Grey ?? false,
weak: config.Weak ?? false,
Expand Down
9 changes: 2 additions & 7 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import type {
VNode,
FunctionalComponent,
PropType as VuePropType,
ComponentPublicInstance
} from "vue";
import type { ECharts } from "echarts";
import type { IconifyIcon } from "@iconify/vue";
import type { TableColumns } from "@pureadmin/table";

/**
Expand Down Expand Up @@ -129,6 +122,7 @@ declare global {
hideFooter?: boolean;
sidebarStatus?: boolean;
epThemeColor?: string;
themeColor?: string;
showLogo?: boolean;
showModel?: string;
mapConfigure?: {
Expand All @@ -155,6 +149,7 @@ declare global {
darkMode?: boolean;
sidebarStatus?: boolean;
epThemeColor?: string;
themeColor?: string;
};
configure: {
grey?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion types/router.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 全局路由类型声明

import { type RouteComponent, type RouteLocationNormalized } from "vue-router";
import type { RouteComponent, RouteLocationNormalized } from "vue-router";
import type { FunctionalComponent } from "vue";

declare global {
interface ToRouteType extends RouteLocationNormalized {
Expand Down

0 comments on commit 6c47908

Please sign in to comment.