fix: 优化移动端全屏侧栏
移动端侧栏改为全屏固定导航,关闭后释放全部正文宽度,并统一使用菜单图标入口。
This commit is contained in:
@@ -132,6 +132,7 @@ describe('管理后台组件边界', () => {
|
||||
expect(wrapper.getComponent(ThemeToggle).findComponent(NTooltip).exists()).toBe(false)
|
||||
expect(wrapper.get('.theme-toggle').attributes('title')).toBeUndefined()
|
||||
expect(wrapper.get('.theme-toggle svg').classes()).toContain('lucide-monitor')
|
||||
expect(wrapper.get('.admin-topbar [aria-controls="main-navigation"] svg').classes()).toContain('lucide-menu')
|
||||
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
for (const [key, label, icon] of [
|
||||
['dark', '暗黑模式', 'moon'],
|
||||
@@ -175,7 +176,7 @@ describe('管理后台组件边界', () => {
|
||||
expect(wrapper.findAll('.admin-nav-scroll .n-menu .n-menu-item')).toHaveLength(8)
|
||||
})
|
||||
|
||||
it('侧栏菜单独立滚动,页脚不参与滚动且窄屏展开平移主栏', () => {
|
||||
it('侧栏菜单独立滚动,窄屏改为不占正文宽度的全屏固定层', () => {
|
||||
const css = readAllStyles()
|
||||
expect(css).toMatch(/\.admin-sider\s*\{[^}]*display:\s*flex;[^}]*flex-direction:\s*column;[^}]*height:\s*100%/)
|
||||
expect(css).toMatch(
|
||||
@@ -190,7 +191,14 @@ describe('管理后台组件边界', () => {
|
||||
expect(css).toMatch(/\.admin-sider\s*\{[^}]*transition:\s*width\s+0\.32s/)
|
||||
expect(css).toMatch(/\.workspace-tools-body\s*\{[^}]*padding:\s*16px/)
|
||||
expect(css).toMatch(/\.workspace-tools-drawer \.n-drawer-header[\s\S]*?padding:\s*16px/)
|
||||
expect(css).toContain('calc(100% - var(--admin-sider-collapsed))')
|
||||
expect(css).toMatch(
|
||||
/@media \(max-width: 800px\)[\s\S]*?\.admin-sider\s*\{[^}]*position:\s*fixed;[^}]*inset:\s*0;[^}]*width:\s*100%\s*!important;[^}]*transform:\s*translateX\(0\)/
|
||||
)
|
||||
expect(css).toMatch(
|
||||
/\.admin-sider\.is-collapsed\s*\{[^}]*transform:\s*translateX\(-100%\);[^}]*visibility:\s*hidden;[^}]*pointer-events:\s*none/
|
||||
)
|
||||
expect(css).toMatch(/\.admin-layout > \.admin-main\s*\{[^}]*width:\s*100%;[^}]*min-width:\s*0/)
|
||||
expect(css).toMatch(/\.mobile-sider-close\s*\{[^}]*display:\s*flex;[^}]*margin-right:\s*8px/)
|
||||
expect(css).toContain('@media (prefers-reduced-motion: reduce)')
|
||||
expect(css).not.toContain('.admin-sider-mask')
|
||||
expect(css).not.toContain('.admin-sider.is-overlay')
|
||||
@@ -201,7 +209,7 @@ describe('管理后台组件边界', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('窄屏展开导航复用同一侧栏并右移主栏,不压缩主栏宽度', async () => {
|
||||
it('窄屏导航关闭时移出视口,打开后全屏显示并可从内部关闭', async () => {
|
||||
const realMatchMedia = window.matchMedia.bind(window)
|
||||
vi.stubGlobal('matchMedia', (query: string) => {
|
||||
if (query.includes('max-width: 800px')) {
|
||||
@@ -234,13 +242,14 @@ describe('管理后台组件边界', () => {
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('.admin-sider')).toHaveLength(1)
|
||||
expect(wrapper.get('.admin-sider').classes()).toContain('is-collapsed')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 48px')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
||||
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBe('true')
|
||||
expect(wrapper.find('.admin-sider-mask').exists()).toBe(false)
|
||||
expect(wrapper.find('.admin-nav-drawer').exists()).toBe(false)
|
||||
expect(wrapper.getComponent(NMenu).props()).toMatchObject({
|
||||
collapsedWidth: 48,
|
||||
indent: 14,
|
||||
rootIndent: 14
|
||||
collapsedWidth: 64,
|
||||
indent: 20,
|
||||
rootIndent: 20
|
||||
})
|
||||
const collapsedBrand = wrapper.get('.admin-brand')
|
||||
expect(collapsedBrand.classes()).toContain('is-collapsed')
|
||||
@@ -248,25 +257,29 @@ describe('管理后台组件边界', () => {
|
||||
const collapsedSettings = wrapper.get('.admin-sider-footer [aria-label="后端连接"]')
|
||||
expect(collapsedSettings.text()).toBe('后端连接')
|
||||
expect(collapsedSettings.classes()).toContain('is-collapsed')
|
||||
await wrapper.get('[aria-label="展开侧栏"]').trigger('click')
|
||||
expect(wrapper.get('.admin-topbar [aria-label="打开主菜单"] svg').classes()).toContain('lucide-menu')
|
||||
await wrapper.get('.admin-topbar [aria-label="打开主菜单"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('.admin-sider')).toHaveLength(1)
|
||||
expect(wrapper.get('.admin-sider').classes()).not.toContain('is-collapsed')
|
||||
expect(wrapper.get('.admin-sider').classes()).not.toContain('is-overlay')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 168px')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
||||
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBeUndefined()
|
||||
expect(wrapper.find('.admin-sider-mask').exists()).toBe(false)
|
||||
expect(wrapper.get('.admin-sider').findAll('.n-menu .n-menu-item')).toHaveLength(8)
|
||||
expect(wrapper.get('[aria-label="折叠侧栏"]').attributes('aria-expanded')).toBe('true')
|
||||
expect(wrapper.get('.admin-topbar [aria-label="关闭主菜单"]').attributes('aria-expanded')).toBe('true')
|
||||
const expandedBrand = wrapper.get('.admin-brand')
|
||||
expect(expandedBrand.classes()).not.toContain('is-collapsed')
|
||||
expect(expandedBrand.text()).toContain('短剧工作台')
|
||||
const expandedSettings = wrapper.get('.admin-sider-footer [aria-label="后端连接"]')
|
||||
expect(expandedSettings.text()).toBe('后端连接')
|
||||
expect(expandedSettings.classes()).not.toContain('is-collapsed')
|
||||
await wrapper.get('[aria-label="折叠侧栏"]').trigger('click')
|
||||
expect(wrapper.get('.mobile-sider-close').attributes('aria-label')).toBe('关闭主菜单')
|
||||
await wrapper.get('.mobile-sider-close').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.get('.admin-sider').classes()).toContain('is-collapsed')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 48px')
|
||||
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
||||
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBe('true')
|
||||
expect(wrapper.get('.admin-brand').text()).toContain('短剧工作台')
|
||||
expect(wrapper.get('.admin-sider-footer [aria-label="后端连接"]').text()).toBe('后端连接')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user