feat:添加字典配置英文标签选项

main
黄伟杰 3 days ago
parent c4e66f90af
commit 56532d415f

@ -4,6 +4,7 @@ export type DictDataVO = {
id: number | undefined id: number | undefined
sort: number | undefined sort: number | undefined
label: string label: string
labelEn?: string
value: string value: string
dictType: string dictType: string
status: number status: number

@ -1081,6 +1081,7 @@ export default {
name: 'Dict Name', name: 'Dict Name',
type: 'Dict Type', type: 'Dict Type',
label: 'Dict Label', label: 'Dict Label',
labelEn: 'Dict Label (EN)',
value: 'Dict Value', value: 'Dict Value',
sort: 'Dict Sort', sort: 'Dict Sort',
status: 'Status', status: 'Status',
@ -1098,6 +1099,7 @@ export default {
namePlaceholder: 'Please input dict name', namePlaceholder: 'Please input dict name',
typePlaceholder: 'Please input dict type', typePlaceholder: 'Please input dict type',
labelPlaceholder: 'Please input data label', labelPlaceholder: 'Please input data label',
labelEnPlaceholder: 'Please input data label (EN)',
valuePlaceholder: 'Please input data value', valuePlaceholder: 'Please input data value',
sortPlaceholder: 'Please input data order', sortPlaceholder: 'Please input data order',
remarkPlaceholder: 'Please input content', remarkPlaceholder: 'Please input content',

@ -1081,6 +1081,7 @@ export default {
name: '字典名称', name: '字典名称',
type: '字典类型', type: '字典类型',
label: '字典标签', label: '字典标签',
labelEn: '字典标签(英文)',
value: '字典键值', value: '字典键值',
sort: '字典排序', sort: '字典排序',
status: '状态', status: '状态',
@ -1098,6 +1099,7 @@ export default {
namePlaceholder: '请输入字典名称', namePlaceholder: '请输入字典名称',
typePlaceholder: '请输入字典类型', typePlaceholder: '请输入字典类型',
labelPlaceholder: '请输入数据标签', labelPlaceholder: '请输入数据标签',
labelEnPlaceholder: '请输入数据标签(英文)',
valuePlaceholder: '请输入数据键值', valuePlaceholder: '请输入数据键值',
sortPlaceholder: '请输入数据顺序', sortPlaceholder: '请输入数据顺序',
remarkPlaceholder: '请输入内容', remarkPlaceholder: '请输入内容',

@ -9,6 +9,7 @@ import { getSimpleDictDataList } from '@/api/system/dict/dict.data'
export interface DictValueType { export interface DictValueType {
value: any value: any
label: string label: string
labelEn?: string
clorType?: string clorType?: string
cssClass?: string cssClass?: string
} }
@ -42,33 +43,41 @@ export const useDictStore = defineStore('dict', {
async setDictMap() { async setDictMap() {
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE) const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
if (dictMap) { if (dictMap) {
this.dictMap = dictMap const dictTypes = Object.keys(dictMap || {})
this.isSetDict = true const firstDictType = dictTypes[0]
} else { const firstList = firstDictType ? dictMap[firstDictType] : undefined
try { const needsUpgrade =
const res = await getSimpleDictDataList() Array.isArray(firstList) && firstList.length > 0 && !('labelEn' in (firstList[0] || {}))
const dictDataMap = new Map<string, any>() if (!needsUpgrade) {
res.forEach((dictData: DictDataVO) => { this.dictMap = dictMap
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<string, any>()
} finally {
this.isSetDict = true this.isSetDict = true
return
} }
} }
try {
const res = await getSimpleDictDataList()
const dictDataMap = new Map<string, any>()
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<string, any>()
} finally {
this.isSetDict = true
}
}, },
getDictByType(type: string) { getDictByType(type: string) {
if (!this.isSetDict) { if (!this.isSetDict) {
@ -89,6 +98,7 @@ export const useDictStore = defineStore('dict', {
dictDataMap[dictData.dictType].push({ dictDataMap[dictData.dictType].push({
value: dictData.value, value: dictData.value,
label: dictData.label, label: dictData.label,
labelEn: (dictData as any).labelEn,
colorType: dictData.colorType, colorType: dictData.colorType,
cssClass: dictData.cssClass cssClass: dictData.cssClass
}) })

@ -2,9 +2,11 @@
* *
*/ */
import { useDictStoreWithOut } from '@/store/modules/dict' import { useDictStoreWithOut } from '@/store/modules/dict'
import { useLocaleStoreWithOut } from '@/store/modules/locale'
import { ElementPlusInfoType } from '@/types/elementPlus' import { ElementPlusInfoType } from '@/types/elementPlus'
const dictStore = useDictStoreWithOut() const dictStore = useDictStoreWithOut()
const localeStore = useLocaleStoreWithOut()
/** /**
* dictType * dictType
@ -15,6 +17,7 @@ const dictStore = useDictStoreWithOut()
export interface DictDataType { export interface DictDataType {
dictType: string dictType: string
label: string label: string
labelEn?: string
value: string | number value: string | number
colorType: ElementPlusInfoType | '' colorType: ElementPlusInfoType | ''
cssClass: string cssClass: string
@ -39,8 +42,10 @@ export const getIntDictOptions = (dictType: string): NumberDictDataType[] => {
// why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时el-option 的 key 会告警 // why 需要特殊转换:避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时el-option 的 key 会告警
const dictOption: NumberDictDataType[] = [] const dictOption: NumberDictDataType[] = []
dictOptions.forEach((dict: DictDataType) => { dictOptions.forEach((dict: DictDataType) => {
const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label
dictOption.push({ dictOption.push({
...dict, ...dict,
label,
value: parseInt(dict.value + '') value: parseInt(dict.value + '')
}) })
}) })
@ -54,8 +59,10 @@ export const getStrDictOptions = (dictType: string) => {
// why 需要特殊转换:避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时el-option 的 key 会告警 // why 需要特殊转换:避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时el-option 的 key 会告警
const dictOption: StringDictDataType[] = [] const dictOption: StringDictDataType[] = []
dictOptions.forEach((dict: DictDataType) => { dictOptions.forEach((dict: DictDataType) => {
const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label
dictOption.push({ dictOption.push({
...dict, ...dict,
label,
value: dict.value + '' value: dict.value + ''
}) })
}) })
@ -66,8 +73,10 @@ export const getBoolDictOptions = (dictType: string) => {
const dictOption: DictDataType[] = [] const dictOption: DictDataType[] = []
const dictOptions: DictDataType[] = getDictOptions(dictType) const dictOptions: DictDataType[] = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => { dictOptions.forEach((dict: DictDataType) => {
const label = localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label
dictOption.push({ dictOption.push({
...dict, ...dict,
label,
value: dict.value + '' === 'true' value: dict.value + '' === 'true'
}) })
}) })
@ -101,7 +110,8 @@ export const getDictLabel = (dictType: string, value: any): string => {
const dictLabel = ref('') const dictLabel = ref('')
dictOptions.forEach((dict: DictDataType) => { dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value + '') { if (dict.value === value + '') {
dictLabel.value = dict.label dictLabel.value =
localeStore.getCurrentLocale?.lang === 'en' ? (dict.labelEn || dict.label) : dict.label
} }
}) })
return dictLabel.value return dictLabel.value

@ -20,6 +20,12 @@
:placeholder="t('SystemManagement.Dict.labelPlaceholder')" :placeholder="t('SystemManagement.Dict.labelPlaceholder')"
/> />
</el-form-item> </el-form-item>
<el-form-item :label="t('SystemManagement.Dict.labelEn')" prop="labelEn">
<el-input
v-model="formData.labelEn"
:placeholder="t('SystemManagement.Dict.labelEnPlaceholder')"
/>
</el-form-item>
<el-form-item :label="t('SystemManagement.Dict.value')" prop="value"> <el-form-item :label="t('SystemManagement.Dict.value')" prop="value">
<el-input <el-input
v-model="formData.value" v-model="formData.value"
@ -93,6 +99,7 @@ const formData = ref({
id: undefined, id: undefined,
sort: undefined, sort: undefined,
label: '', label: '',
labelEn: '',
value: '', value: '',
dictType: '', dictType: '',
status: CommonStatusEnum.ENABLE, status: CommonStatusEnum.ENABLE,
@ -191,6 +198,7 @@ const resetForm = () => {
id: undefined, id: undefined,
sort: undefined, sort: undefined,
label: '', label: '',
labelEn: '',
value: '', value: '',
dictType: '', dictType: '',
status: CommonStatusEnum.ENABLE, status: CommonStatusEnum.ENABLE,

@ -82,6 +82,7 @@
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column :label="t('SystemManagement.Dict.id')" align="center" prop="id" /> <el-table-column :label="t('SystemManagement.Dict.id')" align="center" prop="id" />
<el-table-column :label="t('SystemManagement.Dict.label')" align="center" prop="label" /> <el-table-column :label="t('SystemManagement.Dict.label')" align="center" prop="label" />
<el-table-column :label="t('SystemManagement.Dict.labelEn')" align="center" prop="labelEn" :min-width="120"/>
<el-table-column :label="t('SystemManagement.Dict.value')" align="center" prop="value" /> <el-table-column :label="t('SystemManagement.Dict.value')" align="center" prop="value" />
<el-table-column :label="t('SystemManagement.Dict.sort')" align="center" prop="sort" /> <el-table-column :label="t('SystemManagement.Dict.sort')" align="center" prop="sort" />
<el-table-column :label="t('SystemManagement.Dict.status')" align="center" prop="status" sortable> <el-table-column :label="t('SystemManagement.Dict.status')" align="center" prop="status" sortable>

Loading…
Cancel
Save