From 0bef7c6bd9417b383fab547de0b359410b6f394e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 5 Apr 2025 11:32:38 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=20DictTag=20?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=A0=87=E7=AD=BE=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/adapter/vxe-table.ts | 25 +++----- .../web-antd/src/components/dict-tag/index.ts | 3 + .../src/components/dict-tag/src/DictTag.vue | 60 +++++++++++++++++++ .../views/system/mail/log/modules/detail.vue | 10 ++-- .../system/notify/message/modules/detail.vue | 42 ++++++------- .../views/system/notify/my/modules/detail.vue | 52 ++++++---------- .../views/system/sms/log/modules/detail.vue | 18 ++---- 7 files changed, 113 insertions(+), 97 deletions(-) create mode 100644 apps/web-antd/src/components/dict-tag/index.ts create mode 100644 apps/web-antd/src/components/dict-tag/src/DictTag.vue diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index 2e7f6908d..c773cea4a 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -5,9 +5,8 @@ import { $te } from '@vben/locales'; import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; import { isFunction, isString } from '@vben/utils'; -import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue'; - -import { getDictObj } from '#/utils/dict'; +import { Button, Image, Popconfirm, Switch } from 'ant-design-vue'; +import { DictTag } from '#/components/dict-tag'; import { useVbenForm } from './form'; import type { Recordable } from '@vben/types'; @@ -81,7 +80,6 @@ setupVbenVxeTable({ }); // 表格配置项可以用 cellRender: { name: 'CellDict', props:{dictType: ''} }, - // TODO @芋艿:后续研究下,看看有没优解 vxeUI.renderer.add('CellDict', { renderTableDefault(renderOpts, params) { const { props } = renderOpts; @@ -89,20 +87,11 @@ setupVbenVxeTable({ if (!props) { return ''; } - const dict = getDictObj(props.type, row[column.field]); - // 转义 - if (dict) { - if (`${dict.colorType}` === 'primary') dict.colorType = 'processing'; - else if (`${dict.colorType}` === 'danger') dict.colorType = 'error'; - else if (`${dict.colorType}` === 'info') dict.colorType = 'default'; - else if (!dict.colorType) dict.colorType = 'default'; - return h( - Tag, - { color: dict.colorType }, - { default: () => dict.label }, - ); - } - return ''; + // 使用 DictTag 组件替代原来的实现 + return h(DictTag, { + type: props.type, + value: row[column.field]?.toString(), + }); }, }); diff --git a/apps/web-antd/src/components/dict-tag/index.ts b/apps/web-antd/src/components/dict-tag/index.ts new file mode 100644 index 000000000..4db274209 --- /dev/null +++ b/apps/web-antd/src/components/dict-tag/index.ts @@ -0,0 +1,3 @@ +import DictTag from './src/DictTag.vue' + +export { DictTag } diff --git a/apps/web-antd/src/components/dict-tag/src/DictTag.vue b/apps/web-antd/src/components/dict-tag/src/DictTag.vue new file mode 100644 index 000000000..90078a0c7 --- /dev/null +++ b/apps/web-antd/src/components/dict-tag/src/DictTag.vue @@ -0,0 +1,60 @@ + + + diff --git a/apps/web-antd/src/views/system/mail/log/modules/detail.vue b/apps/web-antd/src/views/system/mail/log/modules/detail.vue index 21b87acad..eac6f12e3 100644 --- a/apps/web-antd/src/views/system/mail/log/modules/detail.vue +++ b/apps/web-antd/src/views/system/mail/log/modules/detail.vue @@ -2,11 +2,12 @@ import type { SystemMailLogApi } from '#/api/system/mail/log'; import { useVbenModal } from '@vben/common-ui'; -import { Descriptions, Tag } from 'ant-design-vue'; +import { Descriptions } from 'ant-design-vue'; +import { DictTag } from '#/components/dict-tag'; import { ref } from 'vue'; import { formatDateTime } from '@vben/utils'; -import { DICT_TYPE, getDictLabel } from '#/utils/dict'; +import { DICT_TYPE } from '#/utils/dict'; const formData = ref(); @@ -63,10 +64,7 @@ const [Modal, modalApi] = useVbenModal({
- - - {{ getDictLabel(DICT_TYPE.SYSTEM_MAIL_SEND_STATUS, formData?.sendStatus ) }} - + {{ formatDateTime(formData?.sendTime || '') }} diff --git a/apps/web-antd/src/views/system/notify/message/modules/detail.vue b/apps/web-antd/src/views/system/notify/message/modules/detail.vue index 6f4786cfb..e5993c275 100644 --- a/apps/web-antd/src/views/system/notify/message/modules/detail.vue +++ b/apps/web-antd/src/views/system/notify/message/modules/detail.vue @@ -2,13 +2,14 @@ import type { SystemNotifyMessageApi } from '#/api/system/notify/message'; import { useVbenModal } from '@vben/common-ui'; -import { Descriptions, Tag } from 'ant-design-vue'; +import { Descriptions } from 'ant-design-vue'; +import { DictTag } from '#/components/dict-tag'; import { ref } from 'vue'; import { formatDateTime } from '@vben/utils'; -import { DICT_TYPE, getDictLabel } from '#/utils/dict'; +import { DICT_TYPE } from '#/utils/dict'; -const messageData = ref(); +const formData = ref(); const [Modal, modalApi] = useVbenModal({ async onOpenChange(isOpen: boolean) { @@ -22,7 +23,7 @@ const [Modal, modalApi] = useVbenModal({ } modalApi.lock(); try { - messageData.value = data; + formData.value = data; } finally { modalApi.lock(false); } @@ -33,48 +34,39 @@ const [Modal, modalApi] = useVbenModal({