移动端集中修改dict字典展示
This commit is contained in:
1 parent
4b9dbe40fb
commit
8bbe4e6a35
16 files changed
+1684
-134
No files matched your search
@@ -305,5 +305,42 @@ export const refreshDict = async (dictTypes) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取字典项的标签类型(Tag Type)
|
||||
* @param {Array} dictData - 字典数据数组
|
||||
* @param {string|number} value - 字典值
|
||||
* @param {Object} fallbackMap - 降级处理映射对象(可选)
|
||||
* @returns {string} 标签类型
|
||||
*/
|
||||
export const getDictTagType = (dictData, value, fallbackMap = {}) => {
|
||||
// 参数验证
|
||||
if (!Array.isArray(dictData) || value === null || value === undefined) {
|
||||
return 'info'; // 默认类型
|
||||
}
|
||||
|
||||
// 优先从字典数据中获取
|
||||
if (dictData.length > 0) {
|
||||
const dictItem = dictData.find((item) => String(item.value) === String(value));
|
||||
|
||||
if (dictItem && dictItem.elTagType) {
|
||||
// 处理特殊值转换
|
||||
let tagType = dictItem.elTagType;
|
||||
if (tagType === 'danger') {
|
||||
tagType = 'error';
|
||||
} else if (tagType === 'default') {
|
||||
tagType = 'primary';
|
||||
}
|
||||
return tagType;
|
||||
}
|
||||
}
|
||||
|
||||
// 字典未加载或无样式信息时的降级处理
|
||||
if (fallbackMap && typeof fallbackMap === 'object') {
|
||||
return fallbackMap[value] || 'info';
|
||||
}
|
||||
|
||||
return 'info';
|
||||
};
|
||||
|
||||
// 导出缓存管理对象(用于高级用法)
|
||||
export { dictCache };
|
||||
Reference in new issue
Block a user