@origen-ui/admin-cli 1.1.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -9
- package/package.json +26 -2
- package/templates/current/clean/.node-version +1 -0
- package/templates/current/clean/CHANGELOG.md +125 -0
- package/templates/current/clean/README.md +2 -1
- package/templates/current/clean/component-catalog.json +58 -17
- package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/clean/package.json +39 -25
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/pnpm-workspace.yaml +18 -0
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/scripts/demo-api.ts +88 -12
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/remove-examples.mjs +4 -4
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/clean/src/api/generated/http-client.ts +28 -26
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/clean/src/app/errorMessage.ts +53 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +39 -0
- package/templates/current/clean/src/app/menu.ts +48 -12
- package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
- package/templates/current/clean/src/demo-api.spec.ts +314 -3
- package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
- package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/clean/src/layouts/TopBar.vue +37 -6
- package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/clean/src/locales/en-US.json +30 -3
- package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/clean/src/locales/index.ts +39 -26
- package/templates/current/clean/src/locales/zh-CN.json +30 -3
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/clean/src/locales/zh-TW.json +30 -3
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +10 -16
- package/templates/current/clean/src/router/componentCache.ts +12 -0
- package/templates/current/clean/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/clean/src/router/paths.spec.ts +50 -0
- package/templates/current/clean/src/router/paths.ts +21 -0
- package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/clean/src/router/routeQuery.ts +4 -1
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/templates/og-table.ts +2 -4
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +55 -8
- package/templates/current/clean/vite.config.ts +30 -0
- package/templates/current/examples/.node-version +1 -0
- package/templates/current/examples/CHANGELOG.md +125 -0
- package/templates/current/examples/README.md +2 -1
- package/templates/current/examples/component-catalog.json +58 -17
- package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/examples/package.json +39 -25
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/pnpm-workspace.yaml +18 -0
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/examples/scripts/demo-api.ts +88 -12
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/remove-examples.mjs +4 -4
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/examples/src/api/generated/http-client.ts +28 -26
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/examples/src/app/errorMessage.ts +53 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +39 -0
- package/templates/current/examples/src/app/menu.ts +48 -12
- package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
- package/templates/current/examples/src/demo-api.spec.ts +314 -3
- package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/examples/src/layouts/TopBar.vue +37 -6
- package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/examples/src/locales/en-US.json +30 -3
- package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/examples/src/locales/index.ts +39 -26
- package/templates/current/examples/src/locales/zh-CN.json +30 -3
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/examples/src/locales/zh-TW.json +30 -3
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/examples/src/main.ts +24 -22
- package/templates/current/examples/src/router/bootstrap.ts +10 -16
- package/templates/current/examples/src/router/componentCache.ts +18 -0
- package/templates/current/examples/src/router/componentRegistry.ts +1 -18
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/examples/src/router/paths.spec.ts +50 -0
- package/templates/current/examples/src/router/paths.ts +21 -0
- package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/examples/src/router/routeQuery.ts +4 -1
- package/templates/current/examples/src/router/staticRoutes.ts +3 -3
- package/templates/current/examples/src/templates/og-table.ts +2 -4
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +55 -8
- package/templates/current/examples/vite.config.ts +30 -0
package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue
CHANGED
|
@@ -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: 'NotFoundPage' })
|
|
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.notFound.code')" :sub-title="t('errors.notFound.message')">
|
|
13
16
|
<template #extra>
|
|
14
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
18
|
+
{{ t('errors.notFound.backHome') }}
|
|
19
|
+
</ElButton>
|
|
15
20
|
</template>
|
|
16
21
|
</ElResult>
|
|
17
22
|
</main>
|
package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue
CHANGED
|
@@ -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: 'ServerErrorPage' })
|
|
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="error" title="
|
|
15
|
+
<ElResult icon="error" :title="t('errors.serverError.code')" :sub-title="t('errors.serverError.message')">
|
|
13
16
|
<template #extra>
|
|
14
|
-
<ElButton type="primary" @click="router.push(
|
|
17
|
+
<ElButton type="primary" @click="router.push(HOME_ROUTE)">
|
|
18
|
+
{{ t('errors.serverError.backHome') }}
|
|
19
|
+
</ElButton>
|
|
15
20
|
</template>
|
|
16
21
|
</ElResult>
|
|
17
22
|
</main>
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { mount } from '@vue/test-utils'
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { createI18n } from 'vue-i18n'
|
|
4
|
+
import zhCN from '../../../locales/zh-CN.json'
|
|
5
|
+
import { HOME_ROUTE } from '../../../router/paths'
|
|
3
6
|
import Forbidden from './Forbidden.vue'
|
|
4
7
|
import NotFound from './NotFound.vue'
|
|
5
8
|
import ServerError from './ServerError.vue'
|
|
6
9
|
|
|
10
|
+
const i18n = createI18n({
|
|
11
|
+
legacy: false,
|
|
12
|
+
locale: 'zh-CN',
|
|
13
|
+
messages: { 'zh-CN': zhCN },
|
|
14
|
+
})
|
|
15
|
+
|
|
7
16
|
const { push } = vi.hoisted(() => ({
|
|
8
17
|
push: vi.fn(),
|
|
9
18
|
}))
|
|
@@ -22,11 +31,11 @@ describe('clean error page navigation', () => {
|
|
|
22
31
|
['404', NotFound],
|
|
23
32
|
['500', ServerError],
|
|
24
33
|
])('returns to the empty workspace from the %s page', async (_status, component) => {
|
|
25
|
-
const wrapper = mount(component)
|
|
34
|
+
const wrapper = mount(component, { global: { plugins: [i18n] } })
|
|
26
35
|
|
|
27
36
|
await wrapper.get('button').trigger('click')
|
|
28
37
|
|
|
29
38
|
expect(push).toHaveBeenCalledOnce()
|
|
30
|
-
expect(push).toHaveBeenCalledWith(
|
|
39
|
+
expect(push).toHaveBeenCalledWith(HOME_ROUTE)
|
|
31
40
|
})
|
|
32
41
|
})
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createApp } from 'vue'
|
|
2
2
|
import App from './App.vue'
|
|
3
|
+
import { translateAdminError } from './app/errorMessage'
|
|
3
4
|
import { permission } from './app/permission'
|
|
4
5
|
import { useAuthStore } from './features/auth/store/auth'
|
|
5
6
|
import { devtoolsProtection } from './features/security/devtoolsProtection'
|
|
7
|
+
import { translateAdminMessage } from './locales'
|
|
8
|
+
import { replaceDynamicMenusWithAccessibleFallback } from './router/dynamicMenuRefresh'
|
|
6
9
|
import { createRuntimeErrorRecovery, createStaleAssetRecovery } from './router/runtimeErrorRecovery'
|
|
7
10
|
import { pinia } from './store'
|
|
8
11
|
import 'element-plus/theme-chalk/src/tabs.scss'
|
|
@@ -46,43 +49,49 @@ async function bootstrap(): Promise<void> {
|
|
|
46
49
|
language.install(app)
|
|
47
50
|
const { createAdminUi } = await import('./app/createAdminUi')
|
|
48
51
|
app.use(createAdminUi(language))
|
|
52
|
+
// 唯一的 errorHandler 装配点:运行期错误统一走提示 + 陈旧资源/运行时恢复。
|
|
49
53
|
app.config.errorHandler = (error: unknown) => {
|
|
50
|
-
|
|
54
|
+
console.error('[admin] runtime error', error)
|
|
55
|
+
const message = translateAdminError(error, {
|
|
56
|
+
fallbackKey: 'common.errors.unknownPageError',
|
|
57
|
+
fallback: '页面发生未知错误',
|
|
58
|
+
})
|
|
51
59
|
void notifyRuntimeError(message)
|
|
60
|
+
if (!staleAssetRecovery.handle(error)) recoverRuntimeError()
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
const auth = useAuthStore(pinia)
|
|
55
64
|
const session = await auth.fetchSession()
|
|
56
65
|
app.use(routing)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
])
|
|
62
|
-
|
|
66
|
+
// 路由就绪是硬性等待;布局仅在登录态下并行预热。catch-tap 保证路由先失败
|
|
67
|
+
// 时预热 rejection 不会变成 unhandled——两个失败最终都按启动失败上报。
|
|
68
|
+
const layoutPreload = session ? import('./layouts/AdminLayout.vue') : undefined
|
|
69
|
+
layoutPreload?.catch(() => {})
|
|
70
|
+
await Promise.all([language.ready, routing.ready()])
|
|
71
|
+
await layoutPreload
|
|
63
72
|
const { authorizationRefreshKey } =
|
|
64
73
|
await import('./features/system/access/composables/useAuthorizationRefresh')
|
|
65
|
-
app.config.errorHandler = (error, instance, info) => {
|
|
66
|
-
reportRuntimeError?.(error, instance, info)
|
|
67
|
-
if (!staleAssetRecovery.handle(error)) recoverRuntimeError()
|
|
68
|
-
}
|
|
69
74
|
app.provide(authorizationRefreshKey, async () => {
|
|
70
75
|
await auth.refreshAuthorization()
|
|
71
|
-
await routing
|
|
76
|
+
await replaceDynamicMenusWithAccessibleFallback(routing)
|
|
72
77
|
})
|
|
73
78
|
app.mount('#app')
|
|
74
79
|
staleAssetRecovery.clear()
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
void bootstrap().catch((error: unknown) => {
|
|
78
|
-
|
|
83
|
+
console.error('[admin] startup failed', error)
|
|
84
|
+
const message = translateAdminError(error, {
|
|
85
|
+
fallbackKey: 'common.errors.startupFailed',
|
|
86
|
+
fallback: '应用启动失败',
|
|
87
|
+
})
|
|
79
88
|
const root = document.querySelector('#app')
|
|
80
89
|
if (root) {
|
|
81
90
|
const panel = document.createElement('main')
|
|
82
91
|
panel.style.padding = '32px'
|
|
83
92
|
panel.style.fontFamily = 'system-ui, sans-serif'
|
|
84
93
|
const heading = document.createElement('h1')
|
|
85
|
-
heading.textContent = '@origen-ui/admin 启动失败'
|
|
94
|
+
heading.textContent = `${'@origen-ui/admin'} ${translateAdminMessage('common.errors.startupFailed', { fallback: '启动失败' })}`
|
|
86
95
|
const detail = document.createElement('p')
|
|
87
96
|
detail.textContent = message
|
|
88
97
|
panel.append(heading, detail)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
|
|
3
|
+
*
|
|
4
|
+
* KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
|
|
5
|
+
* 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
|
|
6
|
+
* 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
|
|
7
|
+
*/
|
|
8
|
+
export const componentCacheNames: Readonly<Record<string, string>> = {
|
|
9
|
+
workspace: 'EmptyPage',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const fallbackComponentKey = 'workspace'
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import type { Component } from 'vue'
|
|
2
2
|
import { RouterViewHost } from '@origen-ui/router'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
|
|
8
|
-
*
|
|
9
|
-
* KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
|
|
10
|
-
* 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
|
|
11
|
-
* 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
|
|
12
|
-
*/
|
|
13
|
-
export const componentCacheNames: Readonly<Record<string, string>> = {
|
|
14
|
-
workspace: 'EmptyPage',
|
|
15
|
-
}
|
|
4
|
+
export { componentCacheNames, fallbackComponentKey } from './componentCache'
|
|
16
5
|
|
|
17
|
-
|
|
6
|
+
type ComponentLoader = () => Promise<Component>
|
|
18
7
|
|
|
19
8
|
export const componentRegistry: Map<string, ComponentLoader> = new Map([
|
|
20
9
|
[
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { componentCacheNames } from './
|
|
3
|
-
import { componentRegistry
|
|
2
|
+
import { componentCacheNames } from './componentCache'
|
|
3
|
+
import { componentRegistry } from './componentRegistry'
|
|
4
|
+
import { routeTransformer } from './dynamicRoutes'
|
|
4
5
|
import { staticRoutes } from './staticRoutes'
|
|
5
6
|
|
|
6
7
|
describe('clean dynamic component registry', () => {
|
|
@@ -16,6 +17,23 @@ describe('clean dynamic component registry', () => {
|
|
|
16
17
|
expect(route?.componentKey).toBe('workspace')
|
|
17
18
|
expect(componentRegistry.has('workspace')).toBe(true)
|
|
18
19
|
})
|
|
20
|
+
|
|
21
|
+
it('rejects flat parentPath entries whose parent route does not exist', () => {
|
|
22
|
+
expect(() =>
|
|
23
|
+
routeTransformer([
|
|
24
|
+
{ code: 'orphan', path: 'orphan', parentPath: '/missing', title: 'Orphan' },
|
|
25
|
+
]),
|
|
26
|
+
).toThrow('Unresolved dynamic route parent path: /missing')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('rejects duplicate route codes with an explicit error', () => {
|
|
30
|
+
expect(() =>
|
|
31
|
+
routeTransformer([
|
|
32
|
+
{ code: 'dup', path: '/first', title: 'First' },
|
|
33
|
+
{ code: 'dup', path: '/second', title: 'Second' },
|
|
34
|
+
]),
|
|
35
|
+
).toThrow('Duplicate dynamic route code: dup')
|
|
36
|
+
})
|
|
19
37
|
})
|
|
20
38
|
|
|
21
39
|
describe('clean keep-alive cache names', () => {
|
|
@@ -25,7 +43,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
25
43
|
|
|
26
44
|
it('generates cache.name from the component name mapping for cached dynamic routes', () => {
|
|
27
45
|
const [workspace] = routeTransformer([
|
|
28
|
-
{
|
|
46
|
+
{
|
|
47
|
+
code: 'workspace',
|
|
48
|
+
path: '/workspace',
|
|
49
|
+
title: 'Workspace',
|
|
50
|
+
componentKey: 'workspace',
|
|
51
|
+
cache: true,
|
|
52
|
+
},
|
|
29
53
|
])
|
|
30
54
|
|
|
31
55
|
expect(workspace?.meta?.cache).toEqual({ enabled: true, name: 'EmptyPage' })
|
|
@@ -33,7 +57,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
33
57
|
|
|
34
58
|
it('omits cache meta when the source disables caching', () => {
|
|
35
59
|
const [workspace] = routeTransformer([
|
|
36
|
-
{
|
|
60
|
+
{
|
|
61
|
+
code: 'workspace',
|
|
62
|
+
path: '/workspace',
|
|
63
|
+
title: 'Workspace',
|
|
64
|
+
componentKey: 'workspace',
|
|
65
|
+
cache: false,
|
|
66
|
+
},
|
|
37
67
|
])
|
|
38
68
|
|
|
39
69
|
expect(workspace?.meta?.cache).toBeUndefined()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RouteMenuItem } from '@origen-ui/router'
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
/** 授权后的默认首页路由;与 staticRoutes 根路由 redirect 由 paths.spec 钉住一致。 */
|
|
5
|
+
export const HOME_ROUTE = '/workspace'
|
|
6
|
+
|
|
7
|
+
/** staticRoutes 中 404 兜底页的路由名。 */
|
|
8
|
+
export const NOT_FOUND_ROUTE_NAME = '404'
|
|
9
|
+
|
|
10
|
+
/** 深度优先取菜单树中首个可导航入口;isReachable 用于剔除重定向到已裁撤路由的目录项。 */
|
|
11
|
+
export function firstMenuTarget(
|
|
12
|
+
items: readonly RouteMenuItem[],
|
|
13
|
+
isReachable: (to: RouteLocationRaw) => boolean = () => true,
|
|
14
|
+
): RouteLocationRaw | undefined {
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
if (item.to && isReachable(item.to)) return item.to
|
|
17
|
+
const child = firstMenuTarget(item.children, isReachable)
|
|
18
|
+
if (child) return child
|
|
19
|
+
}
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
@@ -26,7 +26,7 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
26
26
|
path: '/login',
|
|
27
27
|
name: 'login',
|
|
28
28
|
component: Login,
|
|
29
|
-
meta: { adapter: {
|
|
29
|
+
meta: { adapter: { titleKey: 'auth.login', ...hiddenPublic } },
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
path: '/profile',
|
|
@@ -34,10 +34,10 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
34
34
|
component: Profile,
|
|
35
35
|
meta: {
|
|
36
36
|
adapter: {
|
|
37
|
-
|
|
37
|
+
titleKey: 'menu.profile',
|
|
38
38
|
icon: 'profile',
|
|
39
39
|
menu: { order: 20 },
|
|
40
|
-
breadcrumb: {
|
|
40
|
+
breadcrumb: { labelKey: 'menu.profile' },
|
|
41
41
|
cache: { enabled: true, name: 'ProfilePage' },
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -46,18 +46,18 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
46
46
|
path: '/403',
|
|
47
47
|
name: '403',
|
|
48
48
|
component: Forbidden,
|
|
49
|
-
meta: { adapter: {
|
|
49
|
+
meta: { adapter: { titleKey: 'errors.forbidden.title', ...hiddenPublic } },
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
path: '/404',
|
|
53
53
|
name: '404',
|
|
54
54
|
component: NotFound,
|
|
55
|
-
meta: { adapter: {
|
|
55
|
+
meta: { adapter: { titleKey: 'errors.notFound.title', ...hiddenPublic } },
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
path: '/500',
|
|
59
59
|
name: '500',
|
|
60
60
|
component: ServerError,
|
|
61
|
-
meta: { adapter: {
|
|
61
|
+
meta: { adapter: { titleKey: 'errors.serverError.title', ...hiddenPublic } },
|
|
62
62
|
},
|
|
63
63
|
]
|
|
@@ -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>)
|
|
@@ -214,7 +250,7 @@ function initialState() {
|
|
|
214
250
|
const users: DemoUser[] = [
|
|
215
251
|
{
|
|
216
252
|
id: 'user-admin',
|
|
217
|
-
username: 'admin',
|
|
253
|
+
username: 'demo-admin',
|
|
218
254
|
name: 'Demo Administrator',
|
|
219
255
|
email: 'admin@example.test',
|
|
220
256
|
department: 'Platform',
|
|
@@ -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
|
},
|
|
@@ -429,7 +477,7 @@ export function createDemoApi(): DemoApi {
|
|
|
429
477
|
const body = asRecord(request.body)
|
|
430
478
|
|
|
431
479
|
if (method === 'POST' && path === '/auth/login') {
|
|
432
|
-
if (body.username !== 'admin' || body.password !== '
|
|
480
|
+
if (body.username !== 'demo-admin' || body.password !== 'demo-password')
|
|
433
481
|
return failure('Invalid demo credentials.', 40101)
|
|
434
482
|
return envelope({
|
|
435
483
|
accessToken: ADMIN_TOKEN,
|
|
@@ -437,7 +485,7 @@ export function createDemoApi(): DemoApi {
|
|
|
437
485
|
refreshToken: REFRESH_TOKEN,
|
|
438
486
|
user: {
|
|
439
487
|
id: 'user-admin',
|
|
440
|
-
username: 'admin',
|
|
488
|
+
username: 'demo-admin',
|
|
441
489
|
displayName: 'Demo Administrator',
|
|
442
490
|
email: 'admin@example.test',
|
|
443
491
|
},
|
|
@@ -455,7 +503,7 @@ export function createDemoApi(): DemoApi {
|
|
|
455
503
|
return envelope({
|
|
456
504
|
user: {
|
|
457
505
|
id: 'user-admin',
|
|
458
|
-
username: 'admin',
|
|
506
|
+
username: 'demo-admin',
|
|
459
507
|
displayName: 'Demo Administrator',
|
|
460
508
|
email: 'admin@example.test',
|
|
461
509
|
},
|
|
@@ -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))
|