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