@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
|
@@ -36,6 +36,7 @@ interface DemoMenu {
|
|
|
36
36
|
kind: MenuKind
|
|
37
37
|
code: string
|
|
38
38
|
title: string
|
|
39
|
+
titleKey?: string
|
|
39
40
|
path?: string
|
|
40
41
|
componentKey?: string
|
|
41
42
|
icon?: string
|
|
@@ -46,6 +47,7 @@ interface DemoMenu {
|
|
|
46
47
|
cache: boolean
|
|
47
48
|
tabHidden: boolean
|
|
48
49
|
redirect?: string
|
|
50
|
+
version: number
|
|
49
51
|
createdAt: string
|
|
50
52
|
updatedAt: string
|
|
51
53
|
}
|
|
@@ -108,6 +110,40 @@ function failure(message: string, code = 40001): DemoApiResponse {
|
|
|
108
110
|
return envelope(null, message, code)
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
/**
|
|
114
|
+
* 菜单写路径的结构完整性校验:父级必须存在、不得指向自身或后代(成环后行从
|
|
115
|
+
* 树中不可达),button 必须挂页面且不能拥有子级,带 button 子级的行不能改出 page。
|
|
116
|
+
* 版本冲突业务码 40901 须与 rbac.ts 的 MENU_VERSION_CONFLICT_CODE 保持一致。
|
|
117
|
+
*/
|
|
118
|
+
function menuStructureError(
|
|
119
|
+
menus: readonly DemoMenu[],
|
|
120
|
+
selfId: string | undefined,
|
|
121
|
+
parentId: string | undefined,
|
|
122
|
+
kind: MenuKind,
|
|
123
|
+
): string | undefined {
|
|
124
|
+
if (kind === 'button' && !parentId) return 'Button permission requires a parent menu.'
|
|
125
|
+
if (kind === 'button' && selfId && menus.some((menu) => menu.parentId === selfId))
|
|
126
|
+
return 'Menus with children cannot become button permissions.'
|
|
127
|
+
if (kind !== 'page' && menus.some((menu) => menu.parentId === selfId && menu.kind === 'button'))
|
|
128
|
+
return 'Menus with button children must remain pages.'
|
|
129
|
+
if (!parentId) return undefined
|
|
130
|
+
const parent = menus.find((menu) => menu.id === parentId)
|
|
131
|
+
if (!parent) return 'Menu parent not found.'
|
|
132
|
+
if (parent.kind === 'button') return 'Button permission menus cannot have child menus.'
|
|
133
|
+
if (selfId) {
|
|
134
|
+
if (parentId === selfId) return 'Menu parent cannot be the menu itself.'
|
|
135
|
+
const visited = new Set<string>([parentId])
|
|
136
|
+
let cursorId: string | undefined = parent.parentId
|
|
137
|
+
while (cursorId && !visited.has(cursorId)) {
|
|
138
|
+
visited.add(cursorId)
|
|
139
|
+
if (cursorId === selfId) return 'Menu parent cannot be one of its descendants.'
|
|
140
|
+
cursorId = menus.find((item) => item.id === cursorId)?.parentId
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (kind === 'button' && parent.kind !== 'page') return 'Button permission must attach to a page menu.'
|
|
144
|
+
return undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
111
147
|
function asRecord(value: unknown): Record<string, unknown> {
|
|
112
148
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
113
149
|
? (value as Record<string, unknown>)
|
|
@@ -243,6 +279,7 @@ function initialState() {
|
|
|
243
279
|
kind: 'page',
|
|
244
280
|
code: 'dashboard',
|
|
245
281
|
title: 'Dashboard',
|
|
282
|
+
titleKey: 'menu.dashboard',
|
|
246
283
|
path: '/dashboard',
|
|
247
284
|
componentKey: 'dashboard',
|
|
248
285
|
icon: 'dashboard',
|
|
@@ -252,6 +289,7 @@ function initialState() {
|
|
|
252
289
|
visible: true,
|
|
253
290
|
cache: true,
|
|
254
291
|
tabHidden: false,
|
|
292
|
+
version: 1,
|
|
255
293
|
createdAt: NOW,
|
|
256
294
|
updatedAt: NOW,
|
|
257
295
|
},
|
|
@@ -260,6 +298,7 @@ function initialState() {
|
|
|
260
298
|
kind: 'directory',
|
|
261
299
|
code: 'system',
|
|
262
300
|
title: 'System',
|
|
301
|
+
titleKey: 'menu.system',
|
|
263
302
|
path: '/system',
|
|
264
303
|
componentKey: 'outlet',
|
|
265
304
|
icon: 'system',
|
|
@@ -269,6 +308,7 @@ function initialState() {
|
|
|
269
308
|
cache: false,
|
|
270
309
|
tabHidden: false,
|
|
271
310
|
redirect: '/system/users',
|
|
311
|
+
version: 1,
|
|
272
312
|
createdAt: NOW,
|
|
273
313
|
updatedAt: NOW,
|
|
274
314
|
},
|
|
@@ -278,6 +318,7 @@ function initialState() {
|
|
|
278
318
|
kind: 'page',
|
|
279
319
|
code: 'users',
|
|
280
320
|
title: 'Users',
|
|
321
|
+
titleKey: 'menu.users',
|
|
281
322
|
path: 'users',
|
|
282
323
|
componentKey: 'user-list',
|
|
283
324
|
permission: 'system:user:read',
|
|
@@ -286,6 +327,7 @@ function initialState() {
|
|
|
286
327
|
visible: true,
|
|
287
328
|
cache: true,
|
|
288
329
|
tabHidden: false,
|
|
330
|
+
version: 1,
|
|
289
331
|
createdAt: NOW,
|
|
290
332
|
updatedAt: NOW,
|
|
291
333
|
},
|
|
@@ -295,6 +337,7 @@ function initialState() {
|
|
|
295
337
|
kind: 'page',
|
|
296
338
|
code: 'roles',
|
|
297
339
|
title: 'Roles',
|
|
340
|
+
titleKey: 'menu.roles',
|
|
298
341
|
path: 'roles',
|
|
299
342
|
componentKey: 'role-list',
|
|
300
343
|
permission: 'system:role:read',
|
|
@@ -303,6 +346,7 @@ function initialState() {
|
|
|
303
346
|
visible: true,
|
|
304
347
|
cache: true,
|
|
305
348
|
tabHidden: false,
|
|
349
|
+
version: 1,
|
|
306
350
|
createdAt: NOW,
|
|
307
351
|
updatedAt: NOW,
|
|
308
352
|
},
|
|
@@ -312,6 +356,7 @@ function initialState() {
|
|
|
312
356
|
kind: 'page',
|
|
313
357
|
code: 'menus',
|
|
314
358
|
title: 'Menus',
|
|
359
|
+
titleKey: 'menu.menus',
|
|
315
360
|
path: 'menus',
|
|
316
361
|
componentKey: 'menu-list',
|
|
317
362
|
permission: 'system:menu:read',
|
|
@@ -320,6 +365,7 @@ function initialState() {
|
|
|
320
365
|
visible: true,
|
|
321
366
|
cache: true,
|
|
322
367
|
tabHidden: false,
|
|
368
|
+
version: 1,
|
|
323
369
|
createdAt: NOW,
|
|
324
370
|
updatedAt: NOW,
|
|
325
371
|
},
|
|
@@ -329,6 +375,7 @@ function initialState() {
|
|
|
329
375
|
kind: 'page',
|
|
330
376
|
code: 'audit',
|
|
331
377
|
title: 'Audit log',
|
|
378
|
+
titleKey: 'menu.audit',
|
|
332
379
|
path: 'audit',
|
|
333
380
|
componentKey: 'audit-list',
|
|
334
381
|
permission: 'system:audit:read',
|
|
@@ -337,6 +384,7 @@ function initialState() {
|
|
|
337
384
|
visible: true,
|
|
338
385
|
cache: false,
|
|
339
386
|
tabHidden: false,
|
|
387
|
+
version: 1,
|
|
340
388
|
createdAt: NOW,
|
|
341
389
|
updatedAt: NOW,
|
|
342
390
|
},
|
|
@@ -654,13 +702,23 @@ export function createDemoApi(): DemoApi {
|
|
|
654
702
|
}
|
|
655
703
|
|
|
656
704
|
if (method === 'POST' && path === '/system/menus') {
|
|
705
|
+
const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
|
|
706
|
+
const parentId =
|
|
707
|
+
typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
|
|
708
|
+
const code = String(body.code ?? '').trim()
|
|
709
|
+
const title = String(body.title ?? '').trim()
|
|
710
|
+
if (!code) return failure('Menu code is required.', 40001)
|
|
711
|
+
if (!title) return failure('Menu title is required.', 40001)
|
|
712
|
+
const structureError = menuStructureError(state.menus, undefined, parentId, kind)
|
|
713
|
+
if (structureError) return failure(structureError, 40001)
|
|
657
714
|
const id = `menu-${state.nextId++}`
|
|
658
715
|
const menu: DemoMenu = {
|
|
659
716
|
id,
|
|
660
|
-
parentId
|
|
661
|
-
kind
|
|
662
|
-
code
|
|
663
|
-
title
|
|
717
|
+
parentId,
|
|
718
|
+
kind,
|
|
719
|
+
code,
|
|
720
|
+
title,
|
|
721
|
+
titleKey: typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined,
|
|
664
722
|
path: typeof body.path === 'string' && body.path ? body.path : undefined,
|
|
665
723
|
componentKey:
|
|
666
724
|
typeof body.componentKey === 'string' && body.componentKey
|
|
@@ -675,6 +733,7 @@ export function createDemoApi(): DemoApi {
|
|
|
675
733
|
cache: body.cache !== false,
|
|
676
734
|
tabHidden: body.tabHidden === true,
|
|
677
735
|
redirect: typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined,
|
|
736
|
+
version: 1,
|
|
678
737
|
createdAt: NOW,
|
|
679
738
|
updatedAt: NOW,
|
|
680
739
|
}
|
|
@@ -709,6 +768,7 @@ export function createDemoApi(): DemoApi {
|
|
|
709
768
|
const next = status(body.status)
|
|
710
769
|
for (const menu of state.menus.filter((item) => ids.has(item.id))) {
|
|
711
770
|
menu.status = next
|
|
771
|
+
menu.version += 1
|
|
712
772
|
menu.updatedAt = new Date().toISOString()
|
|
713
773
|
revise('menu.status', 'menu', menu.id, menu.title || menu.code, `Set status to ${next}.`)
|
|
714
774
|
}
|
|
@@ -720,11 +780,26 @@ export function createDemoApi(): DemoApi {
|
|
|
720
780
|
if (!menu) return failure('Menu not found.', 40401)
|
|
721
781
|
if (method === 'GET') return envelope(cloneMenu(menu))
|
|
722
782
|
if (method === 'PUT') {
|
|
723
|
-
|
|
783
|
+
const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
|
|
784
|
+
const parentId =
|
|
724
785
|
typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
786
|
+
const code = String(body.code ?? menu.code).trim()
|
|
787
|
+
const title = String(body.title ?? menu.title).trim()
|
|
788
|
+
if (!code) return failure('Menu code is required.', 40001)
|
|
789
|
+
if (!title) return failure('Menu title is required.', 40001)
|
|
790
|
+
const structureError = menuStructureError(state.menus, menu.id, parentId, kind)
|
|
791
|
+
if (structureError) return failure(structureError, 40001)
|
|
792
|
+
if (body.version !== undefined) {
|
|
793
|
+
const clientVersion = Number(body.version)
|
|
794
|
+
if (!Number.isInteger(clientVersion) || clientVersion !== menu.version)
|
|
795
|
+
return failure('Menu was modified by someone else. Refresh and retry.', 40901)
|
|
796
|
+
}
|
|
797
|
+
menu.parentId = parentId
|
|
798
|
+
menu.kind = kind
|
|
799
|
+
menu.code = code
|
|
800
|
+
menu.title = title
|
|
801
|
+
menu.titleKey =
|
|
802
|
+
typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined
|
|
728
803
|
menu.path = typeof body.path === 'string' && body.path ? body.path : undefined
|
|
729
804
|
menu.componentKey =
|
|
730
805
|
typeof body.componentKey === 'string' && body.componentKey ? body.componentKey : undefined
|
|
@@ -738,6 +813,7 @@ export function createDemoApi(): DemoApi {
|
|
|
738
813
|
menu.tabHidden = body.tabHidden === true
|
|
739
814
|
menu.redirect =
|
|
740
815
|
typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined
|
|
816
|
+
menu.version += 1
|
|
741
817
|
menu.updatedAt = new Date().toISOString()
|
|
742
818
|
revise('menu.update', 'menu', menu.id, menu.title || menu.code, 'Updated demo menu.')
|
|
743
819
|
return envelope(cloneMenu(menu))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile } from 'node:fs/promises'
|
|
1
2
|
import path from 'node:path'
|
|
2
3
|
import { fileURLToPath } from 'node:url'
|
|
3
4
|
// 使用 swagger-typescript-api 从 OpenAPI 规范生成 API 客户端
|
|
@@ -6,10 +7,11 @@ import { generateApi } from 'swagger-typescript-api'
|
|
|
6
7
|
/* eslint-disable node/prefer-global/process */
|
|
7
8
|
|
|
8
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const outputDirectory = path.resolve(__dirname, '../src/api/generated')
|
|
9
11
|
|
|
10
12
|
generateApi({
|
|
11
13
|
name: 'Api.ts',
|
|
12
|
-
output:
|
|
14
|
+
output: outputDirectory,
|
|
13
15
|
input: path.resolve(__dirname, '../openapi.json'),
|
|
14
16
|
modular: true,
|
|
15
17
|
moduleNameFirstTag: true,
|
|
@@ -18,10 +20,92 @@ generateApi({
|
|
|
18
20
|
singleHttpClient: true,
|
|
19
21
|
cleanOutput: true,
|
|
20
22
|
})
|
|
23
|
+
.then(() => normalizeGeneratedApi(outputDirectory))
|
|
21
24
|
.then(() => {
|
|
22
25
|
process.stdout.write('API client generated successfully!\n')
|
|
23
26
|
})
|
|
24
|
-
.catch((
|
|
25
|
-
console.error('Failed to generate API client:',
|
|
27
|
+
.catch((error) => {
|
|
28
|
+
console.error('Failed to generate API client:', error)
|
|
26
29
|
process.exit(1)
|
|
27
30
|
})
|
|
31
|
+
|
|
32
|
+
async function normalizeGeneratedApi(directory: string) {
|
|
33
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
34
|
+
if (!entry.isFile() || !entry.name.endsWith('.ts')) continue
|
|
35
|
+
const filePath = path.join(directory, entry.name)
|
|
36
|
+
const source = await readFile(filePath, 'utf8')
|
|
37
|
+
const normalized = normalizeGeneratedSource(source, entry.name)
|
|
38
|
+
if (normalized !== source) await writeFile(filePath, normalized, 'utf8')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeGeneratedSource(source: string, fileName: string) {
|
|
43
|
+
let normalized = source
|
|
44
|
+
.replace(/^\/\* eslint-disable \*\/\r?\n/u, '')
|
|
45
|
+
.replace(/^\/\* tslint:disable \*\/\r?\n/u, '')
|
|
46
|
+
.replace(/^\/\/ @ts-nocheck\r?\n/u, '')
|
|
47
|
+
.replace(/\bany\b/gu, 'unknown')
|
|
48
|
+
|
|
49
|
+
if (fileName === 'http-client.ts') normalized = normalizeHttpClient(normalized)
|
|
50
|
+
return normalized
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalizeHttpClient(source: string) {
|
|
54
|
+
let normalized = source.replace(
|
|
55
|
+
' return value.map((v: unknown) => this.encodeQueryParam(key, v)).join("&");',
|
|
56
|
+
' if (!Array.isArray(value)) return "";\n return value.map((v) => this.encodeQueryParam(key, v)).join("&");',
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const formatterStart = normalized.indexOf(' private contentFormatters:')
|
|
60
|
+
const formatterEnd = normalized.indexOf('\n\n protected mergeRequestParams', formatterStart)
|
|
61
|
+
if (formatterStart < 0 || formatterEnd < 0)
|
|
62
|
+
throw new Error('Generated HTTP client formatters changed unexpectedly.')
|
|
63
|
+
|
|
64
|
+
const formatter = ` private contentFormatters: Record<ContentType, (input: unknown) => BodyInit | null> = {
|
|
65
|
+
[ContentType.Json]: (input: unknown) =>
|
|
66
|
+
input === null || typeof input === "undefined"
|
|
67
|
+
? null
|
|
68
|
+
: JSON.stringify(input) ?? null,
|
|
69
|
+
[ContentType.JsonApi]: (input: unknown) =>
|
|
70
|
+
input === null || typeof input === "undefined"
|
|
71
|
+
? null
|
|
72
|
+
: JSON.stringify(input) ?? null,
|
|
73
|
+
[ContentType.Text]: (input: unknown) =>
|
|
74
|
+
typeof input === "string" ? input : JSON.stringify(input) ?? null,
|
|
75
|
+
[ContentType.FormData]: (input: unknown) => {
|
|
76
|
+
if (input instanceof FormData) {
|
|
77
|
+
return input;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const record = isRecord(input) ? input : {};
|
|
81
|
+
return Object.keys(record).reduce((formData, key) => {
|
|
82
|
+
const property = record[key];
|
|
83
|
+
formData.append(
|
|
84
|
+
key,
|
|
85
|
+
property instanceof Blob
|
|
86
|
+
? property
|
|
87
|
+
: typeof property === "object" && property !== null
|
|
88
|
+
? JSON.stringify(property) ?? ""
|
|
89
|
+
: String(property),
|
|
90
|
+
);
|
|
91
|
+
return formData;
|
|
92
|
+
}, new FormData());
|
|
93
|
+
},
|
|
94
|
+
[ContentType.UrlEncoded]: (input: unknown) =>
|
|
95
|
+
this.toQueryString(isRecord(input) ? input : {}),
|
|
96
|
+
};`
|
|
97
|
+
normalized = `${normalized.slice(0, formatterStart)}${formatter}${normalized.slice(formatterEnd)}`
|
|
98
|
+
|
|
99
|
+
const classMarker = 'export class HttpClient<SecurityDataType = unknown> {'
|
|
100
|
+
if (!normalized.includes('function isRecord(value: unknown): value is Record<string, unknown>')) {
|
|
101
|
+
normalized = normalized.replace(
|
|
102
|
+
classMarker,
|
|
103
|
+
`function isRecord(value: unknown): value is Record<string, unknown> {
|
|
104
|
+
return typeof value === "object" && value !== null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
${classMarker}`,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
return normalized
|
|
111
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { createAdminBuildOptions, createAdminBuildPlugins } from '../vite.build-policy'
|
|
3
|
+
|
|
4
|
+
describe('admin build chunk policy', () => {
|
|
5
|
+
it('uses native Rolldown code splitting groups', () => {
|
|
6
|
+
const output = createAdminBuildOptions(false)?.rolldownOptions?.output
|
|
7
|
+
expect(Array.isArray(output)).toBe(false)
|
|
8
|
+
if (!output || Array.isArray(output)) throw new Error('Expected one Admin output configuration')
|
|
9
|
+
|
|
10
|
+
expect(output.manualChunks).toBeUndefined()
|
|
11
|
+
expect(output.codeSplitting).not.toBe(true)
|
|
12
|
+
expect(output.codeSplitting).not.toBe(false)
|
|
13
|
+
if (!output.codeSplitting || typeof output.codeSplitting !== 'object') {
|
|
14
|
+
throw new Error('Expected native Rolldown code splitting options')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const groupNames = output.codeSplitting.groups
|
|
18
|
+
?.map((group) => group.name)
|
|
19
|
+
.filter((name): name is string => typeof name === 'string')
|
|
20
|
+
expect(groupNames).toEqual(
|
|
21
|
+
expect.arrayContaining([
|
|
22
|
+
'vendor-vue-runtime',
|
|
23
|
+
'vendor-vue-i18n',
|
|
24
|
+
'vendor-vueuse',
|
|
25
|
+
'vendor-positioning',
|
|
26
|
+
'vendor-async-validator',
|
|
27
|
+
'vendor-table-suite',
|
|
28
|
+
'vendor-initial',
|
|
29
|
+
]),
|
|
30
|
+
)
|
|
31
|
+
expect(output.codeSplitting.groups?.some((group) => group.entriesAware)).toBe(true)
|
|
32
|
+
const tableSuite = output.codeSplitting.groups?.find(
|
|
33
|
+
(group) => group.name === 'vendor-table-suite',
|
|
34
|
+
)
|
|
35
|
+
expect(tableSuite?.maxSize).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('drops debug calls in the production output minifier only', () => {
|
|
39
|
+
const productionOutput = createAdminBuildOptions(false)?.rolldownOptions?.output
|
|
40
|
+
const debugOutput = createAdminBuildOptions(true)?.rolldownOptions?.output
|
|
41
|
+
if (!productionOutput || Array.isArray(productionOutput)) {
|
|
42
|
+
throw new Error('Expected one production output configuration')
|
|
43
|
+
}
|
|
44
|
+
if (!debugOutput || Array.isArray(debugOutput)) {
|
|
45
|
+
throw new Error('Expected one debug output configuration')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
expect(productionOutput.minify).toMatchObject({
|
|
49
|
+
compress: { dropConsole: true, dropDebugger: true },
|
|
50
|
+
mangle: true,
|
|
51
|
+
codegen: true,
|
|
52
|
+
})
|
|
53
|
+
expect(debugOutput.minify).toBeUndefined()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('keeps sourcemaps valid when normalizing empty chunks', async () => {
|
|
57
|
+
const renderChunk = createAdminBuildPlugins()[0]?.renderChunk
|
|
58
|
+
if (typeof renderChunk !== 'function') throw new Error('Expected the empty chunk render hook')
|
|
59
|
+
|
|
60
|
+
const result = await renderChunk.call(
|
|
61
|
+
{} as never,
|
|
62
|
+
'export {};',
|
|
63
|
+
{} as never,
|
|
64
|
+
{} as never,
|
|
65
|
+
{} as never,
|
|
66
|
+
)
|
|
67
|
+
expect(result).toMatchObject({
|
|
68
|
+
code: 'void 0;\n',
|
|
69
|
+
map: { mappings: '' },
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -4,6 +4,7 @@ import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
|
4
4
|
import { useOrigenUiLanguage } from 'origen-ui/language'
|
|
5
5
|
import { computed, defineAsyncComponent, onBeforeUnmount, onMounted } from 'vue'
|
|
6
6
|
import { RouterView, useRoute } from 'vue-router'
|
|
7
|
+
import { embeddedMode } from './app/embedded'
|
|
7
8
|
import { useThemeStore } from './features/appearance/store/theme'
|
|
8
9
|
import DevtoolsProtectionOverlay from './features/security/components/DevtoolsProtectionOverlay.vue'
|
|
9
10
|
import { devtoolsProtection } from './features/security/devtoolsProtection'
|
|
@@ -27,12 +28,17 @@ const elementLocale = computed(
|
|
|
27
28
|
)
|
|
28
29
|
|
|
29
30
|
const theme = useThemeStore()
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
// 嵌入模式下 dark class 由主壳注入桥持有(embedded.ts applyHostTheme),
|
|
32
|
+
// 本应用自身的主题持久化/auto 跟随不生效,避免与主壳下发互相覆盖
|
|
33
|
+
if (!embeddedMode) {
|
|
34
|
+
theme.hydrate()
|
|
35
|
+
theme.apply()
|
|
36
|
+
}
|
|
32
37
|
let mql: MediaQueryList | null = null
|
|
33
38
|
let listener: ((e: MediaQueryListEvent) => void) | null = null
|
|
34
39
|
|
|
35
40
|
onMounted(() => {
|
|
41
|
+
if (embeddedMode) return
|
|
36
42
|
mql = window.matchMedia('(prefers-color-scheme: dark)')
|
|
37
43
|
listener = () => {
|
|
38
44
|
if (theme.mode === 'auto') theme.apply()
|
|
@@ -53,7 +59,8 @@ onBeforeUnmount(() => {
|
|
|
53
59
|
:aria-hidden="devtoolsBlocked ? 'true' : undefined"
|
|
54
60
|
>
|
|
55
61
|
<RouteProgress />
|
|
56
|
-
|
|
62
|
+
<!-- 嵌入模式渲染裸内容页:外壳(侧栏/页签)由主壳提供,壳中壳取一层 -->
|
|
63
|
+
<RouterView v-if="isPublic || embeddedMode" />
|
|
57
64
|
<AdminLayout v-else />
|
|
58
65
|
</div>
|
|
59
66
|
<DevtoolsProtectionOverlay :blocked="devtoolsBlocked" />
|
|
@@ -1,22 +1,92 @@
|
|
|
1
1
|
import type { RefreshResult, TokenStorage } from '@origen-ui/http'
|
|
2
|
+
import type { AxiosAdapter, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
|
2
3
|
import {
|
|
3
4
|
ApiClient,
|
|
4
5
|
createApiEnvelopeAdapter,
|
|
5
6
|
createBearerAuthStrategy,
|
|
6
7
|
TokenManager,
|
|
7
8
|
} from '@origen-ui/http'
|
|
9
|
+
import axios, { AxiosHeaders } from 'axios'
|
|
10
|
+
import { embeddedMode, embeddedTokenStorage, notifyHostUnauthorized, readHostInjection } from '../app/embedded'
|
|
11
|
+
import { currentAdminLocale } from '../app/localeFormat'
|
|
8
12
|
import { appRuntimeConfig } from '../app/runtimeConfig'
|
|
9
13
|
|
|
10
14
|
const { http } = appRuntimeConfig
|
|
11
15
|
const responseAdapter = createApiEnvelopeAdapter(http.responseSuccessCode)
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
// 嵌入模式:iframe 沙箱内相对路径解析到主壳源,API 基址改用主壳按注册表
|
|
18
|
+
// 下发的同源网关路径(dev 期 Vite proxy,生产经网关);独立模式保持相对路径。
|
|
19
|
+
// 沙箱补丁与 Rolldown 打包的 axios XHR/fetch 内置适配器不兼容(请求 status 0
|
|
20
|
+
// 或挂起),嵌入模式改用直调 window.fetch 的自定义适配器,绕开沙箱 XHR 补丁。
|
|
21
|
+
const injected = readHostInjection()
|
|
22
|
+
const apiBaseURL =
|
|
23
|
+
embeddedMode && typeof injected.apiBaseURL === 'string' && injected.apiBaseURL !== ''
|
|
24
|
+
? injected.apiBaseURL
|
|
25
|
+
: http.baseURL
|
|
26
|
+
|
|
27
|
+
function serializeParams(
|
|
28
|
+
url: string,
|
|
29
|
+
params: Record<string, unknown> | URLSearchParams | undefined,
|
|
30
|
+
): string {
|
|
31
|
+
if (!params) return url
|
|
32
|
+
const search = new URLSearchParams()
|
|
33
|
+
if (params instanceof URLSearchParams) {
|
|
34
|
+
params.forEach((value, key) => search.append(key, value))
|
|
35
|
+
} else {
|
|
36
|
+
for (const [key, value] of Object.entries(params)) {
|
|
37
|
+
if (value === undefined || value === null) continue
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
for (const item of value) search.append(key, String(item))
|
|
40
|
+
} else {
|
|
41
|
+
search.append(key, String(value))
|
|
42
|
+
}
|
|
43
|
+
}
|
|
16
44
|
}
|
|
17
|
-
|
|
45
|
+
const query = search.toString()
|
|
46
|
+
if (query === '') return url
|
|
47
|
+
return url + (url.includes('?') ? '&' : '?') + query
|
|
18
48
|
}
|
|
19
49
|
|
|
50
|
+
function createWindowFetchAdapter(): AxiosAdapter {
|
|
51
|
+
return async (config: InternalAxiosRequestConfig): Promise<AxiosResponse> => {
|
|
52
|
+
const method = (config.method ?? 'get').toUpperCase()
|
|
53
|
+
const headers = AxiosHeaders.from(config.headers)
|
|
54
|
+
headers.set('Accept-Language', currentAdminLocale())
|
|
55
|
+
let body: string | undefined
|
|
56
|
+
if (config.data !== undefined && method !== 'GET' && method !== 'HEAD') {
|
|
57
|
+
headers.setContentType('application/json')
|
|
58
|
+
body = typeof config.data === 'string' ? config.data : JSON.stringify(config.data)
|
|
59
|
+
}
|
|
60
|
+
const url = serializeParams(axios.getUri(config), config.params as never)
|
|
61
|
+
const response = await fetch(url, {
|
|
62
|
+
method,
|
|
63
|
+
headers: headers.toJSON() as Record<string, string>,
|
|
64
|
+
body,
|
|
65
|
+
signal: config.signal as AbortSignal | undefined,
|
|
66
|
+
})
|
|
67
|
+
const text = await response.text()
|
|
68
|
+
let data: unknown = text
|
|
69
|
+
try {
|
|
70
|
+
data = text === '' ? null : JSON.parse(text)
|
|
71
|
+
} catch {
|
|
72
|
+
data = text
|
|
73
|
+
}
|
|
74
|
+
const responseHeaders = AxiosHeaders.from(response.headers as unknown as Record<string, string>)
|
|
75
|
+
return {
|
|
76
|
+
data,
|
|
77
|
+
status: response.status,
|
|
78
|
+
statusText: response.statusText,
|
|
79
|
+
headers: responseHeaders,
|
|
80
|
+
config,
|
|
81
|
+
request: { responseURL: response.url },
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const embeddedFetchAdapter: AxiosAdapter | undefined = embeddedMode
|
|
87
|
+
? createWindowFetchAdapter()
|
|
88
|
+
: undefined
|
|
89
|
+
|
|
20
90
|
function browserStorage(): TokenStorage | undefined {
|
|
21
91
|
return typeof localStorage === 'undefined' ? undefined : localStorage
|
|
22
92
|
}
|
|
@@ -30,21 +100,27 @@ function readCookie(name: string): string | null {
|
|
|
30
100
|
|
|
31
101
|
export const tokenManager = new TokenManager({
|
|
32
102
|
accessKey: http.tokenKey,
|
|
33
|
-
accessStorage: browserStorage(),
|
|
103
|
+
accessStorage: embeddedMode ? embeddedTokenStorage : browserStorage(),
|
|
34
104
|
})
|
|
35
105
|
|
|
36
106
|
const refreshClient = new ApiClient({
|
|
37
|
-
baseURL:
|
|
107
|
+
baseURL: apiBaseURL,
|
|
108
|
+
...(embeddedFetchAdapter ? { adapter: embeddedFetchAdapter } : {}),
|
|
38
109
|
responseAdapter,
|
|
39
110
|
retry: http.refreshRetry,
|
|
40
111
|
timeout: http.timeout,
|
|
41
|
-
resolveHeaders: () => ({ 'Accept-Language':
|
|
112
|
+
resolveHeaders: () => ({ 'Accept-Language': currentAdminLocale() }),
|
|
42
113
|
})
|
|
43
114
|
|
|
44
115
|
export const apiClient = new ApiClient({
|
|
45
116
|
auth: createBearerAuthStrategy({
|
|
46
117
|
csrfToken: () => readCookie(http.csrfCookieName),
|
|
47
118
|
onExpired: () => {
|
|
119
|
+
// 嵌入模式:认证由主壳唯一持有,通知主壳重新授权,不做沙箱内硬导航
|
|
120
|
+
if (embeddedMode) {
|
|
121
|
+
notifyHostUnauthorized()
|
|
122
|
+
return
|
|
123
|
+
}
|
|
48
124
|
if (typeof window !== 'undefined' && window.location.pathname !== '/login')
|
|
49
125
|
window.location.assign('/login')
|
|
50
126
|
},
|
|
@@ -60,13 +136,17 @@ export const apiClient = new ApiClient({
|
|
|
60
136
|
},
|
|
61
137
|
)
|
|
62
138
|
},
|
|
139
|
+
// 嵌入模式冻结自刷新:token 轮换由主壳唯一执行(data 通道推送)
|
|
63
140
|
shouldRefresh: (error) =>
|
|
64
|
-
|
|
141
|
+
!embeddedMode &&
|
|
142
|
+
error.kind === 'business' &&
|
|
143
|
+
http.refreshBusinessCodes.includes(error.code ?? -1),
|
|
65
144
|
tokenManager,
|
|
66
145
|
}),
|
|
67
|
-
|
|
146
|
+
...(embeddedFetchAdapter ? { adapter: embeddedFetchAdapter } : {}),
|
|
147
|
+
baseURL: apiBaseURL,
|
|
68
148
|
responseAdapter,
|
|
69
149
|
retry: http.retry,
|
|
70
150
|
timeout: http.timeout,
|
|
71
|
-
resolveHeaders: () => ({ 'Accept-Language':
|
|
151
|
+
resolveHeaders: () => ({ 'Accept-Language': currentAdminLocale() }),
|
|
72
152
|
})
|