From f76cbaa6dc9c7c5926bf05f3aa6d62265782b89c Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Sun, 12 Nov 2023 23:26:28 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dschema=20?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-render/src/form-core/index.tsx | 1 + packages/form-render/src/models/validates.ts | 4 +++- packages/form-render/src/widgets/utils/withFieldWrap.tsx | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/form-render/src/form-core/index.tsx b/packages/form-render/src/form-core/index.tsx index f8aabf580..b149f9ad8 100644 --- a/packages/form-render/src/form-core/index.tsx +++ b/packages/form-render/src/form-core/index.tsx @@ -193,6 +193,7 @@ const FormCore:FC = (props) => { }; const operlabelCol = getFormItemLayout(column, {}, { labelWidth })?.labelCol; + return (
{ const { type, max, min, message } = schema; @@ -68,7 +69,8 @@ export const transformRules = (rules = [], methods: any, form: any) => { })); }; -export default (schema: any, form: any, methods: any, fieldRef: any) => { +export default (_schema: any, form: any, methods: any, fieldRef: any) => { + const schema = cloneDeep(_schema); let { format, rules: ruleList = [], diff --git a/packages/form-render/src/widgets/utils/withFieldWrap.tsx b/packages/form-render/src/widgets/utils/withFieldWrap.tsx index 4fd7cc670..b2fde36fc 100644 --- a/packages/form-render/src/widgets/utils/withFieldWrap.tsx +++ b/packages/form-render/src/widgets/utils/withFieldWrap.tsx @@ -2,7 +2,7 @@ import React from 'react'; const getProps = (props: any, filter: any[]) => { const result = {}; - + Object.keys(props).forEach(key => { if (filter.includes(key)) { return; From f89684f4aabad4f8221f6d54a2a49cec4b577e7e Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 00:55:58 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20list=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/render-core/FieldList/field.tsx | 95 ++++++++++--------- .../src/render-core/FieldList/main.tsx | 7 +- .../src/render-core/FieldList/modules.tsx | 2 +- 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/packages/form-render/src/render-core/FieldList/field.tsx b/packages/form-render/src/render-core/FieldList/field.tsx index 95b53bb61..862df288f 100644 --- a/packages/form-render/src/render-core/FieldList/field.tsx +++ b/packages/form-render/src/render-core/FieldList/field.tsx @@ -1,12 +1,9 @@ -import React, { useContext, useEffect } from 'react'; +import React, { useContext, useEffect, useMemo } from 'react'; import { Form, message, ConfigProvider, Button } from 'antd'; import { isFunction, translation } from '../../utils'; import { getWidget } from '../../models/mapping'; import { transformRules } from '../../models/validates'; - -const getParamValue = (formCtx: any, upperCtx: any, schema: any) => (valueKey: string) => { - return schema[valueKey] ?? upperCtx[valueKey] ?? formCtx[valueKey]; -}; +import { getParamValue } from './modules'; export default (props: any) => { const { @@ -20,7 +17,6 @@ export default (props: any) => { upperCtx, formCtx, configContext, - listData, setListData } = props; @@ -46,18 +42,8 @@ export default (props: any) => { let widgetName = schema.widget || 'cardList'; const Widget = getWidget(widgetName, widgets); - const { props: listProps, removeBtn, rules = [], ...otherSchema } = schema; - - let defaultValue = schema.default ?? schema.defaultValue; - if (defaultValue === undefined && !['drawerList', 'list1'].includes(widgetName)) { - defaultValue = [{}]; - } - - useEffect(() => { - setListData(defaultValue ||[]); - }, []); - + let { addBtnProps, delConfirmProps, @@ -73,6 +59,51 @@ export default (props: any) => { ...otherListProps } = listProps || {}; + const getValueFromKey = getParamValue(formCtx, upperCtx, schema); + + const readOnly = getValueFromKey('readOnly'); + const preRootPath = [...(rootPath || [])].splice(0, rootPath.length - 1); + const displayType = getValueFromKey('displayType'); + + if (hideMove === undefined && globalConfig?.listOperate?.hideMove) { + hideMove = globalConfig?.listOperate.hideMove; + } + + const listData = form.getFieldValue([...preRootPath, ...path]) || []; + if (otherSchema?.min > 0 && listData.length <= otherSchema?.min) { + hideDelete = true; + } + + if (otherSchema?.max > 0 && otherSchema?.max <= listData.length) { + hideAdd = true; + } + + if (hideAdd) { + hideCopy = true; + } + + if (readOnly) { + hideAdd = true; + hideCopy = true; + hideDelete = true; + hideMove = true; + } + + const defaultValue = useMemo(() => { + let result = schema.default ?? schema.defaultValue; + if (result === undefined) { + result = form.getFieldValue([...preRootPath, ...path]); + if (!result && !['drawerList', 'list1'].includes(widgetName)) { + result = [{}]; + } + } + return result; + }, []); + + useEffect(() => { + setListData(defaultValue || []); + }, []); + const handleAdd = (add: any) => (data?: any) => { let addFunc = onAdd; if (typeof onAdd === 'string') { @@ -141,35 +172,6 @@ export default (props: any) => { form.setSchemaByPath(path, { hidden: true }); }; - const getValueFromKey = getParamValue(formCtx, upperCtx, schema); - - const readOnly = getValueFromKey('readOnly'); - const preRootPath = [...(rootPath || [])].splice(0, rootPath.length - 1); - const displayType = getValueFromKey('displayType'); - - if (hideMove === undefined && globalConfig?.listOperate?.hideMove) { - hideMove = globalConfig?.listOperate.hideMove; - } - - if (otherSchema?.min > 0 && listData.length <= otherSchema?.min) { - hideDelete = true; - } - - if (otherSchema?.max > 0 && otherSchema?.max <= listData.length) { - hideAdd = true; - } - - if (hideAdd) { - hideCopy = true; - } - - if (readOnly) { - hideAdd = true; - hideCopy = true; - hideDelete = true; - hideMove = true; - } - const operateBtnType = globalConfig?.listOperate?.btnType; let ruleList: any = []; @@ -281,7 +283,6 @@ export default (props: any) => { {removeBtn?.text || t('delete')} )} - ); } diff --git a/packages/form-render/src/render-core/FieldList/main.tsx b/packages/form-render/src/render-core/FieldList/main.tsx index d7f10a276..5268c9117 100644 --- a/packages/form-render/src/render-core/FieldList/main.tsx +++ b/packages/form-render/src/render-core/FieldList/main.tsx @@ -9,7 +9,7 @@ import Main from './field'; const UpperContext = createContext(() => {}); export default (props: any) => { - const [listData, setListData] = useState([]); + const [_, setListData] = useState([]); const { configContext } = props; const store = useContext(FRContext); @@ -41,7 +41,9 @@ export default (props: any) => { const { labelCol, fieldCol } = getFormListLayout(getValueFromKey, displayType); let isInline = schema.display === 'inline'; - if (!setListData?.length && widgetName !== 'drawerList') { + const preRootPath = [...(props.rootPath || [])].splice(0, props.rootPath.length - 1); + const listData = form.getFieldValue([...preRootPath, ...props.path]); + if (!listData?.length && widgetName !== 'drawerList') { isInline = true; } @@ -79,7 +81,6 @@ export default (props: any) => { widgets={widgets} configContext={configContext} setListData={setListData} - listData={listData} /> diff --git a/packages/form-render/src/render-core/FieldList/modules.tsx b/packages/form-render/src/render-core/FieldList/modules.tsx index 403bea861..8c80eed79 100644 --- a/packages/form-render/src/render-core/FieldList/modules.tsx +++ b/packages/form-render/src/render-core/FieldList/modules.tsx @@ -100,4 +100,4 @@ export const getTooltip = (schema: any, displayType: string) => { } return null; -}; +}; \ No newline at end of file From 7f43c4f36d2d8933d815f95abec7962c40d4437e Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 00:57:25 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20list=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-render/src/form-core/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/form-render/src/form-core/index.tsx b/packages/form-render/src/form-core/index.tsx index b149f9ad8..f8aabf580 100644 --- a/packages/form-render/src/form-core/index.tsx +++ b/packages/form-render/src/form-core/index.tsx @@ -193,7 +193,6 @@ const FormCore:FC = (props) => { }; const operlabelCol = getFormItemLayout(column, {}, { labelWidth })?.labelCol; - return ( Date: Mon, 13 Nov 2023 00:58:27 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20list=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-render/src/widgets/utils/withFieldWrap.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/form-render/src/widgets/utils/withFieldWrap.tsx b/packages/form-render/src/widgets/utils/withFieldWrap.tsx index b2fde36fc..db3ef036d 100644 --- a/packages/form-render/src/widgets/utils/withFieldWrap.tsx +++ b/packages/form-render/src/widgets/utils/withFieldWrap.tsx @@ -2,7 +2,6 @@ import React from 'react'; const getProps = (props: any, filter: any[]) => { const result = {}; - Object.keys(props).forEach(key => { if (filter.includes(key)) { return; From 1d6a4692fc95f59087b49c32fabc68d7e93a4ccc Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 00:58:56 +0800 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=20list=20?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-render/src/widgets/utils/withFieldWrap.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/form-render/src/widgets/utils/withFieldWrap.tsx b/packages/form-render/src/widgets/utils/withFieldWrap.tsx index db3ef036d..b2fde36fc 100644 --- a/packages/form-render/src/widgets/utils/withFieldWrap.tsx +++ b/packages/form-render/src/widgets/utils/withFieldWrap.tsx @@ -2,6 +2,7 @@ import React from 'react'; const getProps = (props: any, filter: any[]) => { const result = {}; + Object.keys(props).forEach(key => { if (filter.includes(key)) { return; From 171cb0862e843096688eaa6ee68da64235b6449a Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 01:10:17 +0800 Subject: [PATCH 6/7] feat: update changelog --- packages/form-render/CHANGELOG.md | 7 ++++++- packages/form-render/package.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/form-render/CHANGELOG.md b/packages/form-render/CHANGELOG.md index 236f39793..0a8fde0ff 100644 --- a/packages/form-render/CHANGELOG.md +++ b/packages/form-render/CHANGELOG.md @@ -1,8 +1,13 @@ # 更新日志 +### 2.3.6 +- [!] 修复 List 组件初始化数据,删除按钮未显示 +- [!] 修复因配置 validator 导致通过 watch 触发 setSchemaBypath 初次不生效 + ### 2.3.5 - [+] labelWidget、descWidget 增加 addons 访问属性 -- [-] 兼容 widget 大小写配置 +- [!] 兼容 widget 大小写配置 + ### 2.3.0 - [+] 优化 search-form 折叠收起逻辑,不再判断 dom 真实渲染高度,提升渲染性能 - [!] form.getValues 判断 removeHiddenData = true 时,才去除隐藏控件数据 diff --git a/packages/form-render/package.json b/packages/form-render/package.json index 966c898e7..22f3ad61c 100644 --- a/packages/form-render/package.json +++ b/packages/form-render/package.json @@ -1,6 +1,6 @@ { "name": "form-render", - "version": "2.3.5", + "version": "2.3.6 ", "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成", "keywords": [ "Form", From 06dc1cb05f3c60c7c9d9b6ac380887fd771f618e Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 01:15:19 +0800 Subject: [PATCH 7/7] feat: update changelog --- 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 22f3ad61c..cf7d72d45 100644 --- a/packages/form-render/package.json +++ b/packages/form-render/package.json @@ -1,6 +1,6 @@ { "name": "form-render", - "version": "2.3.6 ", + "version": "2.3.6", "description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成", "keywords": [ "Form",