From 3b1e039ede80a7f016f6360e3770991fe6586619 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 26 Mar 2025 19:30:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20vxe=20table=20dict=20tag=E3=80=906c4071?= =?UTF-8?q?2d=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/adapter/vxe-table.ts | 32 +++++++++++++++++-- .../src/views/system/post/post.data.ts | 6 +++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index de6c13c31..643bb0996 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -1,8 +1,9 @@ import { h } from 'vue'; import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table'; +import { useDictStore } from '#/store'; -import { Button, Image } from 'ant-design-vue'; +import { Button, Image, Tag } from 'ant-design-vue'; import { useVbenForm } from './form'; @@ -35,7 +36,7 @@ setupVbenVxeTable({ autoLoad: true, response: { result: 'list', - total: 'total' + total: 'total', }, showActiveMsg: true, showResponseMsg: false, @@ -72,6 +73,33 @@ setupVbenVxeTable({ }, }); + // 表格配置项可以用 cellRender: { name: 'CellDict', props:{dictType: ''} }, + // TODO @芋艿:后续研究下,看看有没优解 + vxeUI.renderer.add('CellDict', { + renderTableDefault(renderOpts, params) { + const dictStore = useDictStore(); + const { props } = renderOpts; + const { column, row } = params; + if (!props) { + return ''; + } + const dict = dictStore.getDictData(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 ''; + }, + }); + // 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 // vxeUI.formats.add }, diff --git a/apps/web-antd/src/views/system/post/post.data.ts b/apps/web-antd/src/views/system/post/post.data.ts index f8851cc01..e42382ec5 100644 --- a/apps/web-antd/src/views/system/post/post.data.ts +++ b/apps/web-antd/src/views/system/post/post.data.ts @@ -44,7 +44,11 @@ export const columns: VxeGridProps['columns'] = [ { field: 'code', title: '岗位编码' }, { field: 'sort', title: '岗位顺序' }, { field: 'remark', title: '岗位备注' }, - { field: 'status', title: '状态' }, + { + field: 'status', + title: '状态', + cellRender: { name: 'CellDict', props: { type: 'common_status' } }, + }, { field: 'createTime', formatter: 'formatDateTime', title: '创建时间' }, { field: 'action',