+
{
+ color = color === 'dark' ? 'light' : 'dark';
+ }
+ "
+ >
diff --git a/src/config/index.ts b/src/config/index.ts
index c6b4eb20..bd580865 100644
--- a/src/config/index.ts
+++ b/src/config/index.ts
@@ -2,7 +2,6 @@ import type { App } from 'vue';
import { getConfigInfo } from '@/server/config';
import type { AppConfig } from '@/store/types';
import { setStorageConfig } from '@/utils/storage';
-import { updateColor } from '@/utils/transformTheme';
let config: AppConfig = {} as AppConfig;
@@ -25,7 +24,6 @@ export async function getServerConfig(app: App): Promise
{
}
}
setStorageConfig(config.StorageConfig);
- updateColor();
app.config.globalProperties.$config = getConfig();
return config;
}
diff --git a/src/hooks/useTransformTheme.ts b/src/hooks/useTransformTheme.ts
index c56bfe0b..a8e57b43 100644
--- a/src/hooks/useTransformTheme.ts
+++ b/src/hooks/useTransformTheme.ts
@@ -1 +1,58 @@
-export const useTransformTheme = () => {};
+import { useAppStoreHook } from '@/store/modules/app';
+
+export const useTransformTheme = () => {
+ const appStore = useAppStoreHook();
+
+ const body = document.documentElement as HTMLElement;
+
+ console.log(body.className);
+
+ // hex转rgb
+ function hexToRgb(str: string) {
+ const hxs: string[] = str.replace('#', '').match(/../g) || [];
+ const newHxs: number[] = [];
+ for (let i = 0; i < 3; i++) newHxs[i] = parseInt(hxs[i], 16);
+ return newHxs;
+ }
+
+ // rgb转hex
+ function rgbToHex(a: number, b: number, c: number) {
+ const hexs = [a.toString(16), b.toString(16), c.toString(16)];
+ for (let i = 0; i < 3; i++) {
+ if (hexs[i].length == 1) hexs[i] = `0${hexs[i]}`;
+ }
+ return `#${hexs.join('')}`;
+ }
+
+ // 参考element style 计算
+ function mix(color1: string, color2: string, weight: number) {
+ weight = Math.max(Math.min(Number(weight), 1), 0);
+ const mainColor = hexToRgb(color1);
+ const mixColor = hexToRgb(color2);
+ const hex = [];
+ for (let i = 0; i < mainColor.length; i++)
+ hex[i] = Math.round(mainColor[i] * (1 - weight) + mixColor[i] * weight);
+ return rgbToHex(hex[0], hex[1], hex[2]);
+ }
+
+ function updateColor() {
+ const { primaryColor, themeMode } = appStore.appConfigMode;
+ if (!primaryColor) return;
+ const mixWhite = themeMode === 'dark' ? '#141414' : '#ffffff';
+ body.style.setProperty('--el-color-primary', primaryColor);
+ for (let i = 1; i <= 9; i++) {
+ body.style.setProperty(`--el-color-primary-light-${i}`, mix(primaryColor, mixWhite, i * 0.1));
+ }
+ }
+
+ function themeHtmlClassName(className: string, isShow: boolean) {
+ if (isShow) {
+ body.className = `${body.className} ${className}`;
+ } else {
+ const exp = new RegExp(` ${className}`, 'g');
+ body.className = body.className.replace(exp, '');
+ }
+ }
+
+ return { updateColor, themeHtmlClassName };
+};
diff --git a/src/layouts/pageLayouts/components/Navbart/index.vue b/src/layouts/pageLayouts/components/Navbart/index.vue
index a5c03dd4..8c8da1de 100644
--- a/src/layouts/pageLayouts/components/Navbart/index.vue
+++ b/src/layouts/pageLayouts/components/Navbart/index.vue
@@ -48,7 +48,7 @@
-
+
diff --git a/src/layouts/pageLayouts/components/Seting/ThemeSettings/index.vue b/src/layouts/pageLayouts/components/Seting/ThemeSettings/index.vue
index b545fdbb..abb96c48 100644
--- a/src/layouts/pageLayouts/components/Seting/ThemeSettings/index.vue
+++ b/src/layouts/pageLayouts/components/Seting/ThemeSettings/index.vue
@@ -3,23 +3,38 @@
import { ColorPicker } from 'vue3-colorpicker';
import 'vue3-colorpicker/style.css';
import { useAppStoreHook } from '@/store/modules/app';
- import { updateColor } from '@/utils/transformTheme';
+ import { useTransformTheme } from '@/hooks/useTransformTheme';
import SvgIcon from '@/components/SvgIcon/index.vue';
+ import type { AppConfig } from '@/store/types';
+
+ const { updateColor, themeHtmlClassName } = useTransformTheme();
const appStore = useAppStoreHook();
- const pureColor = ref(appStore.appConfigMode.primaryColor);
+ const { primaryColor, greyMode, colorWeaknessMode } = appStore.appConfigMode;
+
+ const pureColor = ref(primaryColor);
const showPicker = ref
(false);
const colorList = ['#722ed1', '#eb2f96', '#52c41a', '#13c2c2', '#fadb14', '#fa541c', '#f5222d'];
watch([pureColor], () => {
- console.log(pureColor.value);
appStore.appConfigMode.primaryColor = pureColor.value;
appStore.setAppConfigMode(appStore.appConfigMode);
updateColor();
});
+
+ const htmlGrey = ref(greyMode || false);
+ const htmlWeakness = ref(colorWeaknessMode || false);
+
+ const themeChange = (e: boolean, key: string) => {
+ themeHtmlClassName(key, e);
+ const appData = {} as AppConfig;
+ if (key === 'html-grey') appData['greyMode'] = e;
+ else appData['colorWeaknessMode'] = e;
+ appStore.setAppConfigMode(appData);
+ };
@@ -36,7 +51,7 @@