Skip to content

Commit 7d22328

Browse files
committed
Table 组件:增加对字典数据的支持
1 parent ba327cd commit 7d22328

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/hooks/web/useCrudSchemas.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FormSchema } from '@/types/form'
88
import { TableColumn } from '@/types/table'
99
import { DescriptionsSchema } from '@/types/descriptions'
1010
import { ComponentOptions, ComponentProps } from '@/types/components'
11+
import { DictTag } from '@/components/DictTag'
1112

1213
export type CrudSchema = Omit<TableColumn, 'children'> & {
1314
isSearch?: boolean // 是否在查询显示
@@ -151,6 +152,15 @@ const filterTableSchema = (crudSchema: CrudSchema[]): TableColumn[] => {
151152
const tableColumns = treeMap<CrudSchema>(crudSchema, {
152153
conversion: (schema: CrudSchema) => {
153154
if (schema?.isTable !== false && schema?.table?.show !== false) {
155+
// add by 芋艿:增加对 dict 字典数据的支持
156+
if (!schema.formatter && schema.dictType) {
157+
schema.formatter = (_: Recordable, __: TableColumn, cellValue: any) => {
158+
return h(DictTag, {
159+
type: schema.dictType!, // ! 表示一定不为空
160+
value: cellValue
161+
})
162+
}
163+
}
154164
return {
155165
...schema.table,
156166
...schema

0 commit comments

Comments
 (0)