@origen-ui/admin-cli 1.0.2 → 1.1.0
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/package.json +3 -3
- package/templates/current/clean/CHANGELOG.md +53 -0
- package/templates/current/clean/component-catalog.json +9 -9
- package/templates/current/clean/package.json +41 -41
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +71 -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 +268 -0
- package/templates/current/clean/src/api/generated/http-client.ts +266 -0
- 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 +147 -0
- 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 +53 -0
- 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 +66 -0
- 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 +171 -0
- 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 +181 -0
- 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 +169 -0
- 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 +170 -0
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +98 -0
- 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/localeFormat.ts +52 -0
- package/templates/current/clean/src/app/menu.spec.ts +26 -0
- package/templates/current/clean/src/app/menu.ts +4 -0
- 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 +8 -7
- 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 +15 -11
- package/templates/current/clean/src/features/auth/store/auth.ts +13 -3
- 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 +38 -15
- package/templates/current/clean/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/clean/src/features/workspace/pages/Empty.vue +4 -1
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +13 -11
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/clean/src/layouts/TopBar.vue +26 -8
- package/templates/current/clean/src/locales/en-US.json +490 -0
- package/templates/current/clean/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/clean/src/locales/index.ts +129 -45
- 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 +490 -0
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/clean/src/locales/zh-TW.json +490 -0
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/clean/src/router/bootstrap.ts +22 -7
- package/templates/current/clean/src/router/dynamicRoutes.ts +5 -1
- 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/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 +81 -37
- package/templates/current/clean/src/templates/templates.spec.ts +19 -0
- package/templates/current/clean/vite.build-policy.ts +114 -289
- package/templates/current/clean/vite.config.ts +4 -5
- package/templates/current/examples/CHANGELOG.md +53 -0
- package/templates/current/examples/component-catalog.json +9 -9
- package/templates/current/examples/package.json +41 -41
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +71 -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 +268 -0
- package/templates/current/examples/src/api/generated/http-client.ts +266 -0
- 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 +147 -0
- 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 +53 -0
- 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 +66 -0
- 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 +171 -0
- 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 +181 -0
- 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 +169 -0
- 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 +170 -0
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +98 -0
- 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/localeFormat.ts +52 -0
- package/templates/current/examples/src/app/menu.spec.ts +26 -0
- package/templates/current/examples/src/app/menu.ts +4 -0
- 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 +8 -7
- 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 +15 -11
- package/templates/current/examples/src/features/auth/store/auth.ts +13 -3
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +6 -2
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +6 -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 +36 -9
- 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 +38 -15
- package/templates/current/examples/src/features/system/access/api/rbac.ts +37 -27
- package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +43 -38
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +33 -30
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +81 -69
- package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +3 -1
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +18 -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 +13 -11
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -1
- package/templates/current/examples/src/layouts/TopBar.vue +26 -8
- package/templates/current/examples/src/locales/en-US.json +490 -0
- package/templates/current/examples/src/locales/en-US.runtime.ts +20 -0
- package/templates/current/examples/src/locales/index.ts +129 -45
- 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 +490 -0
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +20 -0
- package/templates/current/examples/src/locales/zh-TW.json +490 -0
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +20 -0
- package/templates/current/examples/src/main.ts +31 -5
- package/templates/current/examples/src/router/bootstrap.ts +22 -7
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +17 -0
- package/templates/current/examples/src/router/dynamicRoutes.ts +5 -1
- 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 +1 -1
- 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 +81 -37
- package/templates/current/examples/src/templates/templates.spec.ts +19 -0
- package/templates/current/examples/vite.build-policy.ts +114 -289
- package/templates/current/examples/vite.config.ts +4 -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
|
@@ -5,14 +5,41 @@ import type {
|
|
|
5
5
|
OgTableRequestContext,
|
|
6
6
|
OgTableRow,
|
|
7
7
|
} from '@origen-ui/table'
|
|
8
|
+
import { mount } from '@vue/test-utils'
|
|
8
9
|
import { createPinia, setActivePinia } from 'pinia'
|
|
9
10
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
11
|
+
import { defineComponent } from 'vue'
|
|
12
|
+
import { createI18n } from 'vue-i18n'
|
|
13
|
+
import zhCN from '../locales/zh-CN.json'
|
|
10
14
|
import { useTheme } from './appearance/composables/useTheme'
|
|
11
15
|
import { useAuditManagement } from './system/audit/composables/useAuditManagement'
|
|
12
16
|
import { useMenuManagement } from './system/menus/composables/useMenuManagement'
|
|
13
17
|
import { useRoleManagement } from './system/roles/composables/useRoleManagement'
|
|
14
18
|
import { useUserManagement } from './system/users/composables/useUserManagement'
|
|
15
19
|
|
|
20
|
+
const i18n = createI18n({
|
|
21
|
+
legacy: false,
|
|
22
|
+
locale: 'zh-CN',
|
|
23
|
+
messages: { 'zh-CN': zhCN },
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
/** Calls a composable inside a mounted setup so useI18n()/useAuthStore() work(在挂载 setup 中调用 composable)。 */
|
|
27
|
+
function callInSetup<T>(factory: () => T): T {
|
|
28
|
+
let captured: T | undefined
|
|
29
|
+
mount(
|
|
30
|
+
defineComponent({
|
|
31
|
+
setup: () => {
|
|
32
|
+
captured = factory()
|
|
33
|
+
return () => null
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
{
|
|
37
|
+
global: { plugins: [i18n] },
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
return captured as T
|
|
41
|
+
}
|
|
42
|
+
|
|
16
43
|
vi.mock('../api/client', () => {
|
|
17
44
|
function ensureActive(signal?: AbortSignal): void {
|
|
18
45
|
if (signal?.aborted) throw new DOMException('The operation was aborted.', 'AbortError')
|
|
@@ -175,14 +202,14 @@ describe('feature composables', () => {
|
|
|
175
202
|
})
|
|
176
203
|
|
|
177
204
|
it('exposes audit loading and export configuration', async () => {
|
|
178
|
-
const { config, dataSource } = useAuditManagement()
|
|
205
|
+
const { config, dataSource } = callInSetup(() => useAuditManagement())
|
|
179
206
|
const result = await dataSource.list(
|
|
180
207
|
createTableQuery(),
|
|
181
208
|
createRequestContext(new AbortController().signal),
|
|
182
209
|
)
|
|
183
210
|
|
|
184
211
|
expect(result.total).toBeGreaterThanOrEqual(0)
|
|
185
|
-
expect(config.toolbar?.export).toBe('system:audit:export')
|
|
212
|
+
expect(config.value.toolbar?.export).toBe('system:audit:export')
|
|
186
213
|
expect(
|
|
187
214
|
await dataSource.export?.(createExportRequest(), { signal: new AbortController().signal }),
|
|
188
215
|
).toBeInstanceOf(Blob)
|
|
@@ -191,18 +218,18 @@ describe('feature composables', () => {
|
|
|
191
218
|
it('keeps CRUD feature data sources cancellable', async () => {
|
|
192
219
|
const refresh = vi.fn(async () => undefined)
|
|
193
220
|
const refreshAuthorization = vi.fn(async () => undefined)
|
|
194
|
-
await expectCancellableList(useUserManagement({ refresh, refreshAuthorization }).dataSource)
|
|
195
|
-
await expectCancellableList(useRoleManagement({ refresh, refreshAuthorization }).dataSource)
|
|
196
|
-
await expectCancellableList(useMenuManagement({ refresh, refreshAuthorization }).dataSource)
|
|
221
|
+
await expectCancellableList(callInSetup(() => useUserManagement({ refresh, refreshAuthorization })).dataSource)
|
|
222
|
+
await expectCancellableList(callInSetup(() => useRoleManagement({ refresh, refreshAuthorization })).dataSource)
|
|
223
|
+
await expectCancellableList(callInSetup(() => useMenuManagement({ refresh, refreshAuthorization })).dataSource)
|
|
197
224
|
})
|
|
198
225
|
|
|
199
226
|
it('uses a four-column search baseline for every system management page', () => {
|
|
200
227
|
const refresh = vi.fn(async () => undefined)
|
|
201
228
|
const refreshAuthorization = vi.fn(async () => undefined)
|
|
202
229
|
|
|
203
|
-
expect(useUserManagement({ refresh, refreshAuthorization }).config.search?.columns).toBe(4)
|
|
204
|
-
expect(useRoleManagement({ refresh, refreshAuthorization }).config.search?.columns).toBe(4)
|
|
205
|
-
expect(useMenuManagement({ refresh, refreshAuthorization }).config.search?.columns).toBe(4)
|
|
206
|
-
expect(useAuditManagement().config.search?.columns).toBe(4)
|
|
230
|
+
expect(callInSetup(() => useUserManagement({ refresh, refreshAuthorization })).config.value.search?.columns).toBe(4)
|
|
231
|
+
expect(callInSetup(() => useRoleManagement({ refresh, refreshAuthorization })).config.value.search?.columns).toBe(4)
|
|
232
|
+
expect(callInSetup(() => useMenuManagement({ refresh, refreshAuthorization })).config.value.search?.columns).toBe(4)
|
|
233
|
+
expect(callInSetup(() => useAuditManagement()).config.value.search?.columns).toBe(4)
|
|
207
234
|
})
|
|
208
235
|
})
|
package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { nextTick, useTemplateRef, watch } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
3
4
|
|
|
4
5
|
defineOptions({ name: 'DevtoolsProtectionOverlay' })
|
|
5
6
|
|
|
@@ -7,6 +8,8 @@ const props = defineProps<{
|
|
|
7
8
|
blocked: boolean
|
|
8
9
|
}>()
|
|
9
10
|
|
|
11
|
+
const { t } = useI18n()
|
|
12
|
+
|
|
10
13
|
const overlay = useTemplateRef<HTMLElement>('overlay')
|
|
11
14
|
|
|
12
15
|
watch(
|
|
@@ -27,11 +30,11 @@ watch(
|
|
|
27
30
|
ref="overlay"
|
|
28
31
|
class="devtools-protection-overlay"
|
|
29
32
|
role="alertdialog"
|
|
30
|
-
aria-label="
|
|
33
|
+
:aria-label="t('security.devtoolsBlocked')"
|
|
31
34
|
aria-modal="true"
|
|
32
35
|
tabindex="-1"
|
|
33
36
|
>
|
|
34
|
-
<p
|
|
37
|
+
<p>{{ t('security.devtoolsBlocked') }}</p>
|
|
35
38
|
</section>
|
|
36
39
|
</Teleport>
|
|
37
40
|
</template>
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
+
import type { DevtoolsDetector, KeyboardEventTarget, StorageLike } from './devtoolsProtection'
|
|
1
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
2
3
|
import {
|
|
3
4
|
createDevtoolsProtection,
|
|
4
|
-
|
|
5
|
-
type KeyboardEventTarget,
|
|
6
|
-
type StorageLike,
|
|
5
|
+
|
|
7
6
|
} from './devtoolsProtection'
|
|
8
7
|
|
|
9
8
|
type TestDetector = DevtoolsDetector & {
|
|
10
|
-
callbacks?:
|
|
11
|
-
start: ReturnType<typeof vi.fn>
|
|
9
|
+
callbacks?: Parameters<DevtoolsDetector['start']>[0]
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
function createDetector(): TestDetector {
|
|
15
13
|
const detector: TestDetector = {
|
|
16
|
-
start: vi.fn()
|
|
17
|
-
|
|
14
|
+
start: vi.fn<DevtoolsDetector['start']>((callbacks) => {
|
|
15
|
+
detector.callbacks = callbacks
|
|
16
|
+
}),
|
|
17
|
+
stop: vi.fn<DevtoolsDetector['stop']>(),
|
|
18
18
|
}
|
|
19
|
-
detector.start.mockImplementation((callbacks) => {
|
|
20
|
-
detector.callbacks = callbacks
|
|
21
|
-
})
|
|
22
19
|
return detector
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { ADMIN_USER_DEPARTMENTS, createUserDraft } from './admin-repository'
|
|
3
|
+
|
|
4
|
+
describe('admin repository user defaults', () => {
|
|
5
|
+
it('keeps translated department labels separate from their backend wire values', () => {
|
|
6
|
+
expect(ADMIN_USER_DEPARTMENTS).toEqual([
|
|
7
|
+
{ code: 'platform', labelKey: 'system.users.departments.platform', value: '平台产品' },
|
|
8
|
+
{ code: 'growth', labelKey: 'system.users.departments.growth', value: '增长运营' },
|
|
9
|
+
{ code: 'analytics', labelKey: 'system.users.departments.analytics', value: '数据分析' },
|
|
10
|
+
{ code: 'customer', labelKey: 'system.users.departments.customer', value: '客户成功' },
|
|
11
|
+
])
|
|
12
|
+
expect(createUserDraft().department).toBe('增长运营')
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PageResult } from '@origen-ui/shared'
|
|
2
|
+
import type { AdminMessageKey } from '../../../../locales'
|
|
2
3
|
import type { PageRequest, RbacRole, RbacStatus, RbacUser } from './rbac'
|
|
3
4
|
import { apiClient } from '../../../../api/client'
|
|
5
|
+
import { getAdminI18n } from '../../../../locales'
|
|
4
6
|
|
|
5
7
|
export type AdminRecordStatus = RbacStatus
|
|
6
8
|
|
|
@@ -26,6 +28,14 @@ export interface AdminUserDraft {
|
|
|
26
28
|
status: AdminRecordStatus
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
/** Stable department codes provide translated labels while retaining the current API values. */
|
|
32
|
+
export const ADMIN_USER_DEPARTMENTS = [
|
|
33
|
+
{ code: 'platform', labelKey: 'system.users.departments.platform', value: '平台产品' },
|
|
34
|
+
{ code: 'growth', labelKey: 'system.users.departments.growth', value: '增长运营' },
|
|
35
|
+
{ code: 'analytics', labelKey: 'system.users.departments.analytics', value: '数据分析' },
|
|
36
|
+
{ code: 'customer', labelKey: 'system.users.departments.customer', value: '客户成功' },
|
|
37
|
+
] as const satisfies readonly { code: string, labelKey: AdminMessageKey, value: string }[]
|
|
38
|
+
|
|
29
39
|
export interface AdminUserQuery {
|
|
30
40
|
name?: string
|
|
31
41
|
department?: string
|
|
@@ -221,7 +231,7 @@ export function createUserDraft(row?: AdminUserRecord): AdminUserDraft {
|
|
|
221
231
|
return {
|
|
222
232
|
name: row?.name ?? '',
|
|
223
233
|
email: row?.email ?? '',
|
|
224
|
-
department: row?.department ??
|
|
234
|
+
department: row?.department ?? ADMIN_USER_DEPARTMENTS[1].value,
|
|
225
235
|
roleIds: row?.roleIds ?? [],
|
|
226
236
|
status: row?.status ?? 'active',
|
|
227
237
|
}
|
|
@@ -237,26 +247,38 @@ export function createRoleDraft(row?: AdminRoleRecord): AdminRoleDraft {
|
|
|
237
247
|
}
|
|
238
248
|
}
|
|
239
249
|
|
|
240
|
-
function
|
|
241
|
-
|
|
250
|
+
function rbacText(key: string, named?: Record<string, unknown>): string {
|
|
251
|
+
const global = getAdminI18n()?.global as unknown as
|
|
252
|
+
| { t: (key: string, named?: Record<string, unknown>) => string } |
|
|
253
|
+
undefined
|
|
254
|
+
if (!global) return key
|
|
255
|
+
return named ? global.t(key as AdminMessageKey, named) : global.t(key as AdminMessageKey)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function requiredString(value: unknown, labelKey: string): string {
|
|
259
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
260
|
+
throw new Error(rbacText('rbac.errors.required', { label: rbacText(labelKey) }))
|
|
261
|
+
}
|
|
242
262
|
return value.trim()
|
|
243
263
|
}
|
|
244
264
|
|
|
245
265
|
function requiredStatus(value: unknown): AdminRecordStatus {
|
|
246
266
|
if (value === 'active' || value === 'suspended') return value
|
|
247
|
-
throw new Error('
|
|
267
|
+
throw new Error(rbacText('rbac.errors.requiredStatus'))
|
|
248
268
|
}
|
|
249
269
|
|
|
250
270
|
export function parseUserDraft(value: Record<string, unknown> | undefined): AdminUserDraft {
|
|
251
271
|
const draft = asRecord(value)
|
|
252
|
-
const email = requiredString(draft.email, '
|
|
253
|
-
if (!/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(email))
|
|
272
|
+
const email = requiredString(draft.email, 'rbac.fields.workEmail')
|
|
273
|
+
if (!/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(email)) {
|
|
274
|
+
throw new Error(rbacText('rbac.errors.invalidEmail'))
|
|
275
|
+
}
|
|
254
276
|
const roleIds = readStringArray(draft.roleIds)
|
|
255
|
-
if (!roleIds.length) throw new Error('
|
|
277
|
+
if (!roleIds.length) throw new Error(rbacText('rbac.errors.requireRole'))
|
|
256
278
|
return {
|
|
257
|
-
name: requiredString(draft.name, '
|
|
279
|
+
name: requiredString(draft.name, 'rbac.fields.memberName'),
|
|
258
280
|
email,
|
|
259
|
-
department: requiredString(draft.department, '
|
|
281
|
+
department: requiredString(draft.department, 'rbac.fields.department'),
|
|
260
282
|
roleIds,
|
|
261
283
|
status: requiredStatus(draft.status),
|
|
262
284
|
}
|
|
@@ -264,15 +286,16 @@ export function parseUserDraft(value: Record<string, unknown> | undefined): Admi
|
|
|
264
286
|
|
|
265
287
|
export function parseRoleDraft(value: Record<string, unknown> | undefined): AdminRoleDraft {
|
|
266
288
|
const draft = asRecord(value)
|
|
267
|
-
const code = requiredString(draft.code, '
|
|
268
|
-
if (!/^[a-z][a-z0-9_]{2,31}$/.test(code))
|
|
269
|
-
throw new Error('
|
|
289
|
+
const code = requiredString(draft.code, 'rbac.fields.roleCode')
|
|
290
|
+
if (!/^[a-z][a-z0-9_]{2,31}$/.test(code)) {
|
|
291
|
+
throw new Error(rbacText('rbac.errors.invalidRoleCode'))
|
|
292
|
+
}
|
|
270
293
|
const permissions = readStringArray(draft.permissions)
|
|
271
|
-
if (!permissions.length) throw new Error('
|
|
294
|
+
if (!permissions.length) throw new Error(rbacText('rbac.errors.requirePermission'))
|
|
272
295
|
return {
|
|
273
|
-
name: requiredString(draft.name, '
|
|
296
|
+
name: requiredString(draft.name, 'rbac.fields.roleName'),
|
|
274
297
|
code,
|
|
275
|
-
description: requiredString(draft.description, '
|
|
298
|
+
description: requiredString(draft.description, 'rbac.fields.roleDescription'),
|
|
276
299
|
status: requiredStatus(draft.status),
|
|
277
300
|
permissions,
|
|
278
301
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { PageResult, SelectOption } from '@origen-ui/shared'
|
|
2
|
+
import type { AdminMessageKey } from '../../../../locales'
|
|
2
3
|
import { apiClient } from '../../../../api/client'
|
|
4
|
+
import { getAdminI18n } from '../../../../locales'
|
|
3
5
|
|
|
4
6
|
export type RbacStatus = 'active' | 'suspended'
|
|
5
7
|
export type MenuKind = 'directory' | 'page' | 'button'
|
|
@@ -64,11 +66,16 @@ export interface RbacAuditEvent {
|
|
|
64
66
|
|
|
65
67
|
export interface RbacPageCapability {
|
|
66
68
|
componentKey: string
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
labelKey: string
|
|
70
|
+
descriptionKey: string
|
|
69
71
|
icon: string
|
|
70
72
|
permission: string
|
|
71
|
-
operations: readonly { code: string,
|
|
73
|
+
operations: readonly { code: string, labelKey: string }[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function rbacText(key: string): string {
|
|
77
|
+
const global = getAdminI18n()?.global as unknown as { t: (key: string) => string } | undefined
|
|
78
|
+
return global?.t(key as AdminMessageKey) ?? key
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
export interface PageRequest<TQuery extends object> {
|
|
@@ -82,54 +89,54 @@ export interface PageRequest<TQuery extends object> {
|
|
|
82
89
|
export const RBAC_PAGE_CATALOG: readonly RbacPageCapability[] = [
|
|
83
90
|
{
|
|
84
91
|
componentKey: 'dashboard',
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
labelKey: 'rbac.pages.dashboard.label',
|
|
93
|
+
descriptionKey: 'rbac.pages.dashboard.description',
|
|
87
94
|
icon: 'dashboard',
|
|
88
95
|
permission: 'workspace:dashboard:read',
|
|
89
96
|
operations: [],
|
|
90
97
|
},
|
|
91
98
|
{
|
|
92
99
|
componentKey: 'user-list',
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
labelKey: 'rbac.pages.userList.label',
|
|
101
|
+
descriptionKey: 'rbac.pages.userList.description',
|
|
95
102
|
icon: 'users',
|
|
96
103
|
permission: 'system:user:read',
|
|
97
104
|
operations: [
|
|
98
|
-
{ code: 'system:user:write',
|
|
99
|
-
{ code: 'system:user:role',
|
|
100
|
-
{ code: 'system:user:export',
|
|
105
|
+
{ code: 'system:user:write', labelKey: 'rbac.pages.userList.operations.write' },
|
|
106
|
+
{ code: 'system:user:role', labelKey: 'rbac.pages.userList.operations.role' },
|
|
107
|
+
{ code: 'system:user:export', labelKey: 'rbac.pages.userList.operations.export' },
|
|
101
108
|
],
|
|
102
109
|
},
|
|
103
110
|
{
|
|
104
111
|
componentKey: 'role-list',
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
labelKey: 'rbac.pages.roleList.label',
|
|
113
|
+
descriptionKey: 'rbac.pages.roleList.description',
|
|
107
114
|
icon: 'roles',
|
|
108
115
|
permission: 'system:role:read',
|
|
109
116
|
operations: [
|
|
110
|
-
{ code: 'system:role:write',
|
|
111
|
-
{ code: 'system:role:export',
|
|
117
|
+
{ code: 'system:role:write', labelKey: 'rbac.pages.roleList.operations.write' },
|
|
118
|
+
{ code: 'system:role:export', labelKey: 'rbac.pages.roleList.operations.export' },
|
|
112
119
|
],
|
|
113
120
|
},
|
|
114
121
|
{
|
|
115
122
|
componentKey: 'menu-list',
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
labelKey: 'rbac.pages.menuList.label',
|
|
124
|
+
descriptionKey: 'rbac.pages.menuList.description',
|
|
118
125
|
icon: 'menus',
|
|
119
126
|
permission: 'system:menu:read',
|
|
120
127
|
operations: [
|
|
121
|
-
{ code: 'system:menu:write',
|
|
122
|
-
{ code: 'system:menu:publish',
|
|
123
|
-
{ code: 'system:menu:export',
|
|
128
|
+
{ code: 'system:menu:write', labelKey: 'rbac.pages.menuList.operations.write' },
|
|
129
|
+
{ code: 'system:menu:publish', labelKey: 'rbac.pages.menuList.operations.publish' },
|
|
130
|
+
{ code: 'system:menu:export', labelKey: 'rbac.pages.menuList.operations.export' },
|
|
124
131
|
],
|
|
125
132
|
},
|
|
126
133
|
{
|
|
127
134
|
componentKey: 'audit-list',
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
labelKey: 'rbac.pages.auditList.label',
|
|
136
|
+
descriptionKey: 'rbac.pages.auditList.description',
|
|
130
137
|
icon: 'audit',
|
|
131
138
|
permission: 'system:audit:read',
|
|
132
|
-
operations: [{ code: 'system:audit:export',
|
|
139
|
+
operations: [{ code: 'system:audit:export', labelKey: 'rbac.pages.auditList.operations.export' }],
|
|
133
140
|
},
|
|
134
141
|
]
|
|
135
142
|
|
|
@@ -157,21 +164,24 @@ export function getPageCapability(
|
|
|
157
164
|
export function pageCatalogOptions(boundComponentKeys: readonly string[] = []): SelectOption[] {
|
|
158
165
|
const bound = new Set(boundComponentKeys)
|
|
159
166
|
return RBAC_PAGE_CATALOG.filter((page) => !bound.has(page.componentKey)).map((page) => ({
|
|
160
|
-
label: page.
|
|
167
|
+
label: rbacText(page.labelKey),
|
|
161
168
|
value: page.componentKey,
|
|
162
169
|
}))
|
|
163
170
|
}
|
|
164
171
|
|
|
165
172
|
export async function permissionTree(): Promise<SelectOption[]> {
|
|
166
173
|
return [
|
|
167
|
-
{ label: '
|
|
174
|
+
{ label: rbacText('rbac.allPermissions'), value: '*' },
|
|
168
175
|
...RBAC_PAGE_CATALOG.map((page) => ({
|
|
169
|
-
label: page.
|
|
176
|
+
label: rbacText(page.labelKey),
|
|
170
177
|
value: `group:${page.componentKey}`,
|
|
171
178
|
disabled: true,
|
|
172
179
|
children: [
|
|
173
|
-
{ label: '
|
|
174
|
-
...page.operations.map((operation) => ({
|
|
180
|
+
{ label: rbacText('rbac.accessPage'), value: page.permission },
|
|
181
|
+
...page.operations.map((operation) => ({
|
|
182
|
+
label: rbacText(operation.labelKey),
|
|
183
|
+
value: operation.code,
|
|
184
|
+
})),
|
|
175
185
|
],
|
|
176
186
|
})),
|
|
177
187
|
]
|
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
|
}
|