@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.
- package/package.json +3 -3
- package/templates/current/clean/CHANGELOG.md +34 -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 +3 -3
- package/templates/current/clean/src/api/generated/http-client.ts +1 -1
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +1 -1
- 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 +34 -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 +3 -3
- package/templates/current/examples/src/api/generated/http-client.ts +1 -1
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +1 -1
- 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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { BackendMenuNode } from './menuTypes'
|
|
2
|
+
|
|
3
|
+
// 微前端嵌入模式(architecture.md M4 §5):
|
|
4
|
+
// VITE_EMBEDDED=true 表达嵌入意图;运行时必须探测到主壳注入的环境,
|
|
5
|
+
// 否则回退独立模式并告警——防止误配置导致应用在无主壳时丢失自身外壳。
|
|
6
|
+
// 双框架桥:wujie(props 一次性 + bus 事件)与 micro-app(data 通道)。
|
|
7
|
+
|
|
8
|
+
const wantsEmbedded = import.meta.env.VITE_EMBEDDED === 'true'
|
|
9
|
+
|
|
10
|
+
/** Embedded token storage is intentionally volatile and read-only to consumers. */
|
|
11
|
+
let embeddedAccessToken: string | null = null
|
|
12
|
+
export const embeddedTokenStorage = {
|
|
13
|
+
getItem: (_key: string): string | null => embeddedAccessToken,
|
|
14
|
+
setItem: (_key: string, _value: string): void => undefined,
|
|
15
|
+
removeItem: (_key: string): void => {
|
|
16
|
+
embeddedAccessToken = null
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type HostFramework = 'wujie' | 'micro-app'
|
|
21
|
+
|
|
22
|
+
interface WujieChildApi {
|
|
23
|
+
props?: Record<string, unknown>
|
|
24
|
+
bus?: {
|
|
25
|
+
$emit: (event: string, ...args: unknown[]) => void
|
|
26
|
+
$on: (event: string, callback: (...args: unknown[]) => void) => void
|
|
27
|
+
$off: (event: string, callback: (...args: unknown[]) => void) => void
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface MicroAppChildApi {
|
|
32
|
+
getData?: () => Record<string, unknown>
|
|
33
|
+
addDataListener?: (
|
|
34
|
+
callback: (data: Record<string, unknown>) => void,
|
|
35
|
+
autoTrigger?: boolean,
|
|
36
|
+
) => void
|
|
37
|
+
dispatch?: (data: Record<string, unknown>) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare global {
|
|
41
|
+
interface Window {
|
|
42
|
+
__POWERED_BY_WUJIE__?: boolean
|
|
43
|
+
__MICRO_APP_ENVIRONMENT__?: boolean
|
|
44
|
+
__MICRO_APP_NAME__?: string
|
|
45
|
+
$wujie?: WujieChildApi
|
|
46
|
+
microApp?: MicroAppChildApi
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function detectHostFramework(): HostFramework | null {
|
|
51
|
+
if (typeof window === 'undefined') return null
|
|
52
|
+
if (window.__POWERED_BY_WUJIE__) return 'wujie'
|
|
53
|
+
if (window.__MICRO_APP_ENVIRONMENT__ === true || window.__MICRO_APP_NAME__ !== undefined) {
|
|
54
|
+
return 'micro-app'
|
|
55
|
+
}
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const detected = detectHostFramework()
|
|
60
|
+
export const hostFramework: HostFramework | null = wantsEmbedded ? detected : null
|
|
61
|
+
export const embeddedMode = hostFramework !== null
|
|
62
|
+
|
|
63
|
+
if (wantsEmbedded && detected === null) {
|
|
64
|
+
console.warn('[admin] VITE_EMBEDDED=true 但未检测到主壳注入环境,已回退独立模式')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function wujieProps(): Record<string, unknown> {
|
|
68
|
+
return window.$wujie?.props ?? {}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function microAppData(): Record<string, unknown> {
|
|
72
|
+
return window.microApp?.getData?.() ?? {}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 主壳注入数据快照(wujie 走 props,micro-app 走 data 缓存) */
|
|
76
|
+
export function readHostInjection(): Record<string, unknown> {
|
|
77
|
+
if (!embeddedMode) return {}
|
|
78
|
+
return hostFramework === 'wujie' ? wujieProps() : microAppData()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function applyToken(data: Record<string, unknown> | undefined): void {
|
|
82
|
+
const token = data?.token
|
|
83
|
+
if (typeof token === 'string' && token !== '') embeddedAccessToken = token
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 主壳明暗主题跟随(architecture.md §4.1):与 admin 暗色 token 的
|
|
88
|
+
* :root.dark 约定一致;非法值忽略。嵌入模式下本桥持有 dark class
|
|
89
|
+
* 的所有权(独立模式仍由 admin 自身主题 store 负责,见 App.vue)。
|
|
90
|
+
*/
|
|
91
|
+
export function applyHostTheme(data: Record<string, unknown> | undefined): void {
|
|
92
|
+
const theme = data?.theme
|
|
93
|
+
if (theme !== 'light' && theme !== 'dark') return
|
|
94
|
+
if (typeof document === 'undefined') return
|
|
95
|
+
document.documentElement.classList.toggle('dark', theme === 'dark')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 嵌入模式桥接:token 由主壳唯一持有并推送,本应用只写存储
|
|
100
|
+
* (TokenManager 每次请求先读存储);刷新被冻结,401 时通知主壳。
|
|
101
|
+
* 主题由主壳下发:注入时应用一次,micro-app 通道持续监听变更
|
|
102
|
+
* (wujie 的 props 一次性注入,仅支持挂载时初始主题)。
|
|
103
|
+
*/
|
|
104
|
+
export function startEmbeddedBridge(): void {
|
|
105
|
+
if (!embeddedMode) return
|
|
106
|
+
applyToken(readHostInjection())
|
|
107
|
+
applyHostTheme(readHostInjection())
|
|
108
|
+
if (hostFramework === 'micro-app') {
|
|
109
|
+
window.microApp?.addDataListener?.(applyToken, false)
|
|
110
|
+
window.microApp?.addDataListener?.(applyHostTheme, false)
|
|
111
|
+
}
|
|
112
|
+
// wujie 的 props 在 mount 时注入;admin 为单实例嵌入,无会话中途轮换需求
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 嵌入模式通知主壳:认证失效(主壳决定重新登录/刷新) */
|
|
116
|
+
export function notifyHostUnauthorized(): void {
|
|
117
|
+
if (!embeddedMode) return
|
|
118
|
+
dispatchToHost('sub-app-error', { code: 'unauthorized' })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 子应用→主壳菜单上报单项(主壳契约 SubAppMenuItem 的同构最小集) */
|
|
122
|
+
interface HostMenuItemReport {
|
|
123
|
+
id: string
|
|
124
|
+
title: string
|
|
125
|
+
microRoute: string
|
|
126
|
+
icon?: string
|
|
127
|
+
children?: HostMenuItemReport[]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 子应用→主壳上报事件(与主壳 SubToHostMessage 白名单同构) */
|
|
131
|
+
type HostBridgeEvent = 'sub-app-error' | 'sub-app-menu'
|
|
132
|
+
|
|
133
|
+
/** 事件统一出口:wujie 走 bus $emit,micro-app 走 dispatch(契约消息结构一致) */
|
|
134
|
+
function dispatchToHost(event: HostBridgeEvent, payload: unknown): void {
|
|
135
|
+
const appId = readHostInjection().appId
|
|
136
|
+
const message = { event, ...(typeof appId === 'string' ? { appId } : {}), payload }
|
|
137
|
+
if (hostFramework === 'wujie') {
|
|
138
|
+
window.$wujie?.bus?.$emit(event, message)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
window.microApp?.dispatch?.(message)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 与 router/dynamicRoutes.ts 的 fullPath 同语义:绝对 path 直用;相对 path
|
|
145
|
+
// 拼接父链前缀,无父链时补 "/" 根前缀。主壳契约要求 microRoute 以 / 开头。
|
|
146
|
+
function resolveMicroRoute(prefix: string, path: string): string {
|
|
147
|
+
const trimmed = path.trim()
|
|
148
|
+
if (trimmed.startsWith('/')) return trimmed
|
|
149
|
+
if (prefix === '') return `/${trimmed}`
|
|
150
|
+
return `${prefix.replace(/\/$/, '')}/${trimmed}`
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// BackendMenuNode → 上报契约。fetchMenus 返回扁平列表(父子靠 parentPath
|
|
154
|
+
// 关联,树由路由适配层构建),这里重建两层结构(契约上限):
|
|
155
|
+
// 1. 按 parentPath 链解析每个节点的绝对 microRoute(dynamicRoutes.fullPath 同语义);
|
|
156
|
+
// 2. 父节点本身是顶层(目录)时子项挂为其 children,更深的层级拍平到顶层。
|
|
157
|
+
// 隐藏/非菜单节点过滤;保持后端给定顺序,权限过滤已由菜单装载链完成。
|
|
158
|
+
function toMenuReport(nodes: readonly BackendMenuNode[]): HostMenuItemReport[] {
|
|
159
|
+
// order 升序(缺省排后,稳定排序保持原有相对顺序),与 admin 自身菜单一致
|
|
160
|
+
const usable = nodes
|
|
161
|
+
.filter((node) => node.menu !== false && node.hidden !== true)
|
|
162
|
+
.sort((a, b) => (a.order ?? Number.POSITIVE_INFINITY) - (b.order ?? Number.POSITIVE_INFINITY))
|
|
163
|
+
|
|
164
|
+
const byPath = new Map<string, BackendMenuNode[]>()
|
|
165
|
+
for (const node of usable) {
|
|
166
|
+
const path = node.path.trim()
|
|
167
|
+
byPath.set(path, [...(byPath.get(path) ?? []), node])
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const fullPathMemo = new Map<BackendMenuNode, string>()
|
|
171
|
+
function fullPathOf(node: BackendMenuNode, seen: Set<string>): string | undefined {
|
|
172
|
+
const cached = fullPathMemo.get(node)
|
|
173
|
+
if (cached !== undefined) return cached
|
|
174
|
+
if (seen.has(node.code)) return undefined
|
|
175
|
+
seen.add(node.code)
|
|
176
|
+
const path = node.path.trim()
|
|
177
|
+
if (path === '') return undefined
|
|
178
|
+
let resolved: string
|
|
179
|
+
if (path.startsWith('/')) {
|
|
180
|
+
resolved = path
|
|
181
|
+
} else {
|
|
182
|
+
const parentPath = node.parentPath?.trim()
|
|
183
|
+
const rawCandidates = parentPath ? (byPath.get(parentPath) ?? []) : []
|
|
184
|
+
const canonicalCandidates = parentPath
|
|
185
|
+
? usable.filter((candidate) => fullPathOf(candidate, new Set(seen)) === parentPath)
|
|
186
|
+
: []
|
|
187
|
+
const candidates = [...new Set([...rawCandidates, ...canonicalCandidates])].filter(
|
|
188
|
+
(candidate) => candidate !== node,
|
|
189
|
+
)
|
|
190
|
+
const parent = candidates.length === 1 ? candidates[0] : undefined
|
|
191
|
+
const parentFullPath = parent ? fullPathOf(parent, seen) : undefined
|
|
192
|
+
resolved = parentFullPath === undefined ? `/${path}` : resolveMicroRoute(parentFullPath, path)
|
|
193
|
+
}
|
|
194
|
+
fullPathMemo.set(node, resolved)
|
|
195
|
+
return resolved
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const itemsByNode = new Map<BackendMenuNode, HostMenuItemReport>()
|
|
199
|
+
for (const node of usable) {
|
|
200
|
+
const microRoute = fullPathOf(node, new Set())
|
|
201
|
+
if (microRoute === undefined) continue
|
|
202
|
+
itemsByNode.set(node, {
|
|
203
|
+
id: node.code,
|
|
204
|
+
title: node.title,
|
|
205
|
+
microRoute,
|
|
206
|
+
...(node.icon !== undefined ? { icon: node.icon } : {}),
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function parentOf(node: BackendMenuNode): BackendMenuNode | undefined {
|
|
211
|
+
const parentPath = node.parentPath?.trim()
|
|
212
|
+
if (!parentPath) return undefined
|
|
213
|
+
const rawCandidates = byPath.get(parentPath) ?? []
|
|
214
|
+
const canonicalCandidates = usable.filter(
|
|
215
|
+
(candidate) => fullPathMemo.get(candidate) === parentPath,
|
|
216
|
+
)
|
|
217
|
+
const candidates = [...new Set([...rawCandidates, ...canonicalCandidates])].filter(
|
|
218
|
+
(candidate) => candidate !== node,
|
|
219
|
+
)
|
|
220
|
+
return candidates.length === 1 ? candidates[0] : undefined
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 父节点自身无可用父级(即目录层)时,子项挂为其 children;
|
|
224
|
+
// 更深的层级拍平到顶层,满足契约两层上限。
|
|
225
|
+
const tops: HostMenuItemReport[] = []
|
|
226
|
+
for (const node of usable) {
|
|
227
|
+
const item = itemsByNode.get(node)
|
|
228
|
+
if (!item) continue
|
|
229
|
+
const parent = parentOf(node)
|
|
230
|
+
const parentItem = parent !== undefined ? itemsByNode.get(parent) : undefined
|
|
231
|
+
const parentIsTopLevel =
|
|
232
|
+
parentItem !== undefined && (parent === undefined || parentOf(parent) === undefined)
|
|
233
|
+
if (parentItem !== undefined && parentIsTopLevel) {
|
|
234
|
+
if (parentItem.children === undefined) parentItem.children = []
|
|
235
|
+
parentItem.children.push(item)
|
|
236
|
+
} else {
|
|
237
|
+
tops.push(item)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return tops
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 嵌入模式向主壳上报权限过滤后的菜单树(sub-app-menu 事件,
|
|
245
|
+
* architecture.md §3 过渡聚合源):主壳据此在侧栏渲染应用分组导航。
|
|
246
|
+
* 上报失败只告警,不影响本应用启动与运行;独立模式 no-op。
|
|
247
|
+
*/
|
|
248
|
+
export function reportMenusToHost(nodes: readonly BackendMenuNode[]): void {
|
|
249
|
+
if (!embeddedMode) return
|
|
250
|
+
try {
|
|
251
|
+
dispatchToHost('sub-app-menu', { menus: toMenuReport(nodes) })
|
|
252
|
+
} catch (cause) {
|
|
253
|
+
console.warn('[admin] menu report to host failed (non-blocking)', cause)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { currentAdminLocale } from './adminLocale'
|
|
2
|
+
|
|
3
|
+
export { currentAdminLocale }
|
|
4
|
+
|
|
5
|
+
type DateTimeFormatOptions = Intl.DateTimeFormatOptions
|
|
6
|
+
|
|
7
|
+
const formatterCache = new Map<string, Intl.DateTimeFormat>()
|
|
8
|
+
|
|
9
|
+
function formatter(options: DateTimeFormatOptions, key: string): Intl.DateTimeFormat {
|
|
10
|
+
const cacheKey = `${currentAdminLocale()}|${key}`
|
|
11
|
+
const cached = formatterCache.get(cacheKey)
|
|
12
|
+
if (cached) return cached
|
|
13
|
+
const created = new Intl.DateTimeFormat(currentAdminLocale(), options)
|
|
14
|
+
formatterCache.set(cacheKey, created)
|
|
15
|
+
return created
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function format(value: unknown, options: DateTimeFormatOptions, key: string): string {
|
|
19
|
+
const date = new Date(String(value))
|
|
20
|
+
return Number.isNaN(date.valueOf()) ? '-' : formatter(options, key).format(date)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Formats a calendar date (year-month-day) in the active locale. */
|
|
24
|
+
export function formatAdminDate(value: unknown): string {
|
|
25
|
+
return format(value, { year: 'numeric', month: '2-digit', day: '2-digit' }, 'date')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Formats a full timestamp (date plus hours-minutes-seconds) in the active locale. */
|
|
29
|
+
export function formatAdminDateTime(value: unknown): string {
|
|
30
|
+
return format(
|
|
31
|
+
value,
|
|
32
|
+
{
|
|
33
|
+
year: 'numeric',
|
|
34
|
+
month: '2-digit',
|
|
35
|
+
day: '2-digit',
|
|
36
|
+
hour: '2-digit',
|
|
37
|
+
minute: '2-digit',
|
|
38
|
+
second: '2-digit',
|
|
39
|
+
hour12: false,
|
|
40
|
+
},
|
|
41
|
+
'dateTime',
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Formats a compact timestamp (month-day hours-minutes) in the active locale. */
|
|
46
|
+
export function formatAdminShortDateTime(value: unknown): string {
|
|
47
|
+
return format(
|
|
48
|
+
value,
|
|
49
|
+
{ month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false },
|
|
50
|
+
'shortDateTime',
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -5,6 +5,32 @@ import { fetchMenus, parseMenuResponse } from './menu'
|
|
|
5
5
|
const timestamps = { createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z' }
|
|
6
6
|
|
|
7
7
|
describe('parseMenuResponse', () => {
|
|
8
|
+
it('preserves an optional titleKey on backend menu nodes', () => {
|
|
9
|
+
expect(
|
|
10
|
+
parseMenuResponse([
|
|
11
|
+
{ code: 'dashboard', path: '/dashboard', title: 'Dashboard', titleKey: 'menu.dashboard' },
|
|
12
|
+
]),
|
|
13
|
+
).toEqual([
|
|
14
|
+
{
|
|
15
|
+
code: 'dashboard',
|
|
16
|
+
path: '/dashboard',
|
|
17
|
+
title: 'Dashboard',
|
|
18
|
+
titleKey: 'menu.dashboard',
|
|
19
|
+
componentKey: undefined,
|
|
20
|
+
icon: undefined,
|
|
21
|
+
permissions: undefined,
|
|
22
|
+
parentPath: undefined,
|
|
23
|
+
menu: undefined,
|
|
24
|
+
hidden: undefined,
|
|
25
|
+
order: undefined,
|
|
26
|
+
cache: undefined,
|
|
27
|
+
tabHidden: undefined,
|
|
28
|
+
redirect: undefined,
|
|
29
|
+
children: undefined,
|
|
30
|
+
},
|
|
31
|
+
])
|
|
32
|
+
})
|
|
33
|
+
|
|
8
34
|
it('maps a paged RBAC response into runtime menu nodes', () => {
|
|
9
35
|
const menus = parseMenuResponse({
|
|
10
36
|
list: [
|
|
@@ -43,6 +43,7 @@ function readNode(value: unknown, index: string): BackendMenuNode {
|
|
|
43
43
|
code: value.code,
|
|
44
44
|
path: value.path,
|
|
45
45
|
title: value.title,
|
|
46
|
+
...(typeof value.titleKey === 'string' && value.titleKey ? { titleKey: value.titleKey } : {}),
|
|
46
47
|
componentKey: typeof value.componentKey === 'string' ? value.componentKey : undefined,
|
|
47
48
|
icon: typeof value.icon === 'string' ? value.icon : undefined,
|
|
48
49
|
permissions: Array.isArray(value.permissions)
|
|
@@ -71,6 +72,7 @@ interface RbacMenuNode {
|
|
|
71
72
|
kind: RbacMenuKind
|
|
72
73
|
code: string
|
|
73
74
|
title: string
|
|
75
|
+
titleKey?: string
|
|
74
76
|
path?: string
|
|
75
77
|
componentKey?: string
|
|
76
78
|
icon?: string
|
|
@@ -118,6 +120,7 @@ function readRbacMenuNode(value: unknown, index: string): RbacMenuNode {
|
|
|
118
120
|
kind,
|
|
119
121
|
code: value.code,
|
|
120
122
|
title: value.title,
|
|
123
|
+
titleKey: typeof value.titleKey === 'string' && value.titleKey ? value.titleKey : undefined,
|
|
121
124
|
path: value.path,
|
|
122
125
|
componentKey: typeof value.componentKey === 'string' ? value.componentKey : undefined,
|
|
123
126
|
icon: typeof value.icon === 'string' ? value.icon : undefined,
|
|
@@ -183,6 +186,7 @@ function parseRbacMenuPage(value: Record<string, unknown>): readonly BackendMenu
|
|
|
183
186
|
code: menu.code,
|
|
184
187
|
path: menu.path,
|
|
185
188
|
title: menu.title,
|
|
189
|
+
...(menu.titleKey ? { titleKey: menu.titleKey } : {}),
|
|
186
190
|
componentKey: menu.componentKey,
|
|
187
191
|
icon: menu.icon,
|
|
188
192
|
permissions: menu.permission ? [menu.permission] : undefined,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { resolveAdminLocale
|
|
2
|
+
import { resolveAdminLocale } from './origenUiLocale'
|
|
3
3
|
|
|
4
|
-
describe('admin
|
|
5
|
-
it('
|
|
4
|
+
describe('admin locale resolution', () => {
|
|
5
|
+
it('keeps the supported application locales', () => {
|
|
6
6
|
expect(resolveAdminLocale('zh-CN')).toBe('zh-CN')
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
7
|
+
expect(resolveAdminLocale('en-US')).toBe('en-US')
|
|
8
|
+
expect(resolveAdminLocale('zh-TW')).toBe('zh-TW')
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
it('falls back unknown locales to zh-CN', () => {
|
|
12
12
|
expect(resolveAdminLocale('fr-FR')).toBe('zh-CN')
|
|
13
|
+
expect(resolveAdminLocale(undefined)).toBe('zh-CN')
|
|
13
14
|
})
|
|
14
15
|
})
|
|
@@ -1,65 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { OrigenUiMessages } from 'origen-ui'
|
|
3
|
-
import {
|
|
4
|
-
OG_DIALOG_LOCALE_EN_US,
|
|
5
|
-
OG_DIALOG_LOCALE_ZH_CN,
|
|
6
|
-
OG_DIALOG_LOCALE_ZH_TW,
|
|
7
|
-
} from '@origen-ui/dialog/runtime'
|
|
8
|
-
import {
|
|
9
|
-
OG_FORM_LOCALE_EN_US,
|
|
10
|
-
OG_FORM_LOCALE_ZH_CN,
|
|
11
|
-
OG_FORM_LOCALE_ZH_TW,
|
|
12
|
-
} from '@origen-ui/form/runtime'
|
|
13
|
-
import {
|
|
14
|
-
OG_SEARCH_LOCALE_EN_US,
|
|
15
|
-
OG_SEARCH_LOCALE_ZH_CN,
|
|
16
|
-
OG_SEARCH_LOCALE_ZH_TW,
|
|
17
|
-
} from '@origen-ui/search/runtime'
|
|
18
|
-
import {
|
|
19
|
-
OG_TABLE_LOCALE_EN_US,
|
|
20
|
-
OG_TABLE_LOCALE_ZH_CN,
|
|
21
|
-
OG_TABLE_LOCALE_ZH_TW,
|
|
22
|
-
} from '@origen-ui/table/runtime'
|
|
23
|
-
import {
|
|
24
|
-
OG_TABS_LOCALE_EN_US,
|
|
25
|
-
OG_TABS_LOCALE_ZH_CN,
|
|
26
|
-
OG_TABS_LOCALE_ZH_TW,
|
|
27
|
-
} from '@origen-ui/tabs/runtime'
|
|
1
|
+
import type { AdminLocale } from './adminLocale'
|
|
28
2
|
|
|
29
|
-
export type AdminLocale
|
|
30
|
-
export type OrigenUiLocaleBundle = DeepPartial<OrigenUiMessages>
|
|
3
|
+
export type { AdminLocale } from './adminLocale'
|
|
31
4
|
|
|
32
|
-
/** Resolves
|
|
5
|
+
/** Resolves the application locale selected for vue-i18n and the Origen UI language runtime. */
|
|
33
6
|
export function resolveAdminLocale(locale: string | undefined): AdminLocale {
|
|
34
7
|
if (locale === 'en-US') return 'en-US'
|
|
35
8
|
if (locale === 'zh-TW') return 'zh-TW'
|
|
36
9
|
return 'zh-CN'
|
|
37
10
|
}
|
|
38
|
-
|
|
39
|
-
export function resolveAdminOrigenUiLocale(locale: string | undefined): OrigenUiLocaleBundle {
|
|
40
|
-
if (resolveAdminLocale(locale) === 'en-US') {
|
|
41
|
-
return {
|
|
42
|
-
dialog: OG_DIALOG_LOCALE_EN_US,
|
|
43
|
-
form: OG_FORM_LOCALE_EN_US,
|
|
44
|
-
search: OG_SEARCH_LOCALE_EN_US,
|
|
45
|
-
table: OG_TABLE_LOCALE_EN_US,
|
|
46
|
-
tabs: OG_TABS_LOCALE_EN_US,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (resolveAdminLocale(locale) === 'zh-TW') {
|
|
50
|
-
return {
|
|
51
|
-
dialog: OG_DIALOG_LOCALE_ZH_TW,
|
|
52
|
-
form: OG_FORM_LOCALE_ZH_TW,
|
|
53
|
-
search: OG_SEARCH_LOCALE_ZH_TW,
|
|
54
|
-
table: OG_TABLE_LOCALE_ZH_TW,
|
|
55
|
-
tabs: OG_TABS_LOCALE_ZH_TW,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
dialog: OG_DIALOG_LOCALE_ZH_CN,
|
|
60
|
-
form: OG_FORM_LOCALE_ZH_CN,
|
|
61
|
-
search: OG_SEARCH_LOCALE_ZH_CN,
|
|
62
|
-
table: OG_TABLE_LOCALE_ZH_CN,
|
|
63
|
-
tabs: OG_TABS_LOCALE_ZH_CN,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setActivePinia } from 'pinia'
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
3
|
+
import { useAuthStore } from '../features/auth/store/auth'
|
|
4
|
+
import { pinia } from '../store'
|
|
5
|
+
import { permission } from './permission'
|
|
6
|
+
|
|
7
|
+
describe('admin permission runtime', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// runtime 实例在 app.use(pinia) 之前创建,因此不能读取激活的 Pinia 实例。
|
|
10
|
+
setActivePinia(undefined)
|
|
11
|
+
useAuthStore(pinia).$reset()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('reads permissions from the explicit application Pinia instance before installation', () => {
|
|
15
|
+
useAuthStore(pinia).session = {
|
|
16
|
+
token: 'test-token',
|
|
17
|
+
user: { id: '1', username: 'admin', displayName: 'Admin' },
|
|
18
|
+
permissions: ['system:users:read'],
|
|
19
|
+
roleIds: [],
|
|
20
|
+
authorizationRevision: 3,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
expect(permission.can('system:users:read')).toBe(true)
|
|
24
|
+
expect(permission.can('system:users:write')).toBe(false)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -3,8 +3,12 @@ import type { OgFormGlobalConfig } from '@origen-ui/form'
|
|
|
3
3
|
import type { OgSearchGlobalConfig } from '@origen-ui/search'
|
|
4
4
|
import type { CreateOgTableOptions } from '@origen-ui/table'
|
|
5
5
|
import type { OgTabsGlobalConfig } from '@origen-ui/tabs'
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
function resolveConfiguredLocale(locale: string | undefined): 'zh-CN' | 'en-US' | 'zh-TW' {
|
|
8
|
+
if (locale === 'en-US') return 'en-US'
|
|
9
|
+
if (locale === 'zh-TW') return 'zh-TW'
|
|
10
|
+
return 'zh-CN'
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
export interface AdminRuntimeConfig {
|
|
10
14
|
http: {
|
|
@@ -20,11 +24,10 @@ export interface AdminRuntimeConfig {
|
|
|
20
24
|
csrfHeaderName: string
|
|
21
25
|
refreshBusinessCodes: readonly number[]
|
|
22
26
|
}
|
|
23
|
-
locale: { default: 'zh-CN' | 'en-US' | 'zh-TW'
|
|
27
|
+
locale: { default: 'zh-CN' | 'en-US' | 'zh-TW' }
|
|
24
28
|
router: { workspace: { enabled: boolean, key: string, scope: string, version: number } }
|
|
25
29
|
origenUi: {
|
|
26
30
|
size: 'small' | 'default' | 'large'
|
|
27
|
-
locale: OrigenUiLocaleBundle
|
|
28
31
|
dialog: CreateOgDialogOptions
|
|
29
32
|
form: OgFormGlobalConfig
|
|
30
33
|
search: OgSearchGlobalConfig
|
|
@@ -33,7 +36,7 @@ export interface AdminRuntimeConfig {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
const configuredLocale =
|
|
39
|
+
const configuredLocale = resolveConfiguredLocale(import.meta.env.VITE_DEFAULT_LOCALE)
|
|
37
40
|
|
|
38
41
|
export const appRuntimeConfig: AdminRuntimeConfig = {
|
|
39
42
|
http: {
|
|
@@ -51,7 +54,6 @@ export const appRuntimeConfig: AdminRuntimeConfig = {
|
|
|
51
54
|
},
|
|
52
55
|
locale: {
|
|
53
56
|
default: configuredLocale,
|
|
54
|
-
fallback: 'en-US',
|
|
55
57
|
},
|
|
56
58
|
router: {
|
|
57
59
|
workspace: {
|
|
@@ -63,7 +65,6 @@ export const appRuntimeConfig: AdminRuntimeConfig = {
|
|
|
63
65
|
},
|
|
64
66
|
origenUi: {
|
|
65
67
|
size: 'default',
|
|
66
|
-
locale: resolveAdminOrigenUiLocale(configuredLocale),
|
|
67
68
|
dialog: {},
|
|
68
69
|
form: {},
|
|
69
70
|
search: {},
|
|
@@ -7,8 +7,26 @@ interface ImportMetaEnv {
|
|
|
7
7
|
readonly VITE_DEMO_LOGIN_HINT?: string
|
|
8
8
|
readonly VITE_ROUTE_QUERY_ENCRYPTION?: string
|
|
9
9
|
readonly VITE_ROUTE_QUERY_KEY?: string
|
|
10
|
+
/** 'true' 时意图进入微前端嵌入模式(仍需运行时探测主壳环境,见 app/embedded.ts) */
|
|
11
|
+
readonly VITE_EMBEDDED?: string
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
interface ImportMeta {
|
|
13
15
|
readonly env: ImportMetaEnv
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
/** micro-app 子应用注入环境(app/embedded.ts 探测与桥接使用) */
|
|
19
|
+
interface MicroAppChildEnv {
|
|
20
|
+
__MICRO_APP_ENVIRONMENT__?: boolean
|
|
21
|
+
__MICRO_APP_NAME__?: string
|
|
22
|
+
microApp?: {
|
|
23
|
+
getData?: () => Record<string, unknown>
|
|
24
|
+
addDataListener?: (
|
|
25
|
+
callback: (data: Record<string, unknown>) => void,
|
|
26
|
+
autoTrigger?: boolean,
|
|
27
|
+
) => void
|
|
28
|
+
dispatch?: (data: Record<string, unknown>) => void
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Window extends MicroAppChildEnv {}
|
|
@@ -3,6 +3,8 @@ import type { Component } from 'vue'
|
|
|
3
3
|
import type { ThemeMode } from '../store/theme'
|
|
4
4
|
import { Check, Monitor, Moon, Sunny } from '@element-plus/icons-vue'
|
|
5
5
|
import { ElColorPicker, ElDropdownItem, ElDropdownMenu, ElIcon } from 'element-plus'
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
import { useI18n } from 'vue-i18n'
|
|
6
8
|
import { useTheme } from '../composables/useTheme'
|
|
7
9
|
|
|
8
10
|
defineOptions({ name: 'ThemePanel' })
|
|
@@ -13,19 +15,21 @@ interface ThemeModeOption {
|
|
|
13
15
|
icon: Component
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
{ value: 'light', label: '浅色', icon: Sunny },
|
|
18
|
-
{ value: 'dark', label: '深色', icon: Moon },
|
|
19
|
-
{ value: 'auto', label: '跟随系统', icon: Monitor },
|
|
20
|
-
]
|
|
18
|
+
const { t } = useI18n()
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
{
|
|
24
|
-
{
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const modeOptions = computed<ThemeModeOption[]>(() => [
|
|
21
|
+
{ value: 'light', label: t('appearance.light'), icon: Sunny },
|
|
22
|
+
{ value: 'dark', label: t('appearance.dark'), icon: Moon },
|
|
23
|
+
{ value: 'auto', label: t('appearance.system'), icon: Monitor },
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const primaryPresets = computed(() => [
|
|
27
|
+
{ label: t('appearance.presetIndigo'), value: '#5E6AD2' },
|
|
28
|
+
{ label: t('appearance.presetBlue'), value: '#2563EB' },
|
|
29
|
+
{ label: t('appearance.presetTeal'), value: '#0F766E' },
|
|
30
|
+
{ label: t('appearance.presetRose'), value: '#DB2777' },
|
|
31
|
+
{ label: t('appearance.presetAmber'), value: '#D97706' },
|
|
32
|
+
])
|
|
29
33
|
|
|
30
34
|
const { mode, primary, setMode, setPrimary } = useTheme()
|
|
31
35
|
</script>
|
|
@@ -33,7 +37,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
33
37
|
<template>
|
|
34
38
|
<ElDropdownMenu class="theme-panel">
|
|
35
39
|
<ElDropdownItem class="theme-panel__section" disabled>
|
|
36
|
-
<span
|
|
40
|
+
<span>{{ t('appearance.theme') }}</span>
|
|
37
41
|
</ElDropdownItem>
|
|
38
42
|
<ElDropdownItem
|
|
39
43
|
v-for="option in modeOptions"
|
|
@@ -53,8 +57,8 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
53
57
|
|
|
54
58
|
<li class="theme-panel__separator" aria-hidden="true" />
|
|
55
59
|
<li class="theme-panel__primary">
|
|
56
|
-
<span class="theme-panel__section-label"
|
|
57
|
-
<div class="theme-panel__swatches" aria-label="
|
|
60
|
+
<span class="theme-panel__section-label">{{ t('appearance.primaryColor') }}</span>
|
|
61
|
+
<div class="theme-panel__swatches" :aria-label="t('appearance.primaryPresets')">
|
|
58
62
|
<button
|
|
59
63
|
v-for="preset in primaryPresets"
|
|
60
64
|
:key="preset.value"
|
|
@@ -62,7 +66,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
62
66
|
class="theme-panel__swatch"
|
|
63
67
|
:class="{ 'is-active': primary === preset.value }"
|
|
64
68
|
:style="{ backgroundColor: preset.value }"
|
|
65
|
-
:aria-label="
|
|
69
|
+
:aria-label="t('appearance.usePrimary', { color: preset.label })"
|
|
66
70
|
:aria-pressed="primary === preset.value"
|
|
67
71
|
@click.stop="setPrimary(preset.value)"
|
|
68
72
|
>
|
|
@@ -73,7 +77,7 @@ const { mode, primary, setMode, setPrimary } = useTheme()
|
|
|
73
77
|
</div>
|
|
74
78
|
</li>
|
|
75
79
|
<li class="theme-panel__custom">
|
|
76
|
-
<span
|
|
80
|
+
<span>{{ t('appearance.custom') }}</span>
|
|
77
81
|
<div class="theme-panel__picker">
|
|
78
82
|
<ElColorPicker
|
|
79
83
|
:model-value="primary"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { PrimaryPalette } from '../../../utils/color-mix'
|
|
1
2
|
import { defineStore } from 'pinia'
|
|
2
3
|
import { computed, shallowRef } from 'vue'
|
|
3
|
-
import { derivePrimaryPalette
|
|
4
|
+
import { derivePrimaryPalette } from '../../../utils/color-mix'
|
|
4
5
|
|
|
5
6
|
const STORAGE_KEY = 'og-admin-theme'
|
|
6
7
|
|