Skip to content

Commit

Permalink
feat: default loacle setting
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Jul 27, 2024
1 parent a9b9ff5 commit d9423a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/store/modules/dynamicConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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', {
state: (): DynamicConfig => ({
systemName: '',
systemLogo: '',
showSettingButton: true,
defaultLocale: LOCALE.ZH_CN,
}),
getters: {
getSystemName(): string {
Expand All @@ -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 = '';
Expand Down
8 changes: 7 additions & 1 deletion src/views/sys/login/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
});
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-login';
Expand Down

0 comments on commit d9423a0

Please sign in to comment.