feat(short-drama-agent-front): 新增全局主题和左右布局切换
This commit is contained in:
1 parent
db9aea1694
commit
27ee9fd4ff
10 files changed
+709
-41
No files matched your search
+86
-9
@@ -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<ProjectAccess | null>(null)
|
||||
provide(projectAccessKey, projectAccess)
|
||||
@@ -206,6 +217,7 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
<a href="#main-content" class="skip-link">跳到主要内容</a>
|
||||
<div
|
||||
class="admin-layout"
|
||||
:class="{ 'is-nav-right': workspaceLayout === 'right' }"
|
||||
:style="{
|
||||
'--admin-sider-collapsed': siderCollapsedWidth + 'px',
|
||||
'--admin-sider-expanded': siderExpandedWidth + 'px'
|
||||
@@ -275,7 +287,8 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
<!-- 以下是顶栏与主内容 -->
|
||||
<NLayout class="admin-main">
|
||||
<NLayoutHeader class="admin-topbar">
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<!-- 以下是靠近主导航的折叠按钮与当前页面标题。 -->
|
||||
<div class="admin-topbar-navigation flex min-w-0 items-center gap-3">
|
||||
<NButton
|
||||
quaternary
|
||||
class="icon-button"
|
||||
@@ -285,13 +298,17 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
aria-controls="main-navigation"
|
||||
@click="toggleNav"
|
||||
>
|
||||
<template #icon
|
||||
><component :is="collapsed ? PanelLeftOpen : PanelLeftClose" :size="20"
|
||||
/></template>
|
||||
<template #icon><component :is="navToggleIcon" :size="20" /></template>
|
||||
</NButton>
|
||||
<span class="truncate text-sm">{{ route.meta.title || '工作空间' }}</span>
|
||||
</div>
|
||||
<ThemeToggle v-model="preference" />
|
||||
<!-- 以下是工作台的主色、布局与明暗设置。 -->
|
||||
<ThemeAppearanceControls
|
||||
v-model="preference"
|
||||
v-model:accent="accent"
|
||||
v-model:layout="workspaceLayout"
|
||||
:compact="narrow"
|
||||
/>
|
||||
</NLayoutHeader>
|
||||
<main id="main-content" tabindex="-1" class="admin-content"><RouterView /></main>
|
||||
</NLayout>
|
||||
@@ -325,6 +342,9 @@ const menuOptions = computed<MenuOption[]>(() => {
|
||||
--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<MenuOption[]>(() => {
|
||||
}
|
||||
.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<MenuOption[]>(() => {
|
||||
@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<MenuOption[]>(() => {
|
||||
}
|
||||
.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<MenuOption[]>(() => {
|
||||
.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<MenuOption[]>(() => {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, h, ref } from 'vue'
|
||||
import { Check, Palette, PanelLeft, PanelRight } from '@lucide/vue'
|
||||
import { NButton, NDropdown, NTooltip } from 'naive-ui'
|
||||
import { themeAccents, type ThemeAccent } from '../../composables/themeAccents'
|
||||
import type { ThemePreference } from '../../composables/useTheme'
|
||||
import ThemeToggle from './ThemeToggle.vue'
|
||||
import type { WorkspaceLayout } from '../../composables/useWorkspaceLayout'
|
||||
|
||||
/** 窄屏将色板收进菜单,给页面标题保留空间。 */
|
||||
defineProps<{
|
||||
/** 是否使用窄屏色板菜单。 */
|
||||
compact: boolean
|
||||
}>()
|
||||
|
||||
/** 当前主色预设。 */
|
||||
const accent = defineModel<ThemeAccent>('accent', { required: true })
|
||||
/** 当前明暗偏好。 */
|
||||
const preference = defineModel<ThemePreference>({ required: true })
|
||||
/** 当前工作台主导航位置。 */
|
||||
const layout = defineModel<WorkspaceLayout>('layout', { required: true })
|
||||
/** 布局菜单是否展开。 */
|
||||
const layoutOpen = ref(false)
|
||||
const layoutLabels = { left: '居左', right: '居右' } satisfies Record<WorkspaceLayout, string>
|
||||
const layoutOptions = [
|
||||
{ key: 'left', label: layoutLabels.left, icon: () => h(PanelLeft, { size: 16 }) },
|
||||
{ key: 'right', label: layoutLabels.right, icon: () => h(PanelRight, { size: 16 }) }
|
||||
]
|
||||
/** 窄屏色板菜单的展开状态。 */
|
||||
const open = ref(false)
|
||||
/** 桌面色板的展开状态,同时支持悬停、键盘和触屏。 */
|
||||
const desktopOpen = ref(false)
|
||||
|
||||
const accents = Object.keys(themeAccents) as ThemeAccent[]
|
||||
/** 窄屏菜单为色板增加文字,并标记当前选中的主色。 */
|
||||
const options = computed(() =>
|
||||
accents.map(key => ({
|
||||
key,
|
||||
label: themeAccents[key].label,
|
||||
icon: () =>
|
||||
h(
|
||||
'span',
|
||||
{
|
||||
class: ['theme-accent-dot', { 'is-bright': key === 'yellow' || key === 'green' }],
|
||||
style: { backgroundColor: themeAccents[key].swatch },
|
||||
'aria-hidden': 'true'
|
||||
},
|
||||
key === accent.value ? h(Check, { size: 12, strokeWidth: 3 }) : undefined
|
||||
)
|
||||
}))
|
||||
)
|
||||
|
||||
/**
|
||||
* 鼠标移出后收起色板,键盘仍在操作色点时保持展开。
|
||||
* @param event 色板的指针离开事件
|
||||
*/
|
||||
function leavePalette(event: PointerEvent) {
|
||||
if (event.pointerType === 'touch') return
|
||||
const picker = event.currentTarget as HTMLElement
|
||||
if (!picker.querySelector(':focus-visible')) desktopOpen.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 键盘聚焦调色按钮时展开色板,使下一次 Tab 可以进入色点。
|
||||
* @param event 色板的焦点进入事件
|
||||
*/
|
||||
function focusPalette(event: FocusEvent) {
|
||||
if (event.target instanceof HTMLElement && event.target.matches(':focus-visible')) desktopOpen.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 焦点离开色板且鼠标也不在其中时收起色板。
|
||||
* @param event 色板的焦点离开事件
|
||||
*/
|
||||
function blurPalette(event: FocusEvent) {
|
||||
const picker = event.currentTarget as HTMLElement
|
||||
if (event.relatedTarget instanceof Node && picker.contains(event.relatedTarget)) return
|
||||
if (!window.matchMedia('(hover: hover)').matches || !picker.matches(':hover')) desktopOpen.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用窄屏菜单中选择的主色。
|
||||
* @param key 菜单选项标识
|
||||
*/
|
||||
function selectAccent(key: string | number) {
|
||||
if (Object.hasOwn(themeAccents, key)) accent.value = key as ThemeAccent
|
||||
}
|
||||
/**
|
||||
* 将工作台主导航切换到所选的一侧。
|
||||
* @param key 布局菜单选项标识
|
||||
*/
|
||||
function selectLayout(key: string | number) {
|
||||
if (key === 'left' || key === 'right') layout.value = key
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是全局外观工具栏,统一管理主色、工作台布局和明暗模式。 -->
|
||||
<div class="theme-appearance-controls" role="group" aria-label="外观设置">
|
||||
<!-- 桌面色板从调色图标向顶栏内侧展开,色点折叠时不接收焦点。 -->
|
||||
<div
|
||||
v-if="!compact"
|
||||
class="theme-accent-picker"
|
||||
@pointerenter="desktopOpen = $event.pointerType !== 'touch' || desktopOpen"
|
||||
@pointerleave="leavePalette"
|
||||
@focusin="focusPalette"
|
||||
@focusout="blurPalette"
|
||||
>
|
||||
<NButton
|
||||
quaternary
|
||||
class="theme-accent-toggle icon-button"
|
||||
:aria-label="`主色:${themeAccents[accent].label}`"
|
||||
:aria-expanded="desktopOpen"
|
||||
@click="desktopOpen = true"
|
||||
>
|
||||
<template #icon><Palette :size="18" aria-hidden="true" /></template>
|
||||
</NButton>
|
||||
|
||||
<div
|
||||
class="theme-accent-swatches"
|
||||
:class="{ 'is-open': desktopOpen }"
|
||||
:style="{ '--theme-swatch-count': accents.length }"
|
||||
:inert="!desktopOpen"
|
||||
>
|
||||
<div class="theme-accent-swatch-list" role="group" aria-label="主色">
|
||||
<NTooltip v-for="key in accents" :key="key" placement="bottom">
|
||||
<template #trigger>
|
||||
<button
|
||||
type="button"
|
||||
class="theme-accent-swatch"
|
||||
:aria-label="themeAccents[key].label"
|
||||
:aria-pressed="accent === key"
|
||||
@click="accent = key"
|
||||
>
|
||||
<span
|
||||
class="theme-accent-dot"
|
||||
:class="{ 'is-bright': key === 'yellow' || key === 'green' }"
|
||||
:style="{ backgroundColor: themeAccents[key].swatch }"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<Check v-if="accent === key" :size="12" :stroke-width="3" />
|
||||
</span>
|
||||
</button>
|
||||
</template>
|
||||
{{ themeAccents[key].label }}
|
||||
</NTooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 窄屏使用带色点和名称的菜单,保持顶栏紧凑。 -->
|
||||
<NDropdown
|
||||
v-else
|
||||
v-model:show="open"
|
||||
trigger="click"
|
||||
placement="bottom-end"
|
||||
to="body"
|
||||
:value="accent"
|
||||
:options="options"
|
||||
@select="selectAccent"
|
||||
>
|
||||
<NButton
|
||||
quaternary
|
||||
class="theme-accent-toggle icon-button"
|
||||
:aria-label="`主色:${themeAccents[accent].label}`"
|
||||
aria-haspopup="menu"
|
||||
:aria-expanded="open"
|
||||
>
|
||||
<template #icon><Palette :size="18" aria-hidden="true" /></template>
|
||||
</NButton>
|
||||
</NDropdown>
|
||||
|
||||
<!-- 以下是工作台主导航位置菜单。 -->
|
||||
<NDropdown
|
||||
v-model:show="layoutOpen"
|
||||
trigger="click"
|
||||
placement="bottom-end"
|
||||
to="body"
|
||||
:value="layout"
|
||||
:options="layoutOptions"
|
||||
@select="selectLayout"
|
||||
>
|
||||
<NButton
|
||||
quaternary
|
||||
class="workspace-layout-toggle icon-button"
|
||||
:aria-label="`工作台布局:${layoutLabels[layout]}`"
|
||||
aria-haspopup="menu"
|
||||
:aria-expanded="layoutOpen"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="layout === 'left' ? PanelLeft : PanelRight" :size="18" aria-hidden="true" />
|
||||
</template>
|
||||
</NButton>
|
||||
</NDropdown>
|
||||
|
||||
<!-- 以下是浅色、暗色与跟随系统模式菜单。 -->
|
||||
<ThemeToggle v-model="preference" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.theme-appearance-controls {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding-inline: 3px;
|
||||
background: var(--app-control);
|
||||
}
|
||||
/* 工具栏移到左侧时,明暗与调色入口对调,布局入口仍在中间。 */
|
||||
.is-nav-right .theme-appearance-controls {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
.theme-accent-picker {
|
||||
display: flex;
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
/* 工具栏在左侧时向右展开,调色按钮保持在原位。 */
|
||||
.is-nav-right .theme-accent-picker {
|
||||
flex-direction: row;
|
||||
}
|
||||
.theme-accent-swatches {
|
||||
--theme-swatch-size: 32px;
|
||||
inline-size: 0;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
transition:
|
||||
inline-size 260ms cubic-bezier(0.22, 1, 0.36, 1),
|
||||
opacity 180ms ease-out;
|
||||
}
|
||||
.theme-accent-swatches.is-open {
|
||||
inline-size: calc(var(--theme-swatch-count) * var(--theme-swatch-size));
|
||||
opacity: 1;
|
||||
}
|
||||
.theme-accent-swatch-list {
|
||||
display: flex;
|
||||
inline-size: max-content;
|
||||
}
|
||||
.theme-accent-swatch {
|
||||
display: grid;
|
||||
width: var(--theme-swatch-size);
|
||||
height: 34px;
|
||||
place-items: center;
|
||||
}
|
||||
.theme-accent-swatch:hover {
|
||||
background: var(--app-control-hover);
|
||||
}
|
||||
.theme-accent-swatch:focus-visible {
|
||||
outline-offset: -4px;
|
||||
}
|
||||
.theme-accent-dot {
|
||||
display: inline-grid;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
flex: none;
|
||||
place-items: center;
|
||||
color: #ffffff;
|
||||
}
|
||||
.theme-accent-dot.is-bright {
|
||||
color: #191919;
|
||||
}
|
||||
.theme-appearance-controls .n-button.icon-button {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
min-width: 34px;
|
||||
}
|
||||
.theme-appearance-controls .theme-accent-toggle {
|
||||
color: var(--app-accent-text);
|
||||
}
|
||||
</style>
|
||||
@@ -1,23 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, h, ref } from 'vue'
|
||||
import { computed, h, nextTick, ref, useTemplateRef } from 'vue'
|
||||
import { NButton, NDropdown } from 'naive-ui'
|
||||
import { Monitor, Moon, Sun } from '@lucide/vue'
|
||||
import type { ThemePreference } from '../../composables/useTheme'
|
||||
|
||||
/** 图标表示用户偏好;保留系统跟随选项,不以简单二态切换覆盖偏好。 */
|
||||
const preference = defineModel<ThemePreference>({ required: true })
|
||||
/** 明暗模式菜单是否展开。 */
|
||||
const open = ref(false)
|
||||
/** 动画以这个模式按钮的位置为圆心。 */
|
||||
const trigger = useTemplateRef<InstanceType<typeof NButton>>('themeTrigger')
|
||||
/** 当前切换动画,结束前避免重复抓取页面快照。 */
|
||||
let activeTransition: ViewTransition | undefined
|
||||
const modes = [
|
||||
{ key: 'light', label: '浅色模式', icon: Sun },
|
||||
{ key: 'dark', label: '暗黑模式', icon: Moon },
|
||||
{ key: 'system', label: '跟随系统', icon: Monitor }
|
||||
] as const
|
||||
/** 图标和名称反映当前选中的模式。 */
|
||||
const current = computed(() => modes.find(mode => mode.key === preference.value) ?? modes[2])
|
||||
const options = modes.map(mode => ({ ...mode, icon: () => h(mode.icon, { size: 16 }) }))
|
||||
|
||||
/** Dropdown 的键类型较宽,只接收受支持的主题值。 */
|
||||
/**
|
||||
* 选择主题模式,深浅实际变化时从顶栏按钮的位置过渡。
|
||||
* @param key 菜单选项标识
|
||||
*/
|
||||
function selectTheme(key: string | number) {
|
||||
if (key === 'light' || key === 'dark' || key === 'system') preference.value = key
|
||||
if (key !== 'light' && key !== 'dark' && key !== 'system') return
|
||||
const root = document.documentElement
|
||||
const dark = key === 'dark' || (key === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||||
const button = trigger.value?.$el
|
||||
if (
|
||||
typeof document.startViewTransition !== 'function' ||
|
||||
!(button instanceof HTMLElement) ||
|
||||
dark === (root.dataset.theme === 'dark') ||
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||
) {
|
||||
activeTransition?.skipTransition()
|
||||
preference.value = key
|
||||
return
|
||||
}
|
||||
if (activeTransition) return
|
||||
|
||||
const { left, top, width, height } = button.getBoundingClientRect()
|
||||
const x = left + width / 2
|
||||
const y = top + height / 2
|
||||
const radius = Math.hypot(Math.max(x, window.innerWidth - x), Math.max(y, window.innerHeight - y))
|
||||
root.style.setProperty('--theme-transition-origin', `${x}px ${y}px`)
|
||||
root.style.setProperty('--theme-transition-radius', `${radius}px`)
|
||||
root.classList.add('theme-mode-transition')
|
||||
|
||||
const transition = document.startViewTransition(async () => {
|
||||
preference.value = key
|
||||
await nextTick()
|
||||
})
|
||||
activeTransition = transition
|
||||
|
||||
/** 动画结束或被浏览器跳过时清除快照样式。 */
|
||||
function clearTransition() {
|
||||
activeTransition = undefined
|
||||
root.classList.remove('theme-mode-transition')
|
||||
root.style.removeProperty('--theme-transition-origin')
|
||||
root.style.removeProperty('--theme-transition-radius')
|
||||
}
|
||||
|
||||
// 页面切换标签等情况可能让浏览器跳过快照,主题更新仍会执行。
|
||||
void transition.ready.catch(() => {})
|
||||
void transition.finished.then(clearTransition, clearTransition)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -33,6 +82,7 @@ function selectTheme(key: string | number) {
|
||||
@select="selectTheme"
|
||||
>
|
||||
<NButton
|
||||
ref="themeTrigger"
|
||||
quaternary
|
||||
class="theme-toggle icon-button"
|
||||
:aria-label="`主题模式:${current.label}`"
|
||||
@@ -50,4 +100,31 @@ function selectTheme(key: string | number) {
|
||||
.n-button.theme-toggle {
|
||||
@apply shrink-0 w-[34px] h-[34px];
|
||||
}
|
||||
/* 只替换此次主题切换的快照动画,不影响其它页面过渡。 */
|
||||
.theme-mode-transition::view-transition-group(root),
|
||||
.theme-mode-transition::view-transition-old(root),
|
||||
.theme-mode-transition::view-transition-new(root) {
|
||||
animation: none;
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
.theme-mode-transition::view-transition-new(root) {
|
||||
z-index: 1;
|
||||
animation: theme-mode-reveal 450ms ease-in both;
|
||||
}
|
||||
.theme-mode-transition[data-theme='dark']::view-transition-new(root) {
|
||||
z-index: 0;
|
||||
animation: none;
|
||||
}
|
||||
.theme-mode-transition[data-theme='dark']::view-transition-old(root) {
|
||||
z-index: 1;
|
||||
animation: theme-mode-reveal 450ms ease-in reverse both;
|
||||
}
|
||||
@keyframes theme-mode-reveal {
|
||||
from {
|
||||
clip-path: circle(0 at var(--theme-transition-origin));
|
||||
}
|
||||
to {
|
||||
clip-path: circle(var(--theme-transition-radius) at var(--theme-transition-origin));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -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<string, ThemeAccentPreset>
|
||||
|
||||
/** 用于保存和恢复主色选择的预设标识。 */
|
||||
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
|
||||
}
|
||||
}
|
||||
+77
-26
@@ -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<ThemePreference>(readPreference())
|
||||
/** 用户独立选择的主色。 */
|
||||
const accent = ref<ThemeAccent>(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<GlobalThemeOverrides>(() => {
|
||||
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 }
|
||||
}
|
||||
@@ -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<WorkspaceLayout>(readLayout())
|
||||
watch(layout, value => {
|
||||
try {
|
||||
localStorage.setItem(storageKey, value)
|
||||
} catch {
|
||||
/* 存储不可用时保留当前会话的选择。 */
|
||||
}
|
||||
})
|
||||
return layout
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ afterEach(() => {
|
||||
wrapper = undefined
|
||||
localStorage.clear()
|
||||
delete document.documentElement.dataset.theme
|
||||
document.documentElement.style.colorScheme = ''
|
||||
document.documentElement.removeAttribute('style')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
|
||||
@@ -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<HTMLElement>('.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']) {
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user