Merge pull request '恢复字典组件多语言支持' (#299) from koy07555/Admin.NET.Pro:字典组件多语言支持 into v2
Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/299
This commit is contained in:
commit
b73c193b88
@ -38,7 +38,24 @@ export const useUserInfo = defineStore('userInfo', {
|
||||
var dictList = await getAPI(SysDictTypeApi)
|
||||
.apiSysDictTypeAllDictListGet()
|
||||
.then((res) => res.data.result ?? {});
|
||||
this.dictList = JSON.parse(JSON.stringify(dictList));
|
||||
var dictListTemp = JSON.parse(JSON.stringify(dictList));
|
||||
console.log('dictListTemp', JSON.stringify(dictList));
|
||||
console.log(dictListTemp);
|
||||
await Promise.all(
|
||||
Object.keys(dictList).map(async (key) => {
|
||||
dictList[key].forEach((da: any, index: any) => {
|
||||
setDictLangMessageAsync(dictListTemp[key][index]);
|
||||
});
|
||||
// 字典组件的value统一使用字符串,所有其它处理在业务代码中进行。(另再加这个代码)
|
||||
/*
|
||||
// 如果 key 以 "Enum" 结尾,则转换 value 为数字
|
||||
if (key.endsWith('Enum')) {
|
||||
dictListTemp[key].forEach((e: any) => (e.value = Number(e.value)));
|
||||
}
|
||||
*/
|
||||
})
|
||||
);
|
||||
this.dictList = dictListTemp;
|
||||
},
|
||||
|
||||
// 存储用户表格列到浏览器缓存
|
||||
@ -165,3 +182,10 @@ export const useUserInfo = defineStore('userInfo', {
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// 处理字典国际化, 默认显示字典中的label值
|
||||
const setDictLangMessageAsync = async (dict: any) => {
|
||||
dict.langMessage = `message.dictType.${dict.typeCode}_${dict.value}`;
|
||||
const text = t(dict.langMessage);
|
||||
dict.label = ((text !== dict.langMessage) && (!text.endsWith(`${dict.typeCode}_${dict.value}`))) ? text : dict.label;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user