@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
|
@@ -3,8 +3,12 @@ import type { OgFormGlobalConfig } from '@origen-ui/form'
|
|
|
3
3
|
import type { OgSearchGlobalConfig } from '@origen-ui/search'
|
|
4
4
|
import type { CreateOgTableOptions } from '@origen-ui/table'
|
|
5
5
|
import type { OgTabsGlobalConfig } from '@origen-ui/tabs'
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
function resolveConfiguredLocale(locale: string | undefined): 'zh-CN' | 'en-US' | 'zh-TW' {
|
|
8
|
+
if (locale === 'en-US') return 'en-US'
|
|
9
|
+
if (locale === 'zh-TW') return 'zh-TW'
|
|
10
|
+
return 'zh-CN'
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
export interface AdminRuntimeConfig {
|
|
10
14
|
http: {
|
|
@@ -20,11 +24,10 @@ export interface AdminRuntimeConfig {
|
|
|
20
24
|
csrfHeaderName: string
|
|
21
25
|
refreshBusinessCodes: readonly number[]
|
|
22
26
|
}
|
|
23
|
-
locale: { default: 'zh-CN' | 'en-US' | 'zh-TW'
|
|
27
|
+
locale: { default: 'zh-CN' | 'en-US' | 'zh-TW' }
|
|
24
28
|
router: { workspace: { enabled: boolean, key: string, scope: string, version: number } }
|
|
25
29
|
origenUi: {
|
|
26
30
|
size: 'small' | 'default' | 'large'
|
|
27
|
-
locale: OrigenUiLocaleBundle
|
|
28
31
|
dialog: CreateOgDialogOptions
|
|
29
32
|
form: OgFormGlobalConfig
|
|
30
33
|
search: OgSearchGlobalConfig
|
|
@@ -33,7 +36,7 @@ export interface AdminRuntimeConfig {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
const configuredLocale =
|
|
39
|
+
const configuredLocale = resolveConfiguredLocale(import.meta.env.VITE_DEFAULT_LOCALE)
|
|
37
40
|
|
|
38
41
|
export const appRuntimeConfig: AdminRuntimeConfig = {
|
|
39
42
|
http: {
|
|
@@ -51,19 +54,17 @@ export const appRuntimeConfig: AdminRuntimeConfig = {
|
|
|
51
54
|
},
|
|
52
55
|
locale: {
|
|
53
56
|
default: configuredLocale,
|
|
54
|
-
fallback: 'en-US',
|
|
55
57
|
},
|
|
56
58
|
router: {
|
|
57
59
|
workspace: {
|
|
58
60
|
enabled: true,
|
|
59
61
|
key: 'og-admin-workspace',
|
|
60
62
|
scope: 'admin',
|
|
61
|
-
version:
|
|
63
|
+
version: 4,
|
|
62
64
|
},
|
|
63
65
|
},
|
|
64
66
|
origenUi: {
|
|
65
67
|
size: 'default',
|
|
66
|
-
locale: resolveAdminOrigenUiLocale(configuredLocale),
|
|
67
68
|
dialog: {},
|
|
68
69
|
form: {},
|
|
69
70
|
search: {},
|
|
@@ -165,3 +165,314 @@ describe('admin demo API', () => {
|
|
|
165
165
|
expect(data<{ total: number }>(request(restarted, 'GET', '/system/roles')).total).toBe(2)
|
|
166
166
|
})
|
|
167
167
|
})
|
|
168
|
+
|
|
169
|
+
describe('demo menu guardrails', () => {
|
|
170
|
+
it('rejects button menus whose parent is missing or not a page', () => {
|
|
171
|
+
const api = createDemoApi()
|
|
172
|
+
expect(
|
|
173
|
+
request(api, 'POST', '/system/menus', {
|
|
174
|
+
kind: 'button',
|
|
175
|
+
code: 'ghost-button',
|
|
176
|
+
title: 'Ghost',
|
|
177
|
+
permission: 'system:demo:ghost',
|
|
178
|
+
}).body.code,
|
|
179
|
+
).toBe(40001)
|
|
180
|
+
expect(
|
|
181
|
+
request(api, 'POST', '/system/menus', {
|
|
182
|
+
kind: 'button',
|
|
183
|
+
parentId: 'menu-system',
|
|
184
|
+
code: 'ghost-button',
|
|
185
|
+
title: 'Ghost',
|
|
186
|
+
permission: 'system:demo:ghost',
|
|
187
|
+
}).body.code,
|
|
188
|
+
).toBe(40001)
|
|
189
|
+
expect(
|
|
190
|
+
request(api, 'POST', '/system/menus', {
|
|
191
|
+
kind: 'button',
|
|
192
|
+
parentId: 'menu-nowhere',
|
|
193
|
+
code: 'ghost-button',
|
|
194
|
+
title: 'Ghost',
|
|
195
|
+
permission: 'system:demo:ghost',
|
|
196
|
+
}).body.code,
|
|
197
|
+
).toBe(40001)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('creates button menus under page parents, persists titleKey, and enforces version races', () => {
|
|
201
|
+
const api = createDemoApi()
|
|
202
|
+
const created = data<{ id: string, version: number, titleKey?: string }>(
|
|
203
|
+
request(api, 'POST', '/system/menus', {
|
|
204
|
+
kind: 'button',
|
|
205
|
+
parentId: 'menu-dashboard',
|
|
206
|
+
code: 'dashboard-export',
|
|
207
|
+
title: 'Export',
|
|
208
|
+
permission: 'workspace:dashboard:export',
|
|
209
|
+
titleKey: 'menus.export.title',
|
|
210
|
+
}),
|
|
211
|
+
)
|
|
212
|
+
expect(created.version).toBe(1)
|
|
213
|
+
expect(created.titleKey).toBe('menus.export.title')
|
|
214
|
+
const stale = request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
215
|
+
kind: 'button',
|
|
216
|
+
parentId: 'menu-dashboard',
|
|
217
|
+
code: 'dashboard-export',
|
|
218
|
+
title: 'Export v2',
|
|
219
|
+
permission: 'workspace:dashboard:export',
|
|
220
|
+
version: 0,
|
|
221
|
+
})
|
|
222
|
+
expect(stale.body.code).toBe(40901)
|
|
223
|
+
const fresh = data<{ version: number }>(
|
|
224
|
+
request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
225
|
+
kind: 'button',
|
|
226
|
+
parentId: 'menu-dashboard',
|
|
227
|
+
code: 'dashboard-export',
|
|
228
|
+
title: 'Export v2',
|
|
229
|
+
permission: 'workspace:dashboard:export',
|
|
230
|
+
version: 1,
|
|
231
|
+
}),
|
|
232
|
+
)
|
|
233
|
+
expect(fresh.version).toBe(2)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('rejects page and directory children under button menus on POST and PUT', () => {
|
|
237
|
+
const api = createDemoApi()
|
|
238
|
+
const button = data<{ id: string }>(
|
|
239
|
+
request(api, 'POST', '/system/menus', {
|
|
240
|
+
kind: 'button',
|
|
241
|
+
parentId: 'menu-dashboard',
|
|
242
|
+
code: 'dashboard-export-child-test',
|
|
243
|
+
title: 'Export',
|
|
244
|
+
permission: 'workspace:dashboard:export',
|
|
245
|
+
}),
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
for (const kind of ['page', 'directory'] as const) {
|
|
249
|
+
expect(
|
|
250
|
+
request(api, 'POST', '/system/menus', {
|
|
251
|
+
kind,
|
|
252
|
+
parentId: button.id,
|
|
253
|
+
code: `invalid-${kind}-post`,
|
|
254
|
+
title: `Invalid ${kind}`,
|
|
255
|
+
}).body.code,
|
|
256
|
+
).toBe(40001)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const page = data<{ id: string }>(
|
|
260
|
+
request(api, 'POST', '/system/menus', {
|
|
261
|
+
kind: 'page',
|
|
262
|
+
code: 'page-for-button-parent-test',
|
|
263
|
+
title: 'Page for button parent test',
|
|
264
|
+
path: '/page-for-button-parent-test',
|
|
265
|
+
componentKey: 'dashboard',
|
|
266
|
+
}),
|
|
267
|
+
)
|
|
268
|
+
const directory = data<{ id: string }>(
|
|
269
|
+
request(api, 'POST', '/system/menus', {
|
|
270
|
+
kind: 'directory',
|
|
271
|
+
code: 'directory-for-button-parent-test',
|
|
272
|
+
title: 'Directory for button parent test',
|
|
273
|
+
}),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
for (const menu of [page, directory]) {
|
|
277
|
+
expect(
|
|
278
|
+
request(api, 'PUT', `/system/menus/${menu.id}`, {
|
|
279
|
+
kind: menu === page ? 'page' : 'directory',
|
|
280
|
+
parentId: button.id,
|
|
281
|
+
}).body.code,
|
|
282
|
+
).toBe(40001)
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('rejects turning a menu with page or directory children into a button', () => {
|
|
287
|
+
const api = createDemoApi()
|
|
288
|
+
const page = data<{ id: string }>(
|
|
289
|
+
request(api, 'POST', '/system/menus', {
|
|
290
|
+
kind: 'page',
|
|
291
|
+
code: 'page-with-child-test',
|
|
292
|
+
title: 'Page with child',
|
|
293
|
+
path: '/page-with-child-test',
|
|
294
|
+
componentKey: 'dashboard',
|
|
295
|
+
}),
|
|
296
|
+
)
|
|
297
|
+
const directory = data<{ id: string }>(
|
|
298
|
+
request(api, 'POST', '/system/menus', {
|
|
299
|
+
kind: 'directory',
|
|
300
|
+
code: 'directory-with-child-test',
|
|
301
|
+
title: 'Directory with child',
|
|
302
|
+
}),
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
for (const [menu, childKind] of [
|
|
306
|
+
[page, 'page'],
|
|
307
|
+
[directory, 'directory'],
|
|
308
|
+
] as const) {
|
|
309
|
+
data(
|
|
310
|
+
request(api, 'POST', '/system/menus', {
|
|
311
|
+
kind: childKind,
|
|
312
|
+
parentId: menu.id,
|
|
313
|
+
code: `${childKind}-child-${menu.id}`,
|
|
314
|
+
title: `${childKind} child`,
|
|
315
|
+
...(childKind === 'page'
|
|
316
|
+
? { path: `/${childKind}-child-${menu.id}`, componentKey: 'dashboard' }
|
|
317
|
+
: {}),
|
|
318
|
+
}),
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
expect(
|
|
322
|
+
request(api, 'PUT', `/system/menus/${menu.id}`, {
|
|
323
|
+
kind: 'button',
|
|
324
|
+
parentId: 'menu-dashboard',
|
|
325
|
+
code: `${childKind}-with-child-button-${menu.id}`,
|
|
326
|
+
title: `${childKind} button`,
|
|
327
|
+
permission: 'workspace:dashboard:export',
|
|
328
|
+
}).body.code,
|
|
329
|
+
).toBe(40001)
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('keeps page titleKey through the runtime menu payload', () => {
|
|
334
|
+
const api = createDemoApi()
|
|
335
|
+
data(
|
|
336
|
+
request(api, 'POST', '/system/menus', {
|
|
337
|
+
kind: 'page',
|
|
338
|
+
code: 'coverage-page',
|
|
339
|
+
title: 'Coverage',
|
|
340
|
+
path: '/coverage',
|
|
341
|
+
componentKey: 'dashboard',
|
|
342
|
+
titleKey: 'menus.coverage.title',
|
|
343
|
+
}),
|
|
344
|
+
)
|
|
345
|
+
const runtime = data<{ list: Array<{ code: string, titleKey?: string }> }>(
|
|
346
|
+
request(api, 'GET', '/system/menus', undefined, 'page=1&pageSize=50'),
|
|
347
|
+
)
|
|
348
|
+
expect(
|
|
349
|
+
runtime.list.some(
|
|
350
|
+
(menu) => menu.code === 'coverage-page' && menu.titleKey === 'menus.coverage.title',
|
|
351
|
+
),
|
|
352
|
+
).toBe(true)
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('rejects structural menu writes: ghost parents, self or descendant parents, empty fields', () => {
|
|
356
|
+
const api = createDemoApi()
|
|
357
|
+
expect(
|
|
358
|
+
request(api, 'POST', '/system/menus', {
|
|
359
|
+
kind: 'page',
|
|
360
|
+
code: 'orphan',
|
|
361
|
+
title: 'Orphan',
|
|
362
|
+
path: '/orphan',
|
|
363
|
+
parentId: 'menu-nowhere',
|
|
364
|
+
}).body.code,
|
|
365
|
+
).toBe(40001)
|
|
366
|
+
expect(
|
|
367
|
+
request(api, 'POST', '/system/menus', { kind: 'page', code: '', title: 'NoCode' })
|
|
368
|
+
.body.code,
|
|
369
|
+
).toBe(40001)
|
|
370
|
+
const page = data<{ id: string }>(
|
|
371
|
+
request(api, 'POST', '/system/menus', {
|
|
372
|
+
kind: 'page',
|
|
373
|
+
code: 'self-test',
|
|
374
|
+
title: 'Self',
|
|
375
|
+
path: '/self-test',
|
|
376
|
+
componentKey: 'dashboard',
|
|
377
|
+
}),
|
|
378
|
+
)
|
|
379
|
+
expect(
|
|
380
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
381
|
+
kind: 'page',
|
|
382
|
+
parentId: page.id,
|
|
383
|
+
code: 'self-test',
|
|
384
|
+
title: 'Self',
|
|
385
|
+
path: '/self-test',
|
|
386
|
+
}).body.code,
|
|
387
|
+
).toBe(40001)
|
|
388
|
+
const child = data<{ id: string }>(
|
|
389
|
+
request(api, 'POST', '/system/menus', {
|
|
390
|
+
kind: 'page',
|
|
391
|
+
code: 'child-page',
|
|
392
|
+
title: 'Child',
|
|
393
|
+
path: 'child',
|
|
394
|
+
parentId: page.id,
|
|
395
|
+
componentKey: 'dashboard',
|
|
396
|
+
}),
|
|
397
|
+
)
|
|
398
|
+
expect(
|
|
399
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
400
|
+
kind: 'page',
|
|
401
|
+
parentId: child.id,
|
|
402
|
+
code: 'self-test',
|
|
403
|
+
title: 'Self',
|
|
404
|
+
path: '/self-test',
|
|
405
|
+
}).body.code,
|
|
406
|
+
).toBe(40001)
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
it('rejects kind conversions that orphan button children and tolerates legacy clients without version', () => {
|
|
410
|
+
const api = createDemoApi()
|
|
411
|
+
const page = data<{ id: string }>(
|
|
412
|
+
request(api, 'POST', '/system/menus', {
|
|
413
|
+
kind: 'page',
|
|
414
|
+
code: 'with-buttons',
|
|
415
|
+
title: 'Host',
|
|
416
|
+
path: '/with-buttons',
|
|
417
|
+
componentKey: 'dashboard',
|
|
418
|
+
}),
|
|
419
|
+
)
|
|
420
|
+
data(
|
|
421
|
+
request(api, 'POST', '/system/menus', {
|
|
422
|
+
kind: 'button',
|
|
423
|
+
parentId: page.id,
|
|
424
|
+
code: 'host-write',
|
|
425
|
+
title: 'Write',
|
|
426
|
+
permission: 'system:demo:write',
|
|
427
|
+
}),
|
|
428
|
+
)
|
|
429
|
+
expect(
|
|
430
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
431
|
+
kind: 'directory',
|
|
432
|
+
code: 'with-buttons',
|
|
433
|
+
title: 'Host',
|
|
434
|
+
}).body.code,
|
|
435
|
+
).toBe(40001)
|
|
436
|
+
const legacy = data<{ version: number }>(
|
|
437
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
438
|
+
kind: 'page',
|
|
439
|
+
code: 'with-buttons',
|
|
440
|
+
title: 'Host v2',
|
|
441
|
+
path: '/with-buttons',
|
|
442
|
+
}),
|
|
443
|
+
)
|
|
444
|
+
expect(legacy.version).toBeGreaterThan(1)
|
|
445
|
+
expect(
|
|
446
|
+
request(api, 'PUT', `/system/menus/${page.id}`, {
|
|
447
|
+
kind: 'page',
|
|
448
|
+
code: 'with-buttons',
|
|
449
|
+
title: 'Host v3',
|
|
450
|
+
path: '/with-buttons',
|
|
451
|
+
version: 'nope',
|
|
452
|
+
}).body.code,
|
|
453
|
+
).toBe(40901)
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('bumps version on status changes so open editors conflict instead of reverting', () => {
|
|
457
|
+
const api = createDemoApi()
|
|
458
|
+
const created = data<{ id: string, version: number }>(
|
|
459
|
+
request(api, 'POST', '/system/menus', {
|
|
460
|
+
kind: 'page',
|
|
461
|
+
code: 'status-bump',
|
|
462
|
+
title: 'Status',
|
|
463
|
+
path: '/status-bump',
|
|
464
|
+
componentKey: 'dashboard',
|
|
465
|
+
}),
|
|
466
|
+
)
|
|
467
|
+
data(request(api, 'PATCH', '/system/menus/status', { ids: [created.id], status: 'suspended' }))
|
|
468
|
+
expect(
|
|
469
|
+
request(api, 'PUT', `/system/menus/${created.id}`, {
|
|
470
|
+
kind: 'page',
|
|
471
|
+
code: 'status-bump',
|
|
472
|
+
title: 'Status v2',
|
|
473
|
+
path: '/status-bump',
|
|
474
|
+
version: created.version,
|
|
475
|
+
}).body.code,
|
|
476
|
+
).toBe(40901)
|
|
477
|
+
})
|
|
478
|
+
})
|
|
@@ -7,8 +7,26 @@ interface ImportMetaEnv {
|
|
|
7
7
|
readonly VITE_DEMO_LOGIN_HINT?: string
|
|
8
8
|
readonly VITE_ROUTE_QUERY_ENCRYPTION?: string
|
|
9
9
|
readonly VITE_ROUTE_QUERY_KEY?: string
|
|
10
|
+
/** 'true' 时意图进入微前端嵌入模式(仍需运行时探测主壳环境,见 app/embedded.ts) */
|
|
11
|
+
readonly VITE_EMBEDDED?: string
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
interface ImportMeta {
|
|
13
15
|
readonly env: ImportMetaEnv
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
/** micro-app 子应用注入环境(app/embedded.ts 探测与桥接使用) */
|
|
19
|
+
interface MicroAppChildEnv {
|
|
20
|
+
__MICRO_APP_ENVIRONMENT__?: boolean
|
|
21
|
+
__MICRO_APP_NAME__?: string
|
|
22
|
+
microApp?: {
|
|
23
|
+
getData?: () => Record<string, unknown>
|
|
24
|
+
addDataListener?: (
|
|
25
|
+
callback: (data: Record<string, unknown>) => void,
|
|
26
|
+
autoTrigger?: boolean,
|
|
27
|
+
) => void
|
|
28
|
+
dispatch?: (data: Record<string, unknown>) => void
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Window extends MicroAppChildEnv {}
|
|
@@ -3,6 +3,8 @@ import type { Component } from 'vue'
|
|
|
3
3
|
import type { ThemeMode } from '../store/theme'
|
|
4
4
|
import { Check, Monitor, Moon, Sunny } from '@element-plus/icons-vue'
|
|
5
5
|
import { ElColorPicker, ElDropdownItem, ElDropdownMenu, ElIcon } from 'element-plus'
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
import { useI18n } from 'vue-i18n'
|
|
6
8
|
import { useTheme } from '../composables/useTheme'
|
|
7
9
|
|
|
8
10
|
defineOptions({ name: 'ThemePanel' })
|
|
@@ -13,19 +15,21 @@ interface ThemeModeOption {
|
|
|
13
15
|
icon: Component
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
{ value: 'light', label: '浅色', icon: Sunny },
|
|
18
|
-
{ value: 'dark', label: '深色', icon: Moon },
|
|
19
|
-
{ value: 'auto', label: '跟随系统', icon: Monitor },
|
|
20
|
-
]
|
|
18
|
+
const { t } = useI18n()
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
{
|
|
24
|
-
{
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const modeOptions = computed<ThemeModeOption[]>(() => [
|
|
21
|
+
{ value: 'light', label: t('appearance.light'), icon: Sunny },
|
|
22
|
+
{ value: 'dark', label: t('appearance.dark'), icon: Moon },
|
|
23
|
+
{ value: 'auto', label: t('appearance.system'), icon: Monitor },
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const primaryPresets = computed(() => [
|
|
27
|
+
{ label: t('appearance.presetIndigo'), value: '#5E6AD2' },
|
|
28
|
+
{ label: t('appearance.presetBlue'), value: '#2563EB' },
|
|
29
|
+
{ label: t('appearance.presetTeal'), value: '#0F766E' },
|
|
30
|
+
{ label: t('appearance.presetRose'), value: '#DB2777' },
|
|
31
|
+
{ label: t('appearance.presetAmber'), value: '#D97706' },
|
|
32
|
+
])
|
|
29
33
|
|
|
30
34
|
const { mode, primary, setMode, setPrimary } = useTheme()
|
|
31
35
|
</script>
|
|
@@ -33,7 +37,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
33
37
|
<template>
|
|
34
38
|
<ElDropdownMenu class="theme-panel">
|
|
35
39
|
<ElDropdownItem class="theme-panel__section" disabled>
|
|
36
|
-
<span
|
|
40
|
+
<span>{{ t('appearance.theme') }}</span>
|
|
37
41
|
</ElDropdownItem>
|
|
38
42
|
<ElDropdownItem
|
|
39
43
|
v-for="option in modeOptions"
|
|
@@ -53,8 +57,8 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
53
57
|
|
|
54
58
|
<li class="theme-panel__separator" aria-hidden="true" />
|
|
55
59
|
<li class="theme-panel__primary">
|
|
56
|
-
<span class="theme-panel__section-label"
|
|
57
|
-
<div class="theme-panel__swatches" aria-label="
|
|
60
|
+
<span class="theme-panel__section-label">{{ t('appearance.primaryColor') }}</span>
|
|
61
|
+
<div class="theme-panel__swatches" :aria-label="t('appearance.primaryPresets')">
|
|
58
62
|
<button
|
|
59
63
|
v-for="preset in primaryPresets"
|
|
60
64
|
:key="preset.value"
|
|
@@ -62,7 +66,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
62
66
|
class="theme-panel__swatch"
|
|
63
67
|
:class="{ 'is-active': primary === preset.value }"
|
|
64
68
|
:style="{ backgroundColor: preset.value }"
|
|
65
|
-
:aria-label="
|
|
69
|
+
:aria-label="t('appearance.usePrimary', { color: preset.label })"
|
|
66
70
|
:aria-pressed="primary === preset.value"
|
|
67
71
|
@click.stop="setPrimary(preset.value)"
|
|
68
72
|
>
|
|
@@ -73,7 +77,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
73
77
|
</div>
|
|
74
78
|
</li>
|
|
75
79
|
<li class="theme-panel__custom">
|
|
76
|
-
<span
|
|
80
|
+
<span>{{ t('appearance.custom') }}</span>
|
|
77
81
|
<div class="theme-panel__picker">
|
|
78
82
|
<ElColorPicker
|
|
79
83
|
:model-value="primary"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { PrimaryPalette } from '../../../utils/color-mix'
|
|
1
2
|
import { defineStore } from 'pinia'
|
|
2
3
|
import { computed, shallowRef } from 'vue'
|
|
3
|
-
import { derivePrimaryPalette
|
|
4
|
+
import { derivePrimaryPalette } from '../../../utils/color-mix'
|
|
4
5
|
|
|
5
6
|
const STORAGE_KEY = 'og-admin-theme'
|
|
6
7
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ElAlert, ElButton, ElCard, ElForm, ElFormItem, ElInput } from 'element-plus'
|
|
3
3
|
import { reactive, shallowRef } from 'vue'
|
|
4
|
+
import { useI18n } from 'vue-i18n'
|
|
4
5
|
import { useRoute, useRouter } from 'vue-router'
|
|
6
|
+
import { translateAdminError } from '../../../app/errorMessage'
|
|
7
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
5
8
|
import { useAuthStore } from '../store/auth'
|
|
6
9
|
|
|
7
10
|
defineOptions({ name: 'LoginPage' })
|
|
8
11
|
const auth = useAuthStore()
|
|
9
12
|
const route = useRoute()
|
|
10
13
|
const router = useRouter()
|
|
14
|
+
const { t } = useI18n()
|
|
11
15
|
const loading = shallowRef(false)
|
|
12
16
|
const errorMessage = shallowRef('')
|
|
13
17
|
const form = reactive({ username: '', password: '' })
|
|
@@ -15,17 +19,21 @@ const demoLoginHint = import.meta.env.VITE_DEMO_LOGIN_HINT
|
|
|
15
19
|
|
|
16
20
|
async function submit(): Promise<void> {
|
|
17
21
|
if (!form.username || !form.password) {
|
|
18
|
-
errorMessage.value = '
|
|
22
|
+
errorMessage.value = t('auth.requiredCredentials')
|
|
19
23
|
return
|
|
20
24
|
}
|
|
21
25
|
loading.value = true
|
|
22
26
|
errorMessage.value = ''
|
|
23
27
|
try {
|
|
24
28
|
await auth.login(form)
|
|
25
|
-
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect :
|
|
29
|
+
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : HOME_ROUTE
|
|
26
30
|
await router.push(redirect)
|
|
27
31
|
} catch (error: unknown) {
|
|
28
|
-
errorMessage.value = error
|
|
32
|
+
errorMessage.value = translateAdminError(error, {
|
|
33
|
+
domain: 'auth',
|
|
34
|
+
fallbackKey: 'auth.loginFailed',
|
|
35
|
+
fallback: t('auth.loginFailed'),
|
|
36
|
+
})
|
|
29
37
|
} finally {
|
|
30
38
|
loading.value = false
|
|
31
39
|
}
|
|
@@ -38,10 +46,10 @@ async function submit(): Promise<void> {
|
|
|
38
46
|
<div class="login-card__intro">
|
|
39
47
|
<div class="login-card__mark">HS</div>
|
|
40
48
|
<p class="login-card__eyebrow">@origen-ui Admin</p>
|
|
41
|
-
<h1
|
|
42
|
-
<p
|
|
49
|
+
<h1>{{ t('workspace.welcome') }}</h1>
|
|
50
|
+
<p>{{ t('auth.signInDescription') }}</p>
|
|
43
51
|
</div>
|
|
44
|
-
<p v-if="demoLoginHint" class="login-card__hint"
|
|
52
|
+
<p v-if="demoLoginHint" class="login-card__hint">{{ t('auth.demoHint') }}:{{ demoLoginHint }}</p>
|
|
45
53
|
<ElAlert
|
|
46
54
|
v-if="errorMessage"
|
|
47
55
|
class="login-card__alert"
|
|
@@ -49,27 +57,29 @@ async function submit(): Promise<void> {
|
|
|
49
57
|
type="error"
|
|
50
58
|
:closable="false"
|
|
51
59
|
/>
|
|
52
|
-
<ElForm label-position="top" @submit.prevent="submit">
|
|
53
|
-
<ElFormItem label="
|
|
60
|
+
<ElForm :model="form" label-position="top" @submit.prevent="submit">
|
|
61
|
+
<ElFormItem prop="username" :label="t('auth.username')">
|
|
54
62
|
<ElInput
|
|
63
|
+
id="username"
|
|
55
64
|
v-model="form.username"
|
|
56
65
|
autocomplete="username"
|
|
57
|
-
placeholder="
|
|
66
|
+
:placeholder="t('auth.usernamePlaceholder')"
|
|
58
67
|
@keyup.enter="submit"
|
|
59
68
|
/>
|
|
60
69
|
</ElFormItem>
|
|
61
|
-
<ElFormItem label="
|
|
70
|
+
<ElFormItem prop="password" :label="t('auth.password')">
|
|
62
71
|
<ElInput
|
|
72
|
+
id="password"
|
|
63
73
|
v-model="form.password"
|
|
64
74
|
type="password"
|
|
65
75
|
show-password
|
|
66
76
|
autocomplete="current-password"
|
|
67
|
-
placeholder="
|
|
77
|
+
:placeholder="t('auth.passwordPlaceholder')"
|
|
68
78
|
@keyup.enter="submit"
|
|
69
79
|
/>
|
|
70
80
|
</ElFormItem>
|
|
71
81
|
<ElButton class="login-card__submit" type="primary" :loading="loading" @click="submit">
|
|
72
|
-
|
|
82
|
+
{{ t('auth.login') }}
|
|
73
83
|
</ElButton>
|
|
74
84
|
</ElForm>
|
|
75
85
|
</ElCard>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ApiBusinessError } from '@origen-ui/http'
|
|
2
2
|
import type { Permission } from '@origen-ui/shared'
|
|
3
|
-
import { ApiBusinessError as ApiBusinessErrorClass } from '@origen-ui/http'
|
|
4
3
|
import { hasCodePermission } from '@origen-ui/permission/codes'
|
|
5
4
|
import { defineStore } from 'pinia'
|
|
6
5
|
import { apiClient, tokenManager } from '../../../api/client'
|
|
6
|
+
import { adminErrorKey, createAdminError } from '../../../app/errorMessage'
|
|
7
7
|
|
|
8
8
|
export interface AdminUser {
|
|
9
9
|
id: string
|
|
@@ -101,7 +101,7 @@ function cacheProfile(session: AdminSession): void {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function parseLoginPayload(value: unknown): LoginPayload {
|
|
104
|
-
if (!isRecord(value)) throw
|
|
104
|
+
if (!isRecord(value)) throw createAdminError('auth.invalidResponse')
|
|
105
105
|
return {
|
|
106
106
|
token: readString(value.token),
|
|
107
107
|
accessToken: readString(value.accessToken),
|
|
@@ -127,11 +127,6 @@ function parseProfile(value: unknown, fallbackUsername: string): Omit<AdminSessi
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
function errorMessage(error: unknown): string {
|
|
131
|
-
if (error instanceof ApiBusinessErrorClass || error instanceof Error) return error.message
|
|
132
|
-
return '请求失败'
|
|
133
|
-
}
|
|
134
|
-
|
|
135
130
|
export const useAuthStore = defineStore('admin-auth', {
|
|
136
131
|
state: (): { session: AdminSession | null } => ({ session: null }),
|
|
137
132
|
getters: {
|
|
@@ -152,7 +147,7 @@ export const useAuthStore = defineStore('admin-auth', {
|
|
|
152
147
|
})
|
|
153
148
|
const payload = parseLoginPayload(response)
|
|
154
149
|
const token = payload.accessToken ?? payload.token
|
|
155
|
-
if (!token) throw
|
|
150
|
+
if (!token) throw createAdminError('auth.missingToken')
|
|
156
151
|
const session: AdminSession = {
|
|
157
152
|
token,
|
|
158
153
|
user: normalizeUser(payload.user, credentials.username),
|
|
@@ -166,7 +161,9 @@ export const useAuthStore = defineStore('admin-auth', {
|
|
|
166
161
|
cacheProfile(session)
|
|
167
162
|
return session
|
|
168
163
|
} catch (error: unknown) {
|
|
169
|
-
|
|
164
|
+
const key = adminErrorKey(error, { domain: 'auth', fallbackKey: 'auth.loginFailed' })
|
|
165
|
+
console.error('[admin] login failed', error)
|
|
166
|
+
throw createAdminError(key, error)
|
|
170
167
|
}
|
|
171
168
|
},
|
|
172
169
|
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ElButton, ElResult } from 'element-plus'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
3
4
|
import { useRouter } from 'vue-router'
|
|
5
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
4
6
|
|
|
5
7
|
defineOptions({ name: 'ForbiddenPage' })
|
|
6
8
|
|
|
7
9
|
const router = useRouter()
|
|
10
|
+
const { t } = useI18n()
|
|
8
11
|
</script>
|
|
9
12
|
|
|
10
13
|
<template>
|
|
11
14
|
<main class="error-page">
|
|
12
|
-
<ElResult icon="warning" title="
|
|
15
|
+
<ElResult icon="warning" :title="t('errors.forbidden.code')" :sub-title="t('errors.forbidden.message')">
|
|
13
16
|
<template #extra>
|
|
14
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
18
|
+
{{ t('errors.forbidden.backHome') }}
|
|
19
|
+
</ElButton>
|
|
15
20
|
</template>
|
|
16
21
|
</ElResult>
|
|
17
22
|
</main>
|