feat(语言): 初始化默认语言

This commit is contained in:
baiqi 2024-08-12 16:34:57 +08:00 committed by Craftsman
parent 8f51fc5395
commit 82769d360a
3 changed files with 17 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import {
GeLarkSuiteInfoUrl, GeLarkSuiteInfoUrl,
GetAPIKEYListUrl, GetAPIKEYListUrl,
getAuthenticationUrl, getAuthenticationUrl,
GetDefaultLocaleUrl,
GetDingCallbackUrl, GetDingCallbackUrl,
GetInfoUrl, GetInfoUrl,
GetLarkCallbackUrl, GetLarkCallbackUrl,
@ -54,6 +55,7 @@ import type {
} from '@/models/user'; } from '@/models/user';
import { DingInfo, LarkInfo, WecomInfo } from '@/models/user'; import { DingInfo, LarkInfo, WecomInfo } from '@/models/user';
import type { LocaleType } from '#/global';
import type { RouteRecordNormalized } from 'vue-router'; import type { RouteRecordNormalized } from 'vue-router';
export function login(data: LoginData) { export function login(data: LoginData) {
@ -226,3 +228,8 @@ export function getPlatformAccount() {
export function getPlatformOrgOption() { export function getPlatformOrgOption() {
return MSR.get<OrgOptionItem[]>({ url: GetPlatformOrgOptionUrl }); return MSR.get<OrgOptionItem[]>({ url: GetPlatformOrgOptionUrl });
} }
// 获取默认语言配置
export function getDefaultLocale() {
return MSR.get<LocaleType>({ url: GetDefaultLocaleUrl });
}

View File

@ -35,3 +35,4 @@ export const GeLarkInfoUrl = '/lark/info'; // 获取飞书登陆的配置信息
export const GetLarkCallbackUrl = '/sso/callback/lark'; // 获取飞书登陆的回调信息 export const GetLarkCallbackUrl = '/sso/callback/lark'; // 获取飞书登陆的回调信息
export const GeLarkSuiteInfoUrl = '/lark_suite/info'; // 获取国际飞书登陆的配置信息 export const GeLarkSuiteInfoUrl = '/lark_suite/info'; // 获取国际飞书登陆的配置信息
export const GetLarkSuiteCallbackUrl = '/sso/callback/lark_suite'; // 获取国际飞书登陆的回调信息 export const GetLarkSuiteCallbackUrl = '/sso/callback/lark_suite'; // 获取国际飞书登陆的回调信息
export const GetDefaultLocaleUrl = '/user/local/config/default-locale'; // 获取默认语言配置

View File

@ -17,6 +17,8 @@ import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import '@/assets/style/global.less'; import '@/assets/style/global.less';
import localforage from 'localforage'; import localforage from 'localforage';
import VueDOMPurifyHTML from 'vue-dompurify-html'; import VueDOMPurifyHTML from 'vue-dompurify-html';
import { getDefaultLocale } from './api/modules/user';
import useLocale from './locale/useLocale';
async function bootstrap() { async function bootstrap() {
const app = createApp(App); const app = createApp(App);
@ -24,6 +26,13 @@ async function bootstrap() {
app.use(store); app.use(store);
// 注册国际化,需要异步阻塞,确保语言包加载完毕 // 注册国际化,需要异步阻塞,确保语言包加载完毕
await setupI18n(app); await setupI18n(app);
// 获取默认语言
const defaultLocale = await getDefaultLocale();
const { currentLocale, changeLocale } = useLocale();
if (currentLocale.value !== defaultLocale) {
changeLocale(defaultLocale);
}
app.use(router); app.use(router);
app.use(ArcoVue); app.use(ArcoVue);
app.use(ArcoVueIcon); app.use(ArcoVueIcon);