From 2d05a4d623f90dcadbe3e8114631d8459f99b190 Mon Sep 17 00:00:00 2001 From: siyi98 Date: Tue, 22 Mar 2022 21:13:24 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat(fr):=E4=BF=AE=E6=94=B9schema=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-render/src/index.d.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/form-render/src/index.d.ts b/packages/form-render/src/index.d.ts index ed4d19430..e42ce5c40 100644 --- a/packages/form-render/src/index.d.ts +++ b/packages/form-render/src/index.d.ts @@ -1,8 +1,19 @@ import { RuleItem } from 'async-validator'; import * as React from 'react'; +export type SchemaType = + | 'string' + | 'object' + | 'array' + | 'number' + | 'boolean' + | 'void' + | 'date' + | 'datetime' + | (string & {}) + interface SchemaBase { - type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'range' | 'html'; + type: SchemaType; title: string; description: string; descType: 'text' | 'icon'; @@ -46,7 +57,7 @@ interface SchemaBase { props: Record; } -type Schema = Partial; +export type Schema = Partial; export interface Error { /** 错误的数据路径 */ From 9dead63069a5d1bb133e3e40f65504dbc7735fcb Mon Sep 17 00:00:00 2001 From: siyi98 Date: Tue, 22 Mar 2022 21:14:03 +0800 Subject: [PATCH 2/5] feat(fr):v1.9.6 --- packages/form-render/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/form-render/package.json b/packages/form-render/package.json index f86b0613a..06e450df4 100644 --- a/packages/form-render/package.json +++ b/packages/form-render/package.json @@ -1,6 +1,6 @@ { "name": "form-render", - "version": "1.9.5", + "version": "1.9.6", "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成", "keywords": [ "Form", From dc59ae304fb020e6cf61021b404da06a48daeeba Mon Sep 17 00:00:00 2001 From: siyi98 Date: Wed, 23 Mar 2022 10:58:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat(fr):=E6=96=B0=E5=A2=9E=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=94=A8=E4=BA=8E=E6=8E=A7=E5=88=B6=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/form-render/advanced/display.md | 2 ++ docs/form-render/schema/schema.md | 27 ++++++++++++++++++++ packages/form-render/src/widgets/antd/map.js | 17 ++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/form-render/advanced/display.md b/docs/form-render/advanced/display.md index 0ebc60ebe..2762cc133 100644 --- a/docs/form-render/advanced/display.md +++ b/docs/form-render/advanced/display.md @@ -32,6 +32,7 @@ const schema = displayType => ({ bind: 'obj', description: '这是一个对象类型', type: 'object', + collapsed: false, properties: { input1: { title: '简单输入框', @@ -49,6 +50,7 @@ const schema = displayType => ({ }, }); + export default () => (

display: row

diff --git a/docs/form-render/schema/schema.md b/docs/form-render/schema/schema.md index 74eae8d0a..d1f74029e 100644 --- a/docs/form-render/schema/schema.md +++ b/docs/form-render/schema/schema.md @@ -456,6 +456,33 @@ readOnly=true 的情况,FormRender 默认使用 html 组件渲染。特殊情 } ``` +### collapsed + +只在嵌套的对象类型组件中使用,用于控制折叠面板是否展开 + +- 类型:boolean +- 默认值:false + +```json +{ + "type": "object", + "properties": { + "objectName": { + "type": "object", + "description": "这是一个对象类型", + "collapsed": false, + "properties": { + "input1": { + "title": "简单输入框", + "type": "string", + "required": true, + }, + } + } + } +} +``` + ### enum & enumNames 只在选择类组件中使用,用于描述枚举值的值和文案 diff --git a/packages/form-render/src/widgets/antd/map.js b/packages/form-render/src/widgets/antd/map.js index a2ecea469..f62cd2e74 100644 --- a/packages/form-render/src/widgets/antd/map.js +++ b/packages/form-render/src/widgets/antd/map.js @@ -3,13 +3,20 @@ import React, { useEffect, useState } from 'react'; // import { useStore2 } from '../../hooks'; const { Panel } = Collapse; -export default function Map({ children, title, ...rest }) { +export default function Map({ children, title, schema, ...rest }) { const { theme, displayType, allCollapsed } = {}; // TODO! - const [collapsed, setCollapsed] = useState(false); + const [collapsed, setCollapsed] = useState(schema.collapsed || false); + // useEffect(() => { + // setCollapsed(allCollapsed); + // }, [allCollapsed]); - useEffect(() => { - setCollapsed(allCollapsed); - }, [allCollapsed]); + useEffect(()=>{ + if(schema.hasOwnProperty('collapsed')){ + setCollapsed(schema.collapsed) + } + },[schema.collapsed]) + + if (!title) { return
{children}
; From 1cf2cb1adfdfb600dc299d086d4e59fc7430fc0a Mon Sep 17 00:00:00 2001 From: siyi98 Date: Wed, 23 Mar 2022 11:00:07 +0800 Subject: [PATCH 4/5] feat(fr):v1.9.7 --- docs/form-render/advanced/display.md | 1 - docs/form-render/schema/schema.md | 6 +++--- packages/form-render/CHANGELOG.md | 8 ++++++++ packages/form-render/package.json | 2 +- packages/form-render/src/index.d.ts | 2 +- packages/form-render/src/widgets/antd/map.js | 10 ++++------ 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/form-render/advanced/display.md b/docs/form-render/advanced/display.md index 2762cc133..b34e04c48 100644 --- a/docs/form-render/advanced/display.md +++ b/docs/form-render/advanced/display.md @@ -50,7 +50,6 @@ const schema = displayType => ({ }, }); - export default () => (

display: row

diff --git a/docs/form-render/schema/schema.md b/docs/form-render/schema/schema.md index d1f74029e..62bfdb4e6 100644 --- a/docs/form-render/schema/schema.md +++ b/docs/form-render/schema/schema.md @@ -475,9 +475,9 @@ readOnly=true 的情况,FormRender 默认使用 html 组件渲染。特殊情 "input1": { "title": "简单输入框", "type": "string", - "required": true, - }, - } + "required": true + } + } } } } diff --git a/packages/form-render/CHANGELOG.md b/packages/form-render/CHANGELOG.md index 244e281a5..1e9f1cb45 100644 --- a/packages/form-render/CHANGELOG.md +++ b/packages/form-render/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.9.7 + +- [+] 对嵌套的`对象类型`组件扩展`schema`,新增`collapsed`属性用于控制面板折叠。 + +## 1.9.6 + +- [+] 更新`schema`类型声明 + ## 1.9.5 - [+] 扩展`watch`的能力 diff --git a/packages/form-render/package.json b/packages/form-render/package.json index 06e450df4..b6a4c4157 100644 --- a/packages/form-render/package.json +++ b/packages/form-render/package.json @@ -1,6 +1,6 @@ { "name": "form-render", - "version": "1.9.6", + "version": "1.9.7", "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成", "keywords": [ "Form", diff --git a/packages/form-render/src/index.d.ts b/packages/form-render/src/index.d.ts index e42ce5c40..d74cbe81e 100644 --- a/packages/form-render/src/index.d.ts +++ b/packages/form-render/src/index.d.ts @@ -10,7 +10,7 @@ export type SchemaType = | 'void' | 'date' | 'datetime' - | (string & {}) + | (string & {}); interface SchemaBase { type: SchemaType; diff --git a/packages/form-render/src/widgets/antd/map.js b/packages/form-render/src/widgets/antd/map.js index f62cd2e74..67e2572cd 100644 --- a/packages/form-render/src/widgets/antd/map.js +++ b/packages/form-render/src/widgets/antd/map.js @@ -10,13 +10,11 @@ export default function Map({ children, title, schema, ...rest }) { // setCollapsed(allCollapsed); // }, [allCollapsed]); - useEffect(()=>{ - if(schema.hasOwnProperty('collapsed')){ - setCollapsed(schema.collapsed) + useEffect(() => { + if (schema.hasOwnProperty('collapsed')) { + setCollapsed(schema.collapsed); } - },[schema.collapsed]) - - + }, [schema.collapsed]); if (!title) { return
{children}
; From 14d98035cad06241525fae1ebc8dd313feef2928 Mon Sep 17 00:00:00 2001 From: siyi98 Date: Wed, 23 Mar 2022 11:02:29 +0800 Subject: [PATCH 5/5] feat(docs):update --- docs/form-render/schema/schema.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/form-render/schema/schema.md b/docs/form-render/schema/schema.md index 62bfdb4e6..8e052e089 100644 --- a/docs/form-render/schema/schema.md +++ b/docs/form-render/schema/schema.md @@ -458,7 +458,7 @@ readOnly=true 的情况,FormRender 默认使用 html 组件渲染。特殊情 ### collapsed -只在嵌套的对象类型组件中使用,用于控制折叠面板是否展开 +只在嵌套的对象类型组件中使用,用于控制面板是否折叠 - 类型:boolean - 默认值:false