From eba29fcfcf5a9969b812d7747343461bafd0a89b Mon Sep 17 00:00:00 2001 From: XiaoDaiGua-Ray <51957438+XiaoDaiGua-Ray@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:13:32 +0800 Subject: [PATCH] perf(build): improve admin startup and runtime import boundaries Load sign-in assets in the initial graph and defer the workspace, demo features, and mock client until needed. Split feature dependencies and clear stale files from the default production output. Document feature entry points for runtime imports and record the browser and Harness results. --- AGENTS.md | 1 + __test__/mock/browser.spec.ts | 66 ++++++++-- __test__/router/initialization.spec.ts | 4 +- __test__/utils/setupMiniApp.ts | 5 +- apps/admin/src/App.tsx | 17 ++- .../components/LockScreen/index.tsx | 2 +- .../components/UnlockScreen/index.tsx | 2 +- .../app/AppLockScreen/index.tsx | 2 +- .../app-components/app/AppShareLink/index.tsx | 2 +- .../provider/AppVersionProvider/index.tsx | 4 +- apps/admin/src/documentation-example.tsx | 20 ++- .../Menu/components/SiderBarLogo/index.tsx | 2 +- .../src/layout/components/Menu/index.tsx | 2 +- .../src/layout/components/MenuTag/index.tsx | 3 +- .../components/Search/GlobalSearch/index.tsx | 2 +- .../Search/GlobalSearchButton/index.tsx | 2 +- .../SettingDrawer/components/ThemeSegment.tsx | 3 +- .../SettingDrawer/components/ThemeSwitch.tsx | 2 +- .../components/SettingDrawer/index.tsx | 3 +- .../SiderBar/components/TooltipIcon/index.tsx | 2 +- .../src/layout/components/SiderBar/index.tsx | 2 +- .../src/layout/components/SiderBar/shared.ts | 2 +- .../layout/default/ContentWrapper/index.tsx | 2 +- apps/admin/src/layout/navigation.ts | 2 +- apps/admin/src/locales/index.ts | 8 +- apps/admin/src/locales/lang/en-US.ts | 2 +- apps/admin/src/locales/lang/zh-CN.ts | 2 +- .../locales/utils/get-app-local-messages.ts | 24 ++-- apps/admin/src/main.ts | 17 ++- apps/admin/src/mocks/browser.ts | 114 +++++++++--------- apps/admin/src/mocks/handlers.ts | 2 +- apps/admin/src/mocks/register.ts | 20 +++ apps/admin/src/router/config/views.ts | 33 +++-- apps/admin/src/router/index.ts | 16 ++- apps/admin/src/router/routes.ts | 17 +-- apps/admin/src/router/utils/expand-routes.ts | 2 +- apps/admin/src/router/utils/order-routes.ts | 2 +- apps/admin/src/store/modules/menu/utils.ts | 2 +- apps/admin/src/utils/legacy-crypto/decrypt.ts | 11 +- apps/admin/src/utils/legacy-crypto/encrypt.ts | 5 +- .../admin/src/views/account-profile/index.tsx | 2 +- apps/admin/src/views/dashboard/index.tsx | 2 +- apps/admin/src/views/demo/barcode-demo.tsx | 2 +- apps/admin/src/views/demo/doc/index.tsx | 2 +- apps/admin/src/views/demo/draggable-card.tsx | 4 +- apps/admin/src/views/demo/echart/index.tsx | 2 +- apps/admin/src/views/demo/flow-demo.tsx | 2 +- apps/admin/src/views/demo/form/index.tsx | 2 +- .../src/views/demo/hooks/HookExample.tsx | 2 +- apps/admin/src/views/demo/iframe/index.tsx | 2 +- .../admin/src/views/demo/modal-demo/index.tsx | 2 +- apps/admin/src/views/demo/multi/index.ts | 3 + .../router-demo/router-demo-home/index.tsx | 2 +- apps/admin/src/views/demo/segment/index.tsx | 6 +- apps/admin/src/views/demo/svg-icons/index.tsx | 2 +- .../src/views/demo/tables/auto-height.tsx | 2 +- apps/admin/src/views/demo/tables/basic.tsx | 2 +- apps/admin/src/views/demo/tables/columns.tsx | 2 +- apps/admin/src/views/demo/tables/custom.tsx | 2 +- .../src/views/demo/tables/hooks-output.tsx | 2 +- .../src/views/demo/tables/hooks-query.tsx | 2 +- .../src/views/demo/tables/hooks-selection.tsx | 2 +- apps/admin/src/views/demo/tables/index.ts | 8 ++ apps/admin/src/views/demo/tables/printing.tsx | 4 +- apps/admin/src/views/demo/tables/remote.tsx | 4 +- .../src/views/demo/template-hooks/index.tsx | 2 +- .../src/views/error/PageResult/index.tsx | 2 +- apps/admin/src/views/error/system-errors.ts | 3 + .../login/components/SSOSigning/index.tsx | 2 +- .../views/login/components/Signing/index.tsx | 2 +- apps/admin/src/views/login/index.tsx | 2 +- .../src/views/user-management/UserEditor.tsx | 2 +- .../admin/src/views/user-management/index.tsx | 9 +- apps/admin/src/views/welcome/index.tsx | 2 +- docs/architecture.md | 6 + docs/toolchain-upgrade.md | 14 +++ harness/README.md | 8 ++ packages/admin-shell/src/TopNavigation.tsx | 2 +- packages/routing/package.json | 3 + vite.config.ts | 46 ++++++- 80 files changed, 396 insertions(+), 207 deletions(-) create mode 100644 apps/admin/src/mocks/register.ts create mode 100644 apps/admin/src/views/demo/multi/index.ts create mode 100644 apps/admin/src/views/demo/tables/index.ts create mode 100644 apps/admin/src/views/error/system-errors.ts diff --git a/AGENTS.md b/AGENTS.md index 2d29bb3b..85102e8f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,6 +4,7 @@ A Vue 3 + TSX admin template with an admin application, a documentation site, an - To locate an implementation, choose a topic from the [task index](llms.txt) or `pnpm harness context `. Consult the [architecture map](docs/architecture.md) for changes that cross module boundaries. - Check `git status` first and preserve existing changes. Trace callers and existing data contracts before changing routing, persistence, requests, or shared components. +- Prefer feature entry points for runtime imports. Follow the [runtime import boundaries](harness/README.md#runtime-import-boundaries) when adding exports or changing what loads at startup or on demand. - For complex tasks, the lead agent may choose to use subagents under the [delegation guidelines](harness/README.md#using-subagents-when-useful), when the host supports them and current permissions allow it. Delegation needs no separate approval. The lead agent owns integration and final verification. - Write agent guidance and internal engineering documentation in English. Preserve the intended languages of product copy and reader-facing documentation. - Follow the [comment style](docs/comment-style.md) when adding or editing comments. Maintain both Chinese and English product copy. For visible behavior changes, use [browser verification](harness/README.md#browser-verification) only for affected pages, actions, and dimensions. diff --git a/__test__/mock/browser.spec.ts b/__test__/mock/browser.spec.ts index fb737495..d49da734 100644 --- a/__test__/mock/browser.spec.ts +++ b/__test__/mock/browser.spec.ts @@ -12,25 +12,24 @@ vi.mock('@/api/admin/client', () => ({ apiUrl: (path: string) => `http://localhost/ray-template/api/${path}`, })) +beforeEach(() => { + vi.resetModules() + installGuard.mockClear() + setupWorker.mockReset() +}) + afterEach(() => vi.restoreAllMocks()) -it('restarts the same MSW client across repeated and concurrent recoveries', async () => { - const worker = { start: vi.fn(async () => {}), stop: vi.fn() } +it('starts on the first API request and shares repeated concurrent recoveries', async () => { + const worker = { start: vi.fn(async () => {}), stop: vi.fn(async () => {}) } setupWorker.mockReturnValue(worker) - const { enableApiMock } = await import('@/mocks/browser') + const { registerApiMock } = await import('@/mocks/register') - await Promise.all([enableApiMock(), enableApiMock()]) + registerApiMock() + registerApiMock() expect(installGuard).toHaveBeenCalledOnce() - expect(worker.start).toHaveBeenCalledWith( - expect.objectContaining({ - serviceWorker: { - url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`, - options: { scope: import.meta.env.BASE_URL }, - }, - }), - ) const guard = installGuard.mock.calls[0]![0] const probe = vi @@ -41,6 +40,20 @@ it('restarts the same MSW client across repeated and concurrent recoveries', asy await guard('http://localhost/unrelated') expect(probe).not.toHaveBeenCalled() + expect(setupWorker).not.toHaveBeenCalled() + + await Promise.all([ + guard('http://localhost/ray-template/api/admin/auth/session'), + guard('http://localhost/ray-template/api/admin/routes'), + ]) + expect(worker.start).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + serviceWorker: { + url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`, + options: { scope: import.meta.env.BASE_URL }, + }, + }), + ) for (let attempt = 0; attempt < 2; attempt++) { probe.mockResolvedValueOnce(new Response(null, { status: 404 })) @@ -52,6 +65,33 @@ it('restarts the same MSW client across repeated and concurrent recoveries', asy expect(worker.stop).toHaveBeenCalledTimes(2) expect(worker.start).toHaveBeenCalledTimes(3) - expect(probe).toHaveBeenCalledTimes(4) + expect(probe).toHaveBeenCalledTimes(5) + expect(setupWorker).toHaveBeenCalledOnce() +}) + +it('blocks API requests if startup fails and retries the same client', async () => { + const worker = { + start: vi.fn(async () => {}).mockRejectedValueOnce(new Error('offline')), + stop: vi.fn(async () => {}), + } + + setupWorker.mockReturnValue(worker) + const probe = vi + .spyOn(globalThis, 'fetch') + .mockResolvedValue( + new Response(null, { headers: { 'x-ray-mock': 'active' } }), + ) + const { registerApiMock } = await import('@/mocks/register') + + registerApiMock() + const guard = installGuard.mock.calls[0]![0] + const url = 'http://localhost/ray-template/api/admin/auth/login' + + await expect(guard(url)).rejects.toThrow('offline') + expect(probe).not.toHaveBeenCalled() + await expect(guard(url)).resolves.toBeUndefined() + expect(probe).toHaveBeenCalledOnce() + expect(worker.stop).toHaveBeenCalledOnce() + expect(worker.start).toHaveBeenCalledTimes(2) expect(setupWorker).toHaveBeenCalledOnce() }) diff --git a/__test__/router/initialization.spec.ts b/__test__/router/initialization.spec.ts index fa87a0e1..a14c85da 100644 --- a/__test__/router/initialization.spec.ts +++ b/__test__/router/initialization.spec.ts @@ -16,7 +16,7 @@ vi.mock('../../apps/admin/src/router/config/source', () => ({ resetRouteSource: vi.fn(), })) vi.mock('../../apps/admin/src/router/routes', () => ({ - constantRoutes: [ + getRootRoutes: () => [ { path: '/', name: 'RLayout', component: { render: () => null } }, ], getLayoutRoutes: () => [], @@ -43,7 +43,7 @@ it('loads no business routes before login, then shares a retry and registers gua .mockResolvedValue(void 0) try { - await setupRouter(app, false) + await setupRouter(app, false, { render: () => null }) expect(load).not.toHaveBeenCalled() await expect(loadAccountRoutes()).rejects.toThrow( 'route endpoint unavailable', diff --git a/__test__/utils/setupMiniApp.ts b/__test__/utils/setupMiniApp.ts index f308a530..7668de34 100644 --- a/__test__/utils/setupMiniApp.ts +++ b/__test__/utils/setupMiniApp.ts @@ -2,6 +2,7 @@ import { setupI18n } from '../../apps/admin/src/locales' import { setupRouter } from '../../apps/admin/src/router' import { setupStore } from '../../apps/admin/src/store' import { piniaSigningStore } from '../../apps/admin/src/store/modules/signing' +import Login from '../../apps/admin/src/views/login' import renderHook from '../utils/renderHook' /** @@ -17,14 +18,14 @@ const setupMiniApp = async (authenticated = false) => { const [_, app] = renderHook(() => {}) setupStore(app) - await setupI18n(app) + setupI18n(app) if (authenticated) await app.runWithContext(() => piniaSigningStore().signing({ name: 'admin', pwd: '123456' }), ) - await setupRouter(app, authenticated) + await setupRouter(app, authenticated, Login) return { app, diff --git a/apps/admin/src/App.tsx b/apps/admin/src/App.tsx index 77c9cf6c..33c7360a 100644 --- a/apps/admin/src/App.tsx +++ b/apps/admin/src/App.tsx @@ -1,6 +1,5 @@ import { apiMockEnabled } from '@/api/admin/client' import AppGlobalSpin from '@/app-components/app/AppGlobalSpin' -import AppLockScreen from '@/app-components/app/AppLockScreen' import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider' import AppStyleProvider from '@/app-components/provider/AppStyleProvider' import AppVersionProvider from '@/app-components/provider/AppVersionProvider' @@ -18,10 +17,15 @@ import { provideUiServices } from '@ray-template/ui/services' import { createStorage } from '@ray-template/utils/storage' import { RouterView } from 'vue-router' +const AppLockScreen = defineAsyncComponent( + () => import('@/app-components/app/AppLockScreen'), +) + export default defineComponent({ name: 'App', setup() { - const { getAppTheme, getThemeStyle } = useSettingGetters() + const { getAppTheme, getThemeStyle, getLockScreenSwitch } = + useSettingGetters() const { t } = useI18n() provideUiServices({ @@ -34,12 +38,19 @@ export default defineComponent({ iconUrl: (name, prefix) => `${iconSprites[name.split('/')[0] as IconPackage]}#${prefix}-${name}`, }) + + // 首次打开后保留弹窗实例,让关闭动画正常完成。 + const lockScreenRequested = computed( + (requested) => !!requested || getLockScreenSwitch.value, + ) + + return { lockScreenRequested } }, render() { return ( - {apiMockEnabled && } + {apiMockEnabled && this.lockScreenRequested && } diff --git a/apps/admin/src/app-components/app/AppLockScreen/components/LockScreen/index.tsx b/apps/admin/src/app-components/app/AppLockScreen/components/LockScreen/index.tsx index 1b852517..3c2c8f84 100644 --- a/apps/admin/src/app-components/app/AppLockScreen/components/LockScreen/index.tsx +++ b/apps/admin/src/app-components/app/AppLockScreen/components/LockScreen/index.tsx @@ -5,10 +5,10 @@ import { useLockRules, } from '@/app-components/app/AppLockScreen/shared' import { APP_CATCH_KEY } from '@/app-config' -import { RForm, useForm } from '@/components' import { useI18n } from '@/hooks' import { useSettingActions } from '@/store' import { encrypt, setStorage } from '@/utils' +import { RForm, useForm } from '@ray-template/ui/form' import { NButton, NFormItem, NInput } from 'naive-ui' import type { InputInst } from 'naive-ui' import { useTemplateRef } from 'vue' diff --git a/apps/admin/src/app-components/app/AppLockScreen/components/UnlockScreen/index.tsx b/apps/admin/src/app-components/app/AppLockScreen/components/UnlockScreen/index.tsx index 97c7e332..2be8eb44 100644 --- a/apps/admin/src/app-components/app/AppLockScreen/components/UnlockScreen/index.tsx +++ b/apps/admin/src/app-components/app/AppLockScreen/components/UnlockScreen/index.tsx @@ -6,7 +6,6 @@ import { useLockRules, } from '@/app-components/app/AppLockScreen/shared' import { APP_CATCH_KEY } from '@/app-config' -import { RForm, useForm } from '@/components' import { useDevice, useI18n } from '@/hooks' import { useSettingActions, @@ -14,6 +13,7 @@ import { useSigningActions, } from '@/store' import { decrypt, getStorage, removeStorage } from '@/utils' +import { RForm, useForm } from '@ray-template/ui/form' import { useEventListener } from '@vueuse/core' import dayjs from 'dayjs' import { NButton, NFlex, NFormItem, NInput } from 'naive-ui' diff --git a/apps/admin/src/app-components/app/AppLockScreen/index.tsx b/apps/admin/src/app-components/app/AppLockScreen/index.tsx index edfd52d6..da8c0f53 100644 --- a/apps/admin/src/app-components/app/AppLockScreen/index.tsx +++ b/apps/admin/src/app-components/app/AppLockScreen/index.tsx @@ -1,6 +1,6 @@ -import { RModal } from '@/components' import { useI18n } from '@/hooks' import { useSettingActions, useSettingGetters } from '@/store' +import { RModal } from '@ray-template/ui/modal' import LockScreen from './components/LockScreen' const AppLockScreen = defineComponent({ diff --git a/apps/admin/src/app-components/app/AppShareLink/index.tsx b/apps/admin/src/app-components/app/AppShareLink/index.tsx index a2bc9d20..9f44ec61 100644 --- a/apps/admin/src/app-components/app/AppShareLink/index.tsx +++ b/apps/admin/src/app-components/app/AppShareLink/index.tsx @@ -1,8 +1,8 @@ import './index.scss' import { RAY_TEMPLATE_DOCS_URL } from '@/app-config' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import type { IconName } from '@/icons' +import { RIcon } from '@ray-template/ui/icon' import type { PropType } from 'vue' interface ShareLinkOption { diff --git a/apps/admin/src/app-components/provider/AppVersionProvider/index.tsx b/apps/admin/src/app-components/provider/AppVersionProvider/index.tsx index e3c125e1..83cef583 100644 --- a/apps/admin/src/app-components/provider/AppVersionProvider/index.tsx +++ b/apps/admin/src/app-components/provider/AppVersionProvider/index.tsx @@ -1,8 +1,8 @@ import { APP_CATCH_KEY } from '@/app-config' -import { RModal } from '@/components' import { useI18n } from '@/hooks' import { useSigningActions } from '@/store' -import { getStorage, setStorage } from '@/utils' +import { getStorage, setStorage } from '@/utils/cache' +import { RModal } from '@ray-template/ui/modal' export default defineComponent({ name: 'AppVersionProvider', diff --git a/apps/admin/src/documentation-example.tsx b/apps/admin/src/documentation-example.tsx index cab6f6ed..f4224345 100644 --- a/apps/admin/src/documentation-example.tsx +++ b/apps/admin/src/documentation-example.tsx @@ -1,5 +1,4 @@ import './styles/entry' -import { apiMockEnabled } from '@/api/admin/client' import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider' import AppStyleProvider from '@/app-components/provider/AppStyleProvider' import AppWatermarkProvider from '@/app-components/provider/AppWatermarkProvider' @@ -7,8 +6,8 @@ import { APP_THEME } from '@/app-config' import { setupDayjs } from '@/dayjs' import { setupDirectives } from '@/directives' import { useI18n, useTheme } from '@/hooks' -import Layout from '@/layout' import { setupI18n } from '@/locales' +import { registerApiMock } from '@/mocks/register' import { router } from '@/router' import { getStaticAppRoutes, @@ -119,17 +118,12 @@ const DocumentationExample = defineComponent({ async function mountExample() { useMemoryCache() - - if (apiMockEnabled) { - const { enableApiMock } = await import('./mocks/browser') - - await enableApiMock() - } + registerApiMock() const app = createApp(DocumentationExample) app.use(createPinia()) - await setupI18n(app) + setupI18n(app) setupDayjs() setupDirectives(app) @@ -141,8 +135,6 @@ async function mountExample() { if (params.get('theme') === 'dark') darkTheme() else lightTheme() - router.removeRoute('RLogin') - router.removeRoute('RLayout') setAppRouteModules(examples) const routes = [ @@ -151,7 +143,11 @@ async function mountExample() { ] as unknown as RouteRecordRaw[] if (withLayout) { - router.addRoute({ path: '/', component: Layout, children: routes }) + router.addRoute({ + path: '/', + component: () => import('@/layout'), + children: routes, + }) } else { for (const route of routes) router.addRoute(route) } diff --git a/apps/admin/src/layout/components/Menu/components/SiderBarLogo/index.tsx b/apps/admin/src/layout/components/Menu/components/SiderBarLogo/index.tsx index a8222e29..f15f1b9d 100644 --- a/apps/admin/src/layout/components/Menu/components/SiderBarLogo/index.tsx +++ b/apps/admin/src/layout/components/Menu/components/SiderBarLogo/index.tsx @@ -1,8 +1,8 @@ import { resolveIconName } from '@/icons' import './index.scss' -import { RIcon } from '@/components' import { useSettingGetters } from '@/store' import { isValueType, renderNode } from '@/utils' +import { RIcon } from '@ray-template/ui/icon' import { NEllipsis, NTooltip } from 'naive-ui' export default defineComponent({ diff --git a/apps/admin/src/layout/components/Menu/index.tsx b/apps/admin/src/layout/components/Menu/index.tsx index 61024cec..6fa123e4 100644 --- a/apps/admin/src/layout/components/Menu/index.tsx +++ b/apps/admin/src/layout/components/Menu/index.tsx @@ -1,6 +1,5 @@ import './index.scss' import { LAYOUT_SIDER_REF } from '@/app-config' -import { RIcon } from '@/components' import { useDevice, useI18n } from '@/hooks' import { positionSelectedMenuItem } from '@/layout/utils/position-selected-menu-item' import { @@ -11,6 +10,7 @@ import { useSettingGetters, } from '@/store' import type { AppMenuOption, NaiveMenuOptions } from '@/types' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NDrawer, NLayoutContent, NLayoutSider, NMenu } from 'naive-ui' import type { MenuInst } from 'naive-ui' import type { PropType } from 'vue' diff --git a/apps/admin/src/layout/components/MenuTag/index.tsx b/apps/admin/src/layout/components/MenuTag/index.tsx index 0fd2d42b..086c3f80 100644 --- a/apps/admin/src/layout/components/MenuTag/index.tsx +++ b/apps/admin/src/layout/components/MenuTag/index.tsx @@ -1,10 +1,11 @@ import './index.scss' -import { RIcon, RMoreDropdown } from '@/components' import { useI18n, useMaximize, useSiderBar, useSpinning } from '@/hooks' import { FORBIDDEN_ROUTE_PATH } from '@/router/constant' import { useMenuActions, useMenuGetters, useRuntimeGetters } from '@/store' import type { AppMenuOption, MenuTagOptions } from '@/types' import { ShellTab } from '@ray-template/admin-shell' +import { RIcon } from '@ray-template/ui/icon' +import { RMoreDropdown } from '@ray-template/ui/more-dropdown' import { usePreferredReducedMotion, useResizeObserver } from '@vueuse/core' import { NDropdown, NFlex, NLayoutHeader, NScrollbar } from 'naive-ui' import type { ScrollbarInst } from 'naive-ui' diff --git a/apps/admin/src/layout/components/Search/GlobalSearch/index.tsx b/apps/admin/src/layout/components/Search/GlobalSearch/index.tsx index 8d03c47e..d5be6f83 100644 --- a/apps/admin/src/layout/components/Search/GlobalSearch/index.tsx +++ b/apps/admin/src/layout/components/Search/GlobalSearch/index.tsx @@ -1,5 +1,4 @@ import './index.scss' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { positionSelectedMenuItem } from '@/layout/utils/position-selected-menu-item' import { @@ -9,6 +8,7 @@ import { useNavigationHistoryGetters, } from '@/store' import type { AppMenuOption } from '@/types' +import { RIcon } from '@ray-template/ui/icon' import { useEventListener } from '@vueuse/core' import { NButton, NCard, NInput, NModal, NScrollbar } from 'naive-ui' import type { InputInst } from 'naive-ui' diff --git a/apps/admin/src/layout/components/Search/GlobalSearchButton/index.tsx b/apps/admin/src/layout/components/Search/GlobalSearchButton/index.tsx index b435ac9b..de3c533e 100644 --- a/apps/admin/src/layout/components/Search/GlobalSearchButton/index.tsx +++ b/apps/admin/src/layout/components/Search/GlobalSearchButton/index.tsx @@ -1,7 +1,7 @@ import './index.scss' -import { RIcon } from '@/components' import type { MaybeArray } from '@/types' import { call, detectOperatingSystem } from '@/utils' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NFlex } from 'naive-ui' import type { PropType } from 'vue' diff --git a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSegment.tsx b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSegment.tsx index ef23f081..a12805b7 100644 --- a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSegment.tsx +++ b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSegment.tsx @@ -1,7 +1,8 @@ -import { RIcon, RSegment } from '@/components' import { useI18n } from '@/hooks' import { useSettingActions, useSettingGetters } from '@/store' import type { SettingState } from '@/store/modules/setting/types' +import { RIcon } from '@ray-template/ui/icon' +import { RSegment } from '@ray-template/ui/segment' export default defineComponent({ name: 'ThemeSegment', diff --git a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch.tsx b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch.tsx index 6af742d8..41d7a4a0 100644 --- a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch.tsx +++ b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch.tsx @@ -1,6 +1,6 @@ -import { RIcon } from '@/components' import { useTheme } from '@/hooks' import { useSettingGetters } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import { NFlex, NSwitch, NTooltip } from 'naive-ui' export default defineComponent({ diff --git a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/index.tsx b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/index.tsx index bf4b8132..98e70f56 100644 --- a/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/index.tsx +++ b/apps/admin/src/layout/components/SiderBar/components/SettingDrawer/index.tsx @@ -1,11 +1,12 @@ import './index.scss' -import { RIcon, useModal } from '@/components' import { useI18n } from '@/hooks' import { useMenuActions, useSettingActions } from '@/store' import { getDefaultSettingConfig } from '@/store/modules/setting/constant' import { PREFERENCE_FILE_LIMIT } from '@/store/modules/setting/preference-file' import type { SettingState } from '@/store/modules/setting/types' import { downloadAnyFile } from '@/utils/files' +import { RIcon } from '@ray-template/ui/icon' +import { useModal } from '@ray-template/ui/modal' import { cloneDeep, forIn } from 'lodash-es' import { drawerProps, diff --git a/apps/admin/src/layout/components/SiderBar/components/TooltipIcon/index.tsx b/apps/admin/src/layout/components/SiderBar/components/TooltipIcon/index.tsx index 89bc5116..5419d783 100644 --- a/apps/admin/src/layout/components/SiderBar/components/TooltipIcon/index.tsx +++ b/apps/admin/src/layout/components/SiderBar/components/TooltipIcon/index.tsx @@ -1,7 +1,7 @@ import type { IconName } from '@/icons' import type { PropType } from 'vue' import './index.scss' -import { RIcon } from '@/components' +import { RIcon } from '@ray-template/ui/icon' import { NTooltip, tooltipProps } from 'naive-ui' import type { TooltipProps } from 'naive-ui' diff --git a/apps/admin/src/layout/components/SiderBar/index.tsx b/apps/admin/src/layout/components/SiderBar/index.tsx index 85f76ad3..b29116b1 100644 --- a/apps/admin/src/layout/components/SiderBar/index.tsx +++ b/apps/admin/src/layout/components/SiderBar/index.tsx @@ -2,13 +2,13 @@ import { useRuntimeActions, useRuntimeGetters } from '@/store' import './index.scss' import AppAvatar from '@/app-components/app/AppAvatar' import { LOCAL_OPTIONS } from '@/app-config' -import { RIcon } from '@/components' import { useDevice, useI18n } from '@/hooks' import { useSettingActions, useSettingGetters, useSigningGetters, } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NDropdown, NFlex, NLayoutHeader } from 'naive-ui' import { useFullscreen } from 'vue-hooks-plus' import { diff --git a/apps/admin/src/layout/components/SiderBar/shared.ts b/apps/admin/src/layout/components/SiderBar/shared.ts index e8a2d1f4..0c95e8cd 100644 --- a/apps/admin/src/layout/components/SiderBar/shared.ts +++ b/apps/admin/src/layout/components/SiderBar/shared.ts @@ -1,9 +1,9 @@ import { apiMockEnabled } from '@/api/admin/client' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { router } from '@/router' import { ACCOUNT_PROFILE_PATH } from '@/router/constant' import { useSettingActions, useSigningActions } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import type { IconOptions, IconOptionsFC } from './type' export const createAvatarOptions = (t: ReturnType['t']) => [ diff --git a/apps/admin/src/layout/default/ContentWrapper/index.tsx b/apps/admin/src/layout/default/ContentWrapper/index.tsx index b8af18c0..1f9fc593 100644 --- a/apps/admin/src/layout/default/ContentWrapper/index.tsx +++ b/apps/admin/src/layout/default/ContentWrapper/index.tsx @@ -1,5 +1,5 @@ import AppRequestCancelerProvider from '@/app-components/provider/AppRequestCancelerProvider' -import { RTransitionComponent } from '@/components' +import { RTransitionComponent } from '@/components/RTransitionComponent' import { useRuntimeGetters, useSettingGetters } from '@/store' export default defineComponent({ diff --git a/apps/admin/src/layout/navigation.ts b/apps/admin/src/layout/navigation.ts index c4fd444e..4a30d2ec 100644 --- a/apps/admin/src/layout/navigation.ts +++ b/apps/admin/src/layout/navigation.ts @@ -1 +1 @@ -export { findMenuRoot, firstMenuLeaf } from '@ray-template/routing' +export { findMenuRoot, firstMenuLeaf } from '@ray-template/routing/navigation' diff --git a/apps/admin/src/locales/index.ts b/apps/admin/src/locales/index.ts index be764220..3f16fec9 100644 --- a/apps/admin/src/locales/index.ts +++ b/apps/admin/src/locales/index.ts @@ -22,9 +22,9 @@ if (import.meta.hot) { * * @returns 尚未安装到应用的国际化实例 */ -const createI18nOptions = async () => { +const createI18nOptions = () => { const locale = getAppDefaultLanguage() - const messages = await getAppLocalMessages(LOCAL_OPTIONS) + const messages = getAppLocalMessages(LOCAL_OPTIONS) const i18nInstance = createI18n({ legacy: false, @@ -45,8 +45,8 @@ const createI18nOptions = async () => { * @description * 安装国际化插件,并更新共享的国际化实例。 */ -export const setupI18n = async (app: App) => { - const i18nInstance = await createI18nOptions() +export const setupI18n = (app: App) => { + const i18nInstance = createI18nOptions() app.use(i18nInstance) diff --git a/apps/admin/src/locales/lang/en-US.ts b/apps/admin/src/locales/lang/en-US.ts index 2c7006bb..e7bb3ef9 100644 --- a/apps/admin/src/locales/lang/en-US.ts +++ b/apps/admin/src/locales/lang/en-US.ts @@ -1,5 +1,5 @@ import type { I18nModules } from '@/locales/types' -import { combineI18nMessages } from '@/locales/utils' +import { combineI18nMessages } from '@/locales/utils/combine-i18n-messages' import table from '@ray-template/ui/table-pro/messages/en-US' const modules: I18nModules = import.meta.glob('./en-US/**/*.json', { diff --git a/apps/admin/src/locales/lang/zh-CN.ts b/apps/admin/src/locales/lang/zh-CN.ts index 24e720b1..fbd2ca76 100644 --- a/apps/admin/src/locales/lang/zh-CN.ts +++ b/apps/admin/src/locales/lang/zh-CN.ts @@ -1,5 +1,5 @@ import type { I18nModules } from '@/locales/types' -import { combineI18nMessages } from '@/locales/utils' +import { combineI18nMessages } from '@/locales/utils/combine-i18n-messages' import table from '@ray-template/ui/table-pro/messages/zh-CN' const modules: I18nModules = import.meta.glob('./zh-CN/**/*.json', { diff --git a/apps/admin/src/locales/utils/get-app-local-messages.ts b/apps/admin/src/locales/utils/get-app-local-messages.ts index 667f3af2..f10cfdf2 100644 --- a/apps/admin/src/locales/utils/get-app-local-messages.ts +++ b/apps/admin/src/locales/utils/get-app-local-messages.ts @@ -4,6 +4,11 @@ import type { AppLocalesModules, } from '@/locales/types' +const locales = import.meta.glob('../lang/*.ts', { + eager: true, + import: 'default', +}) + /** * * @param localOptions 语言包下拉配置项 @@ -12,21 +17,18 @@ import type { * 获取当前应用的所有语言包。 * * @example - * const messages = await getAppLocalMessages(localOptions) + * const messages = getAppLocalMessages(localOptions) */ -export const getAppLocalMessages = async ( +export const getAppLocalMessages = ( localOptions: AppLocalesDropdownMixedOption[], ) => { - const message = {} as AppCurrentAppMessages + const entries = localOptions.map(({ key }) => { + const locale = locales[`../lang/${key}.ts`] - for (const curr of localOptions) { - const msg: AppLocalesModules = await import(`@/locales/lang/${curr.key}.ts`) - const key = curr.key as keyof AppCurrentAppMessages + if (!locale) throw new Error(`Unknown locale: ${key}`) - if (key) { - message[key] = msg?.default?.message ?? {} - } - } + return [key, locale.message] as const + }) - return message + return Object.fromEntries(entries) as AppCurrentAppMessages } diff --git a/apps/admin/src/main.ts b/apps/admin/src/main.ts index 59e3889c..8271eed0 100644 --- a/apps/admin/src/main.ts +++ b/apps/admin/src/main.ts @@ -1,19 +1,21 @@ import App from './App' import './styles/entry' import type { App as AppType } from 'vue' -import { apiMockEnabled, bindAdminUnauthorized } from './api/admin/client' +import { bindAdminUnauthorized } from './api/admin/client' import { installAutocompleteDefaults } from './app-components/provider/AppAutocompleteDefaults' import { GLOBAL_CLASS_NAMES } from './app-config' import { setupDayjs } from './dayjs' import { setupDirectives } from './directives' import { runAppDoctor } from './doctor' import { setupI18n } from './locales' +import { registerApiMock } from './mocks/register' import { setupRouter } from './router' import { setupStore } from './store' import { adminSessionChangeKey, piniaSigningStore, } from './store/modules/signing' +import Login from './views/login' const bootSplash = () => document.getElementById(GLOBAL_CLASS_NAMES.preLoadingAnimation) @@ -33,18 +35,13 @@ const showBootError = (error: unknown) => { * 注册时应该注意每个插件的加载顺序。 */ const setupPlugins = async (inst: AppType) => { - if (apiMockEnabled) { - const { enableApiMock } = await import('./mocks/browser') - - await enableApiMock() - } - + registerApiMock() setupStore(inst) - await setupI18n(inst) + setupI18n(inst) const signing = inst.runWithContext(() => piniaSigningStore()) await signing.restoreSession() - await setupRouter(inst, !!signing.signingCallback.id) + await setupRouter(inst, !!signing.signingCallback.id, Login) const unbindUnauthorized = bindAdminUnauthorized(signing.expireSession) const syncSession = (event: StorageEvent) => { if (event.key === adminSessionChangeKey) location.reload() @@ -118,7 +115,7 @@ const setupWujieTemplate = async () => { * # 示例 * const setupTemplate = async () => { * const app = createApp(App) - * await setupRouter(app) + * await setupRouter(app, false, Login) * ... * } * setupTemplate() diff --git a/apps/admin/src/mocks/browser.ts b/apps/admin/src/mocks/browser.ts index 1980581e..86d983f6 100644 --- a/apps/admin/src/mocks/browser.ts +++ b/apps/admin/src/mocks/browser.ts @@ -1,5 +1,4 @@ -import { apiMockEnabled, apiUrl } from '@/api/admin/client' -import { installMockRequestGuard } from '@/axios/instance' +import { apiUrl } from '@/api/admin/client' import { getStorageInstance } from '@/utils/cache-backend' import { setupWorker } from 'msw/browser' import { HttpNetworkFrame } from 'msw/experimental' @@ -8,67 +7,70 @@ import { createMockConnection } from './connection' import { createAdminDatabase } from './database' import { createAdminHandlers } from './handlers' -let ready: Promise | undefined +function createMockClient() { + const base = apiUrl('') + const handlers = createAdminHandlers( + createAdminDatabase(getStorageInstance('localStorage')), + base, + ) + const worker = setupWorker(...handlers) + const start = () => + worker.start({ + serviceWorker: { + // 版本变化时注册新脚本,避免启动阶段与旧版 worker 握手。 + url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`, + options: { scope: import.meta.env.BASE_URL }, + }, + quiet: true, + onUnhandledFrame: ({ frame }) => { + if (!(frame instanceof HttpNetworkFrame)) return -export function enableApiMock() { - if (!apiMockEnabled) return Promise.resolve() + const { method, url } = frame.data.request - ready ??= (async () => { - const base = apiUrl('') - const handlers = createAdminHandlers( - createAdminDatabase(getStorageInstance('localStorage')), - base, - ) - const worker = setupWorker(...handlers) - const start = () => - worker.start({ - serviceWorker: { - // 版本变化时注册新脚本,避免启动阶段与旧版 worker 握手。 - url: `${import.meta.env.BASE_URL}mockServiceWorker.js?v=${mswVersion}`, - options: { scope: import.meta.env.BASE_URL }, - }, - quiet: true, - onUnhandledFrame: ({ frame }) => { - if (!(frame instanceof HttpNetworkFrame)) return + if (!url.startsWith(base)) return - const { method, url } = frame.data.request + console.error( + `[MSW] No mock handler for ${method} ${new URL(url).pathname}`, + ) + // MSW 3 的默认错误回调只记录日志,拒绝此帧才能阻止请求穿透。 + throw Response.error() + }, + }) - if (!url.startsWith(base)) return - - console.error( - `[MSW] No mock handler for ${method} ${new URL(url).pathname}`, - ) - // MSW 3 的默认错误回调只记录日志,拒绝此帧才能阻止请求穿透。 - throw Response.error() - }, + const ensureReady = createMockConnection( + async () => { + const response = await fetch(apiUrl('admin/mock-health'), { + cache: 'no-store', + credentials: 'omit', + redirect: 'error', + signal: AbortSignal.timeout(5000), }) - await start() + return response.ok && response.headers.get('x-ray-mock') === 'active' + }, + async () => { + // Chromium 可能回收后台 worker;在同一个客户端恢复拦截。 + await worker.stop() + await start() + }, + ) + let started: ReturnType | undefined - const ensureReady = createMockConnection( - async () => { - const response = await fetch(apiUrl('admin/mock-health'), { - cache: 'no-store', - credentials: 'omit', - redirect: 'error', - signal: AbortSignal.timeout(5000), - }) + return async () => { + started ??= start().catch(async (error) => { + try { + await worker.stop() + } finally { + started = void 0 + } - return response.ok && response.headers.get('x-ray-mock') === 'active' - }, - async () => { - // 重启同一个实例,保持监听器和拦截状态由同一个客户端管理。 - worker.stop() - await start() - }, - ) - - // Chromium 可能回收后台 worker;先探测并恢复,再发送业务请求,避免写请求意外穿透。 - installMockRequestGuard(async (url) => { - if (new URL(url, document.baseURI).href.startsWith(base)) - await ensureReady() + throw error }) - })() - - return ready + await started + await ensureReady() + } } + +let connect: ReturnType | undefined + +export const ensureApiMock = () => (connect ??= createMockClient())() diff --git a/apps/admin/src/mocks/handlers.ts b/apps/admin/src/mocks/handlers.ts index 709f3fec..fc5b93c4 100644 --- a/apps/admin/src/mocks/handlers.ts +++ b/apps/admin/src/mocks/handlers.ts @@ -1,5 +1,4 @@ import { userListQuerySchema } from '@/api/admin/contracts' -import { listPeople } from '@/demo-data/people' import { chartsQuerySchema, orderSearchInputSchema, @@ -218,6 +217,7 @@ export function createAdminHandlers(database: AdminDatabase, apiBase: string) { if (query.fail) throw new MockApiError(503, 'requestFailed') + const { listPeople } = await import('@/demo-data/people') const result = listPeople({ ...query, page: query.page ?? 1, diff --git a/apps/admin/src/mocks/register.ts b/apps/admin/src/mocks/register.ts new file mode 100644 index 00000000..7a27405a --- /dev/null +++ b/apps/admin/src/mocks/register.ts @@ -0,0 +1,20 @@ +import { apiMockEnabled, apiUrl } from '@/api/admin/client' +import { installMockRequestGuard } from '@/axios/instance' + +let installed = false + +export function registerApiMock() { + if (!apiMockEnabled || installed) return + + const base = apiUrl('') + + installMockRequestGuard(async (url) => { + if (!new URL(url, document.baseURI).href.startsWith(base)) return + + // 业务请求必须等到 Mock 可用后才能发出。 + const { ensureApiMock } = await import('./browser') + + await ensureApiMock() + }) + installed = true +} diff --git a/apps/admin/src/router/config/views.ts b/apps/admin/src/router/config/views.ts index 5504d0a9..bbe3a820 100644 --- a/apps/admin/src/router/config/views.ts +++ b/apps/admin/src/router/config/views.ts @@ -58,17 +58,18 @@ const views = { name: 'ModalDemo', }, 'demo/multi/views/multi-menu-one': { - load: () => import('@/views/demo/multi/views/multi-menu-one/index'), + load: () => + import('@/views/demo/multi').then((views) => views.MultiMenuOne), name: 'MultiMenuOne', }, 'demo/multi/views/multi-menu-two/views/sub-menu-other': { load: () => - import('@/views/demo/multi/views/multi-menu-two/views/sub-menu-other/index'), + import('@/views/demo/multi').then((views) => views.SubMenuOther), name: 'SubMenuOther', }, 'demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one': { load: () => - import('@/views/demo/multi/views/multi-menu-two/views/sub-menu/views/multi-menu-two-one/index'), + import('@/views/demo/multi').then((views) => views.MultiMenuTwoOne), name: 'MultiMenuTwoOne', }, 'demo/precision': { @@ -104,27 +105,33 @@ const views = { name: 'PreviewSVGIcons', }, 'demo/tables/auto-height': { - load: () => import('@/views/demo/tables/auto-height'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoAutoHeight), name: 'TableDemoAutoHeight', }, 'demo/tables/basic': { - load: () => import('@/views/demo/tables/basic'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoBasic), name: 'TableDemoBasic', }, 'demo/tables/columns': { - load: () => import('@/views/demo/tables/columns'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoColumns), name: 'TableDemoColumns', }, 'demo/tables/controlled': { - load: () => import('@/views/demo/tables/controlled'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoControlled), name: 'TableDemoControlled', }, 'demo/tables/custom': { - load: () => import('@/views/demo/tables/custom'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoCustom), name: 'TableDemoCustom', }, 'demo/tables/hooks-output': { - load: () => import('@/views/demo/tables/hooks-output'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoHooksOutput), name: 'TableDemoHooksOutput', }, 'demo/tables/hooks-query': { @@ -132,11 +139,15 @@ const views = { name: 'TableDemoHooksQuery', }, 'demo/tables/hooks-selection': { - load: () => import('@/views/demo/tables/hooks-selection'), + load: () => + import('@/views/demo/tables').then( + (views) => views.TableDemoHooksSelection, + ), name: 'TableDemoHooksSelection', }, 'demo/tables/printing': { - load: () => import('@/views/demo/tables/printing'), + load: () => + import('@/views/demo/tables').then((views) => views.TableDemoPrinting), name: 'TableDemoPrinting', }, 'demo/tables/remote': { diff --git a/apps/admin/src/router/index.ts b/apps/admin/src/router/index.ts index 5f90a863..bc5dd339 100644 --- a/apps/admin/src/router/index.ts +++ b/apps/admin/src/router/index.ts @@ -1,18 +1,18 @@ -import type { App } from 'vue' +import type { App, Component } from 'vue' import { createRouter, createWebHashHistory } from 'vue-router' import { getStaticAppRoutes, setAppRouteModules } from './app-route-modules' import { loadRouteConfig, resetRouteSource } from './config/source' import { - constantRoutes, getAccountProfileRoute, getLayoutRoutes, + getRootRoutes, getSystemRoutes, } from './routes' import { scrollViewToTop, vueRouterRegister } from './utils' export const router = createRouter({ history: createWebHashHistory(), - routes: constantRoutes, + routes: [], scrollBehavior: (to) => { scrollViewToTop(to) }, @@ -63,7 +63,15 @@ export function loadAccountRoutes() { let registered = false -export async function setupRouter(app: App, authenticated: boolean) { +export async function setupRouter( + app: App, + authenticated: boolean, + login: Component, +) { + if (!router.hasRoute('RLayout')) { + for (const route of getRootRoutes(login)) router.addRoute(route) + } + if (authenticated) await loadAccountRoutes() else clearAccountRoutes() diff --git a/apps/admin/src/router/routes.ts b/apps/admin/src/router/routes.ts index cb827dc3..5a4fb5a0 100644 --- a/apps/admin/src/router/routes.ts +++ b/apps/admin/src/router/routes.ts @@ -1,4 +1,4 @@ -import Layout from '@/layout' +import type { Component } from 'vue' import type { RouteRecordRaw } from 'vue-router' import { appExpandRoutes } from './app-route-modules' import { @@ -21,9 +21,9 @@ const legacyRedirects = [ { path: '/table-auto-height', redirect: '/tables/auto-height' }, ] -export const constantRoutes: RouteRecordRaw[] = [ - { path: '/', name: 'RLogin', component: () => import('@/views/login') }, - { path: '/', name: 'RLayout', component: Layout }, +export const getRootRoutes = (login: Component): RouteRecordRaw[] => [ + { path: '/', name: 'RLogin', component: login }, + { path: '/', name: 'RLayout', component: () => import('@/layout') }, ] export function getLayoutRoutes(): RouteRecordRaw[] { @@ -72,19 +72,22 @@ export const getSystemRoutes = (): RouteRecordRaw[] => [ { path: FORBIDDEN_ROUTE_PATH, name: 'ErrorPage403', - component: () => import('@/views/error/views/Error403'), + component: () => + import('@/views/error/system-errors').then((views) => views.Error403), meta: { i18nKey: 'workspaceStates.forbidden.title', hidden: true }, }, { path: NOT_FOUND_PAGE_PATH, name: 'ErrorPage404', - component: () => import('@/views/error/views/Error404'), + component: () => + import('@/views/error/system-errors').then((views) => views.Error404), meta: { i18nKey: 'workspaceStates.notFound.title', hidden: true }, }, { path: SERVER_ERROR_ROUTE_PATH, name: 'ErrorPage500', - component: () => import('@/views/error/views/Error500'), + component: () => + import('@/views/error/system-errors').then((views) => views.Error500), meta: { i18nKey: 'workspaceStates.serverError.title', hidden: true }, }, { diff --git a/apps/admin/src/router/utils/expand-routes.ts b/apps/admin/src/router/utils/expand-routes.ts index 6f456d7b..9203ca79 100644 --- a/apps/admin/src/router/utils/expand-routes.ts +++ b/apps/admin/src/router/utils/expand-routes.ts @@ -1 +1 @@ -export { expandRoutes } from '@ray-template/routing' +export { expandRoutes } from '@ray-template/routing/expand-routes' diff --git a/apps/admin/src/router/utils/order-routes.ts b/apps/admin/src/router/utils/order-routes.ts index 3e248388..07985617 100644 --- a/apps/admin/src/router/utils/order-routes.ts +++ b/apps/admin/src/router/utils/order-routes.ts @@ -1 +1 @@ -export { orderRoutes } from '@ray-template/routing' +export { orderRoutes } from '@ray-template/routing/order-routes' diff --git a/apps/admin/src/store/modules/menu/utils.ts b/apps/admin/src/store/modules/menu/utils.ts index 54e4d7f2..05a2e21b 100644 --- a/apps/admin/src/store/modules/menu/utils.ts +++ b/apps/admin/src/store/modules/menu/utils.ts @@ -1,10 +1,10 @@ import { APP_CATCH_KEY } from '@/app-config' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { resolveIconName } from '@/icons' import type { AppMenuKey, AppMenuOption } from '@/types/modules/app' import { getStorage } from '@/utils/cache' import { isValueType } from '@/utils/core' +import { RIcon } from '@ray-template/ui/icon' import { NTag } from 'naive-ui' import type { TagProps } from 'naive-ui' import { piniaSettingStore } from '../setting' diff --git a/apps/admin/src/utils/legacy-crypto/decrypt.ts b/apps/admin/src/utils/legacy-crypto/decrypt.ts index d9025005..01c3b745 100644 --- a/apps/admin/src/utils/legacy-crypto/decrypt.ts +++ b/apps/admin/src/utils/legacy-crypto/decrypt.ts @@ -1,4 +1,5 @@ -import { AES, enc } from 'crypto-js' +import AES from 'crypto-js/aes' +import CryptoJS from 'crypto-js/core' import { CRYPTO_KEY } from './constant' import type { CipherParams, WordArray } from './types' @@ -18,18 +19,20 @@ export const decrypt = ( const parts = typeof data === 'string' ? /^([a-f0-9]{32}):(.+)$/i.exec(data) : null const iv = - typeof data === 'string' ? parts && enc.Hex.parse(parts[1]) : data.iv + typeof data === 'string' + ? parts && CryptoJS.enc.Hex.parse(parts[1]) + : data.iv if (!iv) throw new Error('Missing AES initialization vector.') const decrypted = AES.decrypt(parts?.[2] ?? data, key, { iv }) - return JSON.parse(decrypted.toString(enc.Utf8)) + return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8)) } const decrypted = AES.decrypt(data, key || CRYPTO_KEY) - return JSON.parse(decrypted.toString(enc.Utf8)) + return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8)) } catch (error) { console.error('[decrypt]: Invalid ciphertext or key.', error) } diff --git a/apps/admin/src/utils/legacy-crypto/encrypt.ts b/apps/admin/src/utils/legacy-crypto/encrypt.ts index 328fbf6e..c23f7fa7 100644 --- a/apps/admin/src/utils/legacy-crypto/encrypt.ts +++ b/apps/admin/src/utils/legacy-crypto/encrypt.ts @@ -1,4 +1,5 @@ -import { AES, lib } from 'crypto-js' +import AES from 'crypto-js/aes' +import CryptoJS from 'crypto-js/core' import { CRYPTO_KEY } from './constant' import type { WordArray } from './types' @@ -21,7 +22,7 @@ export const encrypt = (data: unknown, key?: string | WordArray) => { throw new TypeError('[encrypt]: Value is not JSON serializable.') if (typeof key === 'object') { - const iv = lib.WordArray.random(16) + const iv = CryptoJS.lib.WordArray.random(16) const ciphertext = AES.encrypt(json, key, { iv }) return `${iv.toString()}:${ciphertext.toString()}` diff --git a/apps/admin/src/views/account-profile/index.tsx b/apps/admin/src/views/account-profile/index.tsx index d5caea70..e045fa80 100644 --- a/apps/admin/src/views/account-profile/index.tsx +++ b/apps/admin/src/views/account-profile/index.tsx @@ -10,9 +10,9 @@ import type { AccountProfile } from '@/api/admin/contracts' import AccountPasswordForm from '@/app-components/app/AccountPasswordForm' import AccountAvatar from '@/app-components/app/AppAvatar/AccountAvatar' import AppPageHeader from '@/app-components/app/AppPageHeader' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { useSigningActions, useSigningGetters } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import { NAlert, NButton, diff --git a/apps/admin/src/views/dashboard/index.tsx b/apps/admin/src/views/dashboard/index.tsx index 285f5f99..97a14324 100644 --- a/apps/admin/src/views/dashboard/index.tsx +++ b/apps/admin/src/views/dashboard/index.tsx @@ -1,10 +1,10 @@ import './index.scss' import AppPageHeader from '@/app-components/app/AppPageHeader' import AppShareLink from '@/app-components/app/AppShareLink' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { useMenuGetters } from '@/store' import type { AppMenuOption } from '@/types' +import { RIcon } from '@ray-template/ui/icon' import { NCard, NDescriptions, NDescriptionsItem } from 'naive-ui' import { RouterLink } from 'vue-router' diff --git a/apps/admin/src/views/demo/barcode-demo.tsx b/apps/admin/src/views/demo/barcode-demo.tsx index ea8f8b84..309924ef 100644 --- a/apps/admin/src/views/demo/barcode-demo.tsx +++ b/apps/admin/src/views/demo/barcode-demo.tsx @@ -1,5 +1,5 @@ -import { RBarcode } from '@/components' import { useI18n } from '@/hooks' +import { RBarcode } from '@ray-template/ui/barcode' import { NCard, NFlex, NFormItem, NInput, NSelect, NSwitch } from 'naive-ui' import DemoPage from './components/DemoPage' import DemoResult from './components/DemoResult' diff --git a/apps/admin/src/views/demo/doc/index.tsx b/apps/admin/src/views/demo/doc/index.tsx index 635123d3..62247d6b 100644 --- a/apps/admin/src/views/demo/doc/index.tsx +++ b/apps/admin/src/views/demo/doc/index.tsx @@ -1,6 +1,6 @@ import { RAY_TEMPLATE_DOCS_URL } from '@/app-config' -import { RIframe } from '@/components' import { useI18n } from '@/hooks' +import { RIframe } from '@ray-template/ui/iframe' export default defineComponent({ name: 'RTemplateDoc', diff --git a/apps/admin/src/views/demo/draggable-card.tsx b/apps/admin/src/views/demo/draggable-card.tsx index 0599ac15..9388aea3 100644 --- a/apps/admin/src/views/demo/draggable-card.tsx +++ b/apps/admin/src/views/demo/draggable-card.tsx @@ -1,6 +1,6 @@ -import { RDraggableCard } from '@/components' -import type { DefaultPosition } from '@/components' import { useI18n } from '@/hooks' +import RDraggableCard from '@ray-template/ui/draggable-card' +import type { DefaultPosition } from '@ray-template/ui/draggable-card' import { NButton, NCard, NFlex, NSelect, NSwitch, NTag } from 'naive-ui' import DemoPage from './components/DemoPage' diff --git a/apps/admin/src/views/demo/echart/index.tsx b/apps/admin/src/views/demo/echart/index.tsx index c96bb886..a9d67841 100644 --- a/apps/admin/src/views/demo/echart/index.tsx +++ b/apps/admin/src/views/demo/echart/index.tsx @@ -3,8 +3,8 @@ import DemoResult from '../components/DemoResult' import './index.scss' import { getDemoCharts } from '@/api/demo/data' import type { DemoCharts } from '@/api/demo/data' -import { RChart, useChart } from '@/components' import { useI18n } from '@/hooks' +import { RChart, useChart } from '@ray-template/ui/chart' import { NButton, NCard, NFlex, NSwitch } from 'naive-ui' const Echart = defineComponent({ diff --git a/apps/admin/src/views/demo/flow-demo.tsx b/apps/admin/src/views/demo/flow-demo.tsx index c1c6f5ee..a1b420d6 100644 --- a/apps/admin/src/views/demo/flow-demo.tsx +++ b/apps/admin/src/views/demo/flow-demo.tsx @@ -1,5 +1,5 @@ -import { RFlow, useFlow } from '@/components' import { useI18n } from '@/hooks' +import { RFlow, useFlow } from '@ray-template/ui/flow' import { NButton, NCard, NFlex, NSwitch, NTag } from 'naive-ui' import DemoPage from './components/DemoPage' import DemoResult from './components/DemoResult' diff --git a/apps/admin/src/views/demo/form/index.tsx b/apps/admin/src/views/demo/form/index.tsx index 45483ee2..2d8b944a 100644 --- a/apps/admin/src/views/demo/form/index.tsx +++ b/apps/admin/src/views/demo/form/index.tsx @@ -1,5 +1,5 @@ -import { RForm, useForm } from '@/components' import { useI18n } from '@/hooks' +import { RForm, useForm } from '@ray-template/ui/form' import { NButton, NCard, diff --git a/apps/admin/src/views/demo/hooks/HookExample.tsx b/apps/admin/src/views/demo/hooks/HookExample.tsx index 86b6e525..a3f22ca4 100644 --- a/apps/admin/src/views/demo/hooks/HookExample.tsx +++ b/apps/admin/src/views/demo/hooks/HookExample.tsx @@ -1,6 +1,6 @@ import './index.scss' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NCard } from 'naive-ui' import { exampleFocusKey } from './example-focus' diff --git a/apps/admin/src/views/demo/iframe/index.tsx b/apps/admin/src/views/demo/iframe/index.tsx index 8bd2a0fc..947dd52e 100644 --- a/apps/admin/src/views/demo/iframe/index.tsx +++ b/apps/admin/src/views/demo/iframe/index.tsx @@ -1,5 +1,5 @@ -import { RIframe } from '@/components' import { useI18n } from '@/hooks' +import { RIframe } from '@ray-template/ui/iframe' import { NButton, NCard, NTag } from 'naive-ui' import DemoPage from '../components/DemoPage' diff --git a/apps/admin/src/views/demo/modal-demo/index.tsx b/apps/admin/src/views/demo/modal-demo/index.tsx index c3f54cf2..ded27028 100644 --- a/apps/admin/src/views/demo/modal-demo/index.tsx +++ b/apps/admin/src/views/demo/modal-demo/index.tsx @@ -1,5 +1,5 @@ -import { RModal, useModal } from '@/components' import { useI18n } from '@/hooks' +import { RModal, useModal } from '@ray-template/ui/modal' import { NButton, NCard, NFlex, NInputNumber, NTag } from 'naive-ui' import DemoPage from '../components/DemoPage' import DemoResult from '../components/DemoResult' diff --git a/apps/admin/src/views/demo/multi/index.ts b/apps/admin/src/views/demo/multi/index.ts new file mode 100644 index 00000000..0125a5a5 --- /dev/null +++ b/apps/admin/src/views/demo/multi/index.ts @@ -0,0 +1,3 @@ +export { default as MultiMenuOne } from './views/multi-menu-one' +export { default as MultiMenuTwoOne } from './views/multi-menu-two/views/sub-menu/views/multi-menu-two-one' +export { default as SubMenuOther } from './views/multi-menu-two/views/sub-menu-other' diff --git a/apps/admin/src/views/demo/router-demo/router-demo-home/index.tsx b/apps/admin/src/views/demo/router-demo/router-demo-home/index.tsx index adf9b52a..cdcd59d2 100644 --- a/apps/admin/src/views/demo/router-demo/router-demo-home/index.tsx +++ b/apps/admin/src/views/demo/router-demo/router-demo-home/index.tsx @@ -1,10 +1,10 @@ import { getRouteDemoPeople } from '@/api/demo/data' -import { RTablePro } from '@/components' import { useI18n } from '@/hooks' import type { RouteDemoPerson, RoutePeopleQuery, } from '@ray-template/api-contracts/demo' +import { RTablePro } from '@ray-template/ui/table-pro' import { NButton, NFlex } from 'naive-ui' import type { DataTableColumns } from 'naive-ui' diff --git a/apps/admin/src/views/demo/segment/index.tsx b/apps/admin/src/views/demo/segment/index.tsx index 1a43f5c6..5fa088c4 100644 --- a/apps/admin/src/views/demo/segment/index.tsx +++ b/apps/admin/src/views/demo/segment/index.tsx @@ -1,7 +1,9 @@ -import { RIcon, RSegment } from '@/components' -import type { RSegmentOptions, RSegmentWidth } from '@/components' +import type { RSegmentWidth } from '@/components' import { useI18n } from '@/hooks' import type { ComponentSize } from '@/types' +import { RIcon } from '@ray-template/ui/icon' +import { RSegment } from '@ray-template/ui/segment' +import type { RSegmentOptions } from '@ray-template/ui/segment' import { NCard, NFlex, NRadioButton, NRadioGroup } from 'naive-ui' import DemoPage from '../components/DemoPage' diff --git a/apps/admin/src/views/demo/svg-icons/index.tsx b/apps/admin/src/views/demo/svg-icons/index.tsx index 34aab6f0..947724bf 100644 --- a/apps/admin/src/views/demo/svg-icons/index.tsx +++ b/apps/admin/src/views/demo/svg-icons/index.tsx @@ -1,7 +1,7 @@ import './index.scss' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { iconNames, iconPackages } from '@/icons' +import { RIcon } from '@ray-template/ui/icon' import { NCard, NEmpty, diff --git a/apps/admin/src/views/demo/tables/auto-height.tsx b/apps/admin/src/views/demo/tables/auto-height.tsx index 1db1afe2..b9d0d612 100644 --- a/apps/admin/src/views/demo/tables/auto-height.tsx +++ b/apps/admin/src/views/demo/tables/auto-height.tsx @@ -1,5 +1,5 @@ -import { RTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro } from '@ray-template/ui/table-pro' import { NCheckbox } from 'naive-ui' import { createPeopleColumns } from './people' import { usePeopleData } from './usePeopleData' diff --git a/apps/admin/src/views/demo/tables/basic.tsx b/apps/admin/src/views/demo/tables/basic.tsx index 90bc01cc..a499bf83 100644 --- a/apps/admin/src/views/demo/tables/basic.tsx +++ b/apps/admin/src/views/demo/tables/basic.tsx @@ -1,5 +1,5 @@ -import { RTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro } from '@ray-template/ui/table-pro' import { createPeopleColumns } from './people' import { usePeopleData } from './usePeopleData' diff --git a/apps/admin/src/views/demo/tables/columns.tsx b/apps/admin/src/views/demo/tables/columns.tsx index b50e5fdd..d9ff859a 100644 --- a/apps/admin/src/views/demo/tables/columns.tsx +++ b/apps/admin/src/views/demo/tables/columns.tsx @@ -1,6 +1,6 @@ -import { RTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' import type { Person } from '@ray-template/api-contracts/demo' +import { RTablePro } from '@ray-template/ui/table-pro' import { NCheckbox } from 'naive-ui' import type { DataTableColumns } from 'naive-ui' import { createPeopleColumns } from './people' diff --git a/apps/admin/src/views/demo/tables/custom.tsx b/apps/admin/src/views/demo/tables/custom.tsx index 86ce3a3b..757a3a89 100644 --- a/apps/admin/src/views/demo/tables/custom.tsx +++ b/apps/admin/src/views/demo/tables/custom.tsx @@ -1,5 +1,5 @@ -import { RTablePro, useTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro, useTablePro } from '@ray-template/ui/table-pro' import { NButton, NFlex, NInput } from 'naive-ui' import { createPeopleColumns } from './people' import { usePeopleData } from './usePeopleData' diff --git a/apps/admin/src/views/demo/tables/hooks-output.tsx b/apps/admin/src/views/demo/tables/hooks-output.tsx index 24eb03b0..4a607e53 100644 --- a/apps/admin/src/views/demo/tables/hooks-output.tsx +++ b/apps/admin/src/views/demo/tables/hooks-output.tsx @@ -1,5 +1,5 @@ -import { RTablePro, useTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro, useTablePro } from '@ray-template/ui/table-pro' import { NButton, NFlex } from 'naive-ui' import DemoPage from '../components/DemoPage' import DemoResult from '../components/DemoResult' diff --git a/apps/admin/src/views/demo/tables/hooks-query.tsx b/apps/admin/src/views/demo/tables/hooks-query.tsx index 63963dd2..c2df14c9 100644 --- a/apps/admin/src/views/demo/tables/hooks-query.tsx +++ b/apps/admin/src/views/demo/tables/hooks-query.tsx @@ -1,8 +1,8 @@ import { apiMockEnabled } from '@/api/admin/client' import { getPersonList } from '@/api/demo/mock/person' import type { PersonListParams } from '@/api/demo/mock/person' -import { RTablePro, useTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro, useTablePro } from '@ray-template/ui/table-pro' import { NButton, NCard, diff --git a/apps/admin/src/views/demo/tables/hooks-selection.tsx b/apps/admin/src/views/demo/tables/hooks-selection.tsx index 4d96f57c..e01563dd 100644 --- a/apps/admin/src/views/demo/tables/hooks-selection.tsx +++ b/apps/admin/src/views/demo/tables/hooks-selection.tsx @@ -1,6 +1,6 @@ -import { RTablePro, useTablePro } from '@/components' import { useI18n } from '@/hooks/template/useI18n' import type { Person } from '@ray-template/api-contracts/demo' +import { RTablePro, useTablePro } from '@ray-template/ui/table-pro' import { NButton, NFlex } from 'naive-ui' import type { DataTableColumns } from 'naive-ui' import DemoPage from '../components/DemoPage' diff --git a/apps/admin/src/views/demo/tables/index.ts b/apps/admin/src/views/demo/tables/index.ts new file mode 100644 index 00000000..1ad98c56 --- /dev/null +++ b/apps/admin/src/views/demo/tables/index.ts @@ -0,0 +1,8 @@ +export { default as TableDemoAutoHeight } from './auto-height' +export { default as TableDemoBasic } from './basic' +export { default as TableDemoColumns } from './columns' +export { default as TableDemoControlled } from './controlled' +export { default as TableDemoCustom } from './custom' +export { default as TableDemoHooksOutput } from './hooks-output' +export { default as TableDemoHooksSelection } from './hooks-selection' +export { default as TableDemoPrinting } from './printing' diff --git a/apps/admin/src/views/demo/tables/printing.tsx b/apps/admin/src/views/demo/tables/printing.tsx index 77541322..7076f6e3 100644 --- a/apps/admin/src/views/demo/tables/printing.tsx +++ b/apps/admin/src/views/demo/tables/printing.tsx @@ -1,7 +1,7 @@ import './printing.scss' -import { RTablePro } from '@/components' -import type { TableProInst } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro } from '@ray-template/ui/table-pro' +import type { TableProInst } from '@ray-template/ui/table-pro' import { NButton } from 'naive-ui' import { useTemplateRef } from 'vue' import { createPeopleColumns } from './people' diff --git a/apps/admin/src/views/demo/tables/remote.tsx b/apps/admin/src/views/demo/tables/remote.tsx index ac41c9c3..4841f2b2 100644 --- a/apps/admin/src/views/demo/tables/remote.tsx +++ b/apps/admin/src/views/demo/tables/remote.tsx @@ -1,8 +1,8 @@ import { getPersonList } from '@/api/demo/mock/person' import type { PersonListParams } from '@/api/demo/mock/person' -import { RTablePro } from '@/components' -import type { TableProInst } from '@/components' import { useI18n } from '@/hooks/template/useI18n' +import { RTablePro } from '@ray-template/ui/table-pro' +import type { TableProInst } from '@ray-template/ui/table-pro' import { NButton, NTag } from 'naive-ui' import type { DataTableSortState } from 'naive-ui' import { createPeopleColumns } from './people' diff --git a/apps/admin/src/views/demo/template-hooks/index.tsx b/apps/admin/src/views/demo/template-hooks/index.tsx index 41f2e904..95715383 100644 --- a/apps/admin/src/views/demo/template-hooks/index.tsx +++ b/apps/admin/src/views/demo/template-hooks/index.tsx @@ -1,4 +1,3 @@ -import { RIcon } from '@/components' import { useAppNavigation, useBadge, @@ -13,6 +12,7 @@ import { useWatermark, } from '@/hooks' import { useMenuGetters, useRuntimeGetters, useSettingGetters } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import { useTimeoutFn } from '@vueuse/core' import { NButton, NFlex, NInput, NTag } from 'naive-ui' import DemoPage from '../components/DemoPage' diff --git a/apps/admin/src/views/error/PageResult/index.tsx b/apps/admin/src/views/error/PageResult/index.tsx index fc974ffa..d8026719 100644 --- a/apps/admin/src/views/error/PageResult/index.tsx +++ b/apps/admin/src/views/error/PageResult/index.tsx @@ -1,9 +1,9 @@ import './index.scss' import AppPageHeader from '@/app-components/app/AppPageHeader' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { WELCOME_ROUTE_PATH } from '@/router/constant' import { resolveLandingPath } from '@/router/utils/resolve-landing-path' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NFlex, NResult, resultProps } from 'naive-ui' const statusKeys = { diff --git a/apps/admin/src/views/error/system-errors.ts b/apps/admin/src/views/error/system-errors.ts new file mode 100644 index 00000000..906e7d6a --- /dev/null +++ b/apps/admin/src/views/error/system-errors.ts @@ -0,0 +1,3 @@ +export { default as Error403 } from './views/Error403' +export { default as Error404 } from './views/Error404' +export { default as Error500 } from './views/Error500' diff --git a/apps/admin/src/views/login/components/SSOSigning/index.tsx b/apps/admin/src/views/login/components/SSOSigning/index.tsx index 14673fe6..f35f16ed 100644 --- a/apps/admin/src/views/login/components/SSOSigning/index.tsx +++ b/apps/admin/src/views/login/components/SSOSigning/index.tsx @@ -1,5 +1,5 @@ -import { RIcon } from '@/components' import type { IconName } from '@/icons' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NFlex, NTooltip } from 'naive-ui' const providers = [ diff --git a/apps/admin/src/views/login/components/Signing/index.tsx b/apps/admin/src/views/login/components/Signing/index.tsx index 7962b558..607923db 100644 --- a/apps/admin/src/views/login/components/Signing/index.tsx +++ b/apps/admin/src/views/login/components/Signing/index.tsx @@ -1,10 +1,10 @@ import { AdminApiError, apiMockEnabled } from '@/api/admin/client' -import { RForm, useForm } from '@/components' import { useI18n } from '@/hooks' import { loadAccountRoutes } from '@/router' import { resolveLandingPath } from '@/router/utils/resolve-landing-path' import { useSigningActions } from '@/store' import { announceAdminSessionChange } from '@/store/modules/signing' +import { RForm, useForm } from '@ray-template/ui/form' import { NButton, NFlex, NFormItem, NInput } from 'naive-ui' export default defineComponent({ diff --git a/apps/admin/src/views/login/index.tsx b/apps/admin/src/views/login/index.tsx index ddfc1c3e..ae4ec346 100644 --- a/apps/admin/src/views/login/index.tsx +++ b/apps/admin/src/views/login/index.tsx @@ -2,10 +2,10 @@ import './index.scss' import { apiMockEnabled } from '@/api/admin/client' import AppShareLink from '@/app-components/app/AppShareLink' import { LOCAL_OPTIONS } from '@/app-config' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import ThemeSwitch from '@/layout/components/SiderBar/components/SettingDrawer/components/ThemeSwitch' import { useSettingActions } from '@/store' +import { RIcon } from '@ray-template/ui/icon' import { NButton, NDropdown, NFlex, NTabPane, NTabs } from 'naive-ui' import QRCodeSigning from './components/QRCodeSigning' import Register from './components/Register' diff --git a/apps/admin/src/views/user-management/UserEditor.tsx b/apps/admin/src/views/user-management/UserEditor.tsx index ff61e95d..9c1b54a1 100644 --- a/apps/admin/src/views/user-management/UserEditor.tsx +++ b/apps/admin/src/views/user-management/UserEditor.tsx @@ -1,8 +1,8 @@ import { createUser, updateUser } from '@/api/admin' import { AdminApiError } from '@/api/admin/client' import type { AdminUser, UserInput, UserOptions } from '@/api/admin/contracts' -import { RForm, useForm } from '@/components' import { useAccess, useI18n } from '@/hooks' +import { RForm, useForm } from '@ray-template/ui/form' import { NAlert, NButton, diff --git a/apps/admin/src/views/user-management/index.tsx b/apps/admin/src/views/user-management/index.tsx index a0586f07..08fb958a 100644 --- a/apps/admin/src/views/user-management/index.tsx +++ b/apps/admin/src/views/user-management/index.tsx @@ -12,15 +12,18 @@ import { AdminApiError, apiMockEnabled } from '@/api/admin/client' import type { AdminUser, UserOptions, UserStatus } from '@/api/admin/contracts' import AccountPasswordForm from '@/app-components/app/AccountPasswordForm' import AppPageHeader from '@/app-components/app/AppPageHeader' -import { RIcon, RTablePro } from '@/components' -import type { TableProInst } from '@/components' import { useAccess, useI18n } from '@/hooks' import { useSettingGetters, useSigningActions, useSigningGetters, } from '@/store' -import type { TableProSearchFieldConfig } from '@ray-template/ui/table-pro' +import { RIcon } from '@ray-template/ui/icon' +import { RTablePro } from '@ray-template/ui/table-pro' +import type { + TableProInst, + TableProSearchFieldConfig, +} from '@ray-template/ui/table-pro' import { useElementSize } from '@vueuse/core' import { NAlert, diff --git a/apps/admin/src/views/welcome/index.tsx b/apps/admin/src/views/welcome/index.tsx index ae27329e..01186ac6 100644 --- a/apps/admin/src/views/welcome/index.tsx +++ b/apps/admin/src/views/welcome/index.tsx @@ -1,9 +1,9 @@ import './index.scss' import AppPageHeader from '@/app-components/app/AppPageHeader' -import { RIcon } from '@/components' import { useI18n } from '@/hooks' import { useMenuGetters, useNavigationHistoryGetters } from '@/store' import type { AppMenuOption } from '@/types' +import { RIcon } from '@ray-template/ui/icon' import { RouterLink } from 'vue-router' export default defineComponent({ diff --git a/docs/architecture.md b/docs/architecture.md index 4c969726..af72d553 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -79,6 +79,12 @@ The [root configuration](../tsconfig.json) references four projects. Strict mode `pnpm build` produces admin output in `dist/production`; `pnpm docs:build` produces `apps/docs/.vitepress/dist`. `pnpm pages:build` combines them in `dist/pages`, with documentation under `docs/`. The default admin base is `/ray-template/`; the documentation base is `/ray-template/docs/`. For root hosting or another subpath, align the [admin base](../vite.custom.config.ts), [documentation base](../apps/docs/.vitepress/config.mts), and [legacy redirect targets](../scripts/assemble-pages.mjs). +The default production build clears its generated output directory before writing new assets. Custom output directories follow Vite's usual cleanup rules. + +The admin entry includes the sign-in view so the browser discovers its assets during the initial HTML load. The example entry registers its own routes. The workspace layout and feature views load when their routes match. Both configured language packs are available at startup for synchronous language switching. In demo mode, the request interceptor starts MSW and checks readiness before the first mock API request can leave the client. The demo people generator loads when a people request needs data. + +Built-in views import the [specific UI entry points](../packages/ui/package.json) so a shared component such as an icon can load independently of chart, flow, and barcode code. Keep `@/components` available as a compatibility entry. The [Vite groups](../vite.config.ts) collect shared framework and utility modules and split the chart renderer within the chart route. Group small views when users move among them and they share feature dependencies. Evaluate bundles by the requests and bytes each entry and route loads. + Every push to `main` triggers the Pages workflow. The build job runs `pnpm pages:build` on Ubuntu 24.04 and uploads `dist/pages` as a Pages artifact, including `.nojekyll`. The deployment job publishes that artifact using the `github-pages` environment. Manual dispatch also publishes from `main`. [Pages workflow](../.github/workflows/ci.yaml) In the repository's Pages settings, set the publishing source to **GitHub Actions**. If the `github-pages` environment uses a branch allowlist, allow `main`. For manual publication from a branch, keep `.nojekyll` in the output so assets with underscore prefixes can load. [GitHub Pages source setup](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site) · [Admin .nojekyll file](../apps/admin/public/.nojekyll) diff --git a/docs/toolchain-upgrade.md b/docs/toolchain-upgrade.md index 14e3e295..2a3220a1 100644 --- a/docs/toolchain-upgrade.md +++ b/docs/toolchain-upgrade.md @@ -285,3 +285,17 @@ Vitest and its UI move together to 5.1.0. The sidebar regression waits for the m Two earlier updates required follow-up before verification could pass. The five shared browser packages now declare the same Vue 3.5.45 peer as the apps. The mock client and Node test setup use the MSW 3.0.4 entry points and options, and the checked-in worker matches that release. Unhandled mock API calls fail locally as network errors. Other resources can pass through to the host. [MSW migration guide](https://mswjs.io/docs/migrations/2.x-to-3.x) · [MSW 3.0.4](https://github.com/mswjs/msw/releases/tag/v3.0.4) On macOS with Node.js 26.13.0 and pnpm 12.16.1, the combined candidate passed frozen-lockfile installation, peer dependency checks, and `pnpm harness verify all`. The run covered 575 frontend tests, 12 backend tests, both site builds, and both source distributions. The optional real Redis test was skipped. The assembled Pages preview passed demo sign-in, dashboard navigation, and the embedded TablePro failure and retry flow in Chrome. An existing MSW 2 registration could stall startup after an update. The versioned script URL let Chrome register the 3.0.4 worker and sign in while a tab from the previous build remained open. The 3.0.4 worker answered 37 health probes over 362 seconds. + +## 2026-11-10: Admin startup and bundles + +The [admin entry](../apps/admin/src/main.ts) includes the sign-in view and both configured locale dictionaries in the initial module graph. The workspace shell, chart and flow libraries, lock dialog, route schema converter, and mock code load when needed. In demo mode, the request guard waits for MSW readiness, shares startup between concurrent requests, and retries after a startup failure. [Production bundle conventions](architecture.md#deployment-and-search-discovery) + +The largest minified JS file went from 2,511.83 kB to 498.49 kB with the default 500 kB warning limit. The mock startup chunk dropped from 888.75 kB to 404.41 kB after the people generator moved behind its endpoint. The output grew from 96 to 113 JS files as features gained independent loading boundaries. Related table, nested menu, and error views share entry files. + +The existing local production directory had accumulated 2,165 JS files because Vite's application root is below the workspace output directory. The default production build now clears its own output. The clean output occupies 6.8 MiB on this machine, down from 156 MiB with stale builds present. + +Local Chrome comparison used three cold HTTP cache loads per build, a 390 × 844 viewport, 4× CPU slowdown, 150 ms added network latency, and 1.6 Mbit/s download. The English sign-in heading's median LCP went from 6.78 s to 2.51 s. CLS was 0 on each run. The page loaded 23 JS resources in both builds, and their combined encoded response bodies went from 1,330.43 kB to 359.24 kB. The measured demo sign-in Event Timing sample went from 88 ms to 72 ms. Field Core Web Vitals require real-user measurements. [Google's measurement guidance](https://web.dev/articles/vitals-measurement-getting-started) + +`pnpm harness verify all` passed with loopback access for the server tests. The run covered 576 frontend tests, 12 server tests, both site builds, and both source distributions. The optional Redis integration test was skipped. The admin build stayed below the chunk warning limit. VitePress still reports a large chunk for the TablePro examples page. + +The assembled Pages preview verified demo sign-in, session restoration, chart, flow, barcode, grouped table views, the 404 route, and the first opening of the lock dialog. The documentation iframe fetched rows, cleared them on a simulated failure, and restored them on retry. The example entry also rendered the workspace shell when requested. Browser evidence is in `.harness-local/browser/admin-startup-2026-11-10/report.json`. diff --git a/harness/README.md b/harness/README.md index bedf9aad..31393fdd 100644 --- a/harness/README.md +++ b/harness/README.md @@ -30,6 +30,14 @@ pnpm harness verify table-pro - Requests flow from `apps/admin/src/api` into `apps/admin/src/axios`. Mocks are for demos and local verification. Never place server secrets in `VITE_*` variables that are bundled into the browser. - When maintaining public APIs, inspect callers, exports, and existing regression tests. For engineering configuration changes, update the corresponding documentation and [verification record](../docs/toolchain-upgrade.md). +### Runtime import boundaries + +Across workspaces, prefer the narrowest existing public entry point declared in `package.json#exports`, such as `@ray-template/ui/icon` or `@ray-template/routing/navigation`. Within a workspace, import the owning module or a focused feature entry point. + +Keep aggregate exports for cohesive APIs and existing compatibility. Use feature entry points in startup and shared code to keep unrelated styles, module initialization, and large dependencies outside those paths. Point dynamic imports at the specific feature entry point. + +When changing a startup or lazy loading boundary, inspect the production dependency graph and the requests and bytes loaded by the affected page. + ## Verification and evidence ### Choosing the verification scope diff --git a/packages/admin-shell/src/TopNavigation.tsx b/packages/admin-shell/src/TopNavigation.tsx index e25c5643..0dc9f6ce 100644 --- a/packages/admin-shell/src/TopNavigation.tsx +++ b/packages/admin-shell/src/TopNavigation.tsx @@ -1,6 +1,6 @@ import './TopNavigation.scss' -import { findMenuRoot, firstMenuLeaf } from '@ray-template/routing' import type { AppMenuKey, AppMenuOption } from '@ray-template/routing' +import { findMenuRoot, firstMenuLeaf } from '@ray-template/routing/navigation' import { NMenu } from 'naive-ui' import type { MenuOption } from 'naive-ui' import { computed, defineComponent } from 'vue' diff --git a/packages/routing/package.json b/packages/routing/package.json index 854a2446..59204fe5 100644 --- a/packages/routing/package.json +++ b/packages/routing/package.json @@ -6,7 +6,10 @@ ".": "./src/index.ts", "./schema": "./src/schema.ts", "./json-schema": "./src/json-schema.ts", + "./expand-routes": "./src/expand-routes.ts", "./join-route-path": "./src/join-route-path.ts", + "./navigation": "./src/navigation.ts", + "./order-routes": "./src/order-routes.ts", "./contract": "./src/contract.ts", "./types": "./src/types.ts" }, diff --git a/vite.config.ts b/vite.config.ts index e83e7b5b..2c30c894 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,6 +18,7 @@ export default defineConfig(({ mode }) => { appPrimaryColor, base, } = config + const defaultBuild = buildOptions(mode) const __APP_CFG__ = { pkg: { @@ -42,7 +43,27 @@ export default defineConfig(({ mode }) => { resolve: { alias: alias, }, - plugins: vitePlugins(mode), + plugins: [ + vitePlugins(mode), + mode === 'production' && { + name: 'ray:clean-production-output', + apply: 'build' as const, + config({ build, environments }) { + const client = environments?.client?.build + + // 只清理项目默认产物,保留对自定义输出目录的 Vite 默认保护。 + if ( + (client?.outDir ?? build?.outDir) === defaultBuild.outDir && + client?.emptyOutDir == null && + build?.emptyOutDir == null + ) { + return { + environments: { client: { build: { emptyOutDir: true } } }, + } + } + }, + }, + ], optimizeDeps: { entries: ['index.html'], include: [ @@ -66,7 +87,7 @@ export default defineConfig(({ mode }) => { ], }, build: { - ...buildOptions(mode), + ...defaultBuild, target: 'baseline-widely-available', rolldownOptions: { input: { @@ -78,7 +99,26 @@ export default defineConfig(({ mode }) => { ), }, output: { - // 交由 Rolldown 按依赖图拆包,避免手动按 pnpm 目录分组造成循环依赖。 + // 只归并共用的框架与工具代码,图表渲染器随图表页加载。 + codeSplitting: { + groups: [ + { + name: 'app-framework', + test: /[\\/]node_modules[\\/](?:vue|vue-router|vue-i18n|pinia|@vue[\\/](?:runtime-core|runtime-dom|reactivity|shared))[\\/]/, + priority: 20, + }, + { + name: 'lodash-shared', + test: /[\\/]node_modules[\\/]lodash-es[\\/]/, + minShareCount: 2, + priority: 10, + }, + { + name: 'chart-renderer', + test: /[\\/]node_modules[\\/]zrender[\\/]/, + }, + ], + }, minify: { compress: { dropConsole: mode === 'production',