From 808406ebce335e2fd19caec5913a070d32ee218b Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Fri, 18 Jul 2025 11:40:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AD=97=E5=85=B8(DictTag)=E6=94=AF?= =?UTF-8?q?=E6=8C=81fallback=E5=B1=9E=E6=80=A7(=E6=9C=AA=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=88=B0=E5=AD=97=E5=85=B8=E9=A1=B9=E6=97=B6=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E6=98=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + .../src/components/dict/src/index.vue | 164 +++++++++++++----- .../src/components/dict/src/type.d.ts | 5 + apps/web-antd/src/utils/render.tsx | 15 +- 4 files changed, 138 insertions(+), 48 deletions(-) create mode 100644 apps/web-antd/src/components/dict/src/type.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f4a99672..0a7193c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,12 @@ - 流程表达式 follow后端更新 - websocket功能(默认关闭) - useVbenForm 增加 TimeRangePicker(时间区间选择) 组件 +- 字典(DictTag)支持fallback属性(未匹配到字典项时的回显) **REFACTOR** - Modal/Drawer中使用VxeTable tooltip需要设置更高的z-index 防止被遮挡 +- 字典(DictTag)使用tsx写法重构 **OTHERS** diff --git a/apps/web-antd/src/components/dict/src/index.vue b/apps/web-antd/src/components/dict/src/index.vue index 1edd1274..8078f095 100644 --- a/apps/web-antd/src/components/dict/src/index.vue +++ b/apps/web-antd/src/components/dict/src/index.vue @@ -1,62 +1,134 @@ - - - diff --git a/apps/web-antd/src/components/dict/src/type.d.ts b/apps/web-antd/src/components/dict/src/type.d.ts new file mode 100644 index 00000000..dcc96dac --- /dev/null +++ b/apps/web-antd/src/components/dict/src/type.d.ts @@ -0,0 +1,5 @@ +/** + * fallback的渲染 + * 可返回 字符串/Vnode + */ +export type DictFallback = ((current: number | string) => VNode) | string; diff --git a/apps/web-antd/src/utils/render.tsx b/apps/web-antd/src/utils/render.tsx index 419daf31..0a7f9931 100644 --- a/apps/web-antd/src/utils/render.tsx +++ b/apps/web-antd/src/utils/render.tsx @@ -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 ; } + export function renderIconSpan( icon: ComponentType, value: string,