@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
|
@@ -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
|
+
}
|
package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts
CHANGED
|
@@ -5,34 +5,19 @@ import type {
|
|
|
5
5
|
OgTableRequestContext,
|
|
6
6
|
TableColumn,
|
|
7
7
|
} from '@origen-ui/table'
|
|
8
|
+
import type { RbacAuditEvent } from '../../access/api/rbac'
|
|
9
|
+
import { computed } from 'vue'
|
|
10
|
+
import { useI18n } from 'vue-i18n'
|
|
11
|
+
import { formatAdminDateTime } from '../../../../app/localeFormat'
|
|
8
12
|
import { useAuthStore } from '../../../auth/store/auth'
|
|
9
|
-
import { listAudit
|
|
13
|
+
import { listAudit } from '../../access/api/rbac'
|
|
10
14
|
|
|
11
15
|
interface AuditQuery {
|
|
12
16
|
targetType?: RbacAuditEvent['targetType']
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
function formatDate(value: unknown): string {
|
|
16
|
-
|
|
17
|
-
return Number.isNaN(date.valueOf())
|
|
18
|
-
? '-'
|
|
19
|
-
: new Intl.DateTimeFormat('zh-CN', {
|
|
20
|
-
year: 'numeric',
|
|
21
|
-
month: '2-digit',
|
|
22
|
-
day: '2-digit',
|
|
23
|
-
hour: '2-digit',
|
|
24
|
-
minute: '2-digit',
|
|
25
|
-
second: '2-digit',
|
|
26
|
-
hour12: false,
|
|
27
|
-
}).format(date)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function targetTypeText(value: unknown): string {
|
|
31
|
-
return (
|
|
32
|
-
({ user: '成员', role: '角色', menu: '菜单', authorization: '授权' } as Record<string, string>)[
|
|
33
|
-
String(value)
|
|
34
|
-
] ?? '-'
|
|
35
|
-
)
|
|
20
|
+
return formatAdminDateTime(value)
|
|
36
21
|
}
|
|
37
22
|
|
|
38
23
|
function escapeCsv(value: unknown): string {
|
|
@@ -41,15 +26,28 @@ function escapeCsv(value: unknown): string {
|
|
|
41
26
|
|
|
42
27
|
export function useAuditManagement() {
|
|
43
28
|
const auth = useAuthStore()
|
|
44
|
-
const
|
|
29
|
+
const { t } = useI18n()
|
|
30
|
+
|
|
31
|
+
function targetTypeText(value: unknown): string {
|
|
32
|
+
return (
|
|
33
|
+
({
|
|
34
|
+
user: t('system.audit.targetUser'),
|
|
35
|
+
role: t('system.audit.targetRole'),
|
|
36
|
+
menu: t('system.audit.targetMenu'),
|
|
37
|
+
authorization: t('system.audit.targetAuthorization'),
|
|
38
|
+
} as Record<string, string>)[String(value)] ?? '-'
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const columns = computed<TableColumn<RbacAuditEvent>[]>(() => [
|
|
45
43
|
{ type: 'index', key: 'index', label: '#', width: 58 },
|
|
46
|
-
{ prop: 'at', label: '
|
|
47
|
-
{ prop: 'actorName', label: '
|
|
48
|
-
{ prop: 'action', label: '
|
|
49
|
-
{ prop: 'targetType', label: '
|
|
50
|
-
{ prop: 'targetName', label: '
|
|
51
|
-
{ prop: 'detail', label: '
|
|
52
|
-
]
|
|
44
|
+
{ prop: 'at', label: t('system.audit.occurredAt'), minWidth: 178, sortable: 'custom', format: formatDate },
|
|
45
|
+
{ prop: 'actorName', label: t('system.audit.actor'), minWidth: 112 },
|
|
46
|
+
{ prop: 'action', label: t('system.audit.action'), minWidth: 138 },
|
|
47
|
+
{ prop: 'targetType', label: t('system.audit.targetType'), width: 98, format: targetTypeText },
|
|
48
|
+
{ prop: 'targetName', label: t('system.audit.targetName'), minWidth: 150, copyable: true },
|
|
49
|
+
{ prop: 'detail', label: t('system.audit.detail'), minWidth: 260 },
|
|
50
|
+
])
|
|
53
51
|
|
|
54
52
|
const dataSource: OgTableDataSource<RbacAuditEvent, AuditQuery> = {
|
|
55
53
|
list: (request, context: OgTableRequestContext): Promise<PageResult<RbacAuditEvent>> =>
|
|
@@ -66,7 +64,14 @@ export function useAuditManagement() {
|
|
|
66
64
|
context.signal,
|
|
67
65
|
)
|
|
68
66
|
const rows = [
|
|
69
|
-
[
|
|
67
|
+
[
|
|
68
|
+
t('system.audit.occurredAt'),
|
|
69
|
+
t('system.audit.actor'),
|
|
70
|
+
t('system.audit.action'),
|
|
71
|
+
t('system.audit.targetType'),
|
|
72
|
+
t('system.audit.targetName'),
|
|
73
|
+
t('system.audit.detail'),
|
|
74
|
+
],
|
|
70
75
|
...result.list.map((row) => [
|
|
71
76
|
formatDate(row.at),
|
|
72
77
|
row.actorName,
|
|
@@ -82,20 +87,20 @@ export function useAuditManagement() {
|
|
|
82
87
|
},
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
const config
|
|
90
|
+
const config = computed<OgTableConfig<RbacAuditEvent, AuditQuery>>(() => ({
|
|
86
91
|
search: {
|
|
87
|
-
quickSearch: { placeholder: '
|
|
92
|
+
quickSearch: { placeholder: t('system.audit.searchPlaceholder') },
|
|
88
93
|
columns: 4,
|
|
89
94
|
fields: [
|
|
90
95
|
{
|
|
91
96
|
prop: 'targetType',
|
|
92
|
-
label: '
|
|
97
|
+
label: t('system.audit.targetType'),
|
|
93
98
|
type: 'select',
|
|
94
99
|
options: [
|
|
95
|
-
{ label: '
|
|
96
|
-
{ label: '
|
|
97
|
-
{ label: '
|
|
98
|
-
{ label: '
|
|
100
|
+
{ label: t('system.audit.targetUser'), value: 'user' },
|
|
101
|
+
{ label: t('system.audit.targetRole'), value: 'role' },
|
|
102
|
+
{ label: t('system.audit.targetMenu'), value: 'menu' },
|
|
103
|
+
{ label: t('system.audit.targetAuthorization'), value: 'authorization' },
|
|
99
104
|
],
|
|
100
105
|
},
|
|
101
106
|
],
|
|
@@ -111,7 +116,7 @@ export function useAuditManagement() {
|
|
|
111
116
|
export: 'system:audit:export',
|
|
112
117
|
},
|
|
113
118
|
export: { source: 'display', watermark: false },
|
|
114
|
-
}
|
|
119
|
+
}))
|
|
115
120
|
|
|
116
121
|
return { columns, config, dataSource }
|
|
117
122
|
}
|
|
@@ -1,9 +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
|
+
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'
|
|
7
16
|
|
|
8
17
|
defineOptions({ name: 'MenuEditorForm' })
|
|
9
18
|
|
|
@@ -14,21 +23,7 @@ const props = defineProps<{
|
|
|
14
23
|
componentOptions: SelectOption[]
|
|
15
24
|
}>()
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
parentId: string
|
|
19
|
-
kind: MenuKind
|
|
20
|
-
title: string
|
|
21
|
-
code: string
|
|
22
|
-
path: string
|
|
23
|
-
componentKey: string
|
|
24
|
-
permission: string
|
|
25
|
-
icon: string
|
|
26
|
-
order: number
|
|
27
|
-
status: RbacStatus
|
|
28
|
-
visible: boolean
|
|
29
|
-
cache: boolean
|
|
30
|
-
tabHidden: boolean
|
|
31
|
-
}
|
|
26
|
+
const { t } = useI18n()
|
|
32
27
|
|
|
33
28
|
const model = ref<MenuEditorDraft>({ ...props.initialValue })
|
|
34
29
|
const form = useTemplateRef<OgFormExpose<MenuEditorDraft>>('form')
|
|
@@ -39,13 +34,13 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
39
34
|
fields: [
|
|
40
35
|
{
|
|
41
36
|
prop: 'kind',
|
|
42
|
-
label: '
|
|
37
|
+
label: t('system.menus.form.kind'),
|
|
43
38
|
control: { type: 'radio' },
|
|
44
39
|
required: true,
|
|
45
40
|
options: [
|
|
46
|
-
{ label: '
|
|
47
|
-
{ label: '
|
|
48
|
-
{ label: '
|
|
41
|
+
{ label: t('system.menus.kindPage'), value: 'page' },
|
|
42
|
+
{ label: t('system.menus.kindDirectory'), value: 'directory' },
|
|
43
|
+
{ label: t('system.menus.kindButton'), value: 'button' },
|
|
49
44
|
],
|
|
50
45
|
valueChange: (value) =>
|
|
51
46
|
value === 'button'
|
|
@@ -58,81 +53,158 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
58
53
|
visible: false,
|
|
59
54
|
cache: false,
|
|
60
55
|
tabHidden: true,
|
|
56
|
+
redirect: '',
|
|
61
57
|
}
|
|
62
58
|
: value === 'directory'
|
|
63
59
|
? { componentKey: '', permission: '' }
|
|
64
|
-
: { permission: '' },
|
|
60
|
+
: { permission: '', redirect: '' },
|
|
65
61
|
},
|
|
66
62
|
{
|
|
67
63
|
prop: 'parentId',
|
|
68
|
-
label:
|
|
64
|
+
label:
|
|
65
|
+
model.value.kind === 'button'
|
|
66
|
+
? t('system.menus.form.parentButton')
|
|
67
|
+
: t('system.menus.form.parentDirectory'),
|
|
69
68
|
control: { type: 'select', props: { clearable: true } },
|
|
70
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
|
+
},
|
|
71
74
|
options:
|
|
72
75
|
model.value.kind === 'button'
|
|
73
76
|
? props.pageParentOptions
|
|
74
|
-
: [
|
|
77
|
+
: [
|
|
78
|
+
{ label: t('system.menus.form.rootDirectory'), value: '' },
|
|
79
|
+
...props.directoryParentOptions,
|
|
80
|
+
],
|
|
75
81
|
},
|
|
76
82
|
{
|
|
77
83
|
prop: 'title',
|
|
78
|
-
label: '
|
|
84
|
+
label: t('system.menus.form.title'),
|
|
79
85
|
required: true,
|
|
80
|
-
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
|
+
},
|
|
81
116
|
},
|
|
82
117
|
{
|
|
83
118
|
prop: 'code',
|
|
84
|
-
label: '
|
|
119
|
+
label: t('system.menus.form.code'),
|
|
85
120
|
required: true,
|
|
86
|
-
control: {
|
|
121
|
+
control: {
|
|
122
|
+
type: 'input',
|
|
123
|
+
props: { placeholder: t('system.menus.form.codePlaceholder') },
|
|
124
|
+
},
|
|
87
125
|
rules: [
|
|
88
126
|
{
|
|
89
127
|
pattern: /^[a-z][a-z0-9-]{2,47}$/,
|
|
90
|
-
message: '
|
|
128
|
+
message: t('system.menus.form.codeRuleMessage'),
|
|
91
129
|
trigger: 'blur',
|
|
92
130
|
},
|
|
93
131
|
],
|
|
94
132
|
},
|
|
95
133
|
{
|
|
96
134
|
prop: 'path',
|
|
97
|
-
label: '
|
|
135
|
+
label: t('system.menus.form.path'),
|
|
98
136
|
requiredWhen: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
99
137
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
100
|
-
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'],
|
|
101
149
|
},
|
|
102
150
|
{
|
|
103
151
|
prop: 'componentKey',
|
|
104
|
-
label: '
|
|
152
|
+
label: t('system.menus.form.componentKey'),
|
|
105
153
|
control: {
|
|
106
154
|
type: 'select',
|
|
107
|
-
props: { filterable: true, placeholder: '
|
|
155
|
+
props: { filterable: true, placeholder: t('system.menus.form.componentPlaceholder') },
|
|
108
156
|
},
|
|
109
157
|
requiredWhen: [{ prop: 'kind', op: 'eq', value: 'page' }],
|
|
110
158
|
when: [{ prop: 'kind', op: 'eq', value: 'page' }],
|
|
111
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
|
+
},
|
|
112
169
|
},
|
|
113
170
|
{
|
|
114
171
|
prop: 'permission',
|
|
115
|
-
label: '
|
|
172
|
+
label: t('system.menus.form.permission'),
|
|
116
173
|
requiredWhen: [{ prop: 'kind', op: 'eq', value: 'button' }],
|
|
117
174
|
when: [{ prop: 'kind', op: 'eq', value: 'button' }],
|
|
118
|
-
control: {
|
|
175
|
+
control: {
|
|
176
|
+
type: 'input',
|
|
177
|
+
props: { placeholder: t('system.menus.form.permissionPlaceholder') },
|
|
178
|
+
},
|
|
119
179
|
rules: [
|
|
120
180
|
{
|
|
121
181
|
pattern: /^[a-z][a-z0-9:_-]{2,63}$/,
|
|
122
|
-
message: '
|
|
182
|
+
message: t('system.menus.form.permissionRuleMessage'),
|
|
123
183
|
trigger: 'blur',
|
|
124
184
|
},
|
|
125
185
|
],
|
|
126
186
|
},
|
|
127
187
|
{
|
|
128
188
|
prop: 'icon',
|
|
129
|
-
label: '
|
|
189
|
+
label: t('system.menus.form.icon'),
|
|
130
190
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
131
|
-
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
|
+
},
|
|
132
204
|
},
|
|
133
205
|
{
|
|
134
206
|
prop: 'order',
|
|
135
|
-
label: '
|
|
207
|
+
label: t('system.menus.form.order'),
|
|
136
208
|
control: {
|
|
137
209
|
type: 'number',
|
|
138
210
|
props: { min: 1, max: 9999, numberControlsPosition: 'right' },
|
|
@@ -141,32 +213,50 @@ const schema = computed<OgFormSchema<MenuEditorDraft>>(() => ({
|
|
|
141
213
|
},
|
|
142
214
|
{
|
|
143
215
|
prop: 'status',
|
|
144
|
-
label: '
|
|
216
|
+
label: t('system.menus.form.status'),
|
|
145
217
|
control: { type: 'radio' },
|
|
146
218
|
required: true,
|
|
147
219
|
options: [
|
|
148
|
-
{ label: '
|
|
149
|
-
{ label: '
|
|
220
|
+
{ label: t('system.menus.published'), value: 'active' },
|
|
221
|
+
{ label: t('system.menus.unpublished'), value: 'suspended' },
|
|
150
222
|
],
|
|
151
223
|
},
|
|
152
224
|
{
|
|
153
225
|
prop: 'visible',
|
|
154
|
-
label: '
|
|
155
|
-
control: {
|
|
226
|
+
label: t('system.menus.form.visible'),
|
|
227
|
+
control: {
|
|
228
|
+
type: 'switch',
|
|
229
|
+
props: {
|
|
230
|
+
activeText: t('system.menus.form.show'),
|
|
231
|
+
inactiveText: t('system.menus.form.hide'),
|
|
232
|
+
},
|
|
233
|
+
},
|
|
156
234
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
157
235
|
span: 8,
|
|
158
236
|
},
|
|
159
237
|
{
|
|
160
238
|
prop: 'cache',
|
|
161
|
-
label: '
|
|
162
|
-
control: {
|
|
239
|
+
label: t('system.menus.form.cache'),
|
|
240
|
+
control: {
|
|
241
|
+
type: 'switch',
|
|
242
|
+
props: {
|
|
243
|
+
activeText: t('system.menus.form.on'),
|
|
244
|
+
inactiveText: t('system.menus.form.off'),
|
|
245
|
+
},
|
|
246
|
+
},
|
|
163
247
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
164
248
|
span: 8,
|
|
165
249
|
},
|
|
166
250
|
{
|
|
167
251
|
prop: 'tabHidden',
|
|
168
|
-
label: '
|
|
169
|
-
control: {
|
|
252
|
+
label: t('system.menus.form.tabHidden'),
|
|
253
|
+
control: {
|
|
254
|
+
type: 'switch',
|
|
255
|
+
props: {
|
|
256
|
+
activeText: t('system.menus.form.hide'),
|
|
257
|
+
inactiveText: t('system.menus.form.show'),
|
|
258
|
+
},
|
|
259
|
+
},
|
|
170
260
|
when: [{ prop: 'kind', op: 'neq', value: 'button' }],
|
|
171
261
|
span: 8,
|
|
172
262
|
},
|