From 6f095b763e8deac14631913f9a4918acaadcb5f4 Mon Sep 17 00:00:00 2001 From: XiaoDaiGua-Ray <51957438+XiaoDaiGua-Ray@users.noreply.github.com> Date: Wed, 4 Nov 2026 11:17:27 +0800 Subject: [PATCH] feat: expand layout and route configuration Add navigation presets, page transitions, and visual route editing. Fix Segment sizing and loading placement. Add preference import and export. --- __test__/layout/preferences.spec.ts | 92 +++- __test__/layout/slots.spec.ts | 18 + __test__/router/config.spec.ts | 31 +- docs/docs-handoff.md | 4 + src/app-config/app-config.ts | 5 +- src/components/RSegment/README.md | 2 +- src/components/RSegment/src/index.scss | 3 + .../src/TransitionComponent.vue | 2 +- src/hooks/README.md | 1 + src/layout/README.md | 8 +- src/layout/components/LayoutSettings.scss | 51 ++- src/layout/components/LayoutSettings.tsx | 21 +- src/layout/components/Menu/index.scss | 5 + src/layout/components/Menu/index.tsx | 5 +- .../components/SettingDrawer/index.scss | 17 + .../components/SettingDrawer/index.tsx | 83 +++- src/layout/components/TopNavigation/index.tsx | 6 +- .../default/ContentWrapper/ContentLoading.tsx | 61 +++ src/layout/default/ContentWrapper/index.scss | 40 +- src/layout/default/ContentWrapper/index.tsx | 74 +-- src/layout/index.scss | 71 +-- src/layout/index.tsx | 146 +++--- src/locales/lang/en-US/layout.json | 4 + src/locales/lang/en-US/menu.json | 4 +- src/locales/lang/en-US/preferences.json | 10 + src/locales/lang/en-US/routeManagement.json | 36 +- src/locales/lang/zh-CN/layout.json | 4 + src/locales/lang/zh-CN/menu.json | 4 +- src/locales/lang/zh-CN/preferences.json | 10 + src/locales/lang/zh-CN/routeManagement.json | 36 +- src/router/README.md | 5 +- src/router/app-route-modules.ts | 16 +- src/router/config/contract.ts | 10 +- src/router/constant/index.ts | 1 + src/router/routes.ts | 7 +- src/router/utils/order-routes.ts | 8 +- src/router/utils/scroll-view-to-top.ts | 2 +- src/store/hooks/useSettingStore.ts | 4 + src/store/modules/setting/constant.ts | 13 +- src/store/modules/setting/index.ts | 17 + src/store/modules/setting/preference-file.ts | 103 +++++ src/store/modules/setting/types.ts | 2 +- src/styles/animate.scss | 157 +++---- src/views/route-management/download-json.ts | 13 + src/views/route-management/index.scss | 30 ++ src/views/route-management/index.tsx | 15 +- src/views/route-management/visual.tsx | 433 ++++++++++++++++++ 47 files changed, 1351 insertions(+), 339 deletions(-) create mode 100644 src/layout/default/ContentWrapper/ContentLoading.tsx create mode 100644 src/store/modules/setting/preference-file.ts create mode 100644 src/views/route-management/download-json.ts create mode 100644 src/views/route-management/visual.tsx diff --git a/__test__/layout/preferences.spec.ts b/__test__/layout/preferences.spec.ts index 074c4608..33f3a53d 100644 --- a/__test__/layout/preferences.spec.ts +++ b/__test__/layout/preferences.spec.ts @@ -1,7 +1,7 @@ import { createPinia, disposePinia, setActivePinia } from 'pinia' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import { createApp, nextTick } from 'vue' -import { APP_CATCH_KEY } from '../../src/app-config' +import { APP_CATCH_KEY, GLOBAL_CLASS_NAMES } from '../../src/app-config' import { findMenuRoot, firstMenuLeaf } from '../../src/layout/navigation' import { piniaLockScreenStore } from '../../src/store/modules/lock-screen' import { piniaSettingStore } from '../../src/store/modules/setting' @@ -26,6 +26,16 @@ const menu = ( show, }) +const mountPersistedSettings = () => { + const pinia = createPinia().use(piniaPluginPersistedstate) + const app = createApp({ render: () => null }).use(pinia) + + app.mount(document.createElement('div')) + setActivePinia(pinia) + + return { pinia, app } +} + describe('layout preferences', () => { it('adds defaults and bounds persisted or programmatic invalid values', () => { expect(normalizeLayoutConfig(null)).toEqual( @@ -60,11 +70,7 @@ describe('layout preferences', () => { menuTagSwitch: false, }), ) - const pinia = createPinia().use(piniaPluginPersistedstate) - const app = createApp({ render: () => null }).use(pinia) - - app.mount(document.createElement('div')) - setActivePinia(pinia) + const { pinia, app } = mountPersistedSettings() try { const store = piniaSettingStore() @@ -86,6 +92,80 @@ describe('layout preferences', () => { } }) + it('restores the exported preferences through the existing store and persistence', async () => { + const { pinia, app } = mountPersistedSettings() + const store = piniaSettingStore() + const property = GLOBAL_CLASS_NAMES.rayTemplateThemePrimaryColor + const fadeProperty = GLOBAL_CLASS_NAMES.rayTemplateThemePrimaryFadeColor + const { style } = document.documentElement + + try { + store.updateSettingState('layoutConfig', { mode: 'right' }) + store.updateSettingState('appTheme', 'dark') + store.updateSettingState('watermarkConfig', { content: 'Portable' }) + store.updateSettingState('keepAliveConfig', { + keepAliveExclude: ['Page'], + }) + store.changePrimaryColor('#3468db') + const file = store.exportPreferences() + + store.updateSettingState('layoutConfig', { mode: 'top' }) + store.updateSettingState('appTheme', 'light') + store.updateSettingState('appRootRoute', { path: '/custom-home' }) + store.changePrimaryColor('#000000') + store.importPreferences(JSON.stringify(file)) + await nextTick() + + expect(store.exportPreferences()).toEqual(file) + expect(store._appTheme).toBe(true) + expect(style.getPropertyValue(property)).toBe('#3468db') + expect(store.appRootRoute.path).toBe('/custom-home') + expect(file.preferences).not.toHaveProperty('appRootRoute') + expect(file.preferences).not.toHaveProperty('lockScreenSwitch') + expect( + JSON.parse( + localStorage.getItem(APP_CATCH_KEY.appPiniaSettingStore) ?? 'null', + ), + ).toMatchObject({ layoutConfig: { mode: 'right' }, appTheme: 'dark' }) + } finally { + app.unmount() + disposePinia(pinia) + localStorage.removeItem(APP_CATCH_KEY.appPiniaSettingStore) + style.removeProperty(property) + style.removeProperty(fadeProperty) + } + }) + + it('does not change any preference when the file contains invalid settings', () => { + const pinia = createPinia() + + setActivePinia(pinia) + const store = piniaSettingStore() + const before = store.exportPreferences() + + try { + expect(() => store.importPreferences('{"routes": []}')).toThrow() + expect(() => + store.importPreferences(JSON.stringify({ ...before, version: 2 })), + ).toThrow() + expect(() => + store.importPreferences( + JSON.stringify({ + ...before, + preferences: { + ...before.preferences, + appTheme: 'dark', + menuConfig: { ...before.preferences.menuConfig, menuWidth: -1 }, + }, + }), + ), + ).toThrow() + expect(store.exportPreferences()).toEqual(before) + } finally { + disposePinia(pinia) + } + }) + it('finds mixed navigation roots by nested leaf and skips hidden branches', () => { const root = menu('/root', [ menu('/hidden', [], false), diff --git a/__test__/layout/slots.spec.ts b/__test__/layout/slots.spec.ts index b3ac9b59..40aece8c 100644 --- a/__test__/layout/slots.spec.ts +++ b/__test__/layout/slots.spec.ts @@ -65,3 +65,21 @@ it('offers a restore button for custom content and also exits with Escape', asyn disposePinia(pinia) } }) + +it('moves the full navigation to the right without adding a second menu', () => { + const pinia = createPinia() + + setActivePinia(pinia) + piniaSettingStore().updateSettingState('layoutConfig', { mode: 'right' }) + const wrapper = shallowMount(Layout, { + global: { renderStubDefaultSlot: true, plugins: [router, pinia] }, + }) + + try { + expect(wrapper.get('app-menu-stub').attributes('end')).toBe('true') + expect(wrapper.find('top-navigation-stub').exists()).toBe(false) + } finally { + wrapper.unmount() + disposePinia(pinia) + } +}) diff --git a/__test__/router/config.spec.ts b/__test__/router/config.spec.ts index 5f8bdb73..0f6fdbbd 100644 --- a/__test__/router/config.spec.ts +++ b/__test__/router/config.spec.ts @@ -1,4 +1,8 @@ -import { getStaticAppRoutes } from '@/router/app-route-modules' +import { + appExpandRoutes, + getAppRawRoutes, + getStaticAppRoutes, +} from '@/router/app-route-modules' import { exportRouteConfig, parseRouteConfig, @@ -14,6 +18,26 @@ const parse = (routes: unknown[]) => parseRouteConfig(JSON.stringify({ version: 1, routes })) describe('route configuration', () => { + it('keeps both management pages under the same admin-only menu', () => { + const root = getAppRawRoutes().find( + ({ path }) => path === '/route-management', + ) + const leaves = appExpandRoutes().filter(({ path }) => + path.startsWith('/route-management/'), + ) + + expect(root?.children?.map(({ path }) => path)).toEqual(['visual', 'json']) + expect(leaves.map(({ path }) => path)).toEqual([ + '/route-management/visual', + '/route-management/json', + ]) + + for (const { meta } of leaves) { + expect(validRole(meta, 'admin')).toBe(true) + expect(validRole(meta, 'viewer')).toBe(false) + } + }) + it('round-trips all bundled routes with their view IDs and metadata', () => { const bundled = getStaticAppRoutes() const config = exportRouteConfig(bundled) @@ -73,6 +97,11 @@ describe('route configuration', () => { it.each([ [[{ ...page, path: '/route-management' }], /reserved/i], + [[{ ...page, path: '/ROUTE-MANAGEMENT/Visual' }], /reserved/i], + [ + [{ ...page, path: '/reports', alias: '/route-management/json' }], + /reserved/i, + ], [[{ ...page, path: '/reports', name: 'RLogin' }], /reserved/i], [[{ ...page, path: '/reports', component: 'missing' }], /unknown view/i], [ diff --git a/docs/docs-handoff.md b/docs/docs-handoff.md index eccdad14..943dadca 100644 --- a/docs/docs-handoff.md +++ b/docs/docs-handoff.md @@ -22,3 +22,7 @@ ## 动态路由与示例页交接 应用侧已准备好 [路由接入文档](../src/router/README.md)、[Schema](../src/router/config/schema.ts)、[Segment 说明](../src/components/RSegment/README.md) 和 [页面设计说明](ui-design.md)。应用提交可访问后,在站外的 `guide/routing.md` 补充来源切换、接口示例和版本校验,在组件参考中补充 `fitContent` 的选中态与过渡规则。站外截图使用更新后的登录页与管理页,并核对部署子路径。 + +布局与路由编辑器交付后,站外 `guide/layout.md` 补充右侧导航、通栏分组、减少动态效果和浮动退出按钮;`guide/routing.md` 增加可视化与 JSON 两个入口,明确可视化应用仅保存在当前浏览器;`reference/hooks/layout.md` 说明加载提示以可见内容区为基准。引用对应的应用提交后再验证文档站构建和预览。 + +站外 `guide/layout.md` 同步设置抽屉的偏好导入导出:JSON 只包含抽屉内偏好,校验通过后即时保存,独立于路由管理的 JSON 配置。 diff --git a/src/app-config/app-config.ts b/src/app-config/app-config.ts index 2d043e3e..f6fbc305 100644 --- a/src/app-config/app-config.ts +++ b/src/app-config/app-config.ts @@ -113,8 +113,7 @@ export const APP_CATCH_KEY = { * * @description * 系统内容切换动画配置。 - * 但是在配置的时候,会自动拼接一个 transform 前缀。 - * 例如: transform-fade-bottom。 + * 样式名在配置值后拼接 -transform,例如 fade-bottom-transform。 */ export const CONTENT_TRANSITION_OPTIONS = [ { @@ -141,4 +140,6 @@ export const CONTENT_TRANSITION_OPTIONS = [ label: '底部消退', value: 'fade-bottom', }, + { label: '向上浮入', value: 'slide-up' }, + { label: '向左滑入', value: 'slide-left' }, ] diff --git a/src/components/RSegment/README.md b/src/components/RSegment/README.md index f2c22ef7..dd42a3e8 100644 --- a/src/components/RSegment/README.md +++ b/src/components/RSegment/README.md @@ -4,4 +4,4 @@ 在 Naive UI 2.45.3 中,选中态默认加粗。轨道使用内容宽度时,尤其是标签长短不同或带图标、提示时,切换选中态会改变轨道宽度。NTabs 的轨道 ResizeObserver 随即执行 `handleSegmentResize`,临时加上 `transition-disabled` 并强制同步胶囊位置。这个同步会让刚开始的位移动画跳到终点。 -`fitContent` 模式固定各标签的字重,用颜色和胶囊标示选中态。内容过长时导航区可以横向滚动,避免撑破外层。轨道真正发生尺寸变化时继续让 NTabs 同步位置。减少动态效果偏好下取消胶囊过渡。 +`fitContent` 模式按标签和轨道内边距的实际宽度排版,固定各标签的字重,用颜色和胶囊标示选中态。只有内容宽于可用空间时才横向滚动。轨道真正发生尺寸变化时继续让 NTabs 同步位置。减少动态效果偏好下取消胶囊过渡。 diff --git a/src/components/RSegment/src/index.scss b/src/components/RSegment/src/index.scss index 07a49fc1..f330965e 100644 --- a/src/components/RSegment/src/index.scss +++ b/src/components/RSegment/src/index.scss @@ -9,6 +9,8 @@ } .n-tabs-rail { + box-sizing: border-box; + flex: none; inline-size: max-content; min-inline-size: 100%; } @@ -19,6 +21,7 @@ // 选中前后字重相同,避免 intrinsic rail 触发 Naive UI 的无动画 resize 同步。 .n-tabs-tab { + inline-size: auto; font-weight: var(--n-font-weight-strong); } } diff --git a/src/components/RTransitionComponent/src/TransitionComponent.vue b/src/components/RTransitionComponent/src/TransitionComponent.vue index 2f3193ba..0a824d6e 100644 --- a/src/components/RTransitionComponent/src/TransitionComponent.vue +++ b/src/components/RTransitionComponent/src/TransitionComponent.vue @@ -1,5 +1,5 @@