diff --git a/src/App.vue b/src/App.vue index 0665a5a..c6e0814 100644 --- a/src/App.vue +++ b/src/App.vue @@ -27,13 +27,16 @@ import { Layers, PanelLeftClose, PanelLeftOpen, + PanelRightClose, + PanelRightOpen, Settings2, X } from '@lucide/vue' import ActionMessageProvider from './components/ui/ActionMessageProvider.vue' import { AppDialog, StudioLogo } from './components/ui' import { useTheme } from './composables/useTheme' -import ThemeToggle from './components/ui/ThemeToggle.vue' +import { useWorkspaceLayout } from './composables/useWorkspaceLayout' +import ThemeAppearanceControls from './components/ui/ThemeAppearanceControls.vue' import { projectAccessKey, type ProjectAccess } from './features/projects/access' /** 窄屏将侧栏改为全屏覆盖层,关闭后不再占用正文宽度。 */ @@ -98,7 +101,15 @@ const navToggleLabel = computed(() => { if (narrow.value) return collapsed.value ? '打开主菜单' : '关闭主菜单' return collapsed.value ? '展开侧栏' : '折叠侧栏' }) -const { preference, theme, overrides } = useTheme() +/** 工作台顶栏与全局组件共用的外观偏好。 */ +const { preference, accent, theme, overrides } = useTheme() +/** 布局切换只移动同一份导航和内容容器,保留当前页面的交互状态。 */ +const workspaceLayout = useWorkspaceLayout() +/** 侧栏折叠图标跟随导航所在位置。 */ +const navToggleIcon = computed(() => { + if (workspaceLayout.value === 'right') return collapsed.value ? PanelRightOpen : PanelRightClose + return collapsed.value ? PanelLeftOpen : PanelLeftClose +}) const projectId = computed(() => String(route.params.projectId || '')) const projectAccess = shallowRef(null) provide(projectAccessKey, projectAccess) @@ -206,6 +217,7 @@ const menuOptions = computed(() => {
-
+ +
(() => { aria-controls="main-navigation" @click="toggleNav" > - + {{ route.meta.title || '工作空间' }}
- + +
@@ -325,6 +342,9 @@ const menuOptions = computed(() => { --admin-sider-expanded: 208px; @apply flex h-dvh overflow-hidden; } +.admin-layout.is-nav-right { + flex-direction: row-reverse; +} .admin-main { @apply min-w-0 h-full flex-1; } @@ -413,9 +433,17 @@ const menuOptions = computed(() => { } .admin-topbar { @apply relative z-10 flex items-center justify-between shrink-0 h-11 py-0 pl-5 gap-3 bg-(--app-surface); - /* 主题切换按钮与项目配置、内容工具栏共用右侧对齐线。 */ + /* 外观工具栏与项目操作区共用边距。 */ padding-right: var(--app-content-padding); } +/* 主导航移到右侧时,两组顶栏内容对调,折叠按钮贴近导航。 */ +.is-nav-right .admin-topbar, +.is-nav-right .admin-topbar-navigation { + flex-direction: row-reverse; +} +.is-nav-right .admin-topbar { + padding-left: var(--app-content-padding); +} .admin-sider .n-menu-divider { @apply h-3 bg-transparent; } @@ -426,6 +454,7 @@ const menuOptions = computed(() => { @media (min-width: 801px) { .admin-sider.is-collapsed { --admin-nav-reveal-width: 160px; + --admin-nav-reveal-offset: -6px; --admin-nav-hover-color: #111111; position: relative; z-index: 30; @@ -472,7 +501,7 @@ const menuOptions = computed(() => { } .admin-sider.is-collapsed .admin-menu-label, .admin-sider.is-collapsed .admin-settings-label { - transform: translateX(-6px); + transform: translateX(var(--admin-nav-reveal-offset)); } .admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .n-menu-item-content-header, .admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .admin-settings-label { @@ -528,6 +557,51 @@ const menuOptions = computed(() => { .admin-sider.is-collapsed .admin-settings-button .n-button__border { right: calc(var(--admin-nav-reveal-width) - var(--admin-sider-collapsed)); } + /* 右侧折叠导航悬停时显示贯穿视口的浮层,并预留完整菜单宽度。 */ + .is-nav-right .admin-sider.is-collapsed { + --admin-nav-reveal-width: var(--admin-sider-expanded); + --admin-nav-reveal-offset: 6px; + } + .is-nav-right .admin-sider.is-collapsed::before { + inset: 0 var(--admin-sider-collapsed) 0 auto; + } + .is-nav-right .admin-sider.is-collapsed .admin-nav-scroll.n-scrollbar, + .is-nav-right .admin-sider.is-collapsed .admin-sider-footer { + align-self: flex-end; + clip-path: inset(0 0 0 calc(var(--admin-nav-reveal-width) - var(--admin-sider-collapsed))); + } + .is-nav-right .admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .admin-nav-scroll.n-scrollbar, + .is-nav-right .admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .admin-sider-footer { + clip-path: inset(0); + } + .is-nav-right .admin-sider.is-collapsed .n-menu-item-content { + grid-template-areas: 'arrow content icon'; + grid-template-columns: auto 1fr auto; + padding-left: var(--app-content-padding) !important; + padding-right: calc((var(--admin-sider-collapsed) - 20px) / 2); + text-align: right; + } + .is-nav-right .admin-sider.is-collapsed .admin-settings-button { + flex-direction: row-reverse; + text-align: right; + } + .is-nav-right .admin-sider.is-collapsed .n-menu-item-content__icon { + margin-right: 0 !important; + margin-left: 34px; + } + .is-nav-right .admin-sider.is-collapsed .admin-settings-button .n-button__icon { + margin-right: 0; + margin-left: 34px; + } + .is-nav-right .admin-sider.is-collapsed .admin-settings-label { + margin-left: 0; + } + .is-nav-right .admin-sider.is-collapsed .n-menu-item-content::before, + .is-nav-right .admin-sider.is-collapsed .admin-settings-button .n-button__state-border, + .is-nav-right .admin-sider.is-collapsed .admin-settings-button .n-button__border { + right: 0; + left: calc(var(--admin-nav-reveal-width) - var(--admin-sider-collapsed)); + } } @media (max-width: 800px) { .admin-sider { @@ -547,6 +621,9 @@ const menuOptions = computed(() => { transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0.28s; } + .is-nav-right .admin-sider.is-collapsed { + transform: translateX(100%); + } .admin-layout > .admin-main { @apply w-full min-w-0 max-w-full flex-1; } diff --git a/src/components/ui/ThemeAppearanceControls.vue b/src/components/ui/ThemeAppearanceControls.vue new file mode 100644 index 0000000..3e9947c --- /dev/null +++ b/src/components/ui/ThemeAppearanceControls.vue @@ -0,0 +1,270 @@ + + + + + diff --git a/src/components/ui/ThemeToggle.vue b/src/components/ui/ThemeToggle.vue index beded43..80a9c87 100644 --- a/src/components/ui/ThemeToggle.vue +++ b/src/components/ui/ThemeToggle.vue @@ -1,23 +1,72 @@ @@ -33,6 +82,7 @@ function selectTheme(key: string | number) { @select="selectTheme" > diff --git a/src/composables/themeAccents.ts b/src/composables/themeAccents.ts new file mode 100644 index 0000000..95cfa01 --- /dev/null +++ b/src/composables/themeAccents.ts @@ -0,0 +1,78 @@ +/** 主色预设的显示色和深浅背景下的操作色。 */ +interface ThemeAccentPreset { + /** 色板中展示的名称。 */ + label: string + /** 色板圆点的颜色。 */ + swatch: string + /** 带白字的主按钮底色。 */ + action: string + /** 暗色表面上的强调文字。 */ + darkText: string +} + +/** 顶栏提供与 Vben 色板对应的七种主色,保留工作台原有的品牌绿。 */ +export const themeAccents = { + blue: { label: '蓝色', swatch: '#0070e6', action: '#005cbd', darkText: '#8ebdff' }, + violet: { label: '紫色', swatch: '#7465f0', action: '#6246c9', darkText: '#b8aaff' }, + pink: { label: '玫红', swatch: '#e94a6c', action: '#bd3154', darkText: '#ff9db2' }, + yellow: { label: '金黄', swatch: '#efbd48', action: '#865b00', darkText: '#f5cf71' }, + indigo: { label: '靛蓝', swatch: '#4e66fc', action: '#4053ce', darkText: '#a7b4ff' }, + green: { label: '绿色', swatch: '#07c160', action: '#078640', darkText: '#5cd693' }, + zinc: { label: '石墨灰', swatch: '#3f3f46', action: '#52525b', darkText: '#d4d4d8' } +} satisfies Record + +/** 用于保存和恢复主色选择的预设标识。 */ +export type ThemeAccent = keyof typeof themeAccents + +/** + * 在 sRGB 空间混合两种十六进制颜色,生成可传给 Naive UI 的不透明色值。 + * @param base 基础颜色 + * @param tint 混入的颜色 + * @param weight 混入颜色的比例 + * @returns 六位十六进制色值 + */ +function mixColor(base: string, tint: string, weight: number) { + const channels = [1, 3, 5].map(index => { + const start = Number.parseInt(base.slice(index, index + 2), 16) + const end = Number.parseInt(tint.slice(index, index + 2), 16) + return Math.round(start + (end - start) * weight) + .toString(16) + .padStart(2, '0') + }) + return `#${channels.join('')}` +} + +/** + * 生成业务样式和 Naive UI 共用的主色,延续默认绿色的原有色阶。 + * @param accent 主色预设 + * @param dark 当前是否使用暗色模式 + * @returns 主色、强调文字、选中背景和按钮状态颜色 + */ +export function resolveThemeAccent(accent: ThemeAccent, dark: boolean) { + const { action, darkText, swatch } = themeAccents[accent] + if (accent === 'green') { + return { + primary: swatch, + hover: '#2dcb79', + pressed: '#06ad56', + text: dark ? darkText : '#087c42', + selected: dark ? '#173527' : '#e4f4e9', + button: action, + buttonHover: '#087c42', + buttonPressed: '#066b36' + } + } + const primary = dark ? darkText : action + const buttonHover = mixColor(action, '#000000', 0.12) + const buttonPressed = mixColor(action, '#000000', 0.24) + return { + primary, + hover: dark ? mixColor(primary, '#ffffff', 0.18) : buttonHover, + pressed: dark ? mixColor(primary, '#000000', 0.12) : buttonPressed, + text: primary, + selected: mixColor(dark ? '#191919' : '#ffffff', primary, dark ? 0.17 : 0.09), + button: action, + buttonHover, + buttonPressed + } +} diff --git a/src/composables/useTheme.ts b/src/composables/useTheme.ts index 4d5fdda..2ebeb2e 100644 --- a/src/composables/useTheme.ts +++ b/src/composables/useTheme.ts @@ -1,11 +1,16 @@ import { computed, onScopeDispose, ref, watchEffect } from 'vue' import { darkTheme, type GlobalThemeOverrides } from 'naive-ui' +import { resolveThemeAccent, themeAccents, type ThemeAccent } from './themeAccents' /** 用户主题偏好;system 会跟随系统的实时深浅色变化。 */ export type ThemePreference = 'light' | 'dark' | 'system' const storageKey = 'drama-studio-theme' +const accentStorageKey = 'drama-studio-accent' -/** 读取主题时兼容隐私模式或禁用存储的浏览器。 */ +/** + * 读取明暗偏好,兼容禁用存储的浏览器。 + * @returns 已保存的模式或系统模式 + */ function readPreference(): ThemePreference { try { const value = localStorage.getItem(storageKey) @@ -15,33 +20,60 @@ function readPreference(): ThemePreference { } } -/** 主题只影响展示,不修改项目配置;卸载时移除系统主题监听。 */ +/** + * 读取主色偏好,忽略不存在的预设和不可用的存储。 + * @returns 已保存的主色或默认绿色 + */ +function readAccent(): ThemeAccent { + try { + const value = localStorage.getItem(accentStorageKey) + if (value && Object.hasOwn(themeAccents, value)) return value as ThemeAccent + } catch { + /* 存储不可用时使用默认主色。 */ + } + return 'green' +} + +/** + * 同步工作台、Naive UI 和浏览器的主题,卸载时释放系统主题监听。 + * @returns 明暗与主色偏好、实际明暗状态和 Naive UI 主题配置 + */ export function useTheme() { + /** 用户选择的明暗模式。 */ const preference = ref(readPreference()) + /** 用户独立选择的主色。 */ + const accent = ref(readAccent()) const media = window.matchMedia('(prefers-color-scheme: dark)') + /** 浏览器报告的当前系统明暗状态。 */ const systemDark = ref(media.matches) + /** 当前生效的明暗状态。 */ const isDark = computed(() => preference.value === 'dark' || (preference.value === 'system' && systemDark.value)) + /** 当前生效的全局主色色阶。 */ + const palette = computed(() => resolveThemeAccent(accent.value, isDark.value)) + /** 当前生效的 Naive UI 基础主题。 */ const theme = computed(() => (isDark.value ? darkTheme : null)) + /** 与业务颜色共用同一套主色,并独立设置成功、警告与错误状态色。 */ const overrides = computed(() => { const dark = isDark.value - // 微信风格灰阶表面与绿色操作态;文字绿独立加深,避免浅底小字对比不足。 - const primary = '#07c160' - const hover = '#2dcb79' - const pressed = '#06ad56' - // 实心绿按钮使用白字;按钮底色独立于品牌绿,兼顾正常、悬停和按下态的可读性。 + const { + primary, + hover, + pressed, + text: accentText, + selected, + button: buttonPrimary, + buttonHover, + buttonPressed + } = palette.value const onPrimary = '#ffffff' - const buttonPrimary = '#078640' - const buttonHover = '#087c42' - const buttonPressed = '#066b36' const disabledColor = dark ? '#303030' : '#e4e4e4' const disabledText = dark ? '#808080' : '#8c8c8c' - const accentText = dark ? '#5cd693' : '#087c42' + const success = dark ? '#5cd693' : '#087c42' const body = dark ? '#111111' : '#ffffff' const surface = dark ? '#191919' : '#ffffff' const subtle = dark ? '#232323' : '#f7f7f7' const text = dark ? '#d9d9d9' : '#191919' const muted = dark ? '#a3a3a3' : '#707070' - const selected = dark ? '#173527' : '#e4f4e9' const info = dark ? '#91a8d2' : '#576b95' const danger = dark ? '#fa7373' : '#a93232' const warning = dark ? '#e8b66a' : '#916019' @@ -67,10 +99,10 @@ export function useTheme() { infoColorHover: info, infoColorPressed: info, infoColorSuppl: info, - successColor: accentText, - successColorHover: accentText, - successColorPressed: accentText, - successColorSuppl: accentText, + successColor: success, + successColorHover: success, + successColorPressed: success, + successColorSuppl: success, errorColor: danger, errorColorHover: danger, errorColorPressed: danger, @@ -130,10 +162,10 @@ export function useTheme() { textColorDisabledPrimary: disabledText, textColorTextPrimary: accentText, textColorGhostPrimary: accentText, - colorSuccess: buttonPrimary, - colorHoverSuccess: buttonHover, - colorPressedSuccess: buttonPressed, - colorFocusSuccess: buttonHover, + colorSuccess: '#078640', + colorHoverSuccess: '#087c42', + colorPressedSuccess: '#066b36', + colorFocusSuccess: '#087c42', colorDisabledSuccess: disabledColor, borderSuccess: 'none', borderHoverSuccess: 'none', @@ -145,8 +177,8 @@ export function useTheme() { textColorPressedSuccess: onPrimary, textColorFocusSuccess: onPrimary, textColorDisabledSuccess: disabledText, - textColorTextSuccess: accentText, - textColorGhostSuccess: accentText + textColorTextSuccess: success, + textColorGhostSuccess: success }, Form: { labelFontSizeTopMedium: '12px', @@ -226,7 +258,7 @@ export function useTheme() { tabTextColorActiveLine: accentText, tabTextColorHoverLine: accentText, barColor: primary, - // Tabs 保留横向分隔线,明确导航与内容边界;选中下划线仍使用主绿色。 + // Tabs 保留横向分隔线,选中下划线使用当前主色。 tabBorderColor: dark ? '#333333' : '#dadada' }, Tag: { @@ -240,12 +272,15 @@ export function useTheme() { borderWarning: 'none', borderError: 'none' }, - Checkbox: { checkMarkColor: '#ffffff' }, + Checkbox: { colorChecked: buttonPrimary, checkMarkColor: '#ffffff' }, Switch: { railColorActive: primary }, Progress: { fillColor: primary } } satisfies GlobalThemeOverrides }) - /** 系统切换只更新 system 模式下的实际显示。 */ + /** + * 接收系统主题变化。 + * @param event 系统主题媒体查询事件 + */ function syncSystem(event: MediaQueryListEvent) { systemDark.value = event.matches } @@ -263,5 +298,21 @@ export function useTheme() { /* 存储不可用时保留当前会话偏好。 */ } }) - return { preference, isDark, theme, overrides } + watchEffect(() => { + const colors = palette.value + const style = document.documentElement.style + style.setProperty('--app-accent', colors.primary) + style.setProperty('--app-accent-hover', colors.hover) + style.setProperty('--app-accent-text', colors.text) + style.setProperty('--app-selected', colors.selected) + style.setProperty('--app-button-primary', colors.button) + style.setProperty('--app-button-hover', colors.buttonHover) + style.setProperty('--app-button-pressed', colors.buttonPressed) + try { + localStorage.setItem(accentStorageKey, accent.value) + } catch { + /* 存储不可用时保留当前会话偏好。 */ + } + }) + return { preference, accent, isDark, theme, overrides } } diff --git a/src/composables/useWorkspaceLayout.ts b/src/composables/useWorkspaceLayout.ts new file mode 100644 index 0000000..b35c3e9 --- /dev/null +++ b/src/composables/useWorkspaceLayout.ts @@ -0,0 +1,36 @@ +import { ref, watch } from 'vue' + +/** 全局工作台主导航所在的一侧。 */ +export type WorkspaceLayout = 'left' | 'right' + +const storageKey = 'drama-studio-workspace-layout' + +/** + * 读取工作台布局,缺少偏好或无法访问存储时使用左侧导航。 + * @returns 已保存的主导航位置 + */ +function readLayout(): WorkspaceLayout { + try { + if (localStorage.getItem(storageKey) === 'right') return 'right' + } catch { + /* 存储不可用时使用默认布局。 */ + } + return 'left' +} + +/** + * 保存工作台布局偏好,存储不可用时仍允许在当前页面切换。 + * @returns 当前主导航位置 + */ +export function useWorkspaceLayout() { + /** 侧栏和外观工具栏共用的布局偏好。 */ + const layout = ref(readLayout()) + watch(layout, value => { + try { + localStorage.setItem(storageKey, value) + } catch { + /* 存储不可用时保留当前会话的选择。 */ + } + }) + return layout +} diff --git a/src/features/projects/ProjectLayout.vue b/src/features/projects/ProjectLayout.vue index fb7d2ca..fb1c051 100644 --- a/src/features/projects/ProjectLayout.vue +++ b/src/features/projects/ProjectLayout.vue @@ -433,6 +433,23 @@ onScopeDispose(() => { .project-header .n-page-header__extra { @apply flex items-center; } +/* 右侧布局让返回按钮和项目名称靠近导航,项目操作放到左侧。 */ +.is-nav-right .project-header .n-page-header, +.is-nav-right .project-header .n-page-header__main { + flex-direction: row-reverse; +} +.is-nav-right .project-header .n-page-header__back, +.is-nav-right .project-header .n-page-header__title { + margin-right: 0; + margin-left: 16px; +} +/* 返回入口靠右时,箭头指向右侧导航。 */ +.is-nav-right .project-header .n-page-header__back svg { + transform: scaleX(-1); +} +.is-nav-right .project-header .n-page-header__title { + text-align: right; +} .project-title { @apply block max-w-full text-base font-semibold leading-normal; } diff --git a/tests/components/ui/flatTheme.test.ts b/tests/components/ui/flatTheme.test.ts index 5628f61..314616d 100644 --- a/tests/components/ui/flatTheme.test.ts +++ b/tests/components/ui/flatTheme.test.ts @@ -26,7 +26,7 @@ afterEach(() => { wrapper = undefined localStorage.clear() delete document.documentElement.dataset.theme - document.documentElement.style.colorScheme = '' + document.documentElement.removeAttribute('style') vi.unstubAllGlobals() }) diff --git a/tests/components/ui/layout.test.ts b/tests/components/ui/layout.test.ts index 4657653..39cdc97 100644 --- a/tests/components/ui/layout.test.ts +++ b/tests/components/ui/layout.test.ts @@ -188,6 +188,7 @@ describe('管理后台组件边界', () => { return option!.icon() } expect(firstMenuIcon().type).not.toBe(NPopover) + expect(wrapper.get('.admin-sider-footer').findComponent(NPopover).exists()).toBe(false) expect(wrapper.get('[aria-label="折叠侧栏"] svg').classes()).toContain('lucide-panel-left-close') expect(wrapper.findAll('.studio-logo svg')).toHaveLength(2) @@ -219,6 +220,26 @@ describe('管理后台组件边界', () => { '分镜设计', '镜头生产' ]) + // 切换布局时保留分镜工作区的 DOM,刷新后从已保存的偏好恢复。 + const workspace = wrapper.get('#main-content .workspace-page').element + const layoutToggle = wrapper.get('.workspace-layout-toggle') + await layoutToggle.trigger('click') + await flushPromises() + const layoutOptions = [...document.querySelectorAll('.n-dropdown-option-body')] + .filter(option => option.closest('.n-dropdown-menu')) + .filter(option => ['居左', '居右', '居中'].includes(option.textContent?.trim() ?? '')) + expect(layoutOptions.map(option => option.textContent?.trim())).toEqual(['居左', '居右']) + layoutOptions[1]!.click() + await flushPromises() + expect(wrapper.get('.admin-layout').classes()).toContain('is-nav-right') + expect(wrapper.get('#main-content .workspace-page').element).toBe(workspace) + expect(layoutToggle.attributes('aria-label')).toBe('工作台布局:居右') + expect(wrapper.get('[aria-label="展开侧栏"] svg').classes()).toContain('lucide-panel-right-open') + wrapper.unmount() + wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } }) + await flushPromises() + expect(wrapper.get('.admin-layout').classes()).toContain('is-nav-right') + const settings = wrapper.get('.admin-sider-footer [aria-label="连接设置"]') expect(settings.text()).toBe('连接设置') await settings.trigger('click') @@ -254,7 +275,9 @@ describe('管理后台组件边界', () => { expect(css).toContain('@media (prefers-reduced-motion: reduce)') expect(css).toContain('.admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .n-menu-item-content-header') expect(css).toContain('clip-path: inset(0);') - expect(css).toContain('transform: translateX(-6px);') + expect(css).toContain('transform: translateX(var(--admin-nav-reveal-offset));') + expect(css).toContain('--admin-nav-reveal-offset: -6px;') + expect(css).toContain('--admin-nav-reveal-offset: 6px;') expect(css).not.toContain('.admin-sider-mask') expect(css).not.toContain('.admin-sider.is-overlay') for (const path of ['storyboard/StoryboardPage.vue', 'production/ProductionPage.vue']) { diff --git a/tests/composables/useTheme.test.ts b/tests/composables/useTheme.test.ts index 36abd49..ed2a467 100644 --- a/tests/composables/useTheme.test.ts +++ b/tests/composables/useTheme.test.ts @@ -9,7 +9,7 @@ afterEach(() => { scope = undefined localStorage.clear() delete document.documentElement.dataset.theme - document.documentElement.style.colorScheme = '' + document.documentElement.removeAttribute('style') vi.unstubAllGlobals() vi.restoreAllMocks() }) @@ -152,6 +152,45 @@ describe('微信风格明暗主题', () => { expect(contrast(tokens['accent-text']!, tokens.selected!)).toBeGreaterThanOrEqual(4.5) }) + it('主色同步到 Naive 和业务样式,刷新后与明暗偏好分别恢复', async () => { + const state = setup() + state.accent.value = 'blue' + await nextTick() + const root = document.documentElement + const blue = state.overrides.value.common!.primaryColor! + expect(blue).not.toBe('#07c160') + expect(root.style.getPropertyValue('--app-accent')).toBe(blue) + expect(root.style.getPropertyValue('--app-button-primary')).toBe(state.overrides.value.Button?.colorPrimary) + expect(state.overrides.value.common?.successColor).toBe('#087c42') + state.preference.value = 'dark' + await nextTick() + const darkBlue = state.overrides.value.common!.primaryColor + expect(darkBlue).not.toBe(blue) + scope!.stop() + const restored = setup() + expect(restored.accent.value).toBe('blue') + expect(restored.isDark.value).toBe(true) + expect(restored.overrides.value.common?.primaryColor).toBe(darkBlue) + expect(restored.overrides.value.common?.successColor).toBe('#5cd693') + restored.accent.value = 'green' + await nextTick() + expect(root.style.getPropertyValue('--app-accent')).toBe('#07c160') + }) + + it.each([false, true])('明暗模式 %s 下所有预设的按钮白字和选中文字对比度充足', dark => { + const state = setup(dark) + for (const accent of ['blue', 'violet', 'pink', 'yellow', 'indigo', 'green', 'zinc'] as const) { + state.accent.value = accent + const { Button, Menu } = state.overrides.value + for (const background of [Button!.colorPrimary, Button!.colorHoverPrimary, Button!.colorPressedPrimary]) { + expect(contrast(String(Button!.textColorPrimary), String(background))).toBeGreaterThanOrEqual(4.5) + } + expect(contrast(String(Menu!.itemTextColorActive), String(Menu!.itemColorActive))).toBeGreaterThanOrEqual( + 4.5 + ) + } + }) + it('系统切换时浏览器主题色与页面同步', async () => { const meta = document.createElement('meta') meta.name = 'theme-color'