From 4935dff23104292987245edef230821f6ef96ecc Mon Sep 17 00:00:00 2001 From: wjh Date: Wed, 17 Apr 2024 16:53:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BA=A7=E8=81=94?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=9C=A8=E7=BC=96=E8=BE=91=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=B2=A1=E6=9C=89=E9=BB=98=E8=AE=A4=E5=80=BC=20close?= =?UTF-8?q?=20#633=20(#749)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachycode/pulls/749 Co-authored-by: wjh Co-committed-by: wjh --- .changeset/tasty-melons-think.md | 5 +++++ .../antd/association-field/InternalCascader.tsx | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/tasty-melons-think.md diff --git a/.changeset/tasty-melons-think.md b/.changeset/tasty-melons-think.md new file mode 100644 index 000000000..147629a00 --- /dev/null +++ b/.changeset/tasty-melons-think.md @@ -0,0 +1,5 @@ +--- +"@nocobase/client": patch +--- + +修复级联选择在编辑的时候没有值 diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx index e174bca60..3dbf9391a 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalCascader.tsx @@ -30,7 +30,6 @@ const SchemaField = createSchemaField({ const Cascade = connect((props) => { const { data, mapOptions, onChange } = props; - const [selectedOptions, setSelectedOptions] = useState([]); const [options, setOptions] = useState(data); const fieldSchema = useFieldSchema(); const [loading, setLoading] = useState(false); @@ -41,21 +40,23 @@ const Cascade = connect((props) => { const fieldFilter = fieldSchema['x-component-props']?.service?.params?.filter; const sort = fieldSchema['x-component-props']?.service?.params?.sort; const field: any = useField(); + const [selectedOptions, setSelectedOptions] = useState([]); useEffect(() => { - if (props.value) { - const values = Array.isArray(props.value) + const propsValue = props.value || fieldSchema['x-component-props'].value; + if (propsValue && !selectedOptions.length) { + const values = Array.isArray(propsValue) ? extractLastNonNullValueObjects( - props.value?.filter((v) => v.value), + propsValue?.filter((v) => v.value), true, ) - : transformNestedData(props.value); + : transformNestedData(propsValue); const defaultData = values?.map?.((v) => { return v.id; }); setSelectedOptions(defaultData); } onDropdownVisibleChange('true'); - }, []); + }, [fieldSchema['x-component-props'].value]); const handleGetOptions = async () => { const response = await resource.list({ pageSize: 9999, @@ -85,7 +86,7 @@ const Cascade = connect((props) => { if (index === option.length - 1) { options.push({ key: item.id, - children: null, + children: item.children || null, }); } else { options.push({