修改主题颜色
This commit is contained in:
+35
@@ -21,6 +21,41 @@ import '@/styles/index.scss';
|
||||
// 根据字典编码获取字典列表全局方法
|
||||
import { getDictItemsByTypeCode } from '@/api/system/dict';
|
||||
|
||||
// 主题颜色混合工具
|
||||
import { mix } from '@/utils';
|
||||
|
||||
// 根据环境变量初始化主题颜色
|
||||
const initTheme = () => {
|
||||
const node = document.documentElement;
|
||||
const envTheme = import.meta.env.VITE_APP_THEME;
|
||||
const localStorageTheme = localStorage.getItem('theme');
|
||||
|
||||
// 优先使用环境变量,其次使用 localStorage
|
||||
const themeColor = envTheme || localStorageTheme;
|
||||
|
||||
if (themeColor) {
|
||||
// 设置主主题色
|
||||
node.style.setProperty('--el-color-primary', themeColor);
|
||||
|
||||
// 设置渐变色
|
||||
const mixWhite = '#ffffff';
|
||||
const mixBlack = '#000000';
|
||||
|
||||
for (let i = 1; i < 10; i += 1) {
|
||||
node.style.setProperty(
|
||||
`--el-color-primary-light-${i}`,
|
||||
mix(themeColor, mixWhite, i * 0.1)
|
||||
);
|
||||
}
|
||||
node.style.setProperty('--el-color-primary-dark', mix(themeColor, mixBlack, 0.1));
|
||||
|
||||
localStorage.setItem('theme', themeColor);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化主题颜色
|
||||
initTheme();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
// 自定义指令
|
||||
|
||||
Reference in New Issue
Block a user