feat(settings): expand workspace preferences

Add layout presets, menu controls, a watermark preview, and workspace actions.

Refine tab spacing and user management. Fix cached route transition sequencing.
This commit is contained in:
XiaoDaiGua-Ray 2026-11-06 23:29:23 +08:00
parent 744bb0e693
commit 19ac1805a5
No known key found for this signature in database
22 changed files with 1767 additions and 164 deletions

View File

@ -0,0 +1,233 @@
/* eslint-disable vue/one-component-per-file */
import { APP_CATCH_KEY } from '@/app-config'
import Common from '@/layout/components/SiderBar/components/SettingDrawer/segment-views/Common'
import { piniaKeepAliveStore } from '@/store/modules/keep-alive'
import { piniaNavigationHistoryStore } from '@/store/modules/navigation-history'
import { piniaRuntimeStore } from '@/store/modules/runtime'
import { piniaSettingStore } from '@/store/modules/setting'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import { piniaSigningStore } from '@/store/modules/signing'
import { mount, shallowMount } from '@vue/test-utils'
import type { VueWrapper } from '@vue/test-utils'
import { NButton, NSelect } from 'naive-ui'
import { createPinia, disposePinia, setActivePinia } from 'pinia'
import { defineComponent, h, KeepAlive, nextTick, onUnmounted, ref } from 'vue'
const state = vi.hoisted(() => ({
createModal: vi.fn(),
scrollTo: vi.fn(),
}))
vi.mock('naive-ui', async (original) => ({
...(await original<typeof import('naive-ui')>()),
useModal: () => ({ create: state.createModal }),
}))
vi.mock('@/hooks', async (original) => {
const actual = await original<typeof import('@/hooks')>()
return {
...actual,
useI18n: (namespace?: string) => ({
...actual.useI18n(namespace),
t: (key: string) => key,
}),
useContentScroll: () => state.scrollTo,
}
})
let pinia: ReturnType<typeof createPinia>
let wrapper: VueWrapper
const button = (text: string) => {
const target = wrapper
.findAllComponents(NButton)
.find((item) => item.text() === text)
expect(target).toBeDefined()
return target!
}
const invoke = (handler: unknown, ...args: unknown[]) => {
expect(typeof handler).toBe('function')
Reflect.apply(handler as (...args: unknown[]) => unknown, void 0, args)
}
const confirmAction = () => {
const options = state.createModal.mock.calls.at(-1)?.[0] as {
onPositiveClick: () => void
}
options.onPositiveClick()
}
beforeEach(() => {
vi.clearAllMocks()
localStorage.clear()
sessionStorage.clear()
pinia = createPinia()
setActivePinia(pinia)
piniaSigningStore().signingCallback = {
id: 'settings-user',
name: 'Settings user',
role: 'admin',
}
wrapper = shallowMount(Common, {
global: { plugins: [pinia], renderStubDefaultSlot: true },
})
})
afterEach(() => {
wrapper.unmount()
disposePinia(pinia)
vi.useRealTimers()
})
it('persists language and resets only title/cache preferences, keeping unrelated settings', async () => {
const settings = piniaSettingStore()
const language = wrapper.findAllComponents(NSelect)[0]
invoke(language.props('onUpdateValue'), 'en-US')
await nextTick()
expect(settings.localeLanguage).toBe('en-US')
expect(localStorage.getItem(APP_CATCH_KEY.localeLanguage)).toContain('en-US')
settings.updateSettingState('dynamicDocumentTitle', false)
settings.updateSettingState('keepAliveConfig', {
maxKeepAliveLength: 3,
setupKeepAlive: false,
keepAliveExclude: ['Reports'],
})
settings.updateSettingState('watermarkSwitch', true)
invoke(button('general.reset').props('onClick'))
await nextTick()
expect(settings.keepAliveConfig).toEqual(
getDefaultSettingConfig().keepAliveConfig,
)
expect(settings.dynamicDocumentTitle).toBe(
getDefaultSettingConfig().dynamicDocumentTitle,
)
expect(settings.localeLanguage).toBe('en-US')
expect(settings.watermarkSwitch).toBe(true)
expect(wrapper.get('[role="status"]').text()).toBe('general.resetDone')
})
it('clears inactive KeepAlive instances only after confirmation without reloading the active page', async () => {
const cache = piniaKeepAliveStore()
const active = ref('Alpha')
const unmountedAlpha = vi.fn()
const unmountedBeta = vi.fn()
const alphaCreated = vi.fn()
const pages = {
Alpha: defineComponent({
name: 'PageAlpha',
setup() {
alphaCreated()
onUnmounted(unmountedAlpha)
return () => h('div', 'Alpha')
},
}),
Beta: defineComponent({
name: 'PageBeta',
setup() {
onUnmounted(unmountedBeta)
return () => h('div', 'Beta')
},
}),
}
cache.keepAliveInclude = ['PageAlpha', 'PageBeta']
const host = mount(
defineComponent({
setup: () => () =>
h(KeepAlive, { include: cache.keepAliveInclude }, () =>
h(pages[active.value as keyof typeof pages]),
),
}),
)
try {
active.value = 'Beta'
await nextTick()
invoke(button('general.clearCache').props('onClick'))
await nextTick()
expect(cache.keepAliveInclude).toEqual(['PageAlpha', 'PageBeta'])
expect(unmountedAlpha).not.toHaveBeenCalled()
confirmAction()
await nextTick()
expect(cache.keepAliveInclude).toEqual([])
expect(unmountedAlpha).toHaveBeenCalledOnce()
expect(unmountedBeta).not.toHaveBeenCalled()
expect(host.text()).toBe('Beta')
active.value = 'Alpha'
await nextTick()
expect(alphaCreated).toHaveBeenCalledTimes(2)
} finally {
host.unmount()
}
})
it('clears only the current account recent visits after confirmation and preserves favorites', async () => {
const history = piniaNavigationHistoryStore()
history.recordVisit('/reports')
history.toggleFavorite('/reports')
await nextTick()
invoke(button('general.clearRecent').props('onClick'))
await nextTick()
expect(history.recentPaths).toEqual(['/reports'])
confirmAction()
await nextTick()
expect(history.recentPaths).toEqual([])
expect(history.favoritePaths).toEqual(['/reports'])
expect(wrapper.get('[role="status"]').text()).toBe('general.recentCleared')
})
it('reports a storage failure instead of claiming that history changes were saved', async () => {
const history = piniaNavigationHistoryStore()
history.recordVisit('/reports')
await nextTick()
invoke(button('general.clearRecent').props('onClick'))
const write = vi
.spyOn(window.localStorage, 'setItem')
.mockImplementation(() => {
throw new Error('Storage unavailable')
})
try {
confirmAction()
await nextTick()
expect(history.recentPaths).toEqual([])
expect(history.storageUnavailable).toBe(true)
expect(wrapper.get('[role="status"]').text()).toBe(
'general.historyStorageUnavailable',
)
expect(wrapper.get('[role="alert"]').text()).toBe(
'general.historyStorageUnavailable',
)
} finally {
write.mockRestore()
}
})
it('uses the store-owned remount timer and scrolls content without changing navigation state', async () => {
vi.useFakeTimers()
const runtime = piniaRuntimeStore()
invoke(button('general.refresh').props('onClick'))
await nextTick()
expect(runtime.globalMainLayoutLoad).toBe(false)
expect(button('general.refresh').props('loading')).toBe(true)
await vi.advanceTimersByTimeAsync(800)
expect(runtime.globalMainLayoutLoad).toBe(true)
runtime.globalDrawerValue = true
invoke(button('general.scrollTop').props('onClick'))
await nextTick()
expect(state.scrollTo).toHaveBeenCalledWith({
top: 0,
left: 0,
behavior: 'auto',
})
expect(runtime.globalDrawerValue).toBe(true)
})

View File

@ -0,0 +1,177 @@
import CustomMenu from '@/layout/components/SiderBar/components/SettingDrawer/segment-views/CustomMenu'
import { piniaSettingStore } from '@/store/modules/setting'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import type { AppMenuOption } from '@/types'
import { flushPromises, mount } from '@vue/test-utils'
import type { VueWrapper } from '@vue/test-utils'
import { NButton } from 'naive-ui'
import { createPinia, disposePinia, setActivePinia } from 'pinia'
import { nextTick, ref } from 'vue'
import type { Ref } from 'vue'
const state = vi.hoisted(() => ({
collapsed: null as unknown as Ref<boolean>,
smaller: null as unknown as Ref<boolean>,
options: null as unknown as Ref<AppMenuOption[]>,
menuKey: null as unknown as Ref<string>,
refresh: vi.fn(),
collapse: vi.fn(),
scroll: vi.fn(),
success: vi.fn(),
error: vi.fn(),
}))
vi.mock('@/hooks', () => ({
useI18n: () => ({ t: (key: string) => key, locale: vi.fn() }),
useDayjs: () => ({ locale: vi.fn() }),
useDevice: () => ({ isTabletOrSmaller: state.smaller }),
useSiderScroll: () => state.scroll,
}))
vi.mock('@/store', async () => {
const settings = await import('@/store/hooks/useSettingStore')
return {
...settings,
useMenuGetters: () => ({
getCollapsed: state.collapsed,
getMenuOptions: state.options,
getMenuKey: state.menuKey,
}),
useMenuActions: () => ({
setupAppMenu: state.refresh,
collapsedMenu: state.collapse,
}),
}
})
let wrapper: VueWrapper
let pinia: ReturnType<typeof createPinia>
beforeEach(() => {
vi.clearAllMocks()
state.collapsed = ref(false)
state.smaller = ref(false)
state.options = ref([])
state.menuKey = ref('/reports')
state.refresh.mockResolvedValue(void 0)
vi.stubGlobal('$message', { success: state.success, error: state.error })
pinia = createPinia()
setActivePinia(pinia)
wrapper = mount(CustomMenu)
})
afterEach(() => {
wrapper.unmount()
disposePinia(pinia)
vi.unstubAllGlobals()
})
const button = (label: string) =>
wrapper.findAllComponents(NButton).find((item) => item.text() === label)!
it('applies size presets without replacing menu behavior or layout preferences', async () => {
const settings = piniaSettingStore()
settings.updateSettingState('menuConfig', { accordion: true, inverted: true })
settings.updateSettingState('layoutConfig', { mode: 'right' })
await button('menu.compact').trigger('click')
expect(settings.menuConfig).toMatchObject({
menuWidth: 224,
collapsedWidth: 56,
iconSize: 18,
accordion: true,
inverted: true,
})
expect(settings.layoutConfig.mode).toBe('right')
expect(button('menu.compact').attributes('aria-pressed')).toBe('true')
settings.updateSettingState('menuConfig', { iconSize: 24 })
await nextTick()
expect(button('menu.compact').attributes('aria-pressed')).toBe('false')
})
it('enables sidebar actions only when the active desktop layout has a sidebar', async () => {
const settings = piniaSettingStore()
await button('menu.collapse').trigger('click')
expect(state.collapse).toHaveBeenCalledExactlyOnceWith(true)
settings.updateSettingState('layoutConfig', { mode: 'top' })
await nextTick()
expect(button('menu.collapse').props('disabled')).toBe(true)
expect(button('menu.scrollTop').props('disabled')).toBe(true)
settings.updateSettingState('layoutConfig', { mode: 'mixed' })
await nextTick()
expect(button('menu.collapse').props('disabled')).toBe(true)
state.options.value = [
{
fullPath: '/reports',
path: '/reports',
name: 'Reports',
label: 'Reports',
key: '/reports',
meta: {},
show: true,
children: [
{
fullPath: '/reports/daily',
path: '/reports/daily',
name: 'Daily',
label: 'Daily',
key: '/reports/daily',
meta: {},
show: true,
},
],
},
]
await nextTick()
expect(button('menu.collapse').props('disabled')).toBe(false)
await button('menu.scrollTop').trigger('click')
expect(state.scroll).toHaveBeenCalledExactlyOnceWith({
top: 0,
left: 0,
behavior: 'auto',
})
state.smaller.value = true
await nextTick()
expect(button('menu.collapse').props('disabled')).toBe(true)
})
it('keeps collapse-mode changes local and resets only menu preferences', async () => {
const settings = piniaSettingStore()
settings.updateSettingState('contentTransition', 'none')
settings.updateSettingState('layoutConfig', { mode: 'right' })
await wrapper.get('input[value="transform"]').setValue()
expect(settings.menuConfig.collapsedMode).toBe('transform')
settings.updateSettingState('menuConfig', { accordion: true, menuWidth: 300 })
await button('menu.reset').trigger('click')
await flushPromises()
expect(settings.menuConfig).toEqual(getDefaultSettingConfig().menuConfig)
expect(settings.contentTransition).toBe('none')
expect(settings.layoutConfig.mode).toBe('right')
expect(state.refresh).toHaveBeenCalledOnce()
})
it('shows refresh progress and recovers from a failed refresh', async () => {
let rejectRefresh!: (error: Error) => void
state.refresh.mockImplementationOnce(
() =>
new Promise<void>((_, reject) => {
rejectRefresh = reject
}),
)
await button('menu.refresh').trigger('click')
expect(button('menu.refresh').props('loading')).toBe(true)
expect(button('menu.reset').props('disabled')).toBe(true)
rejectRefresh(new Error('Menu unavailable'))
await flushPromises()
expect(state.error).toHaveBeenCalledExactlyOnceWith('menu.refreshFailed')
expect(button('menu.refresh').props('loading')).toBe(false)
expect(button('menu.reset').props('disabled')).toBe(false)
await button('menu.refresh').trigger('click')
await flushPromises()
expect(state.success).toHaveBeenCalledExactlyOnceWith('menu.refreshed')
})

View File

@ -0,0 +1,131 @@
import { mount } from '@vue/test-utils'
import type { VueWrapper } from '@vue/test-utils'
import { defineComponent, h, nextTick } from 'vue'
import { createMemoryHistory, createRouter } from 'vue-router'
import type { Router } from 'vue-router'
import RouteTransition from '../../packages/admin-shell/src/RouteTransition.vue'
let wrapper: VueWrapper | undefined
let router: Router
let host: HTMLDivElement
let mounts: { one: number; two: number }
beforeEach(() => {
vi.useFakeTimers()
mounts = { one: 0, two: 0 }
host = document.createElement('div')
document.body.append(host)
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
setTimeout(() => callback(performance.now()), 16),
)
const getComputedStyle = window.getComputedStyle.bind(window)
vi.spyOn(window, 'getComputedStyle').mockImplementation((element) => {
const style = getComputedStyle(element)
if (!element.matches('.page-enter-active, .page-leave-active')) return style
return new Proxy(style, {
get(target, key, receiver) {
if (key === 'transitionDuration') return '0.3s'
if (key === 'transitionDelay') return '0s'
if (key === 'transitionProperty') return 'opacity'
if (key === 'animationDuration' || key === 'animationDelay') return '0s'
return Reflect.get(target, key, receiver)
},
})
})
})
afterEach(() => {
wrapper?.unmount()
wrapper = void 0
router?.options.history.destroy()
host.remove()
vi.clearAllTimers()
vi.restoreAllMocks()
vi.unstubAllGlobals()
vi.useRealTimers()
})
const navigate = async (path: string) => {
await router.push(path)
await nextTick()
}
const mountRoutes = async (cache: boolean) => {
const page = (name: 'one' | 'two') =>
defineComponent({
name: name === 'one' ? 'PageOne' : 'PageTwo',
setup() {
const instance = ++mounts[name]
return () => h('div', { 'data-page': name }, `${name}-${instance}`)
},
})
router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/one', component: page('one') },
{ path: '/two', component: page('two') },
],
})
await router.push('/one')
await router.isReady()
wrapper = mount(RouteTransition, {
attachTo: host,
props: {
transitionPropName: 'page',
transitionMode: 'out-in',
transitionAppear: false,
getKeepAliveConfig: {
setupKeepAlive: cache,
maxKeepAliveLength: 10,
keepAliveExclude: [],
},
getKeepAliveInclude: ['PageOne', 'PageTwo'],
},
global: { plugins: [router], stubs: { transition: false } },
})
await nextTick()
}
it.each([true, false])(
'waits for the outgoing page before displaying its successor (cache=%s)',
async (cache) => {
await mountRoutes(cache)
expect(host.querySelector('[data-page="one"]')?.textContent).toBe('one-1')
await navigate('/two')
await vi.advanceTimersByTimeAsync(64)
expect(host.querySelector('[data-page="one"]')).not.toBeNull()
expect(host.querySelector('[data-page="two"]')).toBeNull()
await vi.advanceTimersByTimeAsync(650)
expect(host.querySelector('[data-page="one"]')).toBeNull()
expect(host.querySelector('[data-page="two"]')?.textContent).toBe('two-1')
await navigate('/one')
await vi.advanceTimersByTimeAsync(714)
expect(host.querySelector('[data-page="one"]')?.textContent).toBe(
cache ? 'one-1' : 'one-2',
)
expect(mounts.one).toBe(cache ? 1 : 2)
},
)
it('keeps distinct fullPath cache entries while reusing the same page component', async () => {
await mountRoutes(true)
await navigate('/one?view=other')
await vi.advanceTimersByTimeAsync(714)
expect(host.querySelector('[data-page="one"]')?.textContent).toBe('one-2')
await navigate('/one')
await vi.advanceTimersByTimeAsync(714)
expect(host.querySelector('[data-page="one"]')?.textContent).toBe('one-1')
expect(mounts.one).toBe(2)
})

View File

@ -0,0 +1,124 @@
import { mount } from '@vue/test-utils'
import { NButton, NInput, NInputNumber, NWatermark } from 'naive-ui'
import { createPinia, disposePinia, setActivePinia } from 'pinia'
import { nextTick } from 'vue'
import WatermarkSettings from '../../apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Watermark'
import { piniaSettingStore } from '../../apps/admin/src/store/modules/setting'
import { getDefaultSettingConfig } from '../../apps/admin/src/store/modules/setting/constant'
import { piniaSigningStore } from '../../apps/admin/src/store/modules/signing'
const mountSettings = () =>
mount(WatermarkSettings, { global: { stubs: { Watermark: true } } })
const buttonFor = (wrapper: ReturnType<typeof mountSettings>, key: string) =>
wrapper
.findAllComponents(NButton)
.find((button) => button.text() === `preferences.watermark.${key}`)!
describe('watermark preference controls', () => {
let pinia: ReturnType<typeof createPinia>
beforeEach(() => {
pinia = createPinia()
setActivePinia(pinia)
})
afterEach(() => disposePinia(pinia))
it('previews style presets without changing text, visibility, or other preferences', async () => {
const store = piniaSettingStore()
store.updateSettingState('watermarkConfig', {
content: 'Custom\nWatermark',
})
store.updateSettingState('layoutConfig', { mode: 'top' })
const wrapper = mountSettings()
try {
await buttonFor(wrapper, 'compact').trigger('click')
expect(store.watermarkConfig).toMatchObject({
content: 'Custom\nWatermark',
width: 256,
cross: true,
})
expect(store.watermarkSwitch).toBe(false)
expect(store.layoutConfig.mode).toBe('top')
expect(wrapper.findComponent(NWatermark).props()).toMatchObject({
content: 'Custom\nWatermark',
width: 256,
fullscreen: false,
})
store.updateSettingState('watermarkSwitch', true)
await buttonFor(wrapper, 'horizontal').trigger('click')
expect(store.watermarkConfig.rotate).toBe(0)
expect(store.watermarkSwitch).toBe(true)
await buttonFor(wrapper, 'reset').trigger('click')
expect(store.watermarkConfig).toEqual(
getDefaultSettingConfig().watermarkConfig,
)
expect(store.watermarkSwitch).toBe(false)
expect(store.layoutConfig.mode).toBe('top')
} finally {
wrapper.unmount()
}
})
it('uses available display text and still allows clearing the content', async () => {
const store = piniaSettingStore()
const signing = piniaSigningStore()
const wrapper = mountSettings()
try {
expect(buttonFor(wrapper, 'useAccountName').props('disabled')).toBe(true)
signing.signingCallback = { name: 'Ray', role: 'admin' }
await nextTick()
await buttonFor(wrapper, 'useAccountName').trigger('click')
expect(store.watermarkConfig.content).toBe('Ray')
await buttonFor(wrapper, 'useApplicationTitle').trigger('click')
expect(store.watermarkConfig.content).toBe(store.sideBarLogo?.title)
await wrapper.findComponent(NInput).find('textarea').setValue('')
expect(store.watermarkConfig.content).toBe('')
expect(store.watermarkSwitch).toBe(false)
} finally {
wrapper.unmount()
}
})
it('keeps each generated canvas edge within its supported bounds', async () => {
const store = piniaSettingStore()
const wrapper = mountSettings()
const numberFor = (key: string) =>
wrapper
.findAllComponents(NInputNumber)
.find((input) => input.props('inputProps')?.id?.endsWith(`-${key}`))!
const update = async (key: string, value: number) => {
const handler = numberFor(key).props('onUpdateValue')
if (Array.isArray(handler)) handler.forEach((callback) => callback(value))
else handler?.(value)
await nextTick()
}
try {
await update('xGap', 100)
expect(numberFor('width').props('max')).toBe(3996)
await update('width', 3996)
expect(store.watermarkConfig.width + store.watermarkConfig.xGap).toBe(
4096,
)
await update('width', 3997)
expect(store.watermarkConfig.width).toBe(3996)
await update('xGap', -3996)
expect(store.watermarkConfig.xGap).toBe(100)
await update('xGap', -3995)
expect(store.watermarkConfig.width + store.watermarkConfig.xGap).toBe(1)
await update('height', Number.POSITIVE_INFINITY)
expect(store.watermarkConfig.height).toBe(384)
} finally {
wrapper.unmount()
}
})
})

View File

@ -0,0 +1,91 @@
import { mount } from '@vue/test-utils'
import { createPinia, disposePinia, setActivePinia } from 'pinia'
import Appearance from '../../apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Appearance'
import Layout from '../../apps/admin/src/layout/components/SiderBar/components/SettingDrawer/segment-views/Layout'
import { piniaRuntimeStore } from '../../apps/admin/src/store/modules/runtime'
import { piniaSettingStore } from '../../apps/admin/src/store/modules/setting'
import { getDefaultSettingConfig } from '../../apps/admin/src/store/modules/setting/constant'
describe('workspace preference shortcuts', () => {
let pinia: ReturnType<typeof createPinia>
beforeEach(() => {
pinia = createPinia()
setActivePinia(pinia)
})
afterEach(() => disposePinia(pinia))
it('applies reading spacing without replacing navigation or fixed bars', async () => {
const store = piniaSettingStore()
store.updateSettingState('layoutConfig', {
mode: 'right',
fixedHeader: false,
fixedFooter: false,
})
const wrapper = mount(Layout, { global: { plugins: [pinia] } })
try {
const button = wrapper
.findAll('button')
.find((button) => button.text() === 'preferences.layout.reading')!
await button.trigger('click')
expect(store.layoutConfig).toEqual({
mode: 'right',
fixedHeader: false,
fixedFooter: false,
contentWidth: 'fixed',
contentMaxWidth: 960,
contentPadding: 24,
})
expect(button.attributes('aria-pressed')).toBe('true')
await wrapper
.get('[role="switch"][aria-label="preferences.layout.maximize"]')
.trigger('click')
expect(piniaRuntimeStore().layoutContentMaximize).toBe(true)
expect(store.layoutConfig.mode).toBe('right')
} finally {
wrapper.unmount()
}
})
it('resets appearance independently and leaves the selected color mode intact', async () => {
const store = piniaSettingStore()
store.updateSettingState('appTheme', 'auto')
store.updateSettingState('layoutConfig', { mode: 'top' })
store.updateSettingState('watermarkConfig', { content: 'Keep me' })
store.updateSettingState('themeStyle', 'plain')
store.updateSettingState('contentTransition', 'opacity')
store.changePrimaryColor('#ff0000')
const wrapper = mount(Appearance, { global: { plugins: [pinia] } })
const click = async (text: string) =>
wrapper
.findAll('button')
.find((button) => button.text() === `preferences.${text}`)!
.trigger('click')
try {
await click('appearance.minimal')
expect([
store.breadcrumbSwitch,
store.menuTagSwitch,
store.copyrightSwitch,
]).toEqual([false, false, false])
await click('appearance.reset')
expect(store.contentTransition).toBe(
getDefaultSettingConfig().contentTransition,
)
expect(store.menuTagSwitch).toBe(getDefaultSettingConfig().menuTagSwitch)
expect(store.themeStyle).toBe(getDefaultSettingConfig().themeStyle)
expect(store.primaryColorOverride).toEqual({})
expect(store.appTheme).toBe('auto')
expect(store.layoutConfig.mode).toBe('top')
expect(store.watermarkConfig.content).toBe('Keep me')
} finally {
wrapper.unmount()
}
})
})

View File

@ -6,7 +6,10 @@ export default defineComponent({
return () => (
<section class="r-settings-section" aria-labelledby={id}>
<h3 id={id}>{props.title}</h3>
<div class="r-settings-section__heading">
<h3 id={id}>{props.title}</h3>
{slots.action?.()}
</div>
{slots.default?.()}
</section>
)

View File

@ -65,15 +65,52 @@
&__label {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
min-width: 0;
min-inline-size: 0;
font-size: 12px;
line-height: 1.4;
text-align: center;
}
> .n-tabs-nav {
padding-inline: 8px;
&__text {
min-inline-size: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__icon {
flex: none;
}
> .n-tabs-nav > .n-tabs-rail {
box-sizing: border-box;
gap: 6px;
padding: 8px 14px;
border: 1px solid var(--r-line);
border-radius: var(--r-control-radius);
border-radius: var(--r-radius);
background: var(--r-surface);
> .n-tabs-tab-wrapper {
min-inline-size: 0;
> .n-tabs-tab {
min-block-size: 40px;
box-sizing: border-box;
padding: 8px 6px;
}
> .n-tabs-tab--active {
color: var(--r-primary-text);
}
}
> .n-tabs-capsule {
border-radius: var(--r-control-radius);
background: var(--r-surface-muted);
box-shadow: none;
}
}
> .n-tab-pane {
@ -104,6 +141,14 @@
> .n-button {
justify-self: start;
}
&__heading {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px 12px;
}
}
.r-settings-fields {
@ -128,6 +173,89 @@
background: var(--r-surface-muted);
}
.r-settings-hint {
margin: 0;
color: var(--r-text-secondary);
font-size: 12px;
line-height: 1.7;
overflow-wrap: anywhere;
}
.r-watermark-preview {
min-block-size: 180px;
overflow: hidden;
border: 1px solid var(--r-line);
border-radius: var(--r-control-radius);
background: var(--r-surface-muted);
}
.r-watermark-form {
display: grid;
gap: 24px;
}
.r-watermark-fieldset {
min-inline-size: 0;
margin: 0;
padding: 0;
border: 0;
legend {
margin-block-end: 14px;
padding: 0;
color: var(--r-text-secondary);
font-size: 12px;
font-weight: 600;
}
.r-settings-fields {
gap: 16px;
}
}
.r-settings-action-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
> .n-button {
min-inline-size: 0;
min-block-size: 38px;
block-size: auto;
padding: 9px 12px;
line-height: 1.5;
.n-button__content {
white-space: normal;
overflow-wrap: anywhere;
text-align: center;
}
}
}
.r-settings-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
.n-button[aria-pressed='true'] {
outline: 1px solid var(--r-primary-text);
outline-offset: 1px;
}
}
.r-workspace-presets {
> .n-button[aria-pressed='true'] {
font-weight: 600;
}
&__check {
inline-size: 14px;
margin-inline-start: 6px;
}
}
.r-settings-switch {
display: flex;
align-items: center;
@ -150,14 +278,9 @@
.r-settings-fields {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@container (max-width: 419px) {
.r-settings-tabs__label {
flex-direction: column;
gap: 3px;
font-size: 11px;
line-height: 1.2;
.r-settings-fields--three {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}

View File

@ -1,7 +1,6 @@
import './index.scss'
import { RIcon, useModal } from '@/components'
import { useI18n } from '@/hooks'
import LayoutSettings from '@/layout/components/LayoutSettings'
import { useMenuActions, useSettingActions } from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import { PREFERENCE_FILE_LIMIT } from '@/store/modules/setting/preference-file'
@ -16,24 +15,23 @@ import {
NTabPane,
NTabs,
} from 'naive-ui'
import SettingsSection from './components/SettingsSection'
import Appearance from './segment-views/Appearance'
import Common from './segment-views/Common'
import CustomMenu from './segment-views/CustomMenu'
import Layout from './segment-views/Layout'
import Watermark from './segment-views/Watermark'
const categories = [
{ key: 'layout', icon: 'navigation/layout', view: LayoutSettings },
{ key: 'appearance', icon: 'navigation/appearance', view: Appearance },
{ key: 'menu', icon: 'navigation/menu', view: CustomMenu },
{ key: 'watermark', icon: 'system/watermark', view: Watermark },
{ key: 'general', icon: 'action/setting', view: Common },
] as const
export default defineComponent({
name: 'SettingDrawer',
props: drawerProps,
setup(props) {
const categories = [
{ key: 'layout', icon: 'navigation/layout', view: Layout },
{ key: 'appearance', icon: 'navigation/appearance', view: Appearance },
{ key: 'menu', icon: 'navigation/menu', view: CustomMenu },
{ key: 'watermark', icon: 'system/watermark', view: Watermark },
{ key: 'general', icon: 'action/setting', view: Common },
] as const
const { t } = useI18n('preferences')
const { create } = useModal()
const {
@ -146,10 +144,9 @@ export default defineComponent({
),
default: () => (
<NTabs
type="line"
type="segment"
defaultValue="appearance"
class="r-settings-tabs"
justifyContent="space-between"
>
{categories.map(({ key, icon, view: View }) => (
<NTabPane
@ -157,18 +154,19 @@ export default defineComponent({
name={key}
tab={() => (
<span class="r-settings-tabs__label">
<RIcon name={icon} size={16} aria-hidden="true" />
{t(`section.${key}`)}
<RIcon
class="r-settings-tabs__icon"
name={icon}
size={16}
aria-hidden="true"
/>
<span class="r-settings-tabs__text">
{t(`section.${key}`)}
</span>
</span>
)}
>
{key === 'layout' ? (
<SettingsSection title={t('section.layout')}>
<LayoutSettings />
</SettingsSection>
) : (
<View />
)}
<View />
</NTabPane>
))}
</NTabs>

View File

@ -1,6 +1,7 @@
import { APP_THEME, CONTENT_TRANSITION_OPTIONS } from '@/app-config'
import { useI18n } from '@/hooks'
import { useSettingActions, useSettingGetters } from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import {
DEFAULT_THEME_STYLE,
themeStyleOverrides,
@ -44,6 +45,16 @@ export default defineComponent({
const themeVars = useThemeVars()
const styleName = useId()
const colorOpen = ref(false)
const defaults = getDefaultSettingConfig()
const resetAppearance = () => {
updateSettingState('themeStyle', defaults.themeStyle)
updateSettingState('contentTransition', defaults.contentTransition)
updateSettingState('drawerPlacement', defaults.drawerPlacement)
for (const [key] of switches) updateSettingState(key, defaults[key])
changePrimaryColor()
}
const previews = computed(() => {
const mode = getAppTheme.value ? 'dark' : 'light'
const base = mode === 'dark' ? darkTheme : lightTheme
@ -189,6 +200,27 @@ export default defineComponent({
</NForm>
</SettingsSection>
<SettingsSection title={t('appearance.display')}>
<p class="r-settings-hint">{t('appearance.displayHint')}</p>
<div class="r-settings-actions">
{[true, false].map((visible) => (
<NButton
key={String(visible)}
secondary
aria-pressed={
getBreadcrumbSwitch.value === visible &&
getMenuTagSwitch.value === visible &&
getCopyrightSwitch.value === visible
}
onClick={() => {
updateSettingState('breadcrumbSwitch', visible)
updateSettingState('menuTagSwitch', visible)
updateSettingState('copyrightSwitch', visible)
}}
>
{t(visible ? 'appearance.showAll' : 'appearance.minimal')}
</NButton>
))}
</div>
<div class="r-settings-switches">
{switches.map(([key, value]) => (
<label class="r-settings-switch" key={key}>
@ -206,6 +238,10 @@ export default defineComponent({
))}
</div>
</SettingsSection>
<SettingsSection title={t('appearance.reset')}>
<p class="r-settings-hint">{t('appearance.resetHint')}</p>
<NButton onClick={resetAppearance}>{t('appearance.reset')}</NButton>
</SettingsSection>
</div>
)
},

View File

@ -1,18 +1,91 @@
import { useI18n } from '@/hooks'
import { useSettingActions, useSettingGetters } from '@/store'
import { NDynamicTags, NForm, NFormItem, NInputNumber, NSwitch } from 'naive-ui'
import { LOCAL_OPTIONS } from '@/app-config'
import { useContentScroll, useI18n, useSpinning } from '@/hooks'
import {
useKeepAliveActions,
useKeepAliveGetters,
useNavigationHistoryActions,
useNavigationHistoryGetters,
useRuntimeGetters,
useSettingActions,
useSettingGetters,
} from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import { cloneDeep } from 'lodash-es'
import {
NButton,
NForm,
NFormItem,
NInputNumber,
NSelect,
NSwitch,
useModal,
} from 'naive-ui'
import SettingsSection from '../components/SettingsSection'
export default defineComponent({
name: 'SegmentViewsCommon',
setup() {
const { t } = useI18n('preferences')
const { getKeepAliveConfig, getDynamicDocumentTitle } = useSettingGetters()
const { updateSettingState } = useSettingActions()
const { create } = useModal()
const { getKeepAliveConfig, getDynamicDocumentTitle, getLocaleLanguage } =
useSettingGetters()
const { updateSettingState, updateLocale } = useSettingActions()
const { getKeepAliveInclude } = useKeepAliveGetters()
const { retainKeepAliveInclude } = useKeepAliveActions()
const { recentPaths, storageUnavailable } = useNavigationHistoryGetters()
const { clearRecent } = useNavigationHistoryActions()
const { globalMainLayoutLoad } = useRuntimeGetters()
const { reload } = useSpinning()
const scrollTo = useContentScroll()
const cacheHintId = useId()
const status = ref('')
const confirm = (title: string, content: string, action: () => void) =>
create({
preset: 'dialog',
type: 'warning',
title,
content,
positiveText: title,
negativeText: t('cancel'),
style: { width: 'min(420px, calc(100vw - 32px))' },
onPositiveClick: action,
})
const clearCache = () =>
confirm(t('general.clearCache'), t('general.clearCacheConfirm'), () => {
retainKeepAliveInclude(new Set())
status.value = 'general.cacheCleared'
})
const clearHistory = () =>
confirm(t('general.clearRecent'), t('general.clearRecentConfirm'), () => {
clearRecent()
status.value = storageUnavailable.value
? 'general.historyStorageUnavailable'
: 'general.recentCleared'
})
const reset = () => {
const defaults = getDefaultSettingConfig()
updateSettingState('dynamicDocumentTitle', defaults.dynamicDocumentTitle)
updateSettingState('keepAliveConfig', cloneDeep(defaults.keepAliveConfig))
status.value = 'general.resetDone'
}
return () => (
<div class="r-settings-stack">
<SettingsSection title={t('section.general')}>
<NForm labelPlacement="top" showFeedback={false}>
<NFormItem label={t('general.language')}>
<NSelect
value={getLocaleLanguage.value}
aria-label={t('general.language')}
options={LOCAL_OPTIONS.map(({ key, label }) => ({
value: key,
label,
}))}
onUpdateValue={updateLocale}
/>
</NFormItem>
</NForm>
<div class="r-settings-switches">
<label class="r-settings-switch">
<span>{t('general.title')}</span>
@ -26,6 +99,24 @@ export default defineComponent({
</label>
</div>
</SettingsSection>
<SettingsSection title={t('general.workspaceActions')}>
<p class="r-settings-hint">{t('general.refreshHint')}</p>
<div class="r-settings-actions">
<NButton
loading={!globalMainLayoutLoad.value}
onClick={() => reload()}
>
{t('general.refresh')}
</NButton>
<NButton
onClick={() => {
scrollTo({ top: 0, left: 0, behavior: 'auto' })
}}
>
{t('general.scrollTop')}
</NButton>
</div>
</SettingsSection>
<SettingsSection title={t('general.cache')}>
<div class="r-settings-switches">
<label class="r-settings-switch">
@ -44,11 +135,17 @@ export default defineComponent({
showFeedback={false}
class="r-settings-fields"
>
<NFormItem label={t('general.cacheLimit')}>
<NFormItem
label={t('general.cacheLimit')}
class="r-settings-fields__wide"
>
<NInputNumber
value={getKeepAliveConfig.value.maxKeepAliveLength}
disabled={!getKeepAliveConfig.value.setupKeepAlive}
inputProps={{ 'aria-label': t('general.cacheLimit') }}
inputProps={{
'aria-label': t('general.cacheLimit'),
'aria-describedby': cacheHintId,
}}
min={0}
precision={0}
showButton={false}
@ -60,19 +157,35 @@ export default defineComponent({
}}
/>
</NFormItem>
<NFormItem
label={t('general.cacheExcluded')}
class="r-settings-fields__wide"
>
<NDynamicTags
value={getKeepAliveConfig.value.keepAliveExclude}
onUpdateValue={(keepAliveExclude: string[]) =>
updateSettingState('keepAliveConfig', { keepAliveExclude })
}
/>
</NFormItem>
</NForm>
<p class="r-settings-hint" id={cacheHintId}>
{t('general.cacheLimitHint')}
</p>
<NButton
disabled={!getKeepAliveInclude.value.length}
onClick={clearCache}
>
{t('general.clearCache')}
</NButton>
</SettingsSection>
<SettingsSection title={t('general.history')}>
<p class="r-settings-hint">
{t('general.recentCount', { count: recentPaths.value.length })}
</p>
<NButton disabled={!recentPaths.value.length} onClick={clearHistory}>
{t('general.clearRecent')}
</NButton>
{storageUnavailable.value && (
<p class="r-settings-hint" role="alert">
{t('general.historyStorageUnavailable')}
</p>
)}
</SettingsSection>
<SettingsSection title={t('general.resetSection')}>
<p class="r-settings-hint">{t('general.resetHint')}</p>
<NButton onClick={reset}>{t('general.reset')}</NButton>
</SettingsSection>
{status.value && <p role="status">{t(status.value)}</p>}
</div>
)
},

View File

@ -1,6 +1,21 @@
import { useI18n } from '@/hooks'
import { useMenuActions, useSettingActions, useSettingGetters } from '@/store'
import { NButton, NForm, NFormItem, NInputNumber, NSwitch } from 'naive-ui'
import { useDevice, useI18n, useSiderScroll } from '@/hooks'
import { findMenuRoot } from '@/layout/navigation'
import {
useMenuActions,
useMenuGetters,
useSettingActions,
useSettingGetters,
} from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import {
NButton,
NForm,
NFormItem,
NInputNumber,
NRadioButton,
NRadioGroup,
NSwitch,
} from 'naive-ui'
import SettingsSection from '../components/SettingsSection'
const sizes = [
@ -16,43 +31,156 @@ const switches = [
'accordion',
'nativeScrollbar',
] as const
const sizePresets = {
compact: {
menuWidth: 224,
collapsedWidth: 56,
collapsedIndent: 16,
iconSize: 18,
collapsedIconSize: 20,
},
comfortable: {
menuWidth: 272,
collapsedWidth: 64,
collapsedIndent: 24,
iconSize: 20,
collapsedIconSize: 22,
},
} as const
export default defineComponent({
name: 'SegmentViewsCustomMenu',
setup() {
const { t } = useI18n('preferences')
const { getMenuConfig } = useSettingGetters()
const { getMenuConfig, getLayoutConfig } = useSettingGetters()
const { getCollapsed, getMenuOptions, getMenuKey } = useMenuGetters()
const { updateSettingState } = useSettingActions()
const { setupAppMenu } = useMenuActions()
const { setupAppMenu, collapsedMenu } = useMenuActions()
const { isTabletOrSmaller } = useDevice()
const scrollSider = useSiderScroll()
const refreshing = ref(false)
const id = useId()
const hasDesktopSidebar = computed(() => {
if (isTabletOrSmaller.value) return false
const { mode } = getLayoutConfig.value
if (mode === 'side' || mode === 'right') return true
if (mode === 'top') return false
return !!findMenuRoot(
getMenuOptions.value,
String(getMenuKey.value),
)?.children?.some((option) => option.show !== false)
})
const refreshMenu = async () => {
if (refreshing.value) return
refreshing.value = true
try {
await setupAppMenu()
window.$message.success(t('menu.refreshed'))
} catch {
window.$message.error(t('menu.refreshFailed'))
} finally {
refreshing.value = false
}
}
const resetMenu = async () => {
if (refreshing.value) return
updateSettingState('menuConfig', {
...getDefaultSettingConfig().menuConfig,
})
await refreshMenu()
}
return () => (
<div class="r-settings-stack">
<SettingsSection title={t('menu.size')}>
<div
class="r-settings-actions"
role="group"
aria-label={t('menu.sizePreset')}
>
{(['compact', 'comfortable'] as const).map((preset) => (
<NButton
key={preset}
secondary
aria-pressed={sizes.every(
(key) =>
getMenuConfig.value[key] === sizePresets[preset][key],
)}
onClick={() =>
updateSettingState('menuConfig', sizePresets[preset])
}
>
{t(`menu.${preset}`)}
</NButton>
))}
</div>
<p class="r-settings-hint">{t('menu.sizeHint')}</p>
<NForm
labelPlacement="top"
showFeedback={false}
class="r-settings-fields"
>
{sizes.map((key) => (
<NFormItem label={t(`menu.${key}`)} key={key}>
<NFormItem
label={t(`menu.${key}`)}
labelProps={{ for: `${id}-${key}` }}
key={key}
>
<NInputNumber
value={getMenuConfig.value[key]}
min={0}
min={
key === 'collapsedIndent'
? 0
: key === 'menuWidth'
? Math.max(1, getMenuConfig.value.collapsedWidth)
: 1
}
max={
key === 'collapsedWidth'
? Math.max(1, getMenuConfig.value.menuWidth)
: void 0
}
precision={0}
inputProps={{ 'aria-label': t(`menu.${key}`) }}
inputProps={{ id: `${id}-${key}` }}
onUpdateValue={(value) => {
if (value !== null)
if (value !== null && Number.isFinite(value))
updateSettingState('menuConfig', { [key]: value })
}}
/>
</NFormItem>
))}
</NForm>
<NButton secondary type="primary" onClick={setupAppMenu}>
{t('menu.refresh')}
</NButton>
</SettingsSection>
<SettingsSection title={t('menu.behavior')}>
<NForm labelPlacement="top" showFeedback={false}>
<NFormItem label={t('menu.collapsedMode')}>
<NRadioGroup
value={getMenuConfig.value.collapsedMode}
aria-label={t('menu.collapsedMode')}
aria-describedby={`${id}-mode-hint`}
onUpdateValue={(value) => {
if (value === 'width' || value === 'transform')
updateSettingState('menuConfig', { collapsedMode: value })
}}
>
<NRadioButton value="width">{t('menu.widthMode')}</NRadioButton>
<NRadioButton value="transform">
{t('menu.transformMode')}
</NRadioButton>
</NRadioGroup>
</NFormItem>
</NForm>
<p id={`${id}-mode-hint`} class="r-settings-hint">
{t('menu.collapsedModeHint')}
</p>
<div class="r-settings-switches">
{switches.map((key) => (
<label key={key} class="r-settings-switch">
@ -68,6 +196,36 @@ export default defineComponent({
))}
</div>
</SettingsSection>
<SettingsSection title={t('menu.actions')}>
<p id={`${id}-sidebar-hint`} class="r-settings-hint">
{t(
hasDesktopSidebar.value
? 'menu.sidebarHint'
: 'menu.noSidebarHint',
)}
</p>
<div class="r-settings-action-grid">
<NButton
disabled={!hasDesktopSidebar.value}
aria-describedby={`${id}-sidebar-hint`}
onClick={() => collapsedMenu(!getCollapsed.value)}
>
{t(getCollapsed.value ? 'menu.expand' : 'menu.collapse')}
</NButton>
<NButton
disabled={!hasDesktopSidebar.value}
onClick={() => scrollSider({ top: 0, left: 0, behavior: 'auto' })}
>
{t('menu.scrollTop')}
</NButton>
<NButton loading={refreshing.value} onClick={refreshMenu}>
{t('menu.refresh')}
</NButton>
<NButton disabled={refreshing.value} onClick={resetMenu}>
{t('menu.reset')}
</NButton>
</div>
</SettingsSection>
</div>
)
},

View File

@ -0,0 +1,79 @@
import { useI18n, useMaximize } from '@/hooks'
import LayoutSettings from '@/layout/components/LayoutSettings'
import { useSettingActions, useSettingGetters } from '@/store'
import type { LayoutConfig } from '@/store/modules/setting/types'
import { NButton, NSwitch } from 'naive-ui'
import SettingsSection from '../components/SettingsSection'
const workspacePresets = {
spacious: { contentWidth: 'fluid', contentPadding: 24 },
compact: { contentWidth: 'fluid', contentPadding: 8 },
reading: {
contentWidth: 'fixed',
contentMaxWidth: 960,
contentPadding: 24,
},
} satisfies Record<string, Partial<LayoutConfig>>
export default defineComponent({
name: 'SegmentViewsLayout',
setup() {
const { t } = useI18n('preferences')
const { getLayoutConfig } = useSettingGetters()
const { updateSettingState } = useSettingActions()
const { isLayoutContentMaximized, maximize } = useMaximize()
const maximizeHintId = useId()
const activePreset = computed(
() =>
Object.entries(workspacePresets).find(([, config]) =>
Object.entries(config).every(
([field, value]) =>
getLayoutConfig.value[field as keyof LayoutConfig] === value,
),
)?.[0],
)
return () => (
<div class="r-settings-stack">
<SettingsSection title={t('layout.presets')}>
<p class="r-settings-hint">{t('layout.presetsHint')}</p>
<div class="r-settings-actions r-workspace-presets">
{Object.entries(workspacePresets).map(([key, config]) => (
<NButton
key={key}
secondary
type={activePreset.value === key ? 'primary' : 'default'}
aria-pressed={activePreset.value === key}
onClick={() => updateSettingState('layoutConfig', config)}
>
{t(`layout.${key}`)}
<span class="r-workspace-presets__check" aria-hidden="true">
{activePreset.value === key ? '✓' : ''}
</span>
</NButton>
))}
</div>
</SettingsSection>
<SettingsSection title={t('section.layout')}>
<LayoutSettings showDescription />
</SettingsSection>
<SettingsSection title={t('layout.focus')}>
<div class="r-settings-switches">
<label class="r-settings-switch">
<span>{t('layout.maximize')}</span>
<NSwitch
value={isLayoutContentMaximized.value}
aria-label={t('layout.maximize')}
aria-describedby={maximizeHintId}
onUpdateValue={(value) => maximize(value)}
/>
</label>
</div>
<p id={maximizeHintId} class="r-settings-hint">
{t('layout.maximizeHint')}
</p>
</SettingsSection>
</div>
)
},
})

View File

@ -1,85 +1,251 @@
import { useI18n } from '@/hooks'
import { useSettingActions, useSettingGetters } from '@/store'
import { NForm, NFormItem, NInput, NInputNumber, NSwitch } from 'naive-ui'
import { useI18n, useWatermark } from '@/hooks'
import {
useSettingActions,
useSettingGetters,
useSigningGetters,
} from '@/store'
import { getDefaultSettingConfig } from '@/store/modules/setting/constant'
import type { WatermarkConfig } from '@/store/modules/setting/types'
import {
NButton,
NForm,
NFormItem,
NInput,
NInputNumber,
NSwitch,
NWatermark,
} from 'naive-ui'
import SettingsSection from '../components/SettingsSection'
const dimensions = [
'fontSize',
'lineHeight',
'width',
'height',
'xOffset',
'yOffset',
'xGap',
'yGap',
'rotate',
const dimensionGroups = [
{ key: 'textStyle', fields: ['fontSize', 'lineHeight', 'rotate'] },
{ key: 'tileSize', fields: ['width', 'height'] },
{ key: 'positionAndSpacing', fields: ['xOffset', 'yOffset', 'xGap', 'yGap'] },
] as const
type Dimension = (typeof dimensionGroups)[number]['fields'][number]
const presets = {
spacious: { width: 384, height: 256, rotate: -15, cross: false },
compact: { width: 256, height: 192, rotate: -15, cross: true },
horizontal: { width: 280, height: 160, rotate: 0, cross: false },
} as const
export default defineComponent({
name: 'SegmentViewsWatermark',
setup() {
const { t } = useI18n('preferences')
const { getWatermarkSwitch, getWatermarkConfig } = useSettingGetters()
const { getWatermarkSwitch, getWatermarkConfig, getSideBarLogo } =
useSettingGetters()
const { getSigningCallback } = useSigningGetters()
const { updateSettingState } = useSettingActions()
const { showWatermark, hiddenWatermark, setWatermarkContent } =
useWatermark()
const id = useId()
const accountName = computed(() => getSigningCallback.value.name?.trim())
const applicationTitle = computed(() => getSideBarLogo.value?.title?.trim())
const setContent = (content: string) => {
if (content) setWatermarkContent(content)
else updateSettingState('watermarkConfig', { content })
}
const applyPreset = (preset: keyof typeof presets) =>
updateSettingState('watermarkConfig', {
fontSize: 16,
lineHeight: 22,
xOffset: 16,
yOffset: 48,
xGap: 0,
yGap: 0,
...presets[preset],
})
const reset = () => {
const defaults = getDefaultSettingConfig()
updateSettingState('watermarkConfig', { ...defaults.watermarkConfig })
updateSettingState('watermarkSwitch', defaults.watermarkSwitch)
}
const bounds = (key: Dimension) => {
const config = getWatermarkConfig.value
const pair = {
width: 'xGap',
height: 'yGap',
xGap: 'width',
yGap: 'height',
} as const
if (key in pair) {
const other = config[pair[key as keyof typeof pair]]
return {
min:
key === 'width' || key === 'height'
? Math.max(1, 1 - other)
: 1 - other,
max: 4096 - other,
}
}
return key === 'fontSize' || key === 'lineHeight' ? { min: 1 } : {}
}
const updateDimension = (key: Dimension, value: number | null) => {
if (value === null || !Number.isFinite(value)) return
const config: WatermarkConfig = {
...getWatermarkConfig.value,
[key]: value,
}
// 单元与间距共同决定 Canvas 尺寸,沿用偏好配置的有效范围。
if (
[config.width + config.xGap, config.height + config.yGap].some(
(edge) => edge <= 0 || edge > 4096,
)
)
return
updateSettingState('watermarkConfig', { [key]: value })
}
return () => (
<div class="r-settings-stack">
<SettingsSection title={t('section.watermark')}>
<div class="r-settings-switches">
<label class="r-settings-switch">
<span>{t('watermark.enabled')}</span>
<NSwitch
value={getWatermarkSwitch.value}
aria-label={t('watermark.enabled')}
onUpdateValue={(enabled) =>
updateSettingState('watermarkSwitch', enabled)
}
/>
</label>
<label class="r-settings-switch">
<span>{t('watermark.cross')}</span>
<NSwitch
value={getWatermarkConfig.value.cross}
aria-label={t('watermark.cross')}
onUpdateValue={(cross) =>
updateSettingState('watermarkConfig', { cross })
}
/>
</label>
{{
action: () => (
<NButton size="small" quaternary onClick={reset}>
{t('watermark.reset')}
</NButton>
),
default: () => (
<div class="r-settings-switches">
<label class="r-settings-switch">
<span>{t('watermark.enabled')}</span>
<NSwitch
value={getWatermarkSwitch.value}
aria-label={t('watermark.enabled')}
onUpdateValue={(enabled) =>
enabled ? showWatermark() : hiddenWatermark()
}
/>
</label>
<label class="r-settings-switch">
<span>{t('watermark.cross')}</span>
<NSwitch
value={getWatermarkConfig.value.cross}
aria-label={t('watermark.cross')}
onUpdateValue={(cross) =>
updateSettingState('watermarkConfig', { cross })
}
/>
</label>
</div>
),
}}
</SettingsSection>
<SettingsSection title={t('watermark.presets')}>
<p class="r-settings-hint">{t('watermark.presetsHint')}</p>
<div class="r-settings-actions">
{(Object.keys(presets) as (keyof typeof presets)[]).map(
(preset) => (
<NButton
key={preset}
secondary
onClick={() => applyPreset(preset)}
>
{t(`watermark.${preset}`)}
</NButton>
),
)}
</div>
<p class="r-settings-hint">{t('watermark.previewHint')}</p>
<NWatermark
{...getWatermarkConfig.value}
class="r-watermark-preview"
fullscreen={false}
zIndex={1}
aria-hidden="true"
/>
</SettingsSection>
<SettingsSection title={t('watermark.style')}>
<NForm
labelPlacement="top"
showFeedback={false}
class="r-settings-fields"
class="r-watermark-form"
>
<NFormItem
label={t('watermark.content')}
class="r-settings-fields__wide"
>
<NInput
value={getWatermarkConfig.value.content}
inputProps={{ 'aria-label': t('watermark.content') }}
onUpdateValue={(content) =>
updateSettingState('watermarkConfig', { content })
}
/>
</NFormItem>
{dimensions.map((key) => (
<NFormItem label={t(`watermark.${key}`)} key={key}>
<NInputNumber
value={getWatermarkConfig.value[key]}
precision={0}
showButton={false}
inputProps={{ 'aria-label': t(`watermark.${key}`) }}
onUpdateValue={(value) => {
if (value !== null)
updateSettingState('watermarkConfig', { [key]: value })
}}
<div class="r-settings-stack">
<NFormItem
label={t('watermark.content')}
labelProps={{ for: `${id}-content` }}
>
<NInput
type="textarea"
autosize={{ minRows: 2, maxRows: 4 }}
value={getWatermarkConfig.value.content}
inputProps={{ id: `${id}-content` }}
onUpdateValue={setContent}
/>
</NFormItem>
<div class="r-settings-actions">
<NButton
size="small"
secondary
disabled={!applicationTitle.value}
onClick={() =>
setWatermarkContent(applicationTitle.value ?? '')
}
>
{t('watermark.useApplicationTitle')}
</NButton>
<NButton
size="small"
secondary
disabled={!accountName.value}
onClick={() => setWatermarkContent(accountName.value ?? '')}
>
{t('watermark.useAccountName')}
</NButton>
</div>
</div>
{dimensionGroups.map((group) => (
<fieldset key={group.key} class="r-watermark-fieldset">
<legend>{t(`watermark.${group.key}`)}</legend>
<div
class={[
'r-settings-fields',
group.key === 'textStyle' && 'r-settings-fields--three',
]}
>
{group.fields.map((key) => (
<NFormItem
label={t(`watermark.${key}`)}
labelProps={{ for: `${id}-${key}` }}
key={key}
>
<NInputNumber
value={getWatermarkConfig.value[key]}
{...bounds(key)}
precision={0}
inputProps={{
id: `${id}-${key}`,
'aria-describedby': [
'width',
'height',
'xGap',
'yGap',
].includes(key)
? `${id}-bounds`
: void 0,
}}
onUpdateValue={(value) => updateDimension(key, value)}
/>
</NFormItem>
))}
</div>
</fieldset>
))}
<p id={`${id}-bounds`} class="r-settings-hint">
{t('watermark.dimensionsHint')}
</p>
</NForm>
</SettingsSection>
</div>

View File

@ -1,6 +1,6 @@
{
"title": "Preferences",
"subtitle": "Changes apply immediately and are saved in this browser",
"subtitle": "Preferences save immediately; quick actions affect this workspace",
"reset": "Restore defaults",
"resetDescription": "Restore the default interface style, accent color, layout, menu and general options.",
"cancel": "Cancel",
@ -43,7 +43,12 @@
"breadcrumbSwitch": "Breadcrumbs",
"menuTagSwitch": "Page tabs",
"copyrightSwitch": "Footer",
"colorWeakness": "Color vision mode"
"colorWeakness": "Color vision mode",
"displayHint": "Show or hide breadcrumbs, page tabs, and the footer together, or adjust each below.",
"showAll": "Show all",
"minimal": "Minimal interface",
"reset": "Reset appearance",
"resetHint": "Reset the style, accent, animation, drawer position, and display options. Keep the current color mode."
},
"transition": {
"slide-up": "Rise in",
@ -71,7 +76,24 @@
"inverted": "Inverted menu",
"menuSiderBarLogo": "Brand mark",
"accordion": "Accordion groups",
"nativeScrollbar": "Native scrollbar"
"nativeScrollbar": "Native scrollbar",
"sizePreset": "Menu size presets",
"compact": "Compact menu",
"comfortable": "Comfortable menu",
"sizeHint": "Presets adjust width, indentation, and icon sizes while keeping menu behavior. Sizes are in px.",
"collapsedMode": "Sidebar collapse behavior",
"widthMode": "Shrink content",
"transformMode": "Keep content width",
"collapsedModeHint": "Shrink mode narrows the content with the sidebar. Keep-width mode clips content at its original width. Both use the collapsed width.",
"actions": "Menu shortcuts",
"sidebarHint": "Collapse and scroll actions affect the current sidebar without changing the layout mode.",
"noSidebarHint": "This view has no desktop sidebar to control. Size and behavior preferences are kept for when the sidebar is shown.",
"collapse": "Collapse current sidebar",
"expand": "Expand current sidebar",
"scrollTop": "Scroll menu to top",
"refreshed": "Menu refreshed",
"refreshFailed": "Could not refresh the menu. Please try again.",
"reset": "Reset menu preferences"
},
"watermark": {
"enabled": "Full-page watermark",
@ -86,13 +108,54 @@
"yOffset": "Vertical offset",
"xGap": "Horizontal gap",
"yGap": "Vertical gap",
"rotate": "Rotation"
"rotate": "Rotation",
"presets": "Quick styles and preview",
"presetsHint": "Only adjusts the style. Keeps the watermark text and fullscreen setting.",
"spacious": "Spacious",
"compact": "Compact",
"horizontal": "Horizontal",
"previewHint": "The preview stays visible while the fullscreen watermark is off.",
"useApplicationTitle": "Use application title",
"useAccountName": "Use account name",
"dimensionsHint": "Sizes are in px and angles in °. Cell width + horizontal gap and cell height + vertical gap must each be 1–4096 px. Negative gaps allow overlapping.",
"reset": "Reset watermark settings",
"textStyle": "Text style",
"tileSize": "Tile size",
"positionAndSpacing": "Position and spacing"
},
"general": {
"title": "Dynamic browser title",
"cache": "Page cache",
"enableCache": "Enable caching",
"cacheLimit": "Cache limit",
"cacheExcluded": "Excluded component names"
"language": "Interface language",
"workspaceActions": "Workspace actions",
"refresh": "Refresh workspace",
"refreshHint": "Reload the current page and release workspace page instances. Unsaved form changes will be lost.",
"scrollTop": "Scroll content to top",
"cacheLimitHint": "Pages are queued by recent access. Set to 0 to stop adding pages; turn caching off to disable it immediately.",
"clearCache": "Clear page cache",
"clearCacheConfirm": "Release inactive cached pages. Unsaved changes may be lost. The current page stays open and will be recreated after leaving and returning.",
"cacheCleared": "Page cache cleared. The current page stays open.",
"history": "Recent visits",
"recentCount": "This account has {count} recent visits used by the dashboard and global search.",
"clearRecent": "Clear recent visits",
"clearRecentConfirm": "Clear only this account's recent visits. Favorites and open tabs will be kept.",
"recentCleared": "Recent visits cleared.",
"historyStorageUnavailable": "Browser storage is unavailable. Record changes apply only to this session.",
"resetSection": "Reset general settings",
"resetHint": "Restore only the dynamic title and page cache preferences. Keep the interface language, visit history, and other modules unchanged.",
"reset": "Reset general preferences",
"resetDone": "Dynamic title and cache preferences restored to defaults."
},
"layout": {
"presets": "Workspace presets",
"presetsHint": "Change content width and spacing while keeping navigation and fixed bars.",
"spacious": "Comfortable spacing",
"compact": "Compact spacing",
"reading": "Centered reading",
"focus": "Focus workspace",
"maximize": "Maximize content",
"maximizeHint": "Temporarily hide navigation and the footer. Close settings to see the result, then press Esc or use the exit button to restore. This resets on page reload."
}
}

View File

@ -1,6 +1,6 @@
{
"title": "偏好设置",
"subtitle": "更改即时生效并保存在此浏览器",
"subtitle": "偏好即时保存;快捷操作仅在当前工作区生效",
"reset": "恢复默认设置",
"resetDescription": "将界面风格、主题色、布局、菜单和通用选项恢复为默认值。",
"cancel": "取消",
@ -43,7 +43,12 @@
"breadcrumbSwitch": "面包屑导航",
"menuTagSwitch": "页面标签",
"copyrightSwitch": "页脚信息",
"colorWeakness": "色弱模式"
"colorWeakness": "色弱模式",
"displayHint": "批量调整面包屑、页面标签和页脚,也可继续逐项设置。",
"showAll": "显示全部",
"minimal": "精简界面",
"reset": "恢复外观默认",
"resetHint": "恢复界面风格、主题色、动画、抽屉位置与显示选项,保留当前明暗模式。"
},
"transition": {
"slide-up": "向上浮入",
@ -71,7 +76,24 @@
"inverted": "反色菜单",
"menuSiderBarLogo": "品牌标识",
"accordion": "手风琴展开",
"nativeScrollbar": "原生滚动条"
"nativeScrollbar": "原生滚动条",
"sizePreset": "菜单尺寸预设",
"compact": "紧凑菜单",
"comfortable": "舒适菜单",
"sizeHint": "预设只调整菜单宽度、缩进和图标大小,保留菜单行为。尺寸单位为 px。",
"collapsedMode": "侧栏折叠方式",
"widthMode": "收缩内容宽度",
"transformMode": "保持内容宽度",
"collapsedModeHint": "收缩模式让内容随侧栏变窄;保持模式保留内容原宽度并裁切。两种模式都使用折叠宽度。",
"actions": "菜单快捷操作",
"sidebarHint": "折叠与滚动操作作用于当前侧栏,不改变布局模式。",
"noSidebarHint": "当前界面没有可操作的桌面侧栏。尺寸和行为设置仍会保留,侧栏显示后生效。",
"collapse": "折叠当前侧栏",
"expand": "展开当前侧栏",
"scrollTop": "菜单回到顶部",
"refreshed": "菜单已刷新",
"refreshFailed": "菜单刷新失败,请重试。",
"reset": "恢复菜单默认设置"
},
"watermark": {
"enabled": "全屏水印",
@ -86,13 +108,54 @@
"yOffset": "垂直偏移",
"xGap": "水平间距",
"yGap": "垂直间距",
"rotate": "旋转角度"
"rotate": "旋转角度",
"presets": "快速样式与预览",
"presetsHint": "只调整样式,保留水印文本和全屏开关。",
"spacious": "疏朗",
"compact": "紧凑",
"horizontal": "水平",
"previewHint": "预览始终可见;关闭全屏水印时也可调整样式。",
"useApplicationTitle": "使用应用标题",
"useAccountName": "使用账户昵称",
"dimensionsHint": "尺寸单位为 px,角度单位为 °。单元宽度+水平间距、单元高度+垂直间距均须为 1–4096 px;负间距可让水印重叠。",
"reset": "恢复水印默认设置",
"textStyle": "文字样式",
"tileSize": "平铺尺寸",
"positionAndSpacing": "位置与间距"
},
"general": {
"title": "动态浏览器标题",
"cache": "页面缓存",
"enableCache": "启用缓存",
"cacheLimit": "最大缓存数",
"cacheExcluded": "排除的组件名称"
"language": "界面语言",
"workspaceActions": "工作区操作",
"refresh": "刷新工作区",
"refreshHint": "重新加载当前页面并释放工作区中的页面实例;未保存的表单内容会丢失。",
"scrollTop": "回到内容顶部",
"cacheLimitHint": "按最近访问顺序管理缓存。设为 0 将停止加入新页面;如需立即停用,请关闭页面缓存。",
"clearCache": "清理页面缓存",
"clearCacheConfirm": "释放已离开页面的缓存,未保存内容可能丢失。当前页面不会立即重载,离开后重新打开会重新创建。",
"cacheCleared": "页面缓存已清理,当前页面保持打开。",
"history": "最近访问记录",
"recentCount": "当前账号保存了 {count} 条最近访问记录,供工作台和全局搜索使用。",
"clearRecent": "清空最近访问",
"clearRecentConfirm": "仅清空当前账号的最近访问记录,收藏和已打开标签页保留。",
"recentCleared": "最近访问记录已清空。",
"historyStorageUnavailable": "浏览器存储不可用,本次记录变更仅对当前会话生效。",
"resetSection": "恢复通用设置",
"resetHint": "仅恢复动态标题和页面缓存配置;界面语言、访问记录及其他模块设置保持不变。",
"reset": "恢复通用默认值",
"resetDone": "动态标题和缓存配置已恢复默认值。"
},
"layout": {
"presets": "工作区预设",
"presetsHint": "仅调整内容宽度和间距,保留当前导航方式与固定栏设置。",
"spacious": "舒适间距",
"compact": "紧凑间距",
"reading": "居中阅读",
"focus": "专注工作",
"maximize": "内容区最大化",
"maximizeHint": "临时隐藏导航和页脚。关闭设置抽屉后可查看效果,按 Esc 或点击退出按钮恢复;刷新页面不保留。"
}
}

View File

@ -28,7 +28,7 @@ const defaultSettingConfig: Readonly<Config> = {
mode: 'side',
contentWidth: 'fluid',
contentMaxWidth: 1200,
contentPadding: 16,
contentPadding: 24,
fixedHeader: true,
fixedFooter: true,
},

View File

@ -1,4 +1,5 @@
.r-route-transition {
.opacity-transform-enter-active,
.scale-transform-enter-active,
.fade-scale-transform-enter-active,
.fade-slide-transform-enter-active,
@ -6,20 +7,20 @@
.slide-up-transform-enter-active,
.slide-left-transform-enter-active {
transition:
opacity 180ms ease-out,
transform 180ms var(--r-bezier);
}
.opacity-transform-enter-active {
transition: opacity 160ms ease-out;
opacity 240ms cubic-bezier(0.42, 0, 0.58, 1),
transform 240ms cubic-bezier(0.42, 0, 0.58, 1);
}
.opacity-transform-leave-active,
.scale-transform-leave-active,
.fade-scale-transform-leave-active,
.fade-slide-transform-leave-active,
.fade-bottom-transform-leave-active {
transition: opacity 70ms ease-in;
.fade-bottom-transform-leave-active,
.slide-up-transform-leave-active,
.slide-left-transform-leave-active {
transition:
opacity 190ms cubic-bezier(0.42, 0, 0.58, 1),
transform 190ms cubic-bezier(0.42, 0, 0.58, 1);
pointer-events: none;
}
@ -34,38 +35,66 @@
.scale-transform-leave-to,
.fade-scale-transform-leave-to,
.fade-slide-transform-leave-to,
.fade-bottom-transform-leave-to {
.fade-bottom-transform-leave-to,
.slide-up-transform-leave-to,
.slide-left-transform-leave-to {
opacity: 0;
}
.scale-transform-enter-from {
transform: scale(0.985);
transform: scale(0.99);
}
.scale-transform-leave-to {
transform: scale(1.005);
}
.fade-scale-transform-enter-from {
transform: scale(1.015);
transform: scale(1.01);
}
.fade-scale-transform-leave-to {
transform: scale(0.995);
}
.fade-slide-transform-enter-from {
transform: translateX(-12px);
transform: translateX(-8px);
}
.fade-slide-transform-leave-to {
transform: translateX(4px);
}
.fade-bottom-transform-enter-from {
transform: translateY(-10px);
transform: translateY(-8px);
}
.fade-bottom-transform-leave-to {
transform: translateY(4px);
}
.slide-up-transform-enter-from {
transform: translateY(10px);
transform: translateY(8px);
}
.slide-up-transform-leave-to {
transform: translateY(-4px);
}
.slide-left-transform-enter-from {
transform: translateX(12px);
transform: translateX(8px);
}
.slide-left-transform-leave-to {
transform: translateX(-4px);
}
@media (prefers-reduced-motion: reduce) {
[class*='-transform-enter-active'],
[class*='-transform-leave-active'] {
[class*='-transform-enter-'],
[class*='-transform-leave-'] {
transition: none;
opacity: 1;
transform: none;
}
}
}

View File

@ -22,7 +22,7 @@
}
&__layout {
display: grid;
grid-template-columns: 220px minmax(0, 1fr);
grid-template-columns: clamp(240px, 22%, 360px) minmax(0, 1fr);
grid-template-rows: minmax(0, 1fr);
block-size: 100%;
min-block-size: 0;

View File

@ -27,15 +27,17 @@ updateSettingState('layoutConfig', {
mode: 'mixed',
contentWidth: 'fixed',
contentMaxWidth: 1200,
contentPadding: 16,
contentPadding: 24,
})
```
最大宽度范围是 640–2560px,间距为 0–48px。顶栏和页脚可固定或随内容滚动。旧设置补齐默认值,布局恢复默认只重置 `layoutConfig`。
最大宽度范围是 640–2560px,间距为 0–48px。顶栏和页脚可固定或随内容滚动。设置抽屉默认使用舒适间距(24px),并提供紧凑和居中阅读预设,只调整内容宽度与间距,保留导航方式和固定栏配置。已有浏览器偏好继续沿用,恢复默认布局时应用新的默认间距。内容区最大化复用 `useMaximize`,关闭设置后可查看效果,按 Esc 或退出按钮恢复;这一状态不随刷新保留。旧设置补齐默认值,布局恢复默认只重置 `layoutConfig`。
外观页可批量显示或隐藏面包屑、页面标签和页脚,页面切换动画在「窗口与动效」中选择。各效果进入用时 240ms,退出用时 190ms,完整退出后再进入,并保留小幅位移和缩放。系统偏好减少动态效果时直接切换。恢复外观默认只重置外观选项,保留当前明暗模式。水印页提供疏朗、紧凑和水平预设、独立局部预览,以及应用标题和账户昵称快捷填入;无需开启全屏水印即可调试样式,预设保留已有文本和显隐状态。各模块的恢复按钮只作用于对应模块。
## 菜单图标
展开侧栏、移动端抽屉和顶部导航默认使用 20 px 的图标;折叠侧栏默认 22 px,方便只凭图形辨认菜单。线性图标跟随菜单状态和明暗主题变色。可在「偏好设置 → 菜单」调整「图标尺寸」与「折叠图标尺寸」,修改即时生效。
展开侧栏、移动端抽屉和顶部导航默认使用 20 px 的图标;折叠侧栏默认 22 px,方便只凭图形辨认菜单。线性图标跟随菜单状态和明暗主题变色。可在「偏好设置 → 菜单」调整「图标尺寸」与「折叠图标尺寸」,修改即时生效。紧凑和舒适预设只调整宽度、缩进和图标尺寸;折叠方式、侧栏折叠/展开、回到菜单顶部和刷新菜单也可直接操作。当前布局没有桌面侧栏时,侧栏快捷操作禁用,已配置的尺寸仍会保留。
## 替换布局区域
@ -49,6 +51,8 @@ updateSettingState('layoutConfig', {
| 布局、主题、语言等偏好 | `useSettingGetters` / `useSettingActions` | 沿用设置缓存;旧值补默认配置 |
| 锁屏 | 锁屏 Store | 保留历史布尔值格式和跨标签同步 |
通用页通过 `updateLocale` 同步界面、组件库和日期语言,提供刷新当前页面、回到内容顶部和缓存管理。可调整缓存上限,界面保留缓存管理规则的提示。清理缓存会释放非活动页面实例,当前页面继续保留,后续访问按缓存配置重新创建。刷新当前页面会重新挂载内容,未保存的页面输入可能丢失。通用模块恢复默认仅重置动态标题与缓存配置,保留语言、最近访问和收藏。
新增共享状态按职责放到 `apps/admin/src/store/modules`,对外用 Store hooks。持久化使用 `pick` / `omit` 选择字段;检查历史 key 和序列化格式再变更。
[布局说明与插槽](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/apps/admin/src/layout/README.md) · [状态实现与持久化](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/apps/admin/src/store/README.md)
@ -57,6 +61,6 @@ updateSettingState('layoutConfig', {
## 最近访问和收藏
桌面搜索支持 Ctrl/Command + K。输入页面名称查找,点击星标收藏;空关键词时显示收藏与最近访问,方向键、回车和 Tab 可操作。记录按会话用户 id 隔离,刷新后恢复;清空记录保留收藏。缓存只存菜单路径,展示时重新依据当前菜单和权限筛选,语言切换沿用当前翻译。窄屏继续使用导航抽屉。
桌面搜索支持 Ctrl/Command + K。输入页面名称查找,点击星标收藏;空关键词时显示收藏与最近访问,方向键、回车和 Tab 可操作。记录按会话用户 id 隔离,刷新后恢复;清空记录保留收藏,也可在「偏好设置 → 通用」确认后清理当前账户的最近访问。缓存只存菜单路径,展示时重新依据当前菜单和权限筛选,语言切换沿用当前翻译。窄屏继续使用导航抽屉。
内容页需要撑满工作区时,先复用布局的 `--layout-content-height`、`RTablePro autoHeight` 和 `--r-table-height`,以及 Naive UI 的 `NCard contentScrollable` / `NScrollbar`。父容器提供确定高度,Flex/Grid 子项设置 `min-block-size: 0` 后再承载内部滚动;单纯填充与滚动无需新增通用组件。用户管理页展示了左右独立滚动与窄屏上下排布。

View File

@ -73,6 +73,7 @@ export const LayoutSettings = defineComponent({
<NForm labelPlacement="top" showFeedback={false}>
<NFormItem label={text('contentWidth')}>
<NSelect
aria-label={text('contentWidth')}
value={props.layout.contentWidth}
options={['fluid', 'fixed'].map((value) => ({
value,
@ -85,6 +86,7 @@ export const LayoutSettings = defineComponent({
</NFormItem>
<NFormItem label={text('maxWidth')}>
<NInputNumber
inputProps={{ 'aria-label': text('maxWidth') }}
value={props.layout.contentMaxWidth}
disabled={props.layout.contentWidth !== 'fixed'}
min={640}
@ -98,6 +100,7 @@ export const LayoutSettings = defineComponent({
</NFormItem>
<NFormItem label={text('padding')}>
<NInputNumber
inputProps={{ 'aria-label': text('padding') }}
value={props.layout.contentPadding}
min={0}
max={48}
@ -110,12 +113,14 @@ export const LayoutSettings = defineComponent({
</NFormItem>
<NFormItem label={text('fixedHeader')}>
<NSwitch
aria-label={text('fixedHeader')}
value={props.layout.fixedHeader}
onUpdateValue={(fixedHeader) => update({ fixedHeader })}
/>
</NFormItem>
<NFormItem label={text('fixedFooter')}>
<NSwitch
aria-label={text('fixedFooter')}
value={props.layout.fixedFooter}
onUpdateValue={(fixedFooter) => update({ fixedFooter })}
/>

View File

@ -7,16 +7,19 @@
:mode="transitionMode"
:appear="transitionAppear"
>
<Suspense>
<KeepAlive
v-if="getKeepAliveConfig.setupKeepAlive"
:max="getKeepAliveConfig.maxKeepAliveLength"
:include="getKeepAliveInclude"
:exclude="getKeepAliveConfig.keepAliveExclude"
>
<!-- KeepAlive 必须在 Suspense 外,避免过渡将缓存容器视为同一页面并提前结束退出。 -->
<KeepAlive
v-if="getKeepAliveConfig.setupKeepAlive"
:max="getKeepAliveConfig.maxKeepAliveLength"
:include="getKeepAliveInclude"
:exclude="getKeepAliveConfig.keepAliveExclude"
>
<Suspense>
<Component :is="Component" :key="route.fullPath" />
</KeepAlive>
<Component :is="Component" v-else :key="route.fullPath" />
</Suspense>
</KeepAlive>
<Suspense v-else>
<Component :is="Component" :key="route.fullPath" />
</Suspense>
</Transition>
</template>

View File

@ -76,6 +76,10 @@
font-size: 13px;
}
.menu-tag__item:has(> .menu-tag__close) > .menu-tag__tab {
padding-inline-end: 2px;
}
.menu-tag__close {
position: relative;
isolation: isolate;