refactor: ♻️ 自定义主题色,参考arco.design主题色值修改主色
This commit is contained in:
@@ -44,7 +44,7 @@ module.exports = {
|
|||||||
"at-rule-no-unknown": [
|
"at-rule-no-unknown": [
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
ignoreAtRules: ["apply", "use"],
|
ignoreAtRules: ["apply", "use", "forward"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ onClickOutside(iconSelectRef, () => (popoverVisible.value = false), {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.icon-item:hover {
|
.icon-item:hover {
|
||||||
border-color: #409eff;
|
border-color: #4080ff;
|
||||||
scale: 1.2;
|
scale: 1.2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const emit = defineEmits(["update:modelValue"]);
|
|||||||
|
|
||||||
// 定义颜色预设
|
// 定义颜色预设
|
||||||
const colorPresets = [
|
const colorPresets = [
|
||||||
"#409EFF",
|
"#4080FF",
|
||||||
"#ff4500",
|
"#ff4500",
|
||||||
"#ff8c00",
|
"#ff8c00",
|
||||||
"#90ee90",
|
"#90ee90",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const defaultSettings: AppSettings = {
|
|||||||
theme: mediaQueryList.matches ? ThemeEnum.DARK : ThemeEnum.LIGHT,
|
theme: mediaQueryList.matches ? ThemeEnum.DARK : ThemeEnum.LIGHT,
|
||||||
size: SizeEnum.DEFAULT,
|
size: SizeEnum.DEFAULT,
|
||||||
language: LanguageEnum.ZH_CN,
|
language: LanguageEnum.ZH_CN,
|
||||||
themeColor: "#409EFF",
|
themeColor: "#4080FF",
|
||||||
watermarkEnabled: false,
|
watermarkEnabled: false,
|
||||||
watermarkContent: pkg.name,
|
watermarkContent: pkg.name,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,68 +1,50 @@
|
|||||||
import defaultSettings from "@/settings";
|
import defaultSettings from "@/settings";
|
||||||
import { ThemeEnum } from "@/enums/ThemeEnum";
|
import { ThemeEnum } from "@/enums/ThemeEnum";
|
||||||
import Color from "color";
|
import { generateThemeColors, applyTheme, toggleDarkMode } from "@/utils/theme";
|
||||||
|
|
||||||
type SettingsValue = boolean | string;
|
type SettingsValue = boolean | string;
|
||||||
|
|
||||||
export const useSettingsStore = defineStore("setting", () => {
|
export const useSettingsStore = defineStore("setting", () => {
|
||||||
// 是否显示设置
|
// 基本设置
|
||||||
const settingsVisible = ref(false);
|
const settingsVisible = ref(false);
|
||||||
// 是否显示标签视图
|
// 标签
|
||||||
const tagsView = useStorage<boolean>("tagsView", defaultSettings.tagsView);
|
const tagsView = useStorage<boolean>("tagsView", defaultSettings.tagsView);
|
||||||
// 是否显示侧边栏logo
|
// 侧边栏 Logo
|
||||||
const sidebarLogo = useStorage<boolean>(
|
const sidebarLogo = useStorage<boolean>(
|
||||||
"sidebarLogo",
|
"sidebarLogo",
|
||||||
defaultSettings.sidebarLogo
|
defaultSettings.sidebarLogo
|
||||||
);
|
);
|
||||||
// 是否固定头部
|
// 固定头部
|
||||||
const fixedHeader = useStorage<boolean>(
|
const fixedHeader = useStorage<boolean>(
|
||||||
"fixedHeader",
|
"fixedHeader",
|
||||||
defaultSettings.fixedHeader
|
defaultSettings.fixedHeader
|
||||||
);
|
);
|
||||||
// 布局模式:left-左侧模式(默认) top-顶部模式 mix-混合模式
|
// 布局
|
||||||
const layout = useStorage<string>("layout", defaultSettings.layout);
|
const layout = useStorage<string>("layout", defaultSettings.layout);
|
||||||
// 主题颜色
|
// 水印
|
||||||
const themeColor = useStorage<string>(
|
|
||||||
"themeColor",
|
|
||||||
defaultSettings.themeColor
|
|
||||||
);
|
|
||||||
// 主题:light-亮色(默认) dark-暗色
|
|
||||||
const theme = useStorage<string>("theme", defaultSettings.theme);
|
|
||||||
// 是否开启水印
|
|
||||||
const watermarkEnabled = useStorage<boolean>(
|
const watermarkEnabled = useStorage<boolean>(
|
||||||
"watermarkEnabled",
|
"watermarkEnabled",
|
||||||
defaultSettings.watermarkEnabled
|
defaultSettings.watermarkEnabled
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 主题
|
||||||
|
const themeColor = useStorage<string>(
|
||||||
|
"themeColor",
|
||||||
|
defaultSettings.themeColor
|
||||||
|
);
|
||||||
|
const theme = useStorage<string>("theme", defaultSettings.theme);
|
||||||
|
|
||||||
|
// 监听主题变化
|
||||||
watch(
|
watch(
|
||||||
[theme, themeColor],
|
[theme, themeColor],
|
||||||
([newTheme, newThemeColor], [oldTheme, oldThemeColor]) => {
|
([newTheme, newThemeColor]) => {
|
||||||
if (newTheme !== oldTheme) {
|
toggleDarkMode(newTheme === ThemeEnum.DARK);
|
||||||
if (newTheme === ThemeEnum.DARK) {
|
const colors = generateThemeColors(newThemeColor);
|
||||||
document.documentElement.classList.add("dark");
|
applyTheme(colors);
|
||||||
} else {
|
|
||||||
document.documentElement.classList.remove("dark");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newThemeColor !== oldThemeColor) {
|
|
||||||
const rootStyle = document.documentElement.style;
|
|
||||||
rootStyle.setProperty(`--el-color-primary`, newThemeColor);
|
|
||||||
rootStyle.setProperty(`--el-color-primary-dark-2`, newThemeColor);
|
|
||||||
|
|
||||||
for (let i = 1; i < 10; i++) {
|
|
||||||
rootStyle.setProperty(
|
|
||||||
`--el-color-primary-light-${i}`,
|
|
||||||
`${Color(newThemeColor).alpha(1 - i * 0.1)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{ immediate: true }
|
||||||
immediate: true, // 立即执行,确保在侦听器创建时执行一次
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
// 设置更改函数
|
||||||
const settingsMap: Record<string, Ref<SettingsValue>> = {
|
const settingsMap: Record<string, Ref<SettingsValue>> = {
|
||||||
fixedHeader,
|
fixedHeader,
|
||||||
tagsView,
|
tagsView,
|
||||||
@@ -79,31 +61,17 @@ export const useSettingsStore = defineStore("setting", () => {
|
|||||||
value: SettingsValue;
|
value: SettingsValue;
|
||||||
}) {
|
}) {
|
||||||
const setting = settingsMap[key];
|
const setting = settingsMap[key];
|
||||||
if (setting) {
|
if (setting) setting.value = value;
|
||||||
setting.value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换主题
|
|
||||||
*/
|
|
||||||
function changeTheme(val: string) {
|
function changeTheme(val: string) {
|
||||||
theme.value = val;
|
theme.value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换主题颜色
|
|
||||||
*
|
|
||||||
* @param color 主题颜色
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function changeThemeColor(color: string) {
|
function changeThemeColor(color: string) {
|
||||||
themeColor.value = color;
|
themeColor.value = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换布局
|
|
||||||
*/
|
|
||||||
function changeLayout(val: string) {
|
function changeLayout(val: string) {
|
||||||
layout.value = val;
|
layout.value = val;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,23 @@
|
|||||||
|
@forward "element-plus/theme-chalk/src/common/var.scss" with (
|
||||||
|
$colors: (
|
||||||
|
"primary": (
|
||||||
|
"base": #4080ff,
|
||||||
|
),
|
||||||
|
"success": (
|
||||||
|
"base": #23c343,
|
||||||
|
),
|
||||||
|
"warning": (
|
||||||
|
"base": #ff9a2e,
|
||||||
|
),
|
||||||
|
"danger": (
|
||||||
|
"base": #f76560,
|
||||||
|
),
|
||||||
|
"info": (
|
||||||
|
"base": #a9aeb8,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
/** 全局SCSS变量 */
|
/** 全局SCSS变量 */
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
访问趋势
|
访问趋势
|
||||||
<el-tooltip effect="dark" content="点击试试下载" placement="bottom">
|
<el-tooltip effect="dark" content="点击试试下载" placement="bottom">
|
||||||
<i-ep-download
|
<i-ep-download
|
||||||
class="cursor-pointer hover:color-#409eff ml-1"
|
class="cursor-pointer hover:color-#4080FF ml-1"
|
||||||
@click="handleDownloadChart"
|
@click="handleDownloadChart"
|
||||||
/>
|
/>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
@@ -99,10 +99,10 @@ const setChartOptions = (data: VisitTrendVO) => {
|
|||||||
},
|
},
|
||||||
smooth: true,
|
smooth: true,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: "#409EFF",
|
color: "#4080FF",
|
||||||
},
|
},
|
||||||
lineStyle: {
|
lineStyle: {
|
||||||
color: "#409EFF",
|
color: "#4080FF",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,7 +85,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|||||||
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
|
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
|
||||||
resolvers: [
|
resolvers: [
|
||||||
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
|
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
|
||||||
ElementPlusResolver(),
|
ElementPlusResolver({
|
||||||
|
importStyle: "sass",
|
||||||
|
}),
|
||||||
// 自动导入图标组件
|
// 自动导入图标组件
|
||||||
IconsResolver({}),
|
IconsResolver({}),
|
||||||
],
|
],
|
||||||
@@ -105,7 +107,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|||||||
Components({
|
Components({
|
||||||
resolvers: [
|
resolvers: [
|
||||||
// 自动导入 Element Plus 组件
|
// 自动导入 Element Plus 组件
|
||||||
ElementPlusResolver(),
|
ElementPlusResolver({
|
||||||
|
importStyle: "sass",
|
||||||
|
}),
|
||||||
// 自动注册图标组件
|
// 自动注册图标组件
|
||||||
IconsResolver({
|
IconsResolver({
|
||||||
// element-plus图标库,其他图标库 https://icon-sets.iconify.design/
|
// element-plus图标库,其他图标库 https://icon-sets.iconify.design/
|
||||||
|
|||||||
Reference in New Issue
Block a user