36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
/**
|
|
* features/admin/composables/useElementProvider.ts
|
|
* 用途:管理端 Element Plus 试点的界面语言。
|
|
* 依赖:element-plus locale、vue-i18n。
|
|
* 逻辑:UsersPage、AgentsPage、KbAdminPanel 把 elementLocale 传给 ElConfigProvider;亮暗靠 html.dark 与 Element 暗色变量,不在这里重复切换。
|
|
*/
|
|
import { computed } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
|
import zhTw from 'element-plus/es/locale/lang/zh-tw';
|
|
import en from 'element-plus/es/locale/lang/en';
|
|
import th from 'element-plus/es/locale/lang/th';
|
|
|
|
const ELEMENT_LOCALES = {
|
|
'zh-CN': zhCn,
|
|
'zh-TW': zhTw,
|
|
en,
|
|
th,
|
|
} as const;
|
|
|
|
/**
|
|
* 取当前界面语言对应的 Element Plus 语言包。
|
|
* 核心逻辑:未知语言回退简体中文。
|
|
* @returns elementLocale,随 vue-i18n 语言变化
|
|
*/
|
|
export function useElementProvider() {
|
|
const { locale } = useI18n();
|
|
|
|
const elementLocale = computed(() => {
|
|
const key = locale.value as keyof typeof ELEMENT_LOCALES;
|
|
return ELEMENT_LOCALES[key] ?? zhCn;
|
|
});
|
|
|
|
return { elementLocale };
|
|
}
|