1. 增加字典数据接口

2. 前端接入全局字典数据
This commit is contained in:
YunaiV
2021-01-08 01:28:41 +08:00
parent 74daab066d
commit dba723b8fc
19 changed files with 245 additions and 23 deletions

View File

@@ -0,0 +1,36 @@
/**
* 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 ''
}