@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.
Files changed (163) hide show
  1. package/package.json +3 -3
  2. package/templates/current/clean/CHANGELOG.md +53 -0
  3. package/templates/current/clean/component-catalog.json +9 -9
  4. package/templates/current/clean/package.json +41 -41
  5. package/templates/current/clean/scaffold.lock.json +2 -2
  6. package/templates/current/clean/scripts/vite-build-policy.spec.ts +71 -0
  7. package/templates/current/clean/src/App.vue +10 -3
  8. package/templates/current/clean/src/api/client.ts +90 -10
  9. package/templates/current/clean/src/api/generated/data-contracts.ts +268 -0
  10. package/templates/current/clean/src/api/generated/http-client.ts +266 -0
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +98 -0
  19. package/templates/current/clean/src/app/adminLocale.ts +90 -0
  20. package/templates/current/clean/src/app/createAdminUi.spec.ts +65 -9
  21. package/templates/current/clean/src/app/createAdminUi.ts +14 -29
  22. package/templates/current/clean/src/app/embedded-token.spec.ts +40 -0
  23. package/templates/current/clean/src/app/embedded.spec.ts +135 -0
  24. package/templates/current/clean/src/app/embedded.ts +255 -0
  25. package/templates/current/clean/src/app/localeFormat.ts +52 -0
  26. package/templates/current/clean/src/app/menu.spec.ts +26 -0
  27. package/templates/current/clean/src/app/menu.ts +4 -0
  28. package/templates/current/clean/src/app/menuTypes.ts +1 -0
  29. package/templates/current/clean/src/app/origenUiLocale.spec.ts +6 -5
  30. package/templates/current/clean/src/app/origenUiLocale.ts +3 -58
  31. package/templates/current/clean/src/app/permission.spec.ts +26 -0
  32. package/templates/current/clean/src/app/runtimeConfig.ts +8 -7
  33. package/templates/current/clean/src/env.d.ts +18 -0
  34. package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +21 -17
  35. package/templates/current/clean/src/features/appearance/store/theme.ts +2 -1
  36. package/templates/current/clean/src/features/auth/pages/Login.vue +15 -11
  37. package/templates/current/clean/src/features/auth/store/auth.ts +13 -3
  38. package/templates/current/clean/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
  39. package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +7 -10
  40. package/templates/current/clean/src/features/security/devtoolsProtection.ts +2 -1
  41. package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +14 -0
  42. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +38 -15
  43. package/templates/current/clean/src/features/system/access/api/rbac.ts +37 -27
  44. package/templates/current/clean/src/features/workspace/pages/Empty.vue +4 -1
  45. package/templates/current/clean/src/features/workspace/pages/Profile.vue +13 -11
  46. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -1
  47. package/templates/current/clean/src/layouts/TopBar.vue +26 -8
  48. package/templates/current/clean/src/locales/en-US.json +490 -0
  49. package/templates/current/clean/src/locales/en-US.runtime.ts +20 -0
  50. package/templates/current/clean/src/locales/index.ts +129 -45
  51. package/templates/current/clean/src/locales/messages-types.ts +62 -0
  52. package/templates/current/clean/src/locales/messages.spec.ts +113 -6
  53. package/templates/current/clean/src/locales/vue-i18n.d.ts +5 -0
  54. package/templates/current/clean/src/locales/zh-CN.json +490 -0
  55. package/templates/current/clean/src/locales/zh-CN.runtime.ts +20 -0
  56. package/templates/current/clean/src/locales/zh-TW.json +490 -0
  57. package/templates/current/clean/src/locales/zh-TW.runtime.ts +20 -0
  58. package/templates/current/clean/src/router/bootstrap.ts +22 -7
  59. package/templates/current/clean/src/router/dynamicRoutes.ts +5 -1
  60. package/templates/current/clean/src/router/queryEncryption.spec.ts +30 -4
  61. package/templates/current/clean/src/router/queryEncryption.ts +48 -44
  62. package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +2 -1
  63. package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +2 -1
  64. package/templates/current/clean/src/templates/og-table.ts +81 -37
  65. package/templates/current/clean/src/templates/templates.spec.ts +19 -0
  66. package/templates/current/clean/vite.build-policy.ts +114 -289
  67. package/templates/current/clean/vite.config.ts +4 -5
  68. package/templates/current/examples/CHANGELOG.md +53 -0
  69. package/templates/current/examples/component-catalog.json +9 -9
  70. package/templates/current/examples/package.json +41 -41
  71. package/templates/current/examples/scaffold.lock.json +2 -2
  72. package/templates/current/examples/scripts/vite-build-policy.spec.ts +71 -0
  73. package/templates/current/examples/src/App.vue +10 -3
  74. package/templates/current/examples/src/api/client.ts +90 -10
  75. package/templates/current/examples/src/api/generated/data-contracts.ts +268 -0
  76. package/templates/current/examples/src/api/generated/http-client.ts +266 -0
  77. 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
  78. 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
  79. 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +98 -0
  85. package/templates/current/examples/src/app/adminLocale.ts +90 -0
  86. package/templates/current/examples/src/app/createAdminUi.spec.ts +65 -9
  87. package/templates/current/examples/src/app/createAdminUi.ts +14 -29
  88. package/templates/current/examples/src/app/embedded-token.spec.ts +40 -0
  89. package/templates/current/examples/src/app/embedded.spec.ts +135 -0
  90. package/templates/current/examples/src/app/embedded.ts +255 -0
  91. package/templates/current/examples/src/app/localeFormat.ts +52 -0
  92. package/templates/current/examples/src/app/menu.spec.ts +26 -0
  93. package/templates/current/examples/src/app/menu.ts +4 -0
  94. package/templates/current/examples/src/app/menuTypes.ts +1 -0
  95. package/templates/current/examples/src/app/origenUiLocale.spec.ts +6 -5
  96. package/templates/current/examples/src/app/origenUiLocale.ts +3 -58
  97. package/templates/current/examples/src/app/permission.spec.ts +26 -0
  98. package/templates/current/examples/src/app/runtimeConfig.ts +8 -7
  99. package/templates/current/examples/src/env.d.ts +18 -0
  100. package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +21 -17
  101. package/templates/current/examples/src/features/appearance/store/theme.ts +2 -1
  102. package/templates/current/examples/src/features/auth/pages/Login.vue +15 -11
  103. package/templates/current/examples/src/features/auth/store/auth.ts +13 -3
  104. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +6 -2
  105. package/templates/current/examples/src/features/errors/pages/NotFound.vue +6 -2
  106. package/templates/current/examples/src/features/errors/pages/ServerError.vue +6 -2
  107. package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +9 -1
  108. package/templates/current/examples/src/features/feature-composables.spec.ts +36 -9
  109. package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
  110. package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +7 -10
  111. package/templates/current/examples/src/features/security/devtoolsProtection.ts +2 -1
  112. package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +14 -0
  113. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +38 -15
  114. package/templates/current/examples/src/features/system/access/api/rbac.ts +37 -27
  115. package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +43 -38
  116. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +33 -30
  117. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +81 -69
  118. package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +3 -1
  119. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +18 -15
  120. package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +49 -53
  121. package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +3 -1
  122. package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +22 -19
  123. package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +59 -64
  124. package/templates/current/examples/src/features/system/users/pages/UserList.vue +3 -1
  125. package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +9 -0
  126. package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +54 -26
  127. package/templates/current/examples/src/features/workspace/pages/Empty.vue +4 -1
  128. package/templates/current/examples/src/features/workspace/pages/Profile.vue +13 -11
  129. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -1
  130. package/templates/current/examples/src/layouts/TopBar.vue +26 -8
  131. package/templates/current/examples/src/locales/en-US.json +490 -0
  132. package/templates/current/examples/src/locales/en-US.runtime.ts +20 -0
  133. package/templates/current/examples/src/locales/index.ts +129 -45
  134. package/templates/current/examples/src/locales/messages-types.ts +62 -0
  135. package/templates/current/examples/src/locales/messages.spec.ts +113 -6
  136. package/templates/current/examples/src/locales/vue-i18n.d.ts +5 -0
  137. package/templates/current/examples/src/locales/zh-CN.json +490 -0
  138. package/templates/current/examples/src/locales/zh-CN.runtime.ts +20 -0
  139. package/templates/current/examples/src/locales/zh-TW.json +490 -0
  140. package/templates/current/examples/src/locales/zh-TW.runtime.ts +20 -0
  141. package/templates/current/examples/src/main.ts +31 -5
  142. package/templates/current/examples/src/router/bootstrap.ts +22 -7
  143. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +17 -0
  144. package/templates/current/examples/src/router/dynamicRoutes.ts +5 -1
  145. package/templates/current/examples/src/router/queryEncryption.spec.ts +30 -4
  146. package/templates/current/examples/src/router/queryEncryption.ts +48 -44
  147. package/templates/current/examples/src/router/staticRoutes.ts +1 -1
  148. package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +2 -1
  149. package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +2 -1
  150. package/templates/current/examples/src/templates/og-table.ts +81 -37
  151. package/templates/current/examples/src/templates/templates.spec.ts +19 -0
  152. package/templates/current/examples/vite.build-policy.ts +114 -289
  153. package/templates/current/examples/vite.config.ts +4 -5
  154. package/templates/current/clean/scripts/check-admin-bundle.mjs +0 -214
  155. package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
  156. package/templates/current/clean/src/locales/en-US.ts +0 -55
  157. package/templates/current/clean/src/locales/zh-CN.ts +0 -55
  158. package/templates/current/clean/src/locales/zh-TW.ts +0 -44
  159. package/templates/current/examples/scripts/check-admin-bundle.mjs +0 -214
  160. package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
  161. package/templates/current/examples/src/locales/en-US.ts +0 -55
  162. package/templates/current/examples/src/locales/zh-CN.ts +0 -55
  163. 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
  })
@@ -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>当前页面暂不可用</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
- type DevtoolsDetector,
5
- type KeyboardEventTarget,
6
- type StorageLike,
5
+
7
6
  } from './devtoolsProtection'
8
7
 
9
8
  type TestDetector = DevtoolsDetector & {
10
- callbacks?: { onClose: () => void, onError?: () => void, onOpen: () => void }
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
- stop: vi.fn(),
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
 
@@ -1,4 +1,5 @@
1
- import { readonly, type Ref, shallowRef } from 'vue'
1
+ import type { Ref } from 'vue'
2
+ import { readonly, shallowRef } from 'vue'
2
3
 
3
4
  const unlockStorageKey = 'og-admin-devtools-unlocked'
4
5
  const unlockTimeout = 2_000
@@ -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 requiredString(value: unknown, label: string): string {
241
- if (typeof value !== 'string' || !value.trim()) throw new Error(`请填写${label}`)
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)) throw new Error('请输入有效的工作邮箱')
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('角色标识只能使用 3-32 位小写字母、数字或下划线')
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
- label: string
68
- description: string
69
+ labelKey: string
70
+ descriptionKey: string
69
71
  icon: string
70
72
  permission: string
71
- operations: readonly { code: string, label: 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
- label: '权限工作台',
86
- description: '查看权限运营概览和最近变更。',
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
- label: '用户管理',
94
- description: '维护成员、状态和多角色归属。',
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', label: '新增和编辑成员' },
99
- { code: 'system:user:role', label: '分配成员角色' },
100
- { code: 'system:user:export', label: '导出成员数据' },
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
- label: '角色管理',
106
- description: '维护角色、成员影响和权限边界。',
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', label: '新增和编辑角色' },
111
- { code: 'system:role:export', label: '导出角色数据' },
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
- label: '菜单管理',
117
- description: '动态发布目录和注册页面。',
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', label: '新增和编辑菜单' },
122
- { code: 'system:menu:publish', label: '启停和发布菜单' },
123
- { code: 'system:menu:export', label: '导出菜单配置' },
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
- label: '审计日志',
129
- description: '查询访问控制变更和管理操作。',
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', label: '导出审计日志' }],
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.label,
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: '全局所有权限', value: '*' },
174
+ { label: rbacText('rbac.allPermissions'), value: '*' },
168
175
  ...RBAC_PAGE_CATALOG.map((page) => ({
169
- label: page.label,
176
+ label: rbacText(page.labelKey),
170
177
  value: `group:${page.componentKey}`,
171
178
  disabled: true,
172
179
  children: [
173
- { label: '访问页面', value: page.permission },
174
- ...page.operations.map((operation) => ({ label: operation.label, value: operation.code })),
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
  ]
@@ -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, type RbacAuditEvent } from '../../access/api/rbac'
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
- const date = new Date(String(value))
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 columns: TableColumn<RbacAuditEvent>[] = [
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: '发生时间', minWidth: 178, sortable: 'custom', format: formatDate },
47
- { prop: 'actorName', label: '操作人', minWidth: 112 },
48
- { prop: 'action', label: '操作', minWidth: 138 },
49
- { prop: 'targetType', label: '对象类型', width: 98, format: targetTypeText },
50
- { prop: 'targetName', label: '目标对象', minWidth: 150, copyable: true },
51
- { prop: 'detail', label: '变更说明', minWidth: 260 },
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: OgTableConfig<RbacAuditEvent, AuditQuery> = {
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: '成员', value: 'user' },
96
- { label: '角色', value: 'role' },
97
- { label: '菜单', value: 'menu' },
98
- { label: '授权', value: 'authorization' },
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
  }