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

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

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

@ -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',

@ -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: '请输入内容',

@ -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,9 +43,17 @@ export const useDictStore = defineStore('dict', {
async setDictMap() {
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
if (dictMap) {
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
} else {
return
}
}
try {
const res = await getSimpleDictDataList()
const dictDataMap = new Map<string, any>()
@ -56,6 +65,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
})
@ -68,7 +78,6 @@ export const useDictStore = defineStore('dict', {
} 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
})

@ -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

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

@ -82,6 +82,7 @@
<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.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.sort')" align="center" prop="sort" />
<el-table-column :label="t('SystemManagement.Dict.status')" align="center" prop="status" sortable>

Loading…
Cancel
Save