From d9423a02e803439a74ca67841000beaa2467e40e Mon Sep 17 00:00:00 2001 From: Ryan Su Date: Sat, 27 Jul 2024 10:20:01 +0800 Subject: [PATCH] feat: default loacle setting --- src/store/modules/dynamicConfig.ts | 36 +++++++++++++++++------------- src/views/sys/login/Login.vue | 8 ++++++- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/store/modules/dynamicConfig.ts b/src/store/modules/dynamicConfig.ts index 438e6fb3..b6a7fbc5 100644 --- a/src/store/modules/dynamicConfig.ts +++ b/src/store/modules/dynamicConfig.ts @@ -1,10 +1,12 @@ import { defineStore } from 'pinia'; import { getPublicSystemConfigurationList } from '/@/api/sys/configuration'; +import { LOCALE } from '/@/settings/localeSetting'; interface DynamicConfig { systemName: string; systemLogo: string; showSettingButton: boolean; + defaultLocale: string; } export const useDynamicConfigStore = defineStore('app-dynamic-config', { @@ -12,6 +14,7 @@ export const useDynamicConfigStore = defineStore('app-dynamic-config', { systemName: '', systemLogo: '', showSettingButton: true, + defaultLocale: LOCALE.ZH_CN, }), getters: { getSystemName(): string { @@ -26,22 +29,23 @@ export const useDynamicConfigStore = defineStore('app-dynamic-config', { const config = await getPublicSystemConfigurationList(); if (config.code === 0 && config.data.total !== 0) { - const name = config.data.data.find((v) => v.key == 'sys.ui.name'); - if (name !== undefined) { - this.systemName = name.value !== undefined ? name.value : ''; - } - - const logo = config.data.data.find((v) => v.key == 'sys.ui.logo'); - if (logo !== undefined) { - this.systemLogo = logo.value !== undefined ? logo.value : ''; - } - - const showSettingButton = config.data.data.find((v) => v.key == 'sys.ui.showSettingButton'); - if (showSettingButton !== undefined) { - this.showSettingButton = - showSettingButton.value !== undefined && showSettingButton.value === 'true' - ? true - : false; + for (const v of config.data.data) { + if (v.key != undefined) { + switch (v.key) { + case 'sys.ui.name': + this.systemName = v.value !== undefined ? v.value : ''; + break; + case 'sys.ui.logo': + this.systemLogo = v.value !== undefined ? v.value : ''; + break; + case 'sys.ui.showSettingButton': + this.showSettingButton = v.value !== undefined && v.value === 'true' ? true : false; + break; + case 'sys.ui.defaultLocale': + this.defaultLocale = v.value !== undefined ? v.value : LOCALE.ZH_CN; + break; + } + } } } else if (config.code === 0 && config.data.total === 0) { this.systemName = ''; diff --git a/src/views/sys/login/Login.vue b/src/views/sys/login/Login.vue index 77a8ead1..3425afdd 100644 --- a/src/views/sys/login/Login.vue +++ b/src/views/sys/login/Login.vue @@ -58,6 +58,7 @@ import { useDesign } from '@/hooks/web/useDesign'; import { useLocaleStore } from '@/store/modules/locale'; import { useDynamicConfigStore } from '/@/store/modules/dynamicConfig'; + import { LocaleType } from '/#/config'; defineProps({ sessionTimeout: { @@ -72,7 +73,12 @@ const showLocale = localeStore.getShowPicker; const title = computed(() => globSetting?.title ?? ''); const dynamicConfigStore = useDynamicConfigStore(); - dynamicConfigStore.getDynamicConfigFromServer(); + dynamicConfigStore.getDynamicConfigFromServer().then(() => { + localeStore.setLocaleInfo({ + locale: dynamicConfigStore.defaultLocale as LocaleType, + fallback: dynamicConfigStore.defaultLocale as LocaleType, + }); + });