feat: 字典(DictTag)支持fallback属性(未匹配到字典项时的回显)

This commit is contained in:
dap
2025-07-18 11:40:19 +08:00
parent 253c9b5248
commit 808406ebce
4 changed files with 138 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
import type { Component as ComponentType } from 'vue';
import type { DictData } from '#/api/system/dict/dict-data-model';
import type { DictFallback } from '#/components/dict/src/type';
import { h } from 'vue';
@@ -149,16 +150,26 @@ export function renderDictTags(
);
}
export interface RenderDictOptions {
fallback?: DictFallback;
}
/**
* 显示字典标签 一般是table使用
* @param value 值
* @param dictName dictName
* @returns tag
*/
export function renderDict(value: number | string, dictName: string) {
export function renderDict(
value: number | string,
dictName: string,
options?: RenderDictOptions,
) {
const { fallback } = options ?? {};
const dictInfo = getDictOptions(dictName);
return renderDictTag(value, dictInfo);
return <DictTag dicts={dictInfo} fallback={fallback} value={value}></DictTag>;
}
export function renderIconSpan(
icon: ComponentType,
value: string,