From 56532d415f465a34cbc3a1fcd41eb92ef0e87654 Mon Sep 17 00:00:00 2001 From: hwj Date: Wed, 18 Mar 2026 17:38:38 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E9=85=8D=E7=BD=AE=E8=8B=B1=E6=96=87=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/dict/dict.data.ts | 1 + src/locales/en.ts | 2 + src/locales/zh-CN.ts | 2 + src/store/modules/dict.ts | 58 ++++++++++++--------- src/utils/dict.ts | 12 ++++- src/views/system/dict/data/DictDataForm.vue | 8 +++ src/views/system/dict/data/index.vue | 1 + 7 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/api/system/dict/dict.data.ts b/src/api/system/dict/dict.data.ts index f4286481..f4356df9 100644 --- a/src/api/system/dict/dict.data.ts +++ b/src/api/system/dict/dict.data.ts @@ -4,6 +4,7 @@ export type DictDataVO = { id: number | undefined sort: number | undefined label: string + labelEn?: string value: string dictType: string status: number diff --git a/src/locales/en.ts b/src/locales/en.ts index ec76eead..f3635b38 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -1081,6 +1081,7 @@ export default { name: 'Dict Name', type: 'Dict Type', label: 'Dict Label', + labelEn: 'Dict Label (EN)', value: 'Dict Value', sort: 'Dict Sort', status: 'Status', @@ -1098,6 +1099,7 @@ export default { namePlaceholder: 'Please input dict name', typePlaceholder: 'Please input dict type', labelPlaceholder: 'Please input data label', + labelEnPlaceholder: 'Please input data label (EN)', valuePlaceholder: 'Please input data value', sortPlaceholder: 'Please input data order', remarkPlaceholder: 'Please input content', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 09385d58..19048918 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -1081,6 +1081,7 @@ export default { name: '字典名称', type: '字典类型', label: '字典标签', + labelEn: '字典标签(英文)', value: '字典键值', sort: '字典排序', status: '状态', @@ -1098,6 +1099,7 @@ export default { namePlaceholder: '请输入字典名称', typePlaceholder: '请输入字典类型', labelPlaceholder: '请输入数据标签', + labelEnPlaceholder: '请输入数据标签(英文)', valuePlaceholder: '请输入数据键值', sortPlaceholder: '请输入数据顺序', remarkPlaceholder: '请输入内容', diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts index e94f14f4..e3fda4da 100644 --- a/src/store/modules/dict.ts +++ b/src/store/modules/dict.ts @@ -9,6 +9,7 @@ import { getSimpleDictDataList } from '@/api/system/dict/dict.data' export interface DictValueType { value: any label: string + labelEn?: string clorType?: string cssClass?: string } @@ -42,33 +43,41 @@ export const useDictStore = defineStore('dict', { async setDictMap() { const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE) if (dictMap) { - this.dictMap = dictMap - this.isSetDict = true - } else { - try { - const res = await getSimpleDictDataList() - const dictDataMap = new Map() - res.forEach((dictData: DictDataVO) => { - const enumValueObj = dictDataMap[dictData.dictType] - if (!enumValueObj) { - dictDataMap[dictData.dictType] = [] - } - dictDataMap[dictData.dictType].push({ - value: dictData.value, - label: dictData.label, - colorType: dictData.colorType, - cssClass: dictData.cssClass - }) - }) - this.dictMap = dictDataMap - wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) - } catch (error) { - console.error('加载数据字典失败', error) - this.dictMap = new Map() - } finally { + const dictTypes = Object.keys(dictMap || {}) + const firstDictType = dictTypes[0] + const firstList = firstDictType ? dictMap[firstDictType] : undefined + const needsUpgrade = + Array.isArray(firstList) && firstList.length > 0 && !('labelEn' in (firstList[0] || {})) + if (!needsUpgrade) { + this.dictMap = dictMap this.isSetDict = true + return } } + try { + const res = await getSimpleDictDataList() + const dictDataMap = new Map() + res.forEach((dictData: DictDataVO) => { + const enumValueObj = dictDataMap[dictData.dictType] + if (!enumValueObj) { + dictDataMap[dictData.dictType] = [] + } + dictDataMap[dictData.dictType].push({ + value: dictData.value, + label: dictData.label, + labelEn: (dictData as any).labelEn, + colorType: dictData.colorType, + cssClass: dictData.cssClass + }) + }) + this.dictMap = dictDataMap + wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) + } catch (error) { + console.error('加载数据字典失败', error) + this.dictMap = new Map() + } finally { + this.isSetDict = true + } }, getDictByType(type: string) { if (!this.isSetDict) { @@ -89,6 +98,7 @@ export const useDictStore = defineStore('dict', { dictDataMap[dictData.dictType].push({ value: dictData.value, label: dictData.label, + labelEn: (dictData as any).labelEn, colorType: dictData.colorType, cssClass: dictData.cssClass }) diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 4c1c8ddf..2d3cc806 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -2,9 +2,11 @@ * 数据字典工具类 */ import { useDictStoreWithOut } from '@/store/modules/dict' +import { useLocaleStoreWithOut } from '@/store/modules/locale' import { ElementPlusInfoType } from '@/types/elementPlus' const dictStore = useDictStoreWithOut() +const localeStore = useLocaleStoreWithOut() /** * 获取 dictType 对应的数据字典数组 @@ -15,6 +17,7 @@ const dictStore = useDictStoreWithOut() export interface DictDataType { dictType: string label: string + labelEn?: string value: string | number colorType: ElementPlusInfoType | '' cssClass: string @@ -39,8 +42,10 @@ export const getIntDictOptions = (dictType: string): NumberDictDataType[] => { // why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时,el-option 的 key 会告警 const dictOption: NumberDictDataType[] = [] dictOptions.forEach((dict: DictDataType) => { + const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label dictOption.push({ ...dict, + label, value: parseInt(dict.value + '') }) }) @@ -54,8 +59,10 @@ export const getStrDictOptions = (dictType: string) => { // why 需要特殊转换:避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时,el-option 的 key 会告警 const dictOption: StringDictDataType[] = [] dictOptions.forEach((dict: DictDataType) => { + const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label dictOption.push({ ...dict, + label, value: dict.value + '' }) }) @@ -66,8 +73,10 @@ export const getBoolDictOptions = (dictType: string) => { const dictOption: DictDataType[] = [] const dictOptions: DictDataType[] = getDictOptions(dictType) dictOptions.forEach((dict: DictDataType) => { + const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label dictOption.push({ ...dict, + label, value: dict.value + '' === 'true' }) }) @@ -101,7 +110,8 @@ export const getDictLabel = (dictType: string, value: any): string => { const dictLabel = ref('') dictOptions.forEach((dict: DictDataType) => { if (dict.value === value + '') { - dictLabel.value = dict.label + dictLabel.value = + localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label } }) return dictLabel.value diff --git a/src/views/system/dict/data/DictDataForm.vue b/src/views/system/dict/data/DictDataForm.vue index a35be151..1447dc22 100644 --- a/src/views/system/dict/data/DictDataForm.vue +++ b/src/views/system/dict/data/DictDataForm.vue @@ -20,6 +20,12 @@ :placeholder="t('SystemManagement.Dict.labelPlaceholder')" /> + + + { id: undefined, sort: undefined, label: '', + labelEn: '', value: '', dictType: '', status: CommonStatusEnum.ENABLE, diff --git a/src/views/system/dict/data/index.vue b/src/views/system/dict/data/index.vue index fb10a790..e3747a71 100644 --- a/src/views/system/dict/data/index.vue +++ b/src/views/system/dict/data/index.vue @@ -82,6 +82,7 @@ +