From 0b8e10f9647baa3d34330849178450b3406a45ec Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Fri, 9 Dec 2022 20:38:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9A=97=E9=BB=91?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/optimize.ts | 1 - package.json | 1 - pnpm-lock.yaml | 2 -- src/layout/hooks/useDataThemeChange.ts | 29 ++++++++++------------------- src/style/dark.scss | 2 +- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/build/optimize.ts b/build/optimize.ts index 99e2ba9..f81694b 100644 --- a/build/optimize.ts +++ b/build/optimize.ts @@ -17,7 +17,6 @@ const include = [ "lodash-es", "@vueuse/core", "lodash-unified", - "@ctrl/tinycolor", "@pureadmin/utils", "responsive-storage", "element-resize-detector" diff --git a/package.json b/package.json index 8c95602..2d7bad8 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "not op_mini all" ], "dependencies": { - "@ctrl/tinycolor": "^3.4.1", "@pureadmin/descriptions": "^1.1.0", "@pureadmin/table": "^1.9.0", "@pureadmin/utils": "^1.8.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6308582..3c5c360 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,7 +3,6 @@ lockfileVersion: 5.4 specifiers: "@commitlint/cli": 13.1.0 "@commitlint/config-conventional": 13.1.0 - "@ctrl/tinycolor": ^3.4.1 "@iconify-icons/ep": ^1.2.7 "@iconify-icons/ri": ^1.2.3 "@iconify/vue": ^4.0.0 @@ -90,7 +89,6 @@ specifiers: vue-types: ^4.2.1 dependencies: - "@ctrl/tinycolor": 3.5.0 "@pureadmin/descriptions": 1.1.1_element-plus@2.2.26 "@pureadmin/table": 1.9.0_element-plus@2.2.26 "@pureadmin/utils": 1.8.2_echarts@5.4.0+vue@3.2.45 diff --git a/src/layout/hooks/useDataThemeChange.ts b/src/layout/hooks/useDataThemeChange.ts index a4089b2..0dde987 100644 --- a/src/layout/hooks/useDataThemeChange.ts +++ b/src/layout/hooks/useDataThemeChange.ts @@ -3,7 +3,6 @@ import { getConfig } from "@/config"; import { find } from "lodash-unified"; import { useLayout } from "./useLayout"; import { themeColorsType } from "../types"; -import { TinyColor } from "@ctrl/tinycolor"; import { useGlobal } from "@pureadmin/utils"; import { useEpThemeStoreHook } from "@/store/modules/epTheme"; import { @@ -61,30 +60,22 @@ export function useDataThemeChange() { } } - /** - * @description 自动计算hover和active颜色 - * @see {@link https://element-plus.org/zh-CN/component/button.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%9C%E8%89%B2} - */ - const shadeBgColor = (color: string): string => { - return new TinyColor(color).shade(10).toString(); - }; + function setPropertyPrimary(mode: string, i: number, color: string) { + document.documentElement.style.setProperty( + `--el-color-primary-${mode}-${i}`, + dataTheme.value ? darken(color, i / 10) : lighten(color, i / 10) + ); + } /** 设置 `element-plus` 主题色 */ const setEpThemeColor = (color: string) => { useEpThemeStoreHook().setEpThemeColor(color); - body.style.setProperty("--el-color-primary-active", shadeBgColor(color)); document.documentElement.style.setProperty("--el-color-primary", color); - for (let i = 1; i <= 9; i++) { - document.documentElement.style.setProperty( - `--el-color-primary-light-${i}`, - lighten(color, i / 10) - ); - } for (let i = 1; i <= 2; i++) { - document.documentElement.style.setProperty( - `--el-color-primary-dark-${i}`, - darken(color, i / 10) - ); + setPropertyPrimary("dark", i, color); + } + for (let i = 1; i <= 9; i++) { + setPropertyPrimary("light", i, color); } }; diff --git a/src/style/dark.scss b/src/style/dark.scss index 8f2983f..3e00bd6 100644 --- a/src/style/dark.scss +++ b/src/style/dark.scss @@ -1,4 +1,4 @@ -@import "element-plus/theme-chalk/src/dark/css-vars.scss"; +@use "element-plus/theme-chalk/src/dark/css-vars.scss" as *; /* 暗黑模式适配 */ html.dark {