@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { useAuthorizationPolling } from './useAuthorizationPolling'
|
|
3
|
+
|
|
4
|
+
interface HarnessOptions {
|
|
5
|
+
local?: number | undefined
|
|
6
|
+
remote?: number
|
|
7
|
+
confirmed?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function createHarness({ local, remote = 1, confirmed = true }: HarnessOptions = {}) {
|
|
11
|
+
const fetchRemoteRevision = vi.fn(async () => remote)
|
|
12
|
+
const getLocalRevision = vi.fn(() => local)
|
|
13
|
+
const confirmDrift = vi.fn(async () => confirmed)
|
|
14
|
+
const onDrift = vi.fn(async () => {})
|
|
15
|
+
const polling = useAuthorizationPolling({
|
|
16
|
+
intervalMs: 30_000,
|
|
17
|
+
fetchRemoteRevision,
|
|
18
|
+
getLocalRevision,
|
|
19
|
+
confirmDrift,
|
|
20
|
+
onDrift,
|
|
21
|
+
})
|
|
22
|
+
return { polling, fetchRemoteRevision, getLocalRevision, confirmDrift, onDrift }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('useAuthorizationPolling', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.useFakeTimers()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
vi.useRealTimers()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('skips checks while the session has no revision', async () => {
|
|
35
|
+
const { polling, fetchRemoteRevision, confirmDrift } = createHarness({ local: undefined })
|
|
36
|
+
|
|
37
|
+
await polling.checkOnce()
|
|
38
|
+
|
|
39
|
+
expect(fetchRemoteRevision).not.toHaveBeenCalled()
|
|
40
|
+
expect(confirmDrift).not.toHaveBeenCalled()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('does nothing when revisions match', async () => {
|
|
44
|
+
const { polling, confirmDrift, onDrift } = createHarness({ local: 1, remote: 1 })
|
|
45
|
+
|
|
46
|
+
await polling.checkOnce()
|
|
47
|
+
|
|
48
|
+
expect(confirmDrift).not.toHaveBeenCalled()
|
|
49
|
+
expect(onDrift).not.toHaveBeenCalled()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('prompts and refreshes on drift when confirmed', async () => {
|
|
53
|
+
const { polling, confirmDrift, onDrift } = createHarness({
|
|
54
|
+
local: 1,
|
|
55
|
+
remote: 2,
|
|
56
|
+
confirmed: true,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
await polling.checkOnce()
|
|
60
|
+
|
|
61
|
+
expect(confirmDrift).toHaveBeenCalledTimes(1)
|
|
62
|
+
expect(onDrift).toHaveBeenCalledTimes(1)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('keeps polling when the user postpones the refresh', async () => {
|
|
66
|
+
const { polling, confirmDrift, onDrift } = createHarness({
|
|
67
|
+
local: 1,
|
|
68
|
+
remote: 2,
|
|
69
|
+
confirmed: false,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
await polling.checkOnce()
|
|
73
|
+
expect(onDrift).not.toHaveBeenCalled()
|
|
74
|
+
|
|
75
|
+
await polling.checkOnce()
|
|
76
|
+
expect(confirmDrift).toHaveBeenCalledTimes(2)
|
|
77
|
+
expect(onDrift).not.toHaveBeenCalled()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('stays silent when a revision fetch fails', async () => {
|
|
81
|
+
const fetchRemoteRevision = vi.fn(async () => {
|
|
82
|
+
throw new Error('network down')
|
|
83
|
+
})
|
|
84
|
+
const { checkOnce } = useAuthorizationPolling({
|
|
85
|
+
intervalMs: 30_000,
|
|
86
|
+
fetchRemoteRevision,
|
|
87
|
+
getLocalRevision: () => 1,
|
|
88
|
+
confirmDrift: vi.fn(async () => true),
|
|
89
|
+
onDrift: vi.fn(async () => {}),
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
await expect(checkOnce()).resolves.toBeUndefined()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('ignores overlapping checks while one is in flight', async () => {
|
|
96
|
+
let resolveFetch: (value: number) => void = () => {}
|
|
97
|
+
const fetchRemoteRevision = vi.fn(
|
|
98
|
+
() =>
|
|
99
|
+
new Promise<number>((resolve) => {
|
|
100
|
+
resolveFetch = resolve
|
|
101
|
+
}),
|
|
102
|
+
)
|
|
103
|
+
const confirmDrift = vi.fn(async () => true)
|
|
104
|
+
const onDrift = vi.fn(async () => {})
|
|
105
|
+
const polling = useAuthorizationPolling({
|
|
106
|
+
intervalMs: 30_000,
|
|
107
|
+
fetchRemoteRevision,
|
|
108
|
+
getLocalRevision: () => 1,
|
|
109
|
+
confirmDrift,
|
|
110
|
+
onDrift,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const first = polling.checkOnce()
|
|
114
|
+
const second = polling.checkOnce()
|
|
115
|
+
resolveFetch(2)
|
|
116
|
+
await Promise.all([first, second])
|
|
117
|
+
|
|
118
|
+
expect(fetchRemoteRevision).toHaveBeenCalledTimes(1)
|
|
119
|
+
expect(confirmDrift).toHaveBeenCalledTimes(1)
|
|
120
|
+
expect(onDrift).toHaveBeenCalledTimes(1)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('starts and stops on the configured interval', async () => {
|
|
124
|
+
const { polling, fetchRemoteRevision } = createHarness({ local: 1, remote: 1 })
|
|
125
|
+
|
|
126
|
+
polling.start()
|
|
127
|
+
await vi.advanceTimersByTimeAsync(30_000)
|
|
128
|
+
expect(fetchRemoteRevision).toHaveBeenCalledTimes(1)
|
|
129
|
+
|
|
130
|
+
polling.stop()
|
|
131
|
+
await vi.advanceTimersByTimeAsync(60_000)
|
|
132
|
+
expect(fetchRemoteRevision).toHaveBeenCalledTimes(1)
|
|
133
|
+
})
|
|
134
|
+
})
|
package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getCurrentInstance, onBeforeUnmount, onMounted } from 'vue'
|
|
2
|
+
import { translateAdminMessage } from '../../../../locales'
|
|
3
|
+
import { useAuthStore } from '../../../auth/store/auth'
|
|
4
|
+
import { rbacRevision } from '../api/rbac'
|
|
5
|
+
import { useAuthorizationRefresh } from './useAuthorizationRefresh'
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_AUTHORIZATION_POLLING_INTERVAL_MS = 30_000
|
|
8
|
+
|
|
9
|
+
export interface AuthorizationPollingOptions {
|
|
10
|
+
/** 轮询间隔,默认 30s。 */
|
|
11
|
+
intervalMs?: number
|
|
12
|
+
/** 注入点(测试):远端 revision 来源,默认 /system/rbac/revision。 */
|
|
13
|
+
fetchRemoteRevision?: () => Promise<number>
|
|
14
|
+
/** 注入点(测试):本地会话 revision,默认 auth.session.authorizationRevision。 */
|
|
15
|
+
getLocalRevision?: () => number | undefined
|
|
16
|
+
/** 注入点(测试):漂移确认交互;resolve(true) 表示立即刷新。 */
|
|
17
|
+
confirmDrift?: () => Promise<boolean>
|
|
18
|
+
/** 注入点(测试):确认后的刷新动作,默认 refreshAuthorization 回路。 */
|
|
19
|
+
onDrift?: () => Promise<void>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 默认确认交互:消息框确认,拒绝(关闭/取消)视为稍后处理。 */
|
|
23
|
+
async function confirmByMessageBox(): Promise<boolean> {
|
|
24
|
+
const { ElMessageBox } = await import('element-plus/es/components/message-box/index.mjs')
|
|
25
|
+
try {
|
|
26
|
+
await ElMessageBox.confirm(
|
|
27
|
+
translateAdminMessage('system.access.revision.body'),
|
|
28
|
+
translateAdminMessage('system.access.revision.title'),
|
|
29
|
+
{
|
|
30
|
+
confirmButtonText: translateAdminMessage('system.access.revision.refreshNow'),
|
|
31
|
+
cancelButtonText: translateAdminMessage('common.actions.cancel'),
|
|
32
|
+
type: 'warning',
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
return true
|
|
36
|
+
} catch {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 跨会话权限感知:周期比对服务端 RBAC revision 与本地会话,发现漂移后
|
|
43
|
+
* 提示用户确认再刷新(refreshAuthorization + 动态菜单重建)。取"提示确认"
|
|
44
|
+
* 而非静默替换,避免打断正在填写的表单;轮询失败静默,不干扰主流程。
|
|
45
|
+
* 在组件 setup 中调用时自动随挂载启停;亦可手动 start/stop。
|
|
46
|
+
*/
|
|
47
|
+
export function useAuthorizationPolling(options: AuthorizationPollingOptions = {}) {
|
|
48
|
+
const intervalMs = options.intervalMs ?? DEFAULT_AUTHORIZATION_POLLING_INTERVAL_MS
|
|
49
|
+
const fetchRemoteRevision = options.fetchRemoteRevision ?? rbacRevision
|
|
50
|
+
const getLocalRevision =
|
|
51
|
+
options.getLocalRevision ?? (() => useAuthStore().session?.authorizationRevision)
|
|
52
|
+
const confirmDrift = options.confirmDrift ?? confirmByMessageBox
|
|
53
|
+
const onDrift = options.onDrift ?? useAuthorizationRefresh()
|
|
54
|
+
|
|
55
|
+
let timer: ReturnType<typeof setInterval> | undefined
|
|
56
|
+
let checking = false
|
|
57
|
+
|
|
58
|
+
async function checkOnce(): Promise<void> {
|
|
59
|
+
if (checking) return
|
|
60
|
+
const local = getLocalRevision()
|
|
61
|
+
if (local === undefined) return
|
|
62
|
+
checking = true
|
|
63
|
+
try {
|
|
64
|
+
const remote = await fetchRemoteRevision()
|
|
65
|
+
if (remote === local) return
|
|
66
|
+
// 后台标签页不打扰;回到前台后的下一轮检测到漂移会再次提示。
|
|
67
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
68
|
+
if (!(await confirmDrift())) return
|
|
69
|
+
await onDrift()
|
|
70
|
+
} catch {
|
|
71
|
+
// 保守吞掉:revision 拉取/刷新异常不冒泡到全局错误提示。
|
|
72
|
+
} finally {
|
|
73
|
+
checking = false
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function start(): void {
|
|
78
|
+
if (timer !== undefined) return
|
|
79
|
+
timer = setInterval(() => {
|
|
80
|
+
void checkOnce()
|
|
81
|
+
}, intervalMs)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function stop(): void {
|
|
85
|
+
if (timer === undefined) return
|
|
86
|
+
clearInterval(timer)
|
|
87
|
+
timer = undefined
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (getCurrentInstance()) {
|
|
91
|
+
onMounted(start)
|
|
92
|
+
onBeforeUnmount(stop)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { start, stop, checkOnce }
|
|
96
|
+
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { OgFormExpose, OgFormSchema } from '@origen-ui/form/core'
|
|
3
3
|
import type { FormActionExpose, SelectOption } from '@origen-ui/shared'
|
|
4
|
-
import type {
|
|
4
|
+
import type { MenuEditorDraft } from '../menuDraft'
|
|
5
5
|
import { OgForm } from '@origen-ui/form/core'
|
|
6
6
|
import { computed, ref, useTemplateRef } from 'vue'
|
|
7
7
|
import { useI18n } from 'vue-i18n'
|
|
8
|
+
import { translateAdminMessage } from '../../../../locales'
|
|
9
|
+
import {
|
|
10
|
+
validateMenuComponentKeyRule,
|
|
11
|
+
validateMenuParentRule,
|
|
12
|
+
validateMenuPathRule,
|
|
13
|
+
validateMenuTitleKeyRule,
|
|
14
|
+
validateMenuTitleRule,
|
|
15
|
+
} from '../menuDraft'
|
|
8
16
|
|
|
9
17
|
defineOptions({ name: 'MenuEditorForm' })
|
|
10
18
|
|
|
@@ -17,22 +25,6 @@ const props = defineProps<{
|
|
|
17
25
|
|
|
18
26
|
const { t } = useI18n()
|
|
19
27
|
|
|
20
|
-
export interface MenuEditorDraft {
|
|
21
|
-
parentId: string
|
|
22
|
-
kind: MenuKind
|
|
23
|
-
title: string
|
|
24
|
-
code: string
|
|
25
|
-
path: string
|
|
26
|
-
componentKey: string
|
|
27
|
-
permission: string
|
|
28
|
-
icon: string
|
|
29
|
-
order: number
|
|
30
|
-
status: RbacStatus
|
|
31
|
-
visible: boolean
|
|
32
|
-
cache: boolean
|
|
33
|
-
tabHidden: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
28
|
const model = ref<MenuEditorDraft>({ ...props.initialValue })
|
|
37
29
|
const form = useTemplateRef<OgFormExpose<MenuEditorDraft>>('form')
|
|
38
30
|
|
|
@@ -61,32 +53,75 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
61
53
|
visible: false,
|
|
62
54
|
cache: false,
|
|
63
55
|
tabHidden: true,
|
|
56
|
+
redirect: '',
|
|
64
57
|
}
|
|
65
58
|
: value === 'directory'
|
|
66
59
|
? { componentKey: '', permission: '' }
|
|
67
|
-
: { permission: '' },
|
|
60
|
+
: { permission: '', redirect: '' },
|
|
68
61
|
},
|
|
69
62
|
{
|
|
70
63
|
prop: 'parentId',
|
|
71
|
-
label:
|
|
64
|
+
label:
|
|
65
|
+
model.value.kind === 'button'
|
|
66
|
+
? t('system.menus.form.parentButton')
|
|
67
|
+
: t('system.menus.form.parentDirectory'),
|
|
72
68
|
control: { type: 'select', props: { clearable: true } },
|
|
73
69
|
requiredWhen: [{ prop: 'kind', op: 'eq', value: 'button' }],
|
|
70
|
+
validator: (_rule, value, callback, model) => {
|
|
71
|
+
const errorKey = validateMenuParentRule(value, model)
|
|
72
|
+
return errorKey ? callback(new Error(translateAdminMessage(errorKey))) : callback()
|
|
73
|
+
},
|
|
74
74
|
options:
|
|
75
75
|
model.value.kind === 'button'
|
|
76
76
|
? props.pageParentOptions
|
|
77
|
-
: [
|
|
77
|
+
: [
|
|
78
|
+
{ label: t('system.menus.form.rootDirectory'), value: '' },
|
|
79
|
+
...props.directoryParentOptions,
|
|
80
|
+
],
|
|
78
81
|
},
|
|
79
82
|
{
|
|
80
83
|
prop: 'title',
|
|
81
84
|
label: t('system.menus.form.title'),
|
|
82
85
|
required: true,
|
|
83
|
-
control: {
|
|
86
|
+
control: {
|
|
87
|
+
type: 'input',
|
|
88
|
+
props: { placeholder: t('system.menus.form.titlePlaceholder') },
|
|
89
|
+
},
|
|
90
|
+
// async-validator 的 required 会放行纯空白,这里显式裁剪校验。
|
|
91
|
+
validator: (_rule, value, callback) => {
|
|
92
|
+
const errorKey = validateMenuTitleRule(value)
|
|
93
|
+
return errorKey ? callback(new Error(translateAdminMessage(errorKey))) : callback()
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
prop: 'titleKey',
|
|
98
|
+
label: t('system.menus.form.titleKey'),
|
|
99
|
+
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
100
|
+
requiredWhen: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
101
|
+
control: {
|
|
102
|
+
type: 'input',
|
|
103
|
+
props: { placeholder: t('system.menus.form.titleKeyPlaceholder') },
|
|
104
|
+
},
|
|
105
|
+
rules: [
|
|
106
|
+
{
|
|
107
|
+
pattern: /^[A-Z][\w.-]*$/i,
|
|
108
|
+
message: t('system.menus.form.titleKeyRuleMessage'),
|
|
109
|
+
trigger: 'blur',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
validator: (_rule, value, callback, model) => {
|
|
113
|
+
const errorKey = validateMenuTitleKeyRule(value, model)
|
|
114
|
+
return errorKey ? callback(new Error(translateAdminMessage(errorKey))) : callback()
|
|
115
|
+
},
|
|
84
116
|
},
|
|
85
117
|
{
|
|
86
118
|
prop: 'code',
|
|
87
119
|
label: t('system.menus.form.code'),
|
|
88
120
|
required: true,
|
|
89
|
-
control: {
|
|
121
|
+
control: {
|
|
122
|
+
type: 'input',
|
|
123
|
+
props: { placeholder: t('system.menus.form.codePlaceholder') },
|
|
124
|
+
},
|
|
90
125
|
rules: [
|
|
91
126
|
{
|
|
92
127
|
pattern: /^[a-z][a-z0-9-]{2,47}$/,
|
|
@@ -100,7 +135,17 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
100
135
|
label: t('system.menus.form.path'),
|
|
101
136
|
requiredWhen: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
102
137
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
103
|
-
control: {
|
|
138
|
+
control: {
|
|
139
|
+
type: 'input',
|
|
140
|
+
props: { placeholder: t('system.menus.form.pathPlaceholder') },
|
|
141
|
+
},
|
|
142
|
+
// 根/子路径的斜杠规则依赖 parentId 的取值,属于跨字段校验:
|
|
143
|
+
// 声明 validationDeps 让 parentId 变化时重跑本字段。
|
|
144
|
+
validator: (_rule, value, callback, model) => {
|
|
145
|
+
const errorKey = validateMenuPathRule(value, model)
|
|
146
|
+
return errorKey ? callback(new Error(translateAdminMessage(errorKey))) : callback()
|
|
147
|
+
},
|
|
148
|
+
validationDeps: ['parentId'],
|
|
104
149
|
},
|
|
105
150
|
{
|
|
106
151
|
prop: 'componentKey',
|
|
@@ -112,13 +157,25 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
112
157
|
requiredWhen: [{ prop: 'kind', op: 'eq', value: 'page' }],
|
|
113
158
|
when: [{ prop: 'kind', op: 'eq', value: 'page' }],
|
|
114
159
|
options: props.componentOptions,
|
|
160
|
+
// 目录收缩后存量行的 componentKey 可能已不在目录内,提交前拦截。
|
|
161
|
+
validator: (_rule, value, callback, model) => {
|
|
162
|
+
const errorKey = validateMenuComponentKeyRule(
|
|
163
|
+
value,
|
|
164
|
+
model,
|
|
165
|
+
props.componentOptions.map((option) => String(option.value)),
|
|
166
|
+
)
|
|
167
|
+
return errorKey ? callback(new Error(translateAdminMessage(errorKey))) : callback()
|
|
168
|
+
},
|
|
115
169
|
},
|
|
116
170
|
{
|
|
117
171
|
prop: 'permission',
|
|
118
172
|
label: t('system.menus.form.permission'),
|
|
119
173
|
requiredWhen: [{ prop: 'kind', op: 'eq', value: 'button' }],
|
|
120
174
|
when: [{ prop: 'kind', op: 'eq', value: 'button' }],
|
|
121
|
-
control: {
|
|
175
|
+
control: {
|
|
176
|
+
type: 'input',
|
|
177
|
+
props: { placeholder: t('system.menus.form.permissionPlaceholder') },
|
|
178
|
+
},
|
|
122
179
|
rules: [
|
|
123
180
|
{
|
|
124
181
|
pattern: /^[a-z][a-z0-9:_-]{2,63}$/,
|
|
@@ -131,7 +188,19 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
131
188
|
prop: 'icon',
|
|
132
189
|
label: t('system.menus.form.icon'),
|
|
133
190
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
134
|
-
control: {
|
|
191
|
+
control: {
|
|
192
|
+
type: 'input',
|
|
193
|
+
props: { placeholder: t('system.menus.form.iconPlaceholder') },
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
prop: 'redirect',
|
|
198
|
+
label: t('system.menus.form.redirect'),
|
|
199
|
+
when: [{ prop: 'kind', op: 'eq', value: 'directory' }],
|
|
200
|
+
control: {
|
|
201
|
+
type: 'input',
|
|
202
|
+
props: { placeholder: t('system.menus.form.redirectPlaceholder') },
|
|
203
|
+
},
|
|
135
204
|
},
|
|
136
205
|
{
|
|
137
206
|
prop: 'order',
|
|
@@ -155,21 +224,39 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
155
224
|
{
|
|
156
225
|
prop: 'visible',
|
|
157
226
|
label: t('system.menus.form.visible'),
|
|
158
|
-
control: {
|
|
227
|
+
control: {
|
|
228
|
+
type: 'switch',
|
|
229
|
+
props: {
|
|
230
|
+
activeText: t('system.menus.form.show'),
|
|
231
|
+
inactiveText: t('system.menus.form.hide'),
|
|
232
|
+
},
|
|
233
|
+
},
|
|
159
234
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
160
235
|
span: 8,
|
|
161
236
|
},
|
|
162
237
|
{
|
|
163
238
|
prop: 'cache',
|
|
164
239
|
label: t('system.menus.form.cache'),
|
|
165
|
-
control: {
|
|
240
|
+
control: {
|
|
241
|
+
type: 'switch',
|
|
242
|
+
props: {
|
|
243
|
+
activeText: t('system.menus.form.on'),
|
|
244
|
+
inactiveText: t('system.menus.form.off'),
|
|
245
|
+
},
|
|
246
|
+
},
|
|
166
247
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
167
248
|
span: 8,
|
|
168
249
|
},
|
|
169
250
|
{
|
|
170
251
|
prop: 'tabHidden',
|
|
171
252
|
label: t('system.menus.form.tabHidden'),
|
|
172
|
-
control: {
|
|
253
|
+
control: {
|
|
254
|
+
type: 'switch',
|
|
255
|
+
props: {
|
|
256
|
+
activeText: t('system.menus.form.hide'),
|
|
257
|
+
inactiveText: t('system.menus.form.show'),
|
|
258
|
+
},
|
|
259
|
+
},
|
|
173
260
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
174
261
|
span: 8,
|
|
175
262
|
},
|