diff --git a/docs/form-render/advanced/display.md b/docs/form-render/advanced/display.md index 0ebc60ebe..b34e04c48 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: '简单输入框', diff --git a/docs/form-render/schema/schema.md b/docs/form-render/schema/schema.md index 74eae8d0a..8e052e089 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/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 f86b0613a..b6a4c4157 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.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 ed4d19430..d74cbe81e 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 { /** 错误的数据路径 */ diff --git a/packages/form-render/src/widgets/antd/map.js b/packages/form-render/src/widgets/antd/map.js index a2ecea469..67e2572cd 100644 --- a/packages/form-render/src/widgets/antd/map.js +++ b/packages/form-render/src/widgets/antd/map.js @@ -3,13 +3,18 @@ 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]); + if (schema.hasOwnProperty('collapsed')) { + setCollapsed(schema.collapsed); + } + }, [schema.collapsed]); if (!title) { return
{children}
;