@origen-ui/admin-cli 1.0.3 → 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.
- package/README.md +11 -7
- package/package.json +19 -3
- package/templates/current/clean/CHANGELOG.md +137 -0
- 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 +90 -46
- package/templates/current/clean/package.json +55 -41
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/scaffold.lock.json +2 -2
- 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 +84 -8
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +72 -0
- package/templates/current/clean/src/App.vue +10 -3
- package/templates/current/clean/src/api/client.ts +90 -10
- package/templates/current/clean/src/api/generated/data-contracts.ts +0 -3
- 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 +6 -9
- 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 +7 -10
- 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 +6 -9
- 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 +6 -9
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/adminLocale.ts +90 -0
- package/templates/current/clean/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/clean/src/app/createAdminUi.ts +14 -29
- package/templates/current/clean/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/clean/src/app/embedded.spec.ts +135 -0
- package/templates/current/clean/src/app/embedded.ts +255 -0
- 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/localeFormat.ts +52 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +65 -0
- package/templates/current/clean/src/app/menu.ts +52 -12
- package/templates/current/clean/src/app/menuTypes.ts +1 -0
- package/templates/current/clean/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/clean/src/app/origenUiLocale.ts +3 -58
- package/templates/current/clean/src/app/permission.spec.ts +26 -0
- package/templates/current/clean/src/app/runtimeConfig.ts +9 -8
- package/templates/current/clean/src/demo-api.spec.ts +311 -0
- package/templates/current/clean/src/env.d.ts +18 -0
- package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/clean/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/clean/src/features/auth/pages/Login.vue +22 -12
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -9
- 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/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/clean/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +34 -15
- package/templates/current/clean/src/features/system/access/api/rbac.ts +52 -32
- 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/Empty.vue +4 -1
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +14 -12
- package/templates/current/clean/src/layouts/AdminLayout.vue +6 -1
- package/templates/current/clean/src/layouts/TopBar.vue +60 -11
- 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 +517 -0
- package/templates/current/clean/src/locales/en-US.runtime.ts +22 -0
- package/templates/current/clean/src/locales/index.ts +144 -47
- package/templates/current/clean/src/locales/messages-types.ts +62 -0
- package/templates/current/clean/src/locales/messages.spec.ts +113 -6
- package/templates/current/clean/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/clean/src/locales/zh-CN.json +517 -0
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +22 -0
- package/templates/current/clean/src/locales/zh-TW.json +517 -0
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +22 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +20 -11
- 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 +19 -4
- 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 +30 -4
- package/templates/current/clean/src/router/queryEncryption.ts +48 -44
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/clean/src/templates/og-table.ts +79 -37
- package/templates/current/clean/src/templates/templates.spec.ts +19 -0
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +161 -289
- package/templates/current/clean/vite.config.ts +34 -5
- package/templates/current/examples/CHANGELOG.md +137 -0
- 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 +90 -46
- package/templates/current/examples/package.json +55 -41
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/scaffold.lock.json +2 -2
- 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 +84 -8
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +72 -0
- package/templates/current/examples/src/App.vue +10 -3
- package/templates/current/examples/src/api/client.ts +90 -10
- package/templates/current/examples/src/api/generated/data-contracts.ts +0 -3
- 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 +6 -9
- 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 +7 -10
- 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 +6 -9
- 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 +6 -9
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/adminLocale.ts +90 -0
- package/templates/current/examples/src/app/createAdminUi.spec.ts +65 -9
- package/templates/current/examples/src/app/createAdminUi.ts +14 -29
- package/templates/current/examples/src/app/embedded-token.spec.ts +40 -0
- package/templates/current/examples/src/app/embedded.spec.ts +135 -0
- package/templates/current/examples/src/app/embedded.ts +255 -0
- 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/localeFormat.ts +52 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +65 -0
- package/templates/current/examples/src/app/menu.ts +52 -12
- package/templates/current/examples/src/app/menuTypes.ts +1 -0
- package/templates/current/examples/src/app/origenUiLocale.spec.ts +6 -5
- package/templates/current/examples/src/app/origenUiLocale.ts +3 -58
- package/templates/current/examples/src/app/permission.spec.ts +26 -0
- package/templates/current/examples/src/app/runtimeConfig.ts +9 -8
- package/templates/current/examples/src/demo-api.spec.ts +311 -0
- package/templates/current/examples/src/env.d.ts +18 -0
- package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +21 -17
- package/templates/current/examples/src/features/appearance/store/theme.ts +2 -1
- package/templates/current/examples/src/features/auth/pages/Login.vue +22 -12
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -9
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +9 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +47 -10
- package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
- package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +7 -10
- package/templates/current/examples/src/features/security/devtoolsProtection.ts +2 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +14 -0
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +34 -15
- package/templates/current/examples/src/features/system/access/api/rbac.ts +52 -32
- 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/audit/composables/useAuditManagement.ts +43 -38
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +137 -47
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +215 -107
- 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/menus/pages/MenuList.vue +3 -1
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +19 -15
- package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +49 -53
- package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +3 -1
- package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +22 -19
- package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +59 -64
- package/templates/current/examples/src/features/system/users/pages/UserList.vue +3 -1
- package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +9 -0
- package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +54 -26
- package/templates/current/examples/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +14 -12
- package/templates/current/examples/src/layouts/AdminLayout.vue +6 -1
- package/templates/current/examples/src/layouts/TopBar.vue +60 -11
- 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 +517 -0
- package/templates/current/examples/src/locales/en-US.runtime.ts +22 -0
- package/templates/current/examples/src/locales/index.ts +144 -47
- package/templates/current/examples/src/locales/messages-types.ts +62 -0
- package/templates/current/examples/src/locales/messages.spec.ts +113 -6
- package/templates/current/examples/src/locales/vue-i18n.d.ts +5 -0
- package/templates/current/examples/src/locales/zh-CN.json +517 -0
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +22 -0
- package/templates/current/examples/src/locales/zh-TW.json +517 -0
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +22 -0
- package/templates/current/examples/src/main.ts +43 -15
- package/templates/current/examples/src/router/bootstrap.ts +20 -11
- 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 +37 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +19 -4
- 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 +30 -4
- package/templates/current/examples/src/router/queryEncryption.ts +48 -44
- package/templates/current/examples/src/router/staticRoutes.ts +4 -4
- package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +2 -1
- package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +2 -1
- package/templates/current/examples/src/templates/og-table.ts +79 -37
- package/templates/current/examples/src/templates/templates.spec.ts +19 -0
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +161 -289
- package/templates/current/examples/vite.config.ts +34 -5
- package/templates/current/clean/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/clean/src/locales/en-US.ts +0 -55
- package/templates/current/clean/src/locales/zh-CN.ts +0 -55
- package/templates/current/clean/src/locales/zh-TW.ts +0 -44
- package/templates/current/examples/scripts/check-admin-bundle.mjs +0 -214
- package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
- package/templates/current/examples/src/locales/en-US.ts +0 -55
- package/templates/current/examples/src/locales/zh-CN.ts +0 -55
- package/templates/current/examples/src/locales/zh-TW.ts +0 -44
|
@@ -4,90 +4,186 @@ import type { OrigenUiLanguageModule, OrigenUiLanguageRuntime } from 'origen-ui/
|
|
|
4
4
|
import type { App } from 'vue'
|
|
5
5
|
import type { I18n } from 'vue-i18n'
|
|
6
6
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
7
|
-
import {
|
|
7
|
+
import type { AdminLocale } from '../app/adminLocale'
|
|
8
|
+
import type { AdminMessages } from './messages-types'
|
|
9
|
+
import {
|
|
10
|
+
createOrigenUiLanguageRuntime,
|
|
11
|
+
defineOrigenUiLanguage,
|
|
12
|
+
mergeLocale,
|
|
13
|
+
} from 'origen-ui/language'
|
|
8
14
|
import { watch } from 'vue'
|
|
9
15
|
import { createI18n } from 'vue-i18n'
|
|
10
|
-
import {
|
|
11
|
-
|
|
16
|
+
import {
|
|
17
|
+
LOCALE_STORAGE_KEY,
|
|
18
|
+
normalizeAdminLocale,
|
|
19
|
+
resolveInitialLocale,
|
|
20
|
+
setAdminLocale,
|
|
21
|
+
} from '../app/adminLocale'
|
|
22
|
+
import { enUSLocale, validateAdminLocaleMessages, zhCNLocale, zhTWLocale } from './messages-types'
|
|
23
|
+
import zhCN from './zh-CN.json'
|
|
24
|
+
import { elementPlus as zhCNElementPlus, origenUi as zhCNOrigenUi } from './zh-CN.runtime'
|
|
12
25
|
|
|
13
|
-
export type AdminLocale
|
|
14
|
-
export
|
|
15
|
-
|
|
26
|
+
export type { AdminLocale } from '../app/adminLocale'
|
|
27
|
+
export { currentAdminLocale, normalizeAdminLocale, SUPPORTED_LOCALES } from '../app/adminLocale'
|
|
28
|
+
|
|
29
|
+
export type AdminLanguageModule = OrigenUiLanguageModule<AdminMessages, unknown, OrigenUiMessages>
|
|
30
|
+
|
|
31
|
+
/** Admin 消息树叶子 key 的联合类型(如 'auth.login'),用于动态 key 的编译期标注。 */
|
|
32
|
+
export type AdminMessageKey = PathKeys<AdminMessages>
|
|
33
|
+
|
|
34
|
+
type PathKeys<T, P extends string = ''> = T extends string
|
|
35
|
+
? P
|
|
36
|
+
: T extends readonly unknown[]
|
|
37
|
+
? never
|
|
38
|
+
: T extends object
|
|
39
|
+
? {
|
|
40
|
+
[K in keyof T & string]: PathKeys<T[K], P extends '' ? K : `${P}.${K}`>
|
|
41
|
+
}[keyof T & string]
|
|
42
|
+
: never
|
|
43
|
+
|
|
44
|
+
const zhCNModule: AdminLanguageModule = defineOrigenUiLanguage<
|
|
45
|
+
AdminMessages,
|
|
16
46
|
unknown,
|
|
17
47
|
OrigenUiMessages
|
|
18
|
-
>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
>({
|
|
49
|
+
locale: zhCNLocale,
|
|
50
|
+
messages: zhCN,
|
|
51
|
+
elementPlus: zhCNElementPlus,
|
|
52
|
+
origenUi: zhCNOrigenUi,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const loaders: Record<'en-US' | 'zh-TW', () => Promise<AdminLanguageModule>> = {
|
|
56
|
+
'en-US': async () => {
|
|
57
|
+
const [{ default: messages }, { elementPlus, origenUi }] = await Promise.all([
|
|
58
|
+
import('./en-US.json'),
|
|
59
|
+
import('./en-US.runtime'),
|
|
60
|
+
])
|
|
61
|
+
return defineOrigenUiLanguage<AdminMessages, unknown, OrigenUiMessages>({
|
|
62
|
+
locale: enUSLocale,
|
|
63
|
+
messages,
|
|
64
|
+
elementPlus,
|
|
65
|
+
origenUi,
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
'zh-TW': async () => {
|
|
69
|
+
const [{ default: messages }, { elementPlus, origenUi }] = await Promise.all([
|
|
70
|
+
import('./zh-TW.json'),
|
|
71
|
+
import('./zh-TW.runtime'),
|
|
72
|
+
])
|
|
73
|
+
return defineOrigenUiLanguage<AdminMessages, unknown, OrigenUiMessages>({
|
|
74
|
+
locale: zhTWLocale,
|
|
75
|
+
messages,
|
|
76
|
+
elementPlus,
|
|
77
|
+
origenUi,
|
|
78
|
+
})
|
|
79
|
+
},
|
|
30
80
|
}
|
|
31
81
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return normalizeAdminLocale(localStorage.getItem(LOCALE_STORAGE_KEY))
|
|
36
|
-
} catch {
|
|
37
|
-
return undefined
|
|
38
|
-
}
|
|
82
|
+
export interface AdminI18nRuntime {
|
|
83
|
+
i18n: I18n
|
|
84
|
+
language: OrigenUiLanguageRuntime<AdminMessages, unknown, OrigenUiMessages>
|
|
39
85
|
}
|
|
40
86
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
normalizeAdminLocale(appRuntimeConfig.locale.default) ??
|
|
47
|
-
'zh-CN'
|
|
48
|
-
)
|
|
87
|
+
let runtimeI18n: I18n | null = null
|
|
88
|
+
|
|
89
|
+
/** Returns the active admin i18n instance, or null before bootstrap completes. */
|
|
90
|
+
export function getAdminI18n(): I18n | null {
|
|
91
|
+
return runtimeI18n
|
|
49
92
|
}
|
|
50
93
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
54
98
|
}
|
|
55
99
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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)
|
|
59
114
|
}
|
|
60
115
|
|
|
61
116
|
export function createAdminTitleResolver(
|
|
62
117
|
i18n: I18n,
|
|
63
118
|
): (route: RouteLocationNormalizedLoaded, meta: AdapterRouteMeta) => string | undefined {
|
|
64
119
|
return (_route, meta) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
120
|
+
const key = meta.breadcrumb?.labelKey ?? meta.titleKey
|
|
121
|
+
if (!key) return 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
|
|
68
125
|
}
|
|
69
126
|
}
|
|
70
127
|
|
|
71
128
|
export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
72
|
-
const
|
|
129
|
+
const hostLocale = existing?.global.locale
|
|
130
|
+
const initial =
|
|
131
|
+
normalizeAdminLocale(typeof hostLocale === 'string' ? hostLocale : hostLocale?.value) ??
|
|
132
|
+
resolveInitialLocale()
|
|
73
133
|
const i18n =
|
|
74
134
|
existing ??
|
|
75
135
|
createI18n({
|
|
76
136
|
legacy: false,
|
|
77
137
|
locale: initial,
|
|
78
138
|
fallbackLocale: 'zh-CN',
|
|
79
|
-
messages: { 'zh-CN': zhCN
|
|
139
|
+
messages: { 'zh-CN': zhCN },
|
|
80
140
|
})
|
|
81
141
|
|
|
82
|
-
|
|
142
|
+
// Reject legacy instances early — useI18n() fails at runtime in legacy mode
|
|
143
|
+
// and deep-merge of host messages relies on the Composition API.
|
|
144
|
+
if (i18n.mode !== 'composition') {
|
|
145
|
+
throw new Error(
|
|
146
|
+
'[origen-ui/admin] createAdminI18n expects a Composition-mode vue-i18n instance; found legacy mode.',
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
runtimeI18n = i18n
|
|
150
|
+
|
|
151
|
+
const language = createOrigenUiLanguageRuntime<AdminMessages, unknown, OrigenUiMessages>({
|
|
83
152
|
initial,
|
|
84
153
|
loaders: {
|
|
85
|
-
'zh-CN': () =>
|
|
154
|
+
'zh-CN': () => zhCNModule,
|
|
86
155
|
...loaders,
|
|
87
156
|
},
|
|
88
157
|
bridge: {
|
|
89
158
|
prepare: (module) => {
|
|
90
|
-
if (module.messages)
|
|
159
|
+
if (module.messages) {
|
|
160
|
+
const validation = validateAdminLocaleMessages(zhCN, module.messages)
|
|
161
|
+
if (
|
|
162
|
+
validation.missing.length ||
|
|
163
|
+
validation.extra.length ||
|
|
164
|
+
validation.invalid.length ||
|
|
165
|
+
validation.empty.length ||
|
|
166
|
+
validation.interpolation.length
|
|
167
|
+
) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`[origen-ui/admin] Invalid ${module.locale} messages: ${JSON.stringify(validation)}`,
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
// vue-i18n returns an empty object for unknown locales in normal
|
|
173
|
+
// operation, but callers may provide a custom Composer that returns
|
|
174
|
+
// undefined/null. Normalize that boundary so mergeLocale always
|
|
175
|
+
// clones the Admin payload instead of retaining the module object.
|
|
176
|
+
const hostMessages = i18n.global.getLocaleMessage(module.locale) as unknown
|
|
177
|
+
i18n.global.setLocaleMessage(
|
|
178
|
+
module.locale,
|
|
179
|
+
mergeLocale(
|
|
180
|
+
(hostMessages && typeof hostMessages === 'object'
|
|
181
|
+
? hostMessages
|
|
182
|
+
: {}) as AdminMessages,
|
|
183
|
+
module.messages,
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
}
|
|
91
187
|
},
|
|
92
188
|
install: (app: App, runtime) => {
|
|
93
189
|
const sync = () => {
|
|
@@ -104,6 +200,7 @@ export function createAdminI18n(existing?: I18n): AdminI18nRuntime {
|
|
|
104
200
|
// Storage is optional; language switching remains usable when unavailable.
|
|
105
201
|
}
|
|
106
202
|
}
|
|
203
|
+
setAdminLocale(runtime.current.value as AdminLocale)
|
|
107
204
|
}
|
|
108
205
|
const stop = watch([runtime.current, runtime.active, runtime.status], sync, {
|
|
109
206
|
immediate: true,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type zhCN from './zh-CN.json'
|
|
2
|
+
import { validateLocaleShape } from '@origen-ui/shared'
|
|
3
|
+
|
|
4
|
+
/** 简体中文 locale 标签 */
|
|
5
|
+
export const zhCNLocale = 'zh-CN' as const
|
|
6
|
+
/** 英文 locale 标签 */
|
|
7
|
+
export const enUSLocale = 'en-US' as const
|
|
8
|
+
/** 繁体中文 locale 标签 */
|
|
9
|
+
export const zhTWLocale = 'zh-TW' as const
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Admin 消息树类型基准,由 zh-CN.json 推导。
|
|
13
|
+
* 供 vue-i18n 类型化 keys(DefineLocaleMessage)与 PathKeys 联合类型使用。
|
|
14
|
+
*/
|
|
15
|
+
export type AdminMessages = typeof zhCN
|
|
16
|
+
|
|
17
|
+
export interface AdminLocaleValidation {
|
|
18
|
+
missing: string[]
|
|
19
|
+
extra: string[]
|
|
20
|
+
invalid: string[]
|
|
21
|
+
empty: string[]
|
|
22
|
+
interpolation: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const interpolationPattern = /\{[^{}]+\}/g
|
|
26
|
+
|
|
27
|
+
function placeholders(value: string): string[] {
|
|
28
|
+
return value.match(interpolationPattern) ?? []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Validates official Admin locale shape, leaf values, empties, and placeholders. */
|
|
32
|
+
export function validateAdminLocaleMessages(
|
|
33
|
+
reference: unknown,
|
|
34
|
+
candidate: unknown,
|
|
35
|
+
): AdminLocaleValidation {
|
|
36
|
+
const shape = validateLocaleShape(reference, candidate)
|
|
37
|
+
const empty: string[] = []
|
|
38
|
+
const interpolation: string[] = []
|
|
39
|
+
|
|
40
|
+
const visit = (referenceValue: unknown, candidateValue: unknown, path: string): void => {
|
|
41
|
+
if (typeof referenceValue === 'string') {
|
|
42
|
+
if (typeof candidateValue !== 'string') return
|
|
43
|
+
if (!candidateValue.trim()) empty.push(path)
|
|
44
|
+
const expected = placeholders(referenceValue).sort().join('|')
|
|
45
|
+
const actual = placeholders(candidateValue).sort().join('|')
|
|
46
|
+
if (expected !== actual) interpolation.push(path)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (!referenceValue || typeof referenceValue !== 'object') return
|
|
50
|
+
if (!candidateValue || typeof candidateValue !== 'object') return
|
|
51
|
+
for (const key of Object.keys(referenceValue as Record<string, unknown>)) {
|
|
52
|
+
if (!(key in (candidateValue as Record<string, unknown>))) continue
|
|
53
|
+
visit(
|
|
54
|
+
(referenceValue as Record<string, unknown>)[key],
|
|
55
|
+
(candidateValue as Record<string, unknown>)[key],
|
|
56
|
+
path ? `${path}.${key}` : key,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
visit(reference, candidate, '')
|
|
61
|
+
return { ...shape, empty, interpolation }
|
|
62
|
+
}
|
|
@@ -1,23 +1,130 @@
|
|
|
1
1
|
import type { I18nOptions } from 'vue-i18n'
|
|
2
|
+
import { validateLocaleShape } from '@origen-ui/shared'
|
|
2
3
|
import { describe, expect, it } from 'vitest'
|
|
3
4
|
import { createI18n } from 'vue-i18n'
|
|
4
|
-
import enUS from './en-US'
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import enUS from './en-US.json'
|
|
6
|
+
import { enUSLocale, validateAdminLocaleMessages, zhCNLocale, zhTWLocale } from './messages-types'
|
|
7
|
+
import zhCN from './zh-CN.json'
|
|
8
|
+
import zhTW from './zh-TW.json'
|
|
7
9
|
|
|
8
|
-
const modules = [
|
|
10
|
+
const modules = [
|
|
11
|
+
{ locale: zhCNLocale, messages: zhCN },
|
|
12
|
+
{ locale: enUSLocale, messages: enUS },
|
|
13
|
+
{ locale: zhTWLocale, messages: zhTW },
|
|
14
|
+
]
|
|
9
15
|
|
|
10
16
|
describe('admin locale messages', () => {
|
|
11
17
|
it.each(modules)('compiles the app title for $locale', (module) => {
|
|
12
18
|
const i18n = createI18n({
|
|
13
19
|
legacy: false,
|
|
14
20
|
locale: module.locale,
|
|
15
|
-
messages: { [module.locale]: module.messages
|
|
16
|
-
} as I18nOptions)
|
|
21
|
+
messages: { [module.locale]: module.messages },
|
|
22
|
+
} as unknown as I18nOptions)
|
|
17
23
|
|
|
18
24
|
const title = i18n.global.t('app.title')
|
|
19
25
|
|
|
20
26
|
expect(title).not.toContain('@')
|
|
21
27
|
expect(title).not.toBe('app.title')
|
|
22
28
|
})
|
|
29
|
+
|
|
30
|
+
it.each(modules)('translates shared table actions for $locale', (module) => {
|
|
31
|
+
const i18n = createI18n({
|
|
32
|
+
legacy: false,
|
|
33
|
+
locale: module.locale,
|
|
34
|
+
messages: { [module.locale]: module.messages },
|
|
35
|
+
} as unknown as I18nOptions)
|
|
36
|
+
expect(i18n.global.t('common.actions.approve')).not.toBe('common.actions.approve')
|
|
37
|
+
expect(i18n.global.t('common.actions.batchProcess')).not.toBe('common.actions.batchProcess')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('keeps every official language structurally complete and non-empty against zh-CN', () => {
|
|
41
|
+
for (const module of [zhCN, enUS, zhTW]) {
|
|
42
|
+
expect(validateLocaleShape(zhCN, module)).toEqual({
|
|
43
|
+
missing: [],
|
|
44
|
+
extra: [],
|
|
45
|
+
invalid: [],
|
|
46
|
+
})
|
|
47
|
+
expect(validateAdminLocaleMessages(zhCN, module)).toEqual({
|
|
48
|
+
missing: [],
|
|
49
|
+
extra: [],
|
|
50
|
+
invalid: [],
|
|
51
|
+
empty: [],
|
|
52
|
+
interpolation: [],
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('reports empty leaves and interpolation mismatches', () => {
|
|
58
|
+
expect(
|
|
59
|
+
validateAdminLocaleMessages(
|
|
60
|
+
{ nested: { description: 'Welcome, {name}' } },
|
|
61
|
+
{ nested: { description: ' ' } },
|
|
62
|
+
),
|
|
63
|
+
).toEqual({
|
|
64
|
+
missing: [],
|
|
65
|
+
extra: [],
|
|
66
|
+
invalid: [],
|
|
67
|
+
empty: ['nested.description'],
|
|
68
|
+
interpolation: ['nested.description'],
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('reports structural and leaf-type violations before interpolation checks', () => {
|
|
73
|
+
expect(
|
|
74
|
+
validateAdminLocaleMessages(
|
|
75
|
+
{ nested: { title: 'Title', count: '{count}' } },
|
|
76
|
+
{ nested: { title: 42, count: '{count} {extra}', extra: 'unexpected' } },
|
|
77
|
+
),
|
|
78
|
+
).toEqual({
|
|
79
|
+
missing: [],
|
|
80
|
+
extra: ['nested.extra'],
|
|
81
|
+
invalid: ['nested.title'],
|
|
82
|
+
empty: [],
|
|
83
|
+
interpolation: ['nested.count'],
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('preserves host namespaces while Admin messages take precedence', async () => {
|
|
88
|
+
const host = createI18n({
|
|
89
|
+
legacy: false,
|
|
90
|
+
locale: 'zh-CN',
|
|
91
|
+
messages: {
|
|
92
|
+
'zh-CN': {
|
|
93
|
+
host: { keep: 'host value', nested: { keep: 'nested host value' } },
|
|
94
|
+
app: { title: 'host title', hostOnly: 'retained', nested: { hostOnly: 'nested retained' } },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
} as unknown as I18nOptions)
|
|
98
|
+
const { createAdminI18n } = await import('./index')
|
|
99
|
+
const runtime = createAdminI18n(host)
|
|
100
|
+
await runtime.language.ready
|
|
101
|
+
expect(host.global.t('host.keep')).toBe('host value')
|
|
102
|
+
expect(host.global.t('host.nested.keep')).toBe('nested host value')
|
|
103
|
+
expect(host.global.t('app.title')).toBe(zhCN.app.title)
|
|
104
|
+
expect(host.global.t('app.hostOnly')).toBe('retained')
|
|
105
|
+
expect(host.global.t('app.nested.hostOnly')).toBe('nested retained')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('uses an existing composition locale as the initial Admin locale', async () => {
|
|
109
|
+
const host = createI18n({
|
|
110
|
+
legacy: false,
|
|
111
|
+
locale: 'en-US',
|
|
112
|
+
messages: { 'en-US': { host: { keep: 'host value' } } },
|
|
113
|
+
} as unknown as I18nOptions)
|
|
114
|
+
const { createAdminI18n } = await import('./index')
|
|
115
|
+
const runtime = createAdminI18n(host)
|
|
116
|
+
await runtime.language.ready
|
|
117
|
+
|
|
118
|
+
expect(runtime.language.current.value).toBe('en-US')
|
|
119
|
+
expect(host.global.t('app.title')).toBe(enUS.app.title)
|
|
120
|
+
expect(host.global.t('host.keep')).toBe('host value')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('rejects legacy-mode vue-i18n instances', async () => {
|
|
124
|
+
const { createAdminI18n } = await import('./index')
|
|
125
|
+
const legacy = createI18n(
|
|
126
|
+
{ legacy: true, locale: 'zh-CN', messages: { 'zh-CN': {} } } as unknown as I18nOptions,
|
|
127
|
+
)
|
|
128
|
+
expect(() => createAdminI18n(legacy)).toThrow(/Composition-mode/)
|
|
129
|
+
})
|
|
23
130
|
})
|