@origen-ui/admin-cli 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +11 -7
  2. package/package.json +18 -2
  3. package/templates/current/clean/CHANGELOG.md +103 -0
  4. package/templates/current/clean/component-catalog.json +58 -17
  5. package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
  6. package/templates/current/clean/e2e/demo-shell.spec.ts +90 -46
  7. package/templates/current/clean/package.json +35 -21
  8. package/templates/current/clean/playwright.config.ts +1 -0
  9. package/templates/current/clean/playwright.demo.config.ts +1 -1
  10. package/templates/current/clean/scaffold.lock.json +2 -2
  11. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  12. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  13. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  14. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  15. package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
  16. package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  17. package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  18. package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  19. package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
  20. package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  21. package/templates/current/clean/scripts/demo-api.ts +84 -8
  22. package/templates/current/clean/scripts/generate-api.ts +87 -3
  23. package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
  24. package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
  25. package/templates/current/clean/src/api/generated/http-client.ts +28 -26
  26. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
  27. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
  28. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
  29. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
  30. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
  31. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
  32. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
  33. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
  34. package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
  35. package/templates/current/clean/src/app/errorMessage.ts +53 -0
  36. package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
  37. package/templates/current/clean/src/app/menu.spec.ts +39 -0
  38. package/templates/current/clean/src/app/menu.ts +48 -12
  39. package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
  40. package/templates/current/clean/src/demo-api.spec.ts +311 -0
  41. package/templates/current/clean/src/features/auth/pages/Login.vue +8 -2
  42. package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
  43. package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
  44. package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
  45. package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
  46. package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
  47. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
  48. package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
  49. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  50. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  51. package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
  52. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
  53. package/templates/current/clean/src/layouts/TopBar.vue +37 -6
  54. package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
  55. package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
  56. package/templates/current/clean/src/locales/en-US.json +30 -3
  57. package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
  58. package/templates/current/clean/src/locales/index.ts +39 -26
  59. package/templates/current/clean/src/locales/zh-CN.json +30 -3
  60. package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
  61. package/templates/current/clean/src/locales/zh-TW.json +30 -3
  62. package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
  63. package/templates/current/clean/src/main.ts +23 -14
  64. package/templates/current/clean/src/router/bootstrap.ts +10 -16
  65. package/templates/current/clean/src/router/componentCache.ts +12 -0
  66. package/templates/current/clean/src/router/componentRegistry.ts +2 -13
  67. package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
  68. package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
  69. package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
  70. package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
  71. package/templates/current/clean/src/router/paths.spec.ts +50 -0
  72. package/templates/current/clean/src/router/paths.ts +21 -0
  73. package/templates/current/clean/src/router/staticRoutes.ts +6 -6
  74. package/templates/current/clean/src/templates/og-table.ts +2 -4
  75. package/templates/current/clean/tsconfig.json +0 -1
  76. package/templates/current/clean/vite.build-policy.ts +55 -8
  77. package/templates/current/clean/vite.config.ts +30 -0
  78. package/templates/current/examples/CHANGELOG.md +103 -0
  79. package/templates/current/examples/component-catalog.json +58 -17
  80. package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
  81. package/templates/current/examples/e2e/demo-shell.spec.ts +90 -46
  82. package/templates/current/examples/package.json +35 -21
  83. package/templates/current/examples/playwright.config.ts +1 -0
  84. package/templates/current/examples/playwright.demo.config.ts +1 -1
  85. package/templates/current/examples/scaffold.lock.json +2 -2
  86. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  87. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  88. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  89. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  90. package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
  91. package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  92. package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  93. package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  94. package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
  95. package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  96. package/templates/current/examples/scripts/demo-api.ts +84 -8
  97. package/templates/current/examples/scripts/generate-api.ts +87 -3
  98. package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
  99. package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
  100. package/templates/current/examples/src/api/generated/http-client.ts +28 -26
  101. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
  102. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
  103. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
  104. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
  105. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
  106. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
  107. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
  108. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
  109. package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
  110. package/templates/current/examples/src/app/errorMessage.ts +53 -0
  111. package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
  112. package/templates/current/examples/src/app/menu.spec.ts +39 -0
  113. package/templates/current/examples/src/app/menu.ts +48 -12
  114. package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
  115. package/templates/current/examples/src/demo-api.spec.ts +311 -0
  116. package/templates/current/examples/src/features/auth/pages/Login.vue +8 -2
  117. package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
  118. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
  119. package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
  120. package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
  121. package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
  122. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
  123. package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
  124. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  125. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  126. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
  127. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
  128. package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
  129. package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
  130. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
  131. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
  132. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
  133. package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
  134. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
  135. package/templates/current/examples/src/layouts/TopBar.vue +37 -6
  136. package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
  137. package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
  138. package/templates/current/examples/src/locales/en-US.json +30 -3
  139. package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
  140. package/templates/current/examples/src/locales/index.ts +39 -26
  141. package/templates/current/examples/src/locales/zh-CN.json +30 -3
  142. package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
  143. package/templates/current/examples/src/locales/zh-TW.json +30 -3
  144. package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
  145. package/templates/current/examples/src/main.ts +24 -22
  146. package/templates/current/examples/src/router/bootstrap.ts +10 -16
  147. package/templates/current/examples/src/router/componentCache.ts +18 -0
  148. package/templates/current/examples/src/router/componentRegistry.ts +1 -18
  149. package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
  150. package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
  151. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
  152. package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
  153. package/templates/current/examples/src/router/paths.spec.ts +50 -0
  154. package/templates/current/examples/src/router/paths.ts +21 -0
  155. package/templates/current/examples/src/router/staticRoutes.ts +3 -3
  156. package/templates/current/examples/src/templates/og-table.ts +2 -4
  157. package/templates/current/examples/tsconfig.json +0 -1
  158. package/templates/current/examples/vite.build-policy.ts +55 -8
  159. package/templates/current/examples/vite.config.ts +30 -0
@@ -0,0 +1,18 @@
1
+ /**
2
+ * componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
3
+ *
4
+ * KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
5
+ * 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
6
+ * 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
7
+ */
8
+ export const componentCacheNames: Readonly<Record<string, string>> = {
9
+ 'dashboard': 'DashboardPage',
10
+ 'profile': 'ProfilePage',
11
+ 'user-list': 'UserListPage',
12
+ 'role-list': 'RoleListPage',
13
+ 'menu-list': 'MenuListPage',
14
+ 'audit-list': 'AuditListPage',
15
+ 'empty': 'EmptyPage',
16
+ }
17
+
18
+ export const fallbackComponentKey = 'empty'
@@ -30,24 +30,7 @@ function withComponentStyles(key: string, loadComponent: ComponentLoader): Compo
30
30
  }
31
31
  }
32
32
 
33
- /**
34
- * componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
35
- *
36
- * KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
37
- * 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
38
- * 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
39
- */
40
- export const componentCacheNames: Readonly<Record<string, string>> = {
41
- 'dashboard': 'DashboardPage',
42
- 'profile': 'ProfilePage',
43
- 'user-list': 'UserListPage',
44
- 'role-list': 'RoleListPage',
45
- 'menu-list': 'MenuListPage',
46
- 'audit-list': 'AuditListPage',
47
- 'empty': 'EmptyPage',
48
- }
49
-
50
- export const fallbackComponentKey = 'empty'
33
+ export { componentCacheNames, fallbackComponentKey } from './componentCache'
51
34
 
52
35
  export const componentRegistry: Map<string, ComponentLoader> = new Map([
53
36
  [
@@ -0,0 +1,101 @@
1
+ import type { BackendMenuNode } from '../app/menuTypes'
2
+ import { createRouterAdapter } from '@origen-ui/router'
3
+ import { describe, expect, it } from 'vitest'
4
+ import { defineComponent } from 'vue'
5
+ import { createMemoryHistory } from 'vue-router'
6
+ import { replaceDynamicMenusWithAccessibleFallback } from './dynamicMenuRefresh'
7
+ import { routeTransformer } from './dynamicRoutes'
8
+
9
+ const View = defineComponent({ template: '<div />' })
10
+
11
+ const staticRoutes = [
12
+ { name: 'login', path: '/login', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
13
+ { name: '404', path: '/404', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
14
+ { name: '500', path: '/500', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
15
+ ]
16
+
17
+ function createAdaptersWithMenus(menus: readonly BackendMenuNode[]) {
18
+ let current = menus
19
+ const adapter = createRouterAdapter<BackendMenuNode>({
20
+ history: createMemoryHistory(),
21
+ staticRoutes,
22
+ dynamic: {
23
+ load: async () => current,
24
+ transform: routeTransformer,
25
+ resolveComponent: () => () => Promise.resolve(View),
26
+ },
27
+ fallbacks: { notFound: { name: '404' }, error: { name: '500' } },
28
+ })
29
+ return {
30
+ adapter,
31
+ setMenus(next: readonly BackendMenuNode[]) {
32
+ current = [...next]
33
+ },
34
+ }
35
+ }
36
+
37
+ describe('replaceDynamicMenusWithAccessibleFallback', () => {
38
+ it('falls back to the first reachable menu entry when home is revoked', async () => {
39
+ const { adapter, setMenus } = createAdaptersWithMenus([
40
+ { code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
41
+ { code: 'reports', path: '/reports', title: 'Reports' },
42
+ ])
43
+ await adapter.router.push('/reports')
44
+ await adapter.router.isReady()
45
+ expect(adapter.router.currentRoute.value.path).toBe('/reports')
46
+
47
+ // 主页与当前页同时被裁撤:回落到刷新后菜单里首个真实可达入口。
48
+ setMenus([{ code: 'audit', path: '/audit', title: 'Audit' }])
49
+ await replaceDynamicMenusWithAccessibleFallback(adapter)
50
+
51
+ expect(adapter.router.currentRoute.value.path).toBe('/audit')
52
+ })
53
+
54
+ it('lands on home when the current route disappears but home remains', async () => {
55
+ const { adapter, setMenus } = createAdaptersWithMenus([
56
+ { code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
57
+ { code: 'reports', path: '/reports', title: 'Reports' },
58
+ ])
59
+ await adapter.router.push('/reports')
60
+ await adapter.router.isReady()
61
+
62
+ setMenus([{ code: 'dashboard', path: '/dashboard', title: 'Dashboard' }])
63
+ await replaceDynamicMenusWithAccessibleFallback(adapter)
64
+
65
+ expect(adapter.router.currentRoute.value.path).toBe('/dashboard')
66
+ })
67
+
68
+ it('skips a directory whose redirect target was revoked and lands on a real entry', async () => {
69
+ const { adapter, setMenus } = createAdaptersWithMenus([
70
+ { code: 'system', path: '/system', title: 'System', redirect: '/dashboard' },
71
+ { code: 'reports', path: '/reports', title: 'Reports' },
72
+ ])
73
+ await adapter.router.push('/reports')
74
+ await adapter.router.isReady()
75
+
76
+ // 主页被裁撤后,首个菜单项(目录)的 redirect 仍指向 /dashboard——
77
+ // 可达性校验必须跳过它,否则会再次落回 404。
78
+ setMenus([
79
+ { code: 'system', path: '/system', title: 'System', redirect: '/dashboard' },
80
+ { code: 'audit', path: '/audit', title: 'Audit' },
81
+ ])
82
+ await replaceDynamicMenusWithAccessibleFallback(adapter)
83
+
84
+ expect(adapter.router.currentRoute.value.path).toBe('/audit')
85
+ })
86
+
87
+ it('does not redirect when the session is already on the not-found page', async () => {
88
+ const { adapter, setMenus } = createAdaptersWithMenus([
89
+ { code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
90
+ { code: 'reports', path: '/reports', title: 'Reports' },
91
+ ])
92
+ await adapter.router.push('/reports')
93
+ await adapter.router.isReady()
94
+ await adapter.router.push('/404')
95
+
96
+ setMenus([{ code: 'audit', path: '/audit', title: 'Audit' }])
97
+ await replaceDynamicMenusWithAccessibleFallback(adapter)
98
+
99
+ expect(adapter.router.currentRoute.value.name).toBe('404')
100
+ })
101
+ })
@@ -0,0 +1,24 @@
1
+ import type { RouterAdapter } from '@origen-ui/router'
2
+ import type { RouteLocationRaw } from 'vue-router'
3
+ import type { BackendMenuNode } from '../app/menuTypes'
4
+ import { isUnmatchedRoute } from '@origen-ui/router'
5
+ import { firstMenuTarget, HOME_ROUTE, NOT_FOUND_ROUTE_NAME } from './paths'
6
+
7
+ function isReachableTarget(routing: RouterAdapter<BackendMenuNode>, to: RouteLocationRaw): boolean {
8
+ const resolved = routing.router.resolve(to)
9
+ return resolved.matched.length > 0 && !isUnmatchedRoute(resolved)
10
+ }
11
+
12
+ /**
13
+ * 替换动态菜单并在当前路由失效时回落:优先主页;主页已被裁撤时取
14
+ * 刷新后菜单树的首个真实可达入口,而不是把会话滞留在 404 页。
15
+ */
16
+ export async function replaceDynamicMenusWithAccessibleFallback(
17
+ routing: RouterAdapter<BackendMenuNode>,
18
+ ): Promise<void> {
19
+ const wasOnNotFound = routing.router.currentRoute.value.name === NOT_FOUND_ROUTE_NAME
20
+ await routing.replaceDynamicRoutes(undefined, { fallback: HOME_ROUTE })
21
+ if (wasOnNotFound || routing.router.currentRoute.value.name !== NOT_FOUND_ROUTE_NAME) return
22
+ const fallback = firstMenuTarget(routing.menu.value, (to) => isReachableTarget(routing, to))
23
+ if (fallback) await routing.router.replace(fallback)
24
+ }
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { componentCacheNames } from './componentRegistry'
3
- import { componentRegistry, routeTransformer } from './dynamicRoutes'
2
+ import { componentCacheNames } from './componentCache'
3
+ import { componentRegistry } from './componentRegistry'
4
+ import { routeTransformer } from './dynamicRoutes'
4
5
  import { staticRoutes } from './staticRoutes'
5
6
 
6
7
  describe('dynamic component registry', () => {
@@ -83,6 +84,23 @@ describe('dynamic component registry', () => {
83
84
  children: [{ path: 'users', children: [{ path: 'roles' }] }],
84
85
  })
85
86
  })
87
+
88
+ it('rejects flat parentPath entries whose parent route does not exist', () => {
89
+ expect(() =>
90
+ routeTransformer([
91
+ { code: 'orphan', path: 'orphan', parentPath: '/missing', title: 'Orphan' },
92
+ ]),
93
+ ).toThrow('Unresolved dynamic route parent path: /missing')
94
+ })
95
+
96
+ it('rejects duplicate route codes with an explicit error', () => {
97
+ expect(() =>
98
+ routeTransformer([
99
+ { code: 'dup', path: '/first', title: 'First' },
100
+ { code: 'dup', path: '/second', title: 'Second' },
101
+ ]),
102
+ ).toThrow('Duplicate dynamic route code: dup')
103
+ })
86
104
  })
87
105
 
88
106
  describe('keep-alive cache names', () => {
@@ -1,8 +1,6 @@
1
1
  import type { RouteSourceNode } from '@origen-ui/router'
2
2
  import type { BackendMenuNode } from '../app/menuTypes'
3
- import { componentCacheNames, fallbackComponentKey } from './componentRegistry'
4
-
5
- export { componentRegistry } from './componentRegistry'
3
+ import { componentCacheNames, fallbackComponentKey } from './componentCache'
6
4
 
7
5
  function routeName(source: BackendMenuNode, used: Set<string>): string {
8
6
  const base = `dyn-${source.code.replace(/[^\w-]+/g, '-').replace(/^-|-$/g, '') || 'route'}`
@@ -128,6 +126,8 @@ function buildTree(nodes: readonly BackendMenuNode[]): readonly BackendMenuNode[
128
126
  ])
129
127
  candidates.delete(item)
130
128
  if (candidates.size > 1) throw new Error(`Ambiguous dynamic route parent path: ${parentPath}`)
129
+ if (candidates.size === 0)
130
+ throw new Error(`Unresolved dynamic route parent path: ${parentPath}`)
131
131
  }
132
132
 
133
133
  for (const item of entries) {
@@ -144,7 +144,18 @@ function buildTree(nodes: readonly BackendMenuNode[]): readonly BackendMenuNode[
144
144
  return roots.map(materialize)
145
145
  }
146
146
 
147
+ function assertUniqueCodes(nodes: readonly BackendMenuNode[], seen = new Set<string>()): void {
148
+ for (const node of nodes) {
149
+ if (seen.has(node.code)) throw new Error(`Duplicate dynamic route code: ${node.code}`)
150
+ seen.add(node.code)
151
+ assertUniqueCodes(node.children ?? [], seen)
152
+ }
153
+ }
154
+
147
155
  export function routeTransformer(sources: readonly BackendMenuNode[]): readonly RouteSourceNode[] {
156
+ // buildTree 按 code 去重会静默丢弃后到的重复节点,连同其子树一起消失;
157
+ // 在此显式失败,给出可定位的数据错误。
158
+ assertUniqueCodes(sources)
148
159
  const usedNames = new Set<string>()
149
160
  const tree = buildTree(sources)
150
161
 
@@ -0,0 +1,50 @@
1
+ import type { RouteMenuItem } from '@origen-ui/router'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { firstMenuTarget, HOME_ROUTE, NOT_FOUND_ROUTE_NAME } from './paths'
4
+ import { staticRoutes } from './staticRoutes'
5
+
6
+ describe('router paths', () => {
7
+ it('keeps the root static redirect aligned with HOME_ROUTE', () => {
8
+ const root = staticRoutes.find((route) => route.name === 'root')
9
+ expect(root?.redirect).toBe(HOME_ROUTE)
10
+ })
11
+
12
+ it('pins the not-found fallback to the static 404 route', () => {
13
+ expect(staticRoutes.some((route) => route.name === NOT_FOUND_ROUTE_NAME)).toBe(true)
14
+ })
15
+
16
+ it('resolves the first navigable menu target depth-first', () => {
17
+ const items = [
18
+ { id: 'locked', label: 'Locked', children: [] },
19
+ {
20
+ id: 'section',
21
+ label: 'Section',
22
+ to: { name: 'section' },
23
+ children: [{ id: 'inner', label: 'Inner', to: { name: 'inner' }, children: [] }],
24
+ },
25
+ ] as readonly RouteMenuItem[]
26
+
27
+ expect(firstMenuTarget(items)).toEqual({ name: 'section' })
28
+ })
29
+
30
+ it('returns undefined when no menu item is navigable', () => {
31
+ const items = [{ id: 'empty', label: 'Empty', children: [] }] as readonly RouteMenuItem[]
32
+
33
+ expect(firstMenuTarget(items)).toBeUndefined()
34
+ })
35
+
36
+ it('skips entries rejected by the reachability predicate', () => {
37
+ const items = [
38
+ { id: 'gone', label: 'Gone', to: { path: '/gone' }, children: [] },
39
+ { id: 'live', label: 'Live', to: { name: 'live' }, children: [] },
40
+ ] as readonly RouteMenuItem[]
41
+
42
+ expect(
43
+ firstMenuTarget(items, (to) => {
44
+ const path = typeof to === 'string' ? to : to.path
45
+ return path !== '/gone'
46
+ }),
47
+ ).toEqual({ name: 'live' })
48
+ expect(firstMenuTarget(items, () => false)).toBeUndefined()
49
+ })
50
+ })
@@ -0,0 +1,21 @@
1
+ import type { RouteMenuItem } from '@origen-ui/router'
2
+ import type { RouteLocationRaw } from 'vue-router'
3
+
4
+ /** 授权后的默认首页路由;与 staticRoutes 根路由 redirect 由 paths.spec 钉住一致。 */
5
+ export const HOME_ROUTE = '/dashboard'
6
+
7
+ /** staticRoutes 中 404 兜底页的路由名。 */
8
+ export const NOT_FOUND_ROUTE_NAME = '404'
9
+
10
+ /** 深度优先取菜单树中首个可导航入口;isReachable 用于剔除重定向到已裁撤路由的目录项。 */
11
+ export function firstMenuTarget(
12
+ items: readonly RouteMenuItem[],
13
+ isReachable: (to: RouteLocationRaw) => boolean = () => true,
14
+ ): RouteLocationRaw | undefined {
15
+ for (const item of items) {
16
+ if (item.to && isReachable(item.to)) return item.to
17
+ const child = firstMenuTarget(item.children, isReachable)
18
+ if (child) return child
19
+ }
20
+ return undefined
21
+ }
@@ -46,18 +46,18 @@ export const staticRoutes: RouteRecordRaw[] = [
46
46
  path: '/403',
47
47
  name: '403',
48
48
  component: Forbidden,
49
- meta: { adapter: { titleKey: 'errors.forbidden', ...hiddenPublic } },
49
+ meta: { adapter: { titleKey: 'errors.forbidden.title', ...hiddenPublic } },
50
50
  },
51
51
  {
52
52
  path: '/404',
53
53
  name: '404',
54
54
  component: NotFound,
55
- meta: { adapter: { titleKey: 'errors.notFound', ...hiddenPublic } },
55
+ meta: { adapter: { titleKey: 'errors.notFound.title', ...hiddenPublic } },
56
56
  },
57
57
  {
58
58
  path: '/500',
59
59
  name: '500',
60
60
  component: ServerError,
61
- meta: { adapter: { titleKey: 'errors.server', ...hiddenPublic } },
61
+ meta: { adapter: { titleKey: 'errors.serverError.title', ...hiddenPublic } },
62
62
  },
63
63
  ]
@@ -9,12 +9,10 @@ import type {
9
9
  TableRowKey,
10
10
  } from '@origen-ui/table'
11
11
  import type { AdminMessageKey } from '../locales'
12
- import { getAdminI18n } from '../locales'
12
+ import { translateAdminMessage } from '../locales'
13
13
 
14
14
  function tableText(key: AdminMessageKey): string {
15
- const global = getAdminI18n()?.global as unknown as
16
- { t: (key: AdminMessageKey) => string } | undefined
17
- return global ? global.t(key) : key
15
+ return translateAdminMessage(key)
18
16
  }
19
17
 
20
18
  function withLocalizedLabel<T extends object>(
@@ -9,7 +9,6 @@
9
9
  "DOM",
10
10
  "DOM.Iterable"
11
11
  ],
12
- "baseUrl": ".",
13
12
  "module": "ESNext",
14
13
  "moduleResolution": "Bundler",
15
14
  "paths": {
@@ -7,10 +7,7 @@ const packageBuildDirectories = new Set(['dist', 'es', 'esm', 'lib', 'src'])
7
7
  const MAX_INITIAL_VENDOR_CHUNK_BYTES = 300 * 1024
8
8
  const MAX_ASYNC_VENDOR_CHUNK_BYTES = 400 * 1024
9
9
 
10
- type AdminCodeSplitting = Exclude<
11
- NonNullable<Rolldown.OutputOptions['codeSplitting']>,
12
- boolean
13
- >
10
+ type AdminCodeSplitting = Exclude<NonNullable<Rolldown.OutputOptions['codeSplitting']>, boolean>
14
11
 
15
12
  function chunkName(value: string): string {
16
13
  return value
@@ -20,7 +17,12 @@ function chunkName(value: string): string {
20
17
  .toLowerCase()
21
18
  }
22
19
 
23
- function dependencyPath(normalized: string): { name: string, path: string[] } | undefined {
20
+ interface ModuleLocation {
21
+ name: string
22
+ path: string[]
23
+ }
24
+
25
+ function dependencyPath(normalized: string): ModuleLocation | undefined {
24
26
  const marker = '/node_modules/'
25
27
  const nodeModulesIndex = normalized.lastIndexOf(marker)
26
28
  if (nodeModulesIndex < 0) return undefined
@@ -35,7 +37,7 @@ function dependencyPath(normalized: string): { name: string, path: string[] } |
35
37
  }
36
38
  }
37
39
 
38
- function workspacePackagePath(normalized: string): { name: string, path: string[] } | undefined {
40
+ function workspacePackagePath(normalized: string): ModuleLocation | undefined {
39
41
  const match = normalized.match(/\/packages\/([^/]+)\/(?:dist|src)\/(.+)$/)
40
42
  if (!match) return undefined
41
43
  return { name: `og-${match[1]}`, path: match[2].split('/') }
@@ -62,7 +64,9 @@ function vendorLocation(id: string) {
62
64
 
63
65
  function matchesPackageFamily(id: string, names: readonly string[]): boolean {
64
66
  const name = vendorLocation(id)?.name
65
- return Boolean(name && names.some((candidate) => name === candidate || name.startsWith(`${candidate}/`)))
67
+ return Boolean(
68
+ name && names.some((candidate) => name === candidate || name.startsWith(`${candidate}/`)),
69
+ )
66
70
  }
67
71
 
68
72
  function matchesPackageEntry(id: string, packageName: string, entry: string): boolean {
@@ -70,6 +74,24 @@ function matchesPackageEntry(id: string, packageName: string, entry: string): bo
70
74
  return location?.name === packageName && location.path[0] === entry
71
75
  }
72
76
 
77
+ /**
78
+ * Element Plus table internals are extracted from the table-suite chunk they
79
+ * would otherwise co-locate with. The og-table family chunk itself must stay
80
+ * a single chunk — splitting it creates circular chunk-evaluation edges
81
+ * before Element Plus initializes (see the vendor-table-suite note) — but the
82
+ * Element Plus table code it pulls in is a leaf dependency and splits safely.
83
+ * This separation is what keeps the family chunk under the single-chunk
84
+ * budget instead of carrying the whole Element Plus table surface.
85
+ *
86
+ * `moduleLocation` strips the build directory, so published `es/components/…`
87
+ * paths start at `components`.
88
+ */
89
+ function matchesElementPlusTableModule(id: string, component: 'table' | 'table-v2'): boolean {
90
+ const location = vendorLocation(id)
91
+ if (!location || location.name !== 'element-plus') return false
92
+ return location.path[0] === 'components' && location.path[1] === component
93
+ }
94
+
73
95
  function dynamicPackageGroup(
74
96
  id: string,
75
97
  directory?: 'components' | 'languages' | 'locale',
@@ -77,7 +99,8 @@ function dynamicPackageGroup(
77
99
  const location = vendorLocation(id)
78
100
  if (!location || location.name === 'element-plus') return undefined
79
101
  if (directory && location.path[0] !== directory) return undefined
80
- const suffix = directory === 'components' ? '-components' : directory ? `-${chunkName(directory)}` : ''
102
+ const suffix =
103
+ directory === 'components' ? '-components' : directory ? `-${chunkName(directory)}` : ''
81
104
  return `vendor-${chunkName(location.name)}${suffix}`
82
105
  }
83
106
 
@@ -104,6 +127,14 @@ export function createAdminCodeSplitting(): AdminCodeSplitting {
104
127
  test: (id) => matchesPackageFamily(id, ['@floating-ui', '@sxzz/popperjs-es']),
105
128
  priority: 85,
106
129
  },
130
+ {
131
+ // async-validator is a leaf dependency shared by the form and table
132
+ // surfaces. Keeping it outside the table family avoids making the
133
+ // deliberately single-chunk family carry validation internals.
134
+ name: 'vendor-async-validator',
135
+ test: (id) => matchesPackageFamily(id, ['async-validator']),
136
+ priority: 83,
137
+ },
107
138
  {
108
139
  name: 'vendor-table-suite',
109
140
  test: (id) =>
@@ -122,6 +153,22 @@ export function createAdminCodeSplitting(): AdminCodeSplitting {
122
153
  // circular chunk-evaluation edge before Element Plus initializes.
123
154
  priority: 80,
124
155
  },
156
+ {
157
+ // Leaf dependency of the table-suite family: extracted so the family
158
+ // chunk stays under the single-chunk budget. The priority must sit
159
+ // ABOVE vendor-table-suite — Rolldown lets a higher-priority chunk
160
+ // pull lower-priority-grouped dependencies into itself, which is
161
+ // exactly how the Element Plus table internals ended up inside the
162
+ // family chunk — but still below the positioning/vueuse families.
163
+ name: 'vendor-element-table-v2',
164
+ test: (id) => matchesElementPlusTableModule(id, 'table-v2'),
165
+ priority: 82,
166
+ },
167
+ {
168
+ name: 'vendor-element-table',
169
+ test: (id) => matchesElementPlusTableModule(id, 'table'),
170
+ priority: 81,
171
+ },
125
172
  {
126
173
  name: 'vendor-initial',
127
174
  test: (id) => Boolean(vendorLocation(id)),
@@ -1,3 +1,5 @@
1
+ import { existsSync, readdirSync } from 'node:fs'
2
+ import { dirname, join } from 'node:path'
1
3
  import process from 'node:process'
2
4
  import { fileURLToPath } from 'node:url'
3
5
  import vue from '@vitejs/plugin-vue'
@@ -9,6 +11,17 @@ import { defineConfig } from 'vitest/config'
9
11
  // with the application source as ./vite.build-policy.ts.
10
12
  import { createAdminBuildOptions, createAdminBuildPlugins } from './vite.build-policy.js'
11
13
 
14
+ const elementPlusPackageRoot = dirname(dirname(fileURLToPath(import.meta.resolve('element-plus'))))
15
+ const elementPlusStyleIncludes = readdirSync(join(elementPlusPackageRoot, 'es/components'), {
16
+ withFileTypes: true,
17
+ })
18
+ .filter(
19
+ (entry) =>
20
+ entry.isDirectory() &&
21
+ existsSync(join(elementPlusPackageRoot, 'es/components', entry.name, 'style/index.mjs')),
22
+ )
23
+ .map((entry) => `element-plus/es/components/${entry.name}/style/index`)
24
+
12
25
  export default defineConfig(({ command, mode }) => {
13
26
  const loadedEnv = loadEnv(mode, process.cwd(), '')
14
27
  const apiTarget = loadedEnv.VITE_API_TARGET || 'http://127.0.0.1:8080'
@@ -17,6 +30,23 @@ export default defineConfig(({ command, mode }) => {
17
30
  return {
18
31
  plugins: [vue(), vueJsx(), ...createAdminBuildPlugins(), ElementPlus({ useSource: true })],
19
32
  resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
33
+ optimizeDeps: {
34
+ // Element Plus injects these entries only after lazy SFCs transform.
35
+ // Pre-bundle them up front and keep the dependency set fixed for route loads.
36
+ noDiscovery: true,
37
+ include: [
38
+ '@element-plus/icons-vue',
39
+ '@vueuse/core',
40
+ 'axios',
41
+ 'element-plus',
42
+ 'pinia',
43
+ 'sortablejs',
44
+ 'vue',
45
+ 'vue-i18n',
46
+ 'vue-router',
47
+ ...elementPlusStyleIncludes,
48
+ ],
49
+ },
20
50
  oxc: {
21
51
  jsx: { runtime: 'automatic', importSource: 'vue' },
22
52
  ...(command === 'build' && !isDebugBuild ? { dropConsole: true, dropDebugger: true } : {}),