mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-24 00:01:56 +08:00
37 lines
862 B
JavaScript
37 lines
862 B
JavaScript
|
/**
|
||
|
* Created by 芋道源码
|
||
|
*
|
||
|
* 数据字典工具类
|
||
|
*/
|
||
|
import store from '@/store'
|
||
|
|
||
|
export const DICT_TYPE = {
|
||
|
SYS_COMMON_STATUS: 'sys_common_status'
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取 dictType 对应的数据字典数组
|
||
|
*
|
||
|
* @param dictType 数据类型
|
||
|
* @returns {*|Array} 数据字典数组
|
||
|
*/
|
||
|
export function getDictDatas(dictType) {
|
||
|
return store.getters.dict_datas[dictType] || []
|
||
|
}
|
||
|
|
||
|
export function getDictDataLabel(dictType, value) {
|
||
|
// 获取 dictType 对应的数据字典数组
|
||
|
const dictDatas = getDictDatas(dictType)
|
||
|
if (!dictDatas || dictDatas.length === 0) {
|
||
|
return ''
|
||
|
}
|
||
|
// 获取 value 对应的展示名
|
||
|
value = value + '' // 强制转换成字符串,因为 DictData 小类数值,是字符串
|
||
|
for (const dictData of dictDatas) {
|
||
|
if (dictData.dictValue === value) {
|
||
|
return dictData.dictLabel
|
||
|
}
|
||
|
}
|
||
|
return ''
|
||
|
}
|