Table 组件:增加对字典数据的支持

This commit is contained in:
YunaiV 2023-03-18 11:02:40 +08:00
parent ba327cd8ae
commit 7d22328d69

View File

@ -8,6 +8,7 @@ import { FormSchema } from '@/types/form'
import { TableColumn } from '@/types/table' import { TableColumn } from '@/types/table'
import { DescriptionsSchema } from '@/types/descriptions' import { DescriptionsSchema } from '@/types/descriptions'
import { ComponentOptions, ComponentProps } from '@/types/components' import { ComponentOptions, ComponentProps } from '@/types/components'
import { DictTag } from '@/components/DictTag'
export type CrudSchema = Omit<TableColumn, 'children'> & { export type CrudSchema = Omit<TableColumn, 'children'> & {
isSearch?: boolean // 是否在查询显示 isSearch?: boolean // 是否在查询显示
@ -151,6 +152,15 @@ const filterTableSchema = (crudSchema: CrudSchema[]): TableColumn[] => {
const tableColumns = treeMap<CrudSchema>(crudSchema, { const tableColumns = treeMap<CrudSchema>(crudSchema, {
conversion: (schema: CrudSchema) => { conversion: (schema: CrudSchema) => {
if (schema?.isTable !== false && schema?.table?.show !== false) { if (schema?.isTable !== false && schema?.table?.show !== false) {
// add by 芋艿:增加对 dict 字典数据的支持
if (!schema.formatter && schema.dictType) {
schema.formatter = (_: Recordable, __: TableColumn, cellValue: any) => {
return h(DictTag, {
type: schema.dictType!, // ! 表示一定不为空
value: cellValue
})
}
}
return { return {
...schema.table, ...schema.table,
...schema ...schema