From 3ab93d0f134f9ab9f57fb9b5e0a3e22adf8410c0 Mon Sep 17 00:00:00 2001 From: "liutao.fe" Date: Sun, 28 Aug 2022 14:30:02 +0800 Subject: [PATCH] feat: support array element type Enum --- .../components/Fields/FieldContentEditor.tsx | 35 +++++++++++++++++-- .../components/Fields/FieldContentRender.tsx | 17 +++++++-- .../schema/SchemaFieldEditor/Field.tsx | 26 ++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/packages/admin/src/components/Fields/FieldContentEditor.tsx b/packages/admin/src/components/Fields/FieldContentEditor.tsx index cca1fe7b..4f1d915c 100644 --- a/packages/admin/src/components/Fields/FieldContentEditor.tsx +++ b/packages/admin/src/components/Fields/FieldContentEditor.tsx @@ -4,6 +4,7 @@ import { Rule } from 'antd/es/form' import { IConnectEditor, IDatePicker, IFileAndImageEditor } from '@/components/Fields' import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons' import { IObjectEditor } from './Object' +import { FormListFieldData } from 'antd/es/form/FormList' const MarkdownEditor = React.lazy(() => import('@/components/Fields/Markdown')) const RichTextEditor = React.lazy(() => import('@/components/Fields/RichText')) @@ -154,6 +155,36 @@ export function getFieldEditor(field: SchemaField, key: number) { ) break case 'Array': + const schemaField = field as SchemaField & { [key: string]: any }; + const renderItem = (formField: FormListFieldData) => { + switch (schemaField.elementType) { + case 'Enum': + return ( + + + + ); + default: + return ( + + + + ); + } + } + FieldEditor = ( {(fields, { add, remove }) => { @@ -162,9 +193,7 @@ export function getFieldEditor(field: SchemaField, key: number) { {fields?.map((field, index) => { return ( - - - + {renderItem(field)} { + switch (f.elementType) { + case 'Enum': + const enumOptions = f.enumElements || []; + const displayVal = enumOptions.find(e => e.value === val)?.label; + return {displayVal || val}; + default: + return {val}; + } + } + return ( - {record[name]?.map((val: string, index: number) => ( - {val} - ))} + {record[name]?.map(renderItem)} ) } diff --git a/packages/admin/src/pages/project/schema/SchemaFieldEditor/Field.tsx b/packages/admin/src/pages/project/schema/SchemaFieldEditor/Field.tsx index d6f395d0..fbe56776 100644 --- a/packages/admin/src/pages/project/schema/SchemaFieldEditor/Field.tsx +++ b/packages/admin/src/pages/project/schema/SchemaFieldEditor/Field.tsx @@ -260,6 +260,32 @@ export function getFieldFormItem( ) + case 'Array': + const renderElement = (fieldType: string,) => { + switch (fieldType) { + case 'Enum': + return getFieldFormItem(fieldType, { ...options }); + default: + return null; + } + } + + return ( + <> + + + + + {(ele) => { + const filed = ele.getFieldValue('elementType'); + return renderElement(filed); + }} + + + ) default: return '' }