Skip to content

Commit

Permalink
fix: the brand color setting does not take effect (#4405)
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb authored Sep 14, 2024
1 parent 38fe642 commit c3d0102
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 37 deletions.
1 change: 1 addition & 0 deletions packages/@core/base/shared/src/color/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 函数
Expand Down
29 changes: 15 additions & 14 deletions packages/@core/preferences/src/update-css-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ defineExpose({

<template>
<DialogPortal>
<DialogOverlay v-if="open && modal" @click="() => emits('close')" />
<Transition name="fade">
<DialogOverlay v-if="open && modal" @click="() => emits('close')" />
</Transition>
<DialogContent
ref="contentRef"
v-bind="forwarded"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 bg-overlay fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);

<template>
<DialogPortal>
<SheetOverlay v-if="open && modal" />
<Transition name="fade">
<SheetOverlay v-if="open && modal" />
</Transition>
<DialogContent
:class="cn(sheetVariants({ side }), 'z-[1000]', props.class)"
v-bind="{ ...forwarded, ...$attrs }"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="bg-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>
1 change: 0 additions & 1 deletion packages/stores/src/modules/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useLockStore } from './lock';

describe('useLockStore', () => {
beforeEach(() => {
// 每个测试前重置 Pinia
setActivePinia(createPinia());
});

Expand Down
13 changes: 6 additions & 7 deletions packages/stores/src/modules/tabbar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ describe('useAccessStore', () => {
store.tabs = [
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
] as any;
router.replace = vi.fn(); // 使用 vitest 的 mock 函数
router.replace = vi.fn();

await store.closeAllTabs(router);

expect(store.tabs.length).toBe(1); // 假设没有固定的标签页
// expect(router.replace).toHaveBeenCalled();
expect(store.tabs.length).toBe(1);
});

it('closes a non-affix tab', () => {
Expand Down Expand Up @@ -161,7 +160,7 @@ describe('useAccessStore', () => {
await store._bulkCloseByPaths(['/home', '/contact']);

expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});

it('closes all tabs to the left of the specified tab', async () => {
Expand Down Expand Up @@ -189,7 +188,7 @@ describe('useAccessStore', () => {
await store.closeLeftTabs(targetTab);

expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Contact');
expect(store.tabs[0]?.name).toBe('Contact');
});

it('closes all tabs except the specified tab', async () => {
Expand Down Expand Up @@ -217,7 +216,7 @@ describe('useAccessStore', () => {
await store.closeOtherTabs(targetTab);

expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});

it('closes all tabs to the right of the specified tab', async () => {
Expand Down Expand Up @@ -245,7 +244,7 @@ describe('useAccessStore', () => {
await store.closeRightTabs(targetTab);

expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Home');
expect(store.tabs[0]?.name).toBe('Home');
});

it('closes the tab with the specified key', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/stores/src/modules/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('useUserStore', () => {
expect(store.userInfo).not.toBeNull();
expect(store.userRoles.length).toBeGreaterThan(0);

store.setUserInfo(null as any); // 重置用户信息
store.setUserInfo(null as any);
expect(store.userInfo).toBeNull();
expect(store.userRoles).toEqual([]);
});
Expand Down
11 changes: 4 additions & 7 deletions packages/utils/src/helpers/__tests__/generate-menus.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
createRouter,
createWebHistory,
type Router,
type RouteRecordRaw,
} from 'vue-router';
import type { Router, RouteRecordRaw } from 'vue-router';

import { createRouter, createWebHistory } from 'vue-router';

import { describe, expect, it, vi } from 'vitest';
// 替换为您的实际路径

import { generateMenus } from '../generate-menus';

// Nested route setup to test child inclusion and hideChildrenInMenu functionality
Expand Down
1 change: 1 addition & 0 deletions playground/src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const overridesPreferences = defineOverridesPreferences({
app: {
name: import.meta.env.VITE_APP_TITLE,
},
theme: {},
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function handleClick(type: LoginExpiredModeType) {
接口请求遇到401状态码时,需要重新登录。有两种方式:
<p>1.转到登录页,登录成功后跳转回原页面</p>
<p>
2.弹出重新登录弹窗,登录后关闭弹窗,不进行任何页面跳转(刷新后调整登录页面
2.弹出重新登录弹窗,登录后关闭弹窗,不进行任何页面跳转(刷新后还是会跳转登录页面
</p>
</div>
</template>
Expand Down

0 comments on commit c3d0102

Please sign in to comment.