From c3d0102cdad95e2a204c45bcb7f16838359650cf Mon Sep 17 00:00:00 2001 From: Vben Date: Sat, 14 Sep 2024 21:35:12 +0800 Subject: [PATCH] fix: the brand color setting does not take effect (#4405) --- .../@core/base/shared/src/color/generator.ts | 1 + .../shared/src/utils/__tests__/window.test.ts | 2 +- .../preferences/src/update-css-variables.ts | 29 ++++++++++--------- .../src/modal/__tests__/modal-api.test.ts | 2 +- .../components/ui/dialog/DialogContent.vue | 4 ++- .../components/ui/dialog/DialogOverlay.vue | 2 +- .../src/components/ui/sheet/SheetContent.vue | 4 ++- .../src/components/ui/sheet/SheetOverlay.vue | 2 +- packages/stores/src/modules/lock.test.ts | 1 - packages/stores/src/modules/tabbar.test.ts | 13 ++++----- packages/stores/src/modules/user.test.ts | 2 +- .../helpers/__tests__/generate-menus.test.ts | 11 +++---- playground/src/preferences.ts | 1 + .../demos/features/login-expired/index.vue | 2 +- 14 files changed, 39 insertions(+), 37 deletions(-) diff --git a/packages/@core/base/shared/src/color/generator.ts b/packages/@core/base/shared/src/color/generator.ts index c7a5cbb2..ac7bd8ad 100644 --- a/packages/@core/base/shared/src/color/generator.ts +++ b/packages/@core/base/shared/src/color/generator.ts @@ -14,6 +14,7 @@ function generatorColorVariables(colorItems: ColorItem[]) { colorItems.forEach(({ alias, color, name }) => { if (color) { const colorsMap = getColors(new TinyColor(color).toHexString()); + let mainColor = colorsMap['500']; const colorKeys = Object.keys(colorsMap); diff --git a/packages/@core/base/shared/src/utils/__tests__/window.test.ts b/packages/@core/base/shared/src/utils/__tests__/window.test.ts index 69ad4f7d..ebb04bb0 100644 --- a/packages/@core/base/shared/src/utils/__tests__/window.test.ts +++ b/packages/@core/base/shared/src/utils/__tests__/window.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { openWindow } from '../window'; // 假设你的函数在 'openWindow' 文件中 +import { openWindow } from '../window'; describe('openWindow', () => { // 保存原始的 window.open 函数 diff --git a/packages/@core/preferences/src/update-css-variables.ts b/packages/@core/preferences/src/update-css-variables.ts index 507da91c..ae6f7e5e 100644 --- a/packages/@core/preferences/src/update-css-variables.ts +++ b/packages/@core/preferences/src/update-css-variables.ts @@ -86,21 +86,22 @@ function updateMainColorVariables(preference: Preferences) { { alias: 'destructive', color: colorDestructive, name: 'red' }, ]); - if (colorPrimary) { - const mainColor = colorVariables['--primary-500']; - mainColor && - document.documentElement.style.setProperty('--primary', mainColor); - } + // 要设置的 CSS 变量映射 + const colorMappings = { + '--green-500': '--success', + '--primary-500': '--primary', + '--red-500': '--destructive', + '--yellow-500': '--warning', + }; + + // 统一处理颜色变量的更新 + Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => { + const colorValue = colorVariables[sourceVar]; + if (colorValue) { + document.documentElement.style.setProperty(targetVar, colorValue); + } + }); - if (colorVariables['--green-500']) { - colorVariables['--success'] = colorVariables['--green-500']; - } - if (colorVariables['--yellow-500']) { - colorVariables['--warning'] = colorVariables['--yellow-500']; - } - if (colorVariables['--red-500']) { - colorVariables['--destructive'] = colorVariables['--red-500']; - } executeUpdateCSSVariables(colorVariables); } diff --git a/packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts b/packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts index 41ca2ad1..e12b144f 100644 --- a/packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts +++ b/packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts @@ -1,7 +1,7 @@ import type { ModalState } from '../modal'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -// 假设 ModalApi 位于同一目录 + import { ModalApi } from '../modal-api'; vi.mock('@vben-core/shared/store', () => { diff --git a/packages/@core/ui-kit/shadcn-ui/src/components/ui/dialog/DialogContent.vue b/packages/@core/ui-kit/shadcn-ui/src/components/ui/dialog/DialogContent.vue index 3f12dc16..233a2778 100644 --- a/packages/@core/ui-kit/shadcn-ui/src/components/ui/dialog/DialogContent.vue +++ b/packages/@core/ui-kit/shadcn-ui/src/components/ui/dialog/DialogContent.vue @@ -52,7 +52,9 @@ defineExpose({