@origen-ui/admin-cli 1.0.3 → 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 +34 -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 +3 -3
  10. package/templates/current/clean/src/api/generated/http-client.ts +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +2 -3
  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 +3 -5
  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 +2 -3
  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 +2 -3
  18. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +1 -1
  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 +34 -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 +3 -3
  76. package/templates/current/examples/src/api/generated/http-client.ts +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +2 -3
  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 +3 -5
  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 +2 -3
  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 +2 -3
  84. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +1 -1
  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
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { ElAlert, ElButton, ElCard, ElForm, ElFormItem, ElInput } from 'element-plus'
3
3
  import { reactive, shallowRef } from 'vue'
4
+ import { useI18n } from 'vue-i18n'
4
5
  import { useRoute, useRouter } from 'vue-router'
5
6
  import { useAuthStore } from '../store/auth'
6
7
 
@@ -8,6 +9,7 @@ defineOptions({ name: 'LoginPage' })
8
9
  const auth = useAuthStore()
9
10
  const route = useRoute()
10
11
  const router = useRouter()
12
+ const { t } = useI18n()
11
13
  const loading = shallowRef(false)
12
14
  const errorMessage = shallowRef('')
13
15
  const form = reactive({ username: '', password: '' })
@@ -15,7 +17,7 @@ const demoLoginHint = import.meta.env.VITE_DEMO_LOGIN_HINT
15
17
 
16
18
  async function submit(): Promise<void> {
17
19
  if (!form.username || !form.password) {
18
- errorMessage.value = '请输入账号和密码'
20
+ errorMessage.value = t('auth.requiredCredentials')
19
21
  return
20
22
  }
21
23
  loading.value = true
@@ -25,7 +27,7 @@ async function submit(): Promise<void> {
25
27
  const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/dashboard'
26
28
  await router.push(redirect)
27
29
  } catch (error: unknown) {
28
- errorMessage.value = error instanceof Error ? error.message : '登录失败,请稍后重试'
30
+ errorMessage.value = error instanceof Error ? error.message : t('auth.loginFailed')
29
31
  } finally {
30
32
  loading.value = false
31
33
  }
@@ -38,10 +40,10 @@ async function submit(): Promise<void> {
38
40
  <div class="login-card__intro">
39
41
  <div class="login-card__mark">HS</div>
40
42
  <p class="login-card__eyebrow">@origen-ui Admin</p>
41
- <h1>欢迎回来</h1>
42
- <p>登录控制台,管理你的业务工作区。</p>
43
+ <h1>{{ t('workspace.welcome') }}</h1>
44
+ <p>{{ t('auth.signInDescription') }}</p>
43
45
  </div>
44
- <p v-if="demoLoginHint" class="login-card__hint">演示账号:{{ demoLoginHint }}</p>
46
+ <p v-if="demoLoginHint" class="login-card__hint">{{ t('auth.demoHint') }}:{{ demoLoginHint }}</p>
45
47
  <ElAlert
46
48
  v-if="errorMessage"
47
49
  class="login-card__alert"
@@ -49,27 +51,29 @@ async function submit(): Promise<void> {
49
51
  type="error"
50
52
  :closable="false"
51
53
  />
52
- <ElForm label-position="top" @submit.prevent="submit">
53
- <ElFormItem label="账号">
54
+ <ElForm :model="form" label-position="top" @submit.prevent="submit">
55
+ <ElFormItem prop="username" :label="t('auth.username')">
54
56
  <ElInput
57
+ id="username"
55
58
  v-model="form.username"
56
59
  autocomplete="username"
57
- placeholder="请输入账号"
60
+ :placeholder="t('auth.usernamePlaceholder')"
58
61
  @keyup.enter="submit"
59
62
  />
60
63
  </ElFormItem>
61
- <ElFormItem label="密码">
64
+ <ElFormItem prop="password" :label="t('auth.password')">
62
65
  <ElInput
66
+ id="password"
63
67
  v-model="form.password"
64
68
  type="password"
65
69
  show-password
66
70
  autocomplete="current-password"
67
- placeholder="请输入密码"
71
+ :placeholder="t('auth.passwordPlaceholder')"
68
72
  @keyup.enter="submit"
69
73
  />
70
74
  </ElFormItem>
71
75
  <ElButton class="login-card__submit" type="primary" :loading="loading" @click="submit">
72
- 登录
76
+ {{ t('auth.login') }}
73
77
  </ElButton>
74
78
  </ElForm>
75
79
  </ElCard>
@@ -1,9 +1,19 @@
1
1
  import type { ApiBusinessError } from '@origen-ui/http'
2
2
  import type { Permission } from '@origen-ui/shared'
3
+ import type { AdminMessageKey } from '../../../locales'
3
4
  import { ApiBusinessError as ApiBusinessErrorClass } from '@origen-ui/http'
4
5
  import { hasCodePermission } from '@origen-ui/permission/codes'
5
6
  import { defineStore } from 'pinia'
6
7
  import { apiClient, tokenManager } from '../../../api/client'
8
+ import { getAdminI18n } from '../../../locales'
9
+
10
+ function translate(key: string): string {
11
+ const global = getAdminI18n()?.global as unknown as
12
+ | { te?: (key: string) => boolean, t: (key: string) => string } |
13
+ undefined
14
+ if (!global) return key
15
+ return global.te?.(key) ? global.t(key as AdminMessageKey) : key
16
+ }
7
17
 
8
18
  export interface AdminUser {
9
19
  id: string
@@ -101,7 +111,7 @@ function cacheProfile(session: AdminSession): void {
101
111
  }
102
112
 
103
113
  function parseLoginPayload(value: unknown): LoginPayload {
104
- if (!isRecord(value)) throw new Error('登录响应格式无效')
114
+ if (!isRecord(value)) throw new Error(translate('auth.invalidResponse'))
105
115
  return {
106
116
  token: readString(value.token),
107
117
  accessToken: readString(value.accessToken),
@@ -129,7 +139,7 @@ function parseProfile(value: unknown, fallbackUsername: string): Omit<AdminSessi
129
139
 
130
140
  function errorMessage(error: unknown): string {
131
141
  if (error instanceof ApiBusinessErrorClass || error instanceof Error) return error.message
132
- return '请求失败'
142
+ return translate('auth.requestFailed')
133
143
  }
134
144
 
135
145
  export const useAuthStore = defineStore('admin-auth', {
@@ -152,7 +162,7 @@ export const useAuthStore = defineStore('admin-auth', {
152
162
  })
153
163
  const payload = parseLoginPayload(response)
154
164
  const token = payload.accessToken ?? payload.token
155
- if (!token) throw new Error('登录响应缺少访问令牌')
165
+ if (!token) throw new Error(translate('auth.missingToken'))
156
166
  const session: AdminSession = {
157
167
  token,
158
168
  user: normalizeUser(payload.user, credentials.username),
@@ -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
  ]
@@ -1,12 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import { ElCard, ElEmpty } from 'element-plus'
3
+ import { useI18n } from 'vue-i18n'
3
4
 
4
5
  defineOptions({ name: 'EmptyPage' })
6
+
7
+ const { t } = useI18n()
5
8
  </script>
6
9
 
7
10
  <template>
8
11
  <ElCard shadow="never" class="empty-page">
9
- <ElEmpty description="这是一个可由后端菜单映射的空白页面" />
12
+ <ElEmpty :description="t('workspace.empty.description')" />
10
13
  </ElCard>
11
14
  </template>
12
15
 
@@ -2,15 +2,17 @@
2
2
  import { CircleCheckFilled, Key, Lock, Monitor } from '@element-plus/icons-vue'
3
3
  import { ElAvatar, ElCard, ElDescriptions, ElDescriptionsItem, ElIcon, ElTag } from 'element-plus'
4
4
  import { computed } from 'vue'
5
+ import { useI18n } from 'vue-i18n'
5
6
  import { useAuthStore } from '../../auth/store/auth'
6
7
 
7
8
  defineOptions({ name: 'ProfilePage' })
8
9
 
9
10
  const auth = useAuthStore()
11
+ const { t } = useI18n()
10
12
  const user = computed(() => auth.session?.user)
11
13
  const permissions = computed(() => auth.session?.permissions ?? [])
12
14
  const sessionId = computed(() =>
13
- auth.session?.token ? `${auth.session.token.slice(0, 8)}••••` : '未建立会话',
15
+ auth.session?.token ? `${auth.session.token.slice(0, 8)}••••` : t('workspace.profile.noSession'),
14
16
  )
15
17
  </script>
16
18
 
@@ -22,21 +24,21 @@ const sessionId = computed(() =>
22
24
  {{ user?.displayName.slice(0, 1) }}
23
25
  </ElAvatar>
24
26
  <div>
25
- <h2>{{ user?.displayName ?? '管理员' }}</h2>
27
+ <h2>{{ user?.displayName ?? t('workspace.profile.admin') }}</h2>
26
28
  <p>{{ user?.email ?? 'admin@example.com' }}</p>
27
29
  </div>
28
30
  <ElTag type="success" effect="plain">
29
- <ElIcon><CircleCheckFilled /></ElIcon> 当前在线
31
+ <ElIcon><CircleCheckFilled /></ElIcon> {{ t('workspace.profile.online') }}
30
32
  </ElTag>
31
33
  </div>
32
34
  <ElDescriptions :column="1" class="profile-card__details">
33
- <ElDescriptionsItem label="登录账号">
35
+ <ElDescriptionsItem :label="t('workspace.profile.loginAccount')">
34
36
  {{ user?.username ?? '-' }}
35
37
  </ElDescriptionsItem>
36
- <ElDescriptionsItem label="用户 ID">
38
+ <ElDescriptionsItem :label="t('workspace.profile.userId')">
37
39
  {{ user?.id ?? '-' }}
38
40
  </ElDescriptionsItem>
39
- <ElDescriptionsItem label="会话标识">
41
+ <ElDescriptionsItem :label="t('workspace.profile.sessionId')">
40
42
  {{ sessionId }}
41
43
  </ElDescriptionsItem>
42
44
  </ElDescriptions>
@@ -46,9 +48,9 @@ const sessionId = computed(() =>
46
48
  <template #header>
47
49
  <div class="profile-card__heading">
48
50
  <div>
49
- <ElIcon><Key /></ElIcon><strong>访问授权</strong>
51
+ <ElIcon><Key /></ElIcon><strong>{{ t('workspace.profile.accessGrant') }}</strong>
50
52
  </div>
51
- <span>{{ permissions.length }} 项权限</span>
53
+ <span>{{ permissions.length }} {{ t('workspace.profile.permissionItems') }}</span>
52
54
  </div>
53
55
  </template>
54
56
  <div class="permission-list">
@@ -58,13 +60,13 @@ const sessionId = computed(() =>
58
60
  </div>
59
61
  </ElCard>
60
62
 
61
- <section class="profile-page__sessions og-card" aria-label="安全状态">
63
+ <section class="profile-page__sessions og-card" :aria-label="t('workspace.profile.securityStatus')">
62
64
  <div class="profile-page__session-icon">
63
65
  <ElIcon><Monitor /></ElIcon>
64
66
  </div>
65
67
  <div>
66
- <h2>当前会话</h2>
67
- <p>本设备通过受保护会话访问管理工作区。</p>
68
+ <h2>{{ t('workspace.profile.currentSession') }}</h2>
69
+ <p>{{ t('workspace.profile.sessionDescription') }}</p>
68
70
  </div>
69
71
  <ElIcon class="profile-page__session-lock">
70
72
  <Lock />
@@ -2,6 +2,7 @@
2
2
  import { OgDialogHost } from '@origen-ui/dialog'
3
3
  import { RouterViewHost } from '@origen-ui/router'
4
4
  import { ElDrawer } from 'element-plus'
5
+ import { useI18n } from 'vue-i18n'
5
6
  import AdminWatermark from '../features/shell/components/AdminWatermark.vue'
6
7
  import { useSidebarStore } from '../features/shell/store/sidebar'
7
8
  import BreadcrumbBar from './BreadcrumbBar.vue'
@@ -11,6 +12,7 @@ import WorkspaceTabs from './WorkspaceTabs.vue'
11
12
 
12
13
  defineOptions({ name: 'AdminLayout' })
13
14
  const sidebar = useSidebarStore()
15
+ const { t } = useI18n()
14
16
  </script>
15
17
 
16
18
  <template>
@@ -18,7 +20,7 @@ const sidebar = useSidebarStore()
18
20
  <div class="admin-shell">
19
21
  <TopBar />
20
22
  <div class="admin-shell__body" :class="{ 'is-collapsed': sidebar.collapsed }">
21
- <aside class="admin-shell__sidebar" aria-label="主导航">
23
+ <aside class="admin-shell__sidebar" :aria-label="t('shell.applicationNavigation')">
22
24
  <SideMenu />
23
25
  </aside>
24
26
  <main class="admin-shell__main">
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { Expand, Fold, Search, Setting } from '@element-plus/icons-vue'
2
+ import { Expand, Fold, Refresh, Search, Setting } from '@element-plus/icons-vue'
3
3
  import {
4
4
  ElAvatar,
5
5
  ElButton,
@@ -32,21 +32,35 @@ const { t } = useI18n()
32
32
  const auth = useAuthStore()
33
33
  const user = computed(() => auth.session?.user)
34
34
  const menuSearchValue = shallowRef<string>()
35
+ const menuRefreshFailed = shallowRef(false)
35
36
  const language = useOrigenUiLanguage()!
36
- const languageOptions = [
37
- { value: 'zh-CN', label: '简体中文' },
38
- { value: 'en-US', label: 'English' },
39
- { value: 'zh-TW', label: '繁體中文' },
40
- ] as const
37
+ const languageOptions = computed(() => [
38
+ { value: 'zh-CN', label: t('shell.languageZhCN') },
39
+ { value: 'en-US', label: t('shell.languageEnUS') },
40
+ { value: 'zh-TW', label: t('shell.languageZhTW') },
41
+ ])
41
42
  const menuSearchOptions = computed(() => flattenMenuSearchOptions(getRouting().menu.value))
42
43
 
44
+ async function refreshLocalizedMenus(): Promise<void> {
45
+ try {
46
+ await getRouting().replaceDynamicRoutes(undefined, { fallback: '/dashboard' })
47
+ menuRefreshFailed.value = false
48
+ } catch {
49
+ menuRefreshFailed.value = true
50
+ ElMessage.error({ message: t('shell.menuRefreshFailed'), showClose: true })
51
+ }
52
+ }
53
+
43
54
  async function switchLanguage(locale: string): Promise<void> {
44
55
  if (!language || language.current.value === locale) return
45
56
  try {
46
- await language.setLocale(locale)
57
+ const result = await language.setLocale(locale)
58
+ if (!result.applied) return
47
59
  } catch {
48
- ElMessage.error(t('shell.languageLoadFailed'))
60
+ ElMessage.error({ message: t('shell.languageLoadFailed'), showClose: true })
61
+ return
49
62
  }
63
+ await refreshLocalizedMenus()
50
64
  }
51
65
 
52
66
  function navigateToMenu(id: string | undefined): void {
@@ -131,6 +145,10 @@ async function logout(): Promise<void> {
131
145
  >
132
146
  {{ item.label }}
133
147
  </ElDropdownItem>
148
+ <ElDropdownItem v-if="menuRefreshFailed" divided @click="refreshLocalizedMenus">
149
+ <ElIcon><Refresh /></ElIcon>
150
+ {{ t('shell.retryMenuRefresh') }}
151
+ </ElDropdownItem>
134
152
  </ElDropdownMenu>
135
153
  </template>
136
154
  </ElDropdown>