@origen-ui/admin-cli 1.1.0 → 2.0.2
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.
- package/README.md +41 -9
- package/package.json +26 -2
- package/templates/current/clean/.node-version +1 -0
- package/templates/current/clean/CHANGELOG.md +125 -0
- package/templates/current/clean/README.md +2 -1
- package/templates/current/clean/component-catalog.json +58 -17
- package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/clean/package.json +39 -25
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/pnpm-workspace.yaml +18 -0
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/scripts/demo-api.ts +88 -12
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/remove-examples.mjs +4 -4
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/clean/src/api/generated/http-client.ts +28 -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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/clean/src/app/errorMessage.ts +53 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +39 -0
- package/templates/current/clean/src/app/menu.ts +48 -12
- package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
- package/templates/current/clean/src/demo-api.spec.ts +314 -3
- package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
- package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/clean/src/layouts/TopBar.vue +37 -6
- package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/clean/src/locales/en-US.json +30 -3
- package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/clean/src/locales/index.ts +39 -26
- package/templates/current/clean/src/locales/zh-CN.json +30 -3
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/clean/src/locales/zh-TW.json +30 -3
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +10 -16
- package/templates/current/clean/src/router/componentCache.ts +12 -0
- package/templates/current/clean/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/clean/src/router/paths.spec.ts +50 -0
- package/templates/current/clean/src/router/paths.ts +21 -0
- package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/clean/src/router/routeQuery.ts +4 -1
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/templates/og-table.ts +2 -4
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +55 -8
- package/templates/current/clean/vite.config.ts +30 -0
- package/templates/current/examples/.node-version +1 -0
- package/templates/current/examples/CHANGELOG.md +125 -0
- package/templates/current/examples/README.md +2 -1
- package/templates/current/examples/component-catalog.json +58 -17
- package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/examples/package.json +39 -25
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/pnpm-workspace.yaml +18 -0
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/examples/scripts/demo-api.ts +88 -12
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/remove-examples.mjs +4 -4
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/examples/src/api/generated/http-client.ts +28 -26
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/examples/src/app/errorMessage.ts +53 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +39 -0
- package/templates/current/examples/src/app/menu.ts +48 -12
- package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
- package/templates/current/examples/src/demo-api.spec.ts +314 -3
- package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/examples/src/layouts/TopBar.vue +37 -6
- package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/examples/src/locales/en-US.json +30 -3
- package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/examples/src/locales/index.ts +39 -26
- package/templates/current/examples/src/locales/zh-CN.json +30 -3
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/examples/src/locales/zh-TW.json +30 -3
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/examples/src/main.ts +24 -22
- package/templates/current/examples/src/router/bootstrap.ts +10 -16
- package/templates/current/examples/src/router/componentCache.ts +18 -0
- package/templates/current/examples/src/router/componentRegistry.ts +1 -18
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/examples/src/router/paths.spec.ts +50 -0
- package/templates/current/examples/src/router/paths.ts +21 -0
- package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/examples/src/router/routeQuery.ts +4 -1
- package/templates/current/examples/src/router/staticRoutes.ts +3 -3
- package/templates/current/examples/src/templates/og-table.ts +2 -4
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +55 -8
- package/templates/current/examples/vite.config.ts +30 -0
|
@@ -6,7 +6,11 @@ import type { I18n } from 'vue-i18n'
|
|
|
6
6
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
7
7
|
import type { AdminLocale } from '../app/adminLocale'
|
|
8
8
|
import type { AdminMessages } from './messages-types'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
createOrigenUiLanguageRuntime,
|
|
11
|
+
defineOrigenUiLanguage,
|
|
12
|
+
mergeLocale,
|
|
13
|
+
} from 'origen-ui/language'
|
|
10
14
|
import { watch } from 'vue'
|
|
11
15
|
import { createI18n } from 'vue-i18n'
|
|
12
16
|
import {
|
|
@@ -15,26 +19,14 @@ import {
|
|
|
15
19
|
resolveInitialLocale,
|
|
16
20
|
setAdminLocale,
|
|
17
21
|
} from '../app/adminLocale'
|
|
18
|
-
import {
|
|
19
|
-
enUSLocale,
|
|
20
|
-
validateAdminLocaleMessages,
|
|
21
|
-
zhCNLocale,
|
|
22
|
-
zhTWLocale,
|
|
23
|
-
} from './messages-types'
|
|
22
|
+
import { enUSLocale, validateAdminLocaleMessages, zhCNLocale, zhTWLocale } from './messages-types'
|
|
24
23
|
import zhCN from './zh-CN.json'
|
|
25
|
-
import {
|
|
26
|
-
elementPlus as zhCNElementPlus,
|
|
27
|
-
origenUi as zhCNOrigenUi,
|
|
28
|
-
} from './zh-CN.runtime'
|
|
24
|
+
import { elementPlus as zhCNElementPlus, origenUi as zhCNOrigenUi } from './zh-CN.runtime'
|
|
29
25
|
|
|
30
26
|
export type { AdminLocale } from '../app/adminLocale'
|
|
31
27
|
export { currentAdminLocale, normalizeAdminLocale, SUPPORTED_LOCALES } from '../app/adminLocale'
|
|
32
28
|
|
|
33
|
-
export type AdminLanguageModule = OrigenUiLanguageModule<
|
|
34
|
-
AdminMessages,
|
|
35
|
-
unknown,
|
|
36
|
-
OrigenUiMessages
|
|
37
|
-
>
|
|
29
|
+
export type AdminLanguageModule = OrigenUiLanguageModule<AdminMessages, unknown, OrigenUiMessages>
|
|
38
30
|
|
|
39
31
|
/** Admin 消息树叶子 key 的联合类型(如 'auth.login'),用于动态 key 的编译期标注。 */
|
|
40
32
|
export type AdminMessageKey = PathKeys<AdminMessages>
|
|
@@ -99,26 +91,45 @@ export function getAdminI18n(): I18n | null {
|
|
|
99
91
|
return runtimeI18n
|
|
100
92
|
}
|
|
101
93
|
|
|
94
|
+
/** vue-i18n Composer narrowed to the admin message keys. */
|
|
95
|
+
export interface AdminTranslator {
|
|
96
|
+
t: (key: AdminMessageKey, named?: Record<string, unknown>) => string
|
|
97
|
+
te: (key: AdminMessageKey) => boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function translatorOf(i18n: I18n | null | undefined): AdminTranslator | undefined {
|
|
101
|
+
// The single cast boundary: vue-i18n's Composer is generic over message
|
|
102
|
+
// schemas, while admin callers pass runtime string keys guarded by te().
|
|
103
|
+
return i18n?.global as unknown as AdminTranslator | undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** te-guarded translation: unknown keys and pre-bootstrap calls return `options.fallback ?? key`. */
|
|
107
|
+
export function translateAdminMessage(
|
|
108
|
+
key: string,
|
|
109
|
+
options: { fallback?: string, named?: Record<string, unknown> } = {},
|
|
110
|
+
): string {
|
|
111
|
+
const translator = translatorOf(getAdminI18n())
|
|
112
|
+
if (!translator || !translator.te(key as AdminMessageKey)) return options.fallback ?? key
|
|
113
|
+
return translator.t(key as AdminMessageKey, options.named)
|
|
114
|
+
}
|
|
115
|
+
|
|
102
116
|
export function createAdminTitleResolver(
|
|
103
117
|
i18n: I18n,
|
|
104
118
|
): (route: RouteLocationNormalizedLoaded, meta: AdapterRouteMeta) => string | undefined {
|
|
105
119
|
return (_route, meta) => {
|
|
106
120
|
const key = meta.breadcrumb?.labelKey ?? meta.titleKey
|
|
107
121
|
if (!key) return meta.title
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
if (global.te?.(key)) return global.t(key as AdminMessageKey)
|
|
113
|
-
return meta.breadcrumb?.labelKey ? meta.breadcrumb?.label ?? meta.title : meta.title
|
|
122
|
+
const translator = translatorOf(i18n)
|
|
123
|
+
if (translator?.te(key as AdminMessageKey)) return translator.t(key as AdminMessageKey)
|
|
124
|
+
return meta.breadcrumb?.labelKey ? (meta.breadcrumb?.label ?? meta.title) : meta.title
|
|
114
125
|
}
|
|
115
126
|
}
|
|
116
127
|
|
|
117
128
|
export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
118
129
|
const hostLocale = existing?.global.locale
|
|
119
|
-
const initial =
|
|
120
|
-
typeof hostLocale === 'string' ? hostLocale : hostLocale?.value
|
|
121
|
-
|
|
130
|
+
const initial =
|
|
131
|
+
normalizeAdminLocale(typeof hostLocale === 'string' ? hostLocale : hostLocale?.value) ??
|
|
132
|
+
resolveInitialLocale()
|
|
122
133
|
const i18n =
|
|
123
134
|
existing ??
|
|
124
135
|
createI18n({
|
|
@@ -166,7 +177,9 @@ export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
|
166
177
|
i18n.global.setLocaleMessage(
|
|
167
178
|
module.locale,
|
|
168
179
|
mergeLocale(
|
|
169
|
-
(hostMessages && typeof hostMessages === 'object'
|
|
180
|
+
(hostMessages && typeof hostMessages === 'object'
|
|
181
|
+
? hostMessages
|
|
182
|
+
: {}) as AdminMessages,
|
|
170
183
|
module.messages,
|
|
171
184
|
),
|
|
172
185
|
)
|
|
@@ -138,7 +138,9 @@
|
|
|
138
138
|
},
|
|
139
139
|
"errors": {
|
|
140
140
|
"unknownPageError": "页面发生未知错误",
|
|
141
|
-
"startupFailed": "应用启动失败"
|
|
141
|
+
"startupFailed": "应用启动失败",
|
|
142
|
+
"networkError": "网络异常,请稍后再试",
|
|
143
|
+
"invalidResponse": "服务响应格式无效"
|
|
142
144
|
}
|
|
143
145
|
},
|
|
144
146
|
"workspace": {
|
|
@@ -202,7 +204,8 @@
|
|
|
202
204
|
"permissionItems": "项权限",
|
|
203
205
|
"securityStatus": "安全状态",
|
|
204
206
|
"currentSession": "当前会话",
|
|
205
|
-
"sessionDescription": "本设备通过受保护会话访问管理工作区。"
|
|
207
|
+
"sessionDescription": "本设备通过受保护会话访问管理工作区。",
|
|
208
|
+
"noEmail": "未设置邮箱"
|
|
206
209
|
}
|
|
207
210
|
},
|
|
208
211
|
"errors": {
|
|
@@ -440,15 +443,32 @@
|
|
|
440
443
|
"pathRequired": "请填写菜单路由路径",
|
|
441
444
|
"submenuRelativePath": "子菜单应使用相对路由路径",
|
|
442
445
|
"rootPathSlash": "根菜单路由必须以 / 开头",
|
|
443
|
-
"componentRequired": "请选择已注册的页面能力"
|
|
446
|
+
"componentRequired": "请选择已注册的页面能力",
|
|
447
|
+
"treeCycle": "菜单父子关系存在循环引用",
|
|
448
|
+
"treeOrphanParent": "上级菜单不存在或已被删除",
|
|
449
|
+
"treeDuplicateId": "菜单标识重复",
|
|
450
|
+
"treeDuplicateCode": "菜单编码重复",
|
|
451
|
+
"treeDuplicatePath": "解析后的路由路径重复",
|
|
452
|
+
"treeAmbiguousParent": "上级路由路径存在歧义",
|
|
453
|
+
"treeUnresolvedParent": "上级路由路径无法解析",
|
|
454
|
+
"treePrecheckFailed": "菜单树校验未通过",
|
|
455
|
+
"treeTitleKeyMissing": "菜单标题缺少翻译键",
|
|
456
|
+
"treeDetail": "详情:{detail}",
|
|
457
|
+
"titleKeyRequired": "请输入菜单标题翻译键",
|
|
458
|
+
"versionConflict": "菜单已被他人修改,请刷新列表后重试"
|
|
444
459
|
},
|
|
445
460
|
"form": {
|
|
446
461
|
"kind": "节点类型",
|
|
462
|
+
"redirect": "目录重定向",
|
|
463
|
+
"redirectPlaceholder": "留空则回退到首页路由",
|
|
447
464
|
"parentButton": "所属页面",
|
|
448
465
|
"parentDirectory": "上级目录",
|
|
449
466
|
"rootDirectory": "根目录",
|
|
450
467
|
"title": "菜单名称",
|
|
451
468
|
"titlePlaceholder": "例如:组件覆盖率",
|
|
469
|
+
"titleKey": "标题翻译键",
|
|
470
|
+
"titleKeyPlaceholder": "例如:menus.coverage.title",
|
|
471
|
+
"titleKeyRuleMessage": "使用字母开头的翻译键,可含字母、数字、点或连字符",
|
|
452
472
|
"code": "菜单编码",
|
|
453
473
|
"codePlaceholder": "例如:user-list",
|
|
454
474
|
"codeRuleMessage": "使用 3-48 位小写字母、数字或连字符",
|
|
@@ -472,6 +492,13 @@
|
|
|
472
492
|
"tabHidden": "隐藏标签页"
|
|
473
493
|
}
|
|
474
494
|
},
|
|
495
|
+
"access": {
|
|
496
|
+
"revision": {
|
|
497
|
+
"title": "权限已更新",
|
|
498
|
+
"body": "检测到菜单或权限配置已变更,是否立即刷新?",
|
|
499
|
+
"refreshNow": "立即刷新"
|
|
500
|
+
}
|
|
501
|
+
},
|
|
475
502
|
"audit": {
|
|
476
503
|
"title": "审计日志",
|
|
477
504
|
"occurredAt": "发生时间",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OG_DIALOG_LOCALE_ZH_CN } from '@origen-ui/dialog/locale'
|
|
2
2
|
import { OG_EDITOR_LOCALE_ZH_CN } from '@origen-ui/editor/locale'
|
|
3
|
+
import { OG_FORM_TABLE_LOCALE_ZH_CN } from '@origen-ui/form-table/locale'
|
|
3
4
|
import { OG_FORM_LOCALE_ZH_CN } from '@origen-ui/form/locale'
|
|
4
5
|
import { OG_SEARCH_LOCALE_ZH_CN } from '@origen-ui/search/locale'
|
|
5
6
|
import { OG_TABLE_LOCALE_ZH_CN } from '@origen-ui/table/locale'
|
|
@@ -13,6 +14,7 @@ export const origenUi = {
|
|
|
13
14
|
dialog: OG_DIALOG_LOCALE_ZH_CN,
|
|
14
15
|
editor: OG_EDITOR_LOCALE_ZH_CN,
|
|
15
16
|
form: OG_FORM_LOCALE_ZH_CN,
|
|
17
|
+
formTable: OG_FORM_TABLE_LOCALE_ZH_CN,
|
|
16
18
|
search: OG_SEARCH_LOCALE_ZH_CN,
|
|
17
19
|
table: OG_TABLE_LOCALE_ZH_CN,
|
|
18
20
|
tabs: OG_TABS_LOCALE_ZH_CN,
|
|
@@ -138,7 +138,9 @@
|
|
|
138
138
|
},
|
|
139
139
|
"errors": {
|
|
140
140
|
"unknownPageError": "頁面發生未知錯誤",
|
|
141
|
-
"startupFailed": "應用程式啟動失敗"
|
|
141
|
+
"startupFailed": "應用程式啟動失敗",
|
|
142
|
+
"networkError": "網路異常,請稍後再試",
|
|
143
|
+
"invalidResponse": "服務回應格式無效"
|
|
142
144
|
}
|
|
143
145
|
},
|
|
144
146
|
"workspace": {
|
|
@@ -202,7 +204,8 @@
|
|
|
202
204
|
"permissionItems": "項權限",
|
|
203
205
|
"securityStatus": "安全狀態",
|
|
204
206
|
"currentSession": "目前工作階段",
|
|
205
|
-
"sessionDescription": "本裝置透過受保護的工作階段訪問管理工作區。"
|
|
207
|
+
"sessionDescription": "本裝置透過受保護的工作階段訪問管理工作區。",
|
|
208
|
+
"noEmail": "未設定電子郵件"
|
|
206
209
|
}
|
|
207
210
|
},
|
|
208
211
|
"errors": {
|
|
@@ -440,15 +443,32 @@
|
|
|
440
443
|
"pathRequired": "請填寫選單路由路徑",
|
|
441
444
|
"submenuRelativePath": "子選單應使用相對路由路徑",
|
|
442
445
|
"rootPathSlash": "根選單路由必須以 / 開頭",
|
|
443
|
-
"componentRequired": "請選擇已註冊的頁面能力"
|
|
446
|
+
"componentRequired": "請選擇已註冊的頁面能力",
|
|
447
|
+
"treeCycle": "選單父子關係存在循環參照",
|
|
448
|
+
"treeOrphanParent": "上層選單不存在或已被刪除",
|
|
449
|
+
"treeDuplicateId": "選單識別碼重複",
|
|
450
|
+
"treeDuplicateCode": "選單編碼重複",
|
|
451
|
+
"treeDuplicatePath": "解析後的路由路徑重複",
|
|
452
|
+
"treeAmbiguousParent": "上層路由路徑存在歧義",
|
|
453
|
+
"treeUnresolvedParent": "上層路由路徑無法解析",
|
|
454
|
+
"treePrecheckFailed": "選單樹校驗未通過",
|
|
455
|
+
"treeTitleKeyMissing": "選單標題缺少翻譯鍵",
|
|
456
|
+
"treeDetail": "詳情:{detail}",
|
|
457
|
+
"titleKeyRequired": "請輸入選單標題翻譯鍵",
|
|
458
|
+
"versionConflict": "選單已被他人修改,請重新整理後再試"
|
|
444
459
|
},
|
|
445
460
|
"form": {
|
|
446
461
|
"kind": "節點類型",
|
|
462
|
+
"redirect": "目錄重定向",
|
|
463
|
+
"redirectPlaceholder": "留空則回退到首頁路由",
|
|
447
464
|
"parentButton": "所屬頁面",
|
|
448
465
|
"parentDirectory": "上級目錄",
|
|
449
466
|
"rootDirectory": "根目錄",
|
|
450
467
|
"title": "選單名稱",
|
|
451
468
|
"titlePlaceholder": "例如:元件覆蓋率",
|
|
469
|
+
"titleKey": "標題翻譯鍵",
|
|
470
|
+
"titleKeyPlaceholder": "例如:menus.coverage.title",
|
|
471
|
+
"titleKeyRuleMessage": "使用字母開頭的翻譯鍵,可含字母、數字、點或連字號",
|
|
452
472
|
"code": "選單編碼",
|
|
453
473
|
"codePlaceholder": "例如:user-list",
|
|
454
474
|
"codeRuleMessage": "使用 3-48 位小寫字母、數字或連字號",
|
|
@@ -472,6 +492,13 @@
|
|
|
472
492
|
"tabHidden": "隱藏分頁"
|
|
473
493
|
}
|
|
474
494
|
},
|
|
495
|
+
"access": {
|
|
496
|
+
"revision": {
|
|
497
|
+
"title": "權限已更新",
|
|
498
|
+
"body": "檢測到選單或權限配置已變更,是否立即重新整理?",
|
|
499
|
+
"refreshNow": "立即重新整理"
|
|
500
|
+
}
|
|
501
|
+
},
|
|
475
502
|
"audit": {
|
|
476
503
|
"title": "稽核日誌",
|
|
477
504
|
"occurredAt": "發生時間",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OG_DIALOG_LOCALE_ZH_TW } from '@origen-ui/dialog/locale'
|
|
2
2
|
import { OG_EDITOR_LOCALE_ZH_TW } from '@origen-ui/editor/locale'
|
|
3
|
+
import { OG_FORM_TABLE_LOCALE_ZH_TW } from '@origen-ui/form-table/locale'
|
|
3
4
|
import { OG_FORM_LOCALE_ZH_TW } from '@origen-ui/form/locale'
|
|
4
5
|
import { OG_SEARCH_LOCALE_ZH_TW } from '@origen-ui/search/locale'
|
|
5
6
|
import { OG_TABLE_LOCALE_ZH_TW } from '@origen-ui/table/locale'
|
|
@@ -13,6 +14,7 @@ export const origenUi = {
|
|
|
13
14
|
dialog: OG_DIALOG_LOCALE_ZH_TW,
|
|
14
15
|
editor: OG_EDITOR_LOCALE_ZH_TW,
|
|
15
16
|
form: OG_FORM_LOCALE_ZH_TW,
|
|
17
|
+
formTable: OG_FORM_TABLE_LOCALE_ZH_TW,
|
|
16
18
|
search: OG_SEARCH_LOCALE_ZH_TW,
|
|
17
19
|
table: OG_TABLE_LOCALE_ZH_TW,
|
|
18
20
|
tabs: OG_TABS_LOCALE_ZH_TW,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createApp } from 'vue'
|
|
2
2
|
import App from './App.vue'
|
|
3
|
+
import { translateAdminError } from './app/errorMessage'
|
|
3
4
|
import { permission } from './app/permission'
|
|
4
5
|
import { useAuthStore } from './features/auth/store/auth'
|
|
5
6
|
import { devtoolsProtection } from './features/security/devtoolsProtection'
|
|
7
|
+
import { translateAdminMessage } from './locales'
|
|
8
|
+
import { replaceDynamicMenusWithAccessibleFallback } from './router/dynamicMenuRefresh'
|
|
6
9
|
import { createRuntimeErrorRecovery, createStaleAssetRecovery } from './router/runtimeErrorRecovery'
|
|
7
10
|
import { pinia } from './store'
|
|
8
11
|
import 'element-plus/theme-chalk/src/tabs.scss'
|
|
@@ -46,43 +49,49 @@ async function bootstrap(): Promise<void> {
|
|
|
46
49
|
language.install(app)
|
|
47
50
|
const { createAdminUi } = await import('./app/createAdminUi')
|
|
48
51
|
app.use(createAdminUi(language))
|
|
52
|
+
// 唯一的 errorHandler 装配点:运行期错误统一走提示 + 陈旧资源/运行时恢复。
|
|
49
53
|
app.config.errorHandler = (error: unknown) => {
|
|
50
|
-
|
|
54
|
+
console.error('[admin] runtime error', error)
|
|
55
|
+
const message = translateAdminError(error, {
|
|
56
|
+
fallbackKey: 'common.errors.unknownPageError',
|
|
57
|
+
fallback: '页面发生未知错误',
|
|
58
|
+
})
|
|
51
59
|
void notifyRuntimeError(message)
|
|
60
|
+
if (!staleAssetRecovery.handle(error)) recoverRuntimeError()
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
const auth = useAuthStore(pinia)
|
|
55
64
|
const session = await auth.fetchSession()
|
|
56
65
|
app.use(routing)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
])
|
|
62
|
-
|
|
66
|
+
// 路由就绪是硬性等待;布局仅在登录态下并行预热。catch-tap 保证路由先失败
|
|
67
|
+
// 时预热 rejection 不会变成 unhandled——两个失败最终都按启动失败上报。
|
|
68
|
+
const layoutPreload = session ? import('./layouts/AdminLayout.vue') : undefined
|
|
69
|
+
layoutPreload?.catch(() => {})
|
|
70
|
+
await Promise.all([language.ready, routing.ready()])
|
|
71
|
+
await layoutPreload
|
|
63
72
|
const { authorizationRefreshKey } =
|
|
64
73
|
await import('./features/system/access/composables/useAuthorizationRefresh')
|
|
65
|
-
app.config.errorHandler = (error, instance, info) => {
|
|
66
|
-
reportRuntimeError?.(error, instance, info)
|
|
67
|
-
if (!staleAssetRecovery.handle(error)) recoverRuntimeError()
|
|
68
|
-
}
|
|
69
74
|
app.provide(authorizationRefreshKey, async () => {
|
|
70
75
|
await auth.refreshAuthorization()
|
|
71
|
-
await routing
|
|
76
|
+
await replaceDynamicMenusWithAccessibleFallback(routing)
|
|
72
77
|
})
|
|
73
78
|
app.mount('#app')
|
|
74
79
|
staleAssetRecovery.clear()
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
void bootstrap().catch((error: unknown) => {
|
|
78
|
-
|
|
83
|
+
console.error('[admin] startup failed', error)
|
|
84
|
+
const message = translateAdminError(error, {
|
|
85
|
+
fallbackKey: 'common.errors.startupFailed',
|
|
86
|
+
fallback: '应用启动失败',
|
|
87
|
+
})
|
|
79
88
|
const root = document.querySelector('#app')
|
|
80
89
|
if (root) {
|
|
81
90
|
const panel = document.createElement('main')
|
|
82
91
|
panel.style.padding = '32px'
|
|
83
92
|
panel.style.fontFamily = 'system-ui, sans-serif'
|
|
84
93
|
const heading = document.createElement('h1')
|
|
85
|
-
heading.textContent = '@origen-ui/admin 启动失败'
|
|
94
|
+
heading.textContent = `${'@origen-ui/admin'} ${translateAdminMessage('common.errors.startupFailed', { fallback: '启动失败' })}`
|
|
86
95
|
const detail = document.createElement('p')
|
|
87
96
|
detail.textContent = message
|
|
88
97
|
panel.append(heading, detail)
|
|
@@ -2,13 +2,15 @@ import type { RouterAdapter } from '@origen-ui/router'
|
|
|
2
2
|
import type { BackendMenuNode } from '../app/menuTypes'
|
|
3
3
|
import { createAccessPolicy, createRouterAdapter, createWebStorageAdapter } from '@origen-ui/router'
|
|
4
4
|
import { createWebHistory } from 'vue-router'
|
|
5
|
-
import { embeddedMode,
|
|
6
|
-
import {
|
|
5
|
+
import { embeddedMode, reportMenusToHost } from '../app/embedded'
|
|
6
|
+
import { loadMenusFromHost } from '../app/menu'
|
|
7
7
|
import { appRuntimeConfig } from '../app/runtimeConfig'
|
|
8
8
|
import { useAuthStore } from '../features/auth/store/auth'
|
|
9
9
|
import { pinia } from '../store'
|
|
10
10
|
import { hasPermission } from '../utils/permissions'
|
|
11
|
-
import { componentRegistry
|
|
11
|
+
import { componentRegistry } from './componentRegistry'
|
|
12
|
+
import { routeTransformer } from './dynamicRoutes'
|
|
13
|
+
import { NOT_FOUND_ROUTE_NAME } from './paths'
|
|
12
14
|
import { staticRoutes } from './staticRoutes'
|
|
13
15
|
|
|
14
16
|
type QueryCodecs = Pick<
|
|
@@ -23,16 +25,6 @@ type TitleOptions = Pick<
|
|
|
23
25
|
|
|
24
26
|
let routing: RouterAdapter<BackendMenuNode> | undefined
|
|
25
27
|
|
|
26
|
-
// 嵌入模式:动态菜单优先取主壳聚合下发(data 通道 backendMenus 字段,契约随
|
|
27
|
-
// M3/D-2 定稿);主壳未下发时回落到子应用经主壳网关拉取自身菜单,独立模式不受影响。
|
|
28
|
-
function loadMenusFromHost(): Promise<BackendMenuNode[]> {
|
|
29
|
-
const menus = readHostInjection().backendMenus
|
|
30
|
-
if (Array.isArray(menus) && menus.length > 0) {
|
|
31
|
-
return Promise.resolve(menus as BackendMenuNode[])
|
|
32
|
-
}
|
|
33
|
-
return fetchMenus().then((menus) => [...menus])
|
|
34
|
-
}
|
|
35
|
-
|
|
36
28
|
export function getRouting(): RouterAdapter<BackendMenuNode> {
|
|
37
29
|
if (!routing) {
|
|
38
30
|
throw new Error('Routing has not been initialized yet')
|
|
@@ -55,7 +47,7 @@ export function initializeRouting(
|
|
|
55
47
|
syncDocumentTitle: !embeddedMode,
|
|
56
48
|
access: createAccessPolicy({
|
|
57
49
|
getSession: () => useAuthStore(pinia).session,
|
|
58
|
-
canAccess: (
|
|
50
|
+
canAccess: (_to, session, meta) => hasPermission(session, meta.permissions ?? []),
|
|
59
51
|
loginRoute: { name: 'login' },
|
|
60
52
|
forbiddenRoute: { name: '403' },
|
|
61
53
|
}),
|
|
@@ -63,7 +55,9 @@ export function initializeRouting(
|
|
|
63
55
|
// 嵌入模式:菜单装载完成后向主壳上报(sub-app-menu);独立模式不触发。
|
|
64
56
|
// 上报在 embedded.ts 内 try/catch 兜底,装载主流程不受影响。
|
|
65
57
|
load: async () => {
|
|
66
|
-
|
|
58
|
+
// 嵌入模式:菜单装载完成后向主壳上报(sub-app-menu);独立模式不触发。
|
|
59
|
+
// loadMenusFromHost 内部处理主壳未下发时的 fetchMenus 回落。
|
|
60
|
+
const menus = await loadMenusFromHost()
|
|
67
61
|
if (embeddedMode) reportMenusToHost(menus)
|
|
68
62
|
return menus
|
|
69
63
|
},
|
|
@@ -71,7 +65,7 @@ export function initializeRouting(
|
|
|
71
65
|
resolveComponent: (key) => componentRegistry.get(key),
|
|
72
66
|
},
|
|
73
67
|
fallbacks: {
|
|
74
|
-
notFound: { name:
|
|
68
|
+
notFound: { name: NOT_FOUND_ROUTE_NAME },
|
|
75
69
|
error: { name: '500' },
|
|
76
70
|
},
|
|
77
71
|
workspace: {
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
workspace: 'EmptyPage',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const fallbackComponentKey = 'workspace'
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import type { Component } from 'vue'
|
|
2
2
|
import { RouterViewHost } from '@origen-ui/router'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
|
|
8
|
-
*
|
|
9
|
-
* KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
|
|
10
|
-
* 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
|
|
11
|
-
* 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
|
|
12
|
-
*/
|
|
13
|
-
export const componentCacheNames: Readonly<Record<string, string>> = {
|
|
14
|
-
workspace: 'EmptyPage',
|
|
15
|
-
}
|
|
4
|
+
export { componentCacheNames, fallbackComponentKey } from './componentCache'
|
|
16
5
|
|
|
17
|
-
|
|
6
|
+
type ComponentLoader = () => Promise<Component>
|
|
18
7
|
|
|
19
8
|
export const componentRegistry: Map<string, ComponentLoader> = new Map([
|
|
20
9
|
[
|
|
@@ -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 './
|
|
3
|
-
import { componentRegistry
|
|
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('clean dynamic component registry', () => {
|
|
@@ -16,6 +17,23 @@ describe('clean dynamic component registry', () => {
|
|
|
16
17
|
expect(route?.componentKey).toBe('workspace')
|
|
17
18
|
expect(componentRegistry.has('workspace')).toBe(true)
|
|
18
19
|
})
|
|
20
|
+
|
|
21
|
+
it('rejects flat parentPath entries whose parent route does not exist', () => {
|
|
22
|
+
expect(() =>
|
|
23
|
+
routeTransformer([
|
|
24
|
+
{ code: 'orphan', path: 'orphan', parentPath: '/missing', title: 'Orphan' },
|
|
25
|
+
]),
|
|
26
|
+
).toThrow('Unresolved dynamic route parent path: /missing')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('rejects duplicate route codes with an explicit error', () => {
|
|
30
|
+
expect(() =>
|
|
31
|
+
routeTransformer([
|
|
32
|
+
{ code: 'dup', path: '/first', title: 'First' },
|
|
33
|
+
{ code: 'dup', path: '/second', title: 'Second' },
|
|
34
|
+
]),
|
|
35
|
+
).toThrow('Duplicate dynamic route code: dup')
|
|
36
|
+
})
|
|
19
37
|
})
|
|
20
38
|
|
|
21
39
|
describe('clean keep-alive cache names', () => {
|
|
@@ -25,7 +43,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
25
43
|
|
|
26
44
|
it('generates cache.name from the component name mapping for cached dynamic routes', () => {
|
|
27
45
|
const [workspace] = routeTransformer([
|
|
28
|
-
{
|
|
46
|
+
{
|
|
47
|
+
code: 'workspace',
|
|
48
|
+
path: '/workspace',
|
|
49
|
+
title: 'Workspace',
|
|
50
|
+
componentKey: 'workspace',
|
|
51
|
+
cache: true,
|
|
52
|
+
},
|
|
29
53
|
])
|
|
30
54
|
|
|
31
55
|
expect(workspace?.meta?.cache).toEqual({ enabled: true, name: 'EmptyPage' })
|
|
@@ -33,7 +57,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
33
57
|
|
|
34
58
|
it('omits cache meta when the source disables caching', () => {
|
|
35
59
|
const [workspace] = routeTransformer([
|
|
36
|
-
{
|
|
60
|
+
{
|
|
61
|
+
code: 'workspace',
|
|
62
|
+
path: '/workspace',
|
|
63
|
+
title: 'Workspace',
|
|
64
|
+
componentKey: 'workspace',
|
|
65
|
+
cache: false,
|
|
66
|
+
},
|
|
37
67
|
])
|
|
38
68
|
|
|
39
69
|
expect(workspace?.meta?.cache).toBeUndefined()
|