From 19bad669af24cc1923ae2d8b58ad2419966e1a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Tue, 21 Nov 2023 17:28:37 +0800 Subject: [PATCH] fix(linkage): avoid infinite loop (#3069) --- .../schema-component/antd/form-v2/Form.tsx | 2 -- .../schema-component/antd/form-v2/utils.tsx | 32 +++++-------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx index 392feee73..2015092fa 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx @@ -140,8 +140,6 @@ const WithForm = (props: WithFormProps) => { }); // 如果是 linkageRules 数组的最后一个元素 if (index === linkageRules.length - 1) { - // 等待异步操作完成 - await new Promise((resolve) => setTimeout(resolve, 0)); // 清空 linkagefields 数组中对象的属性 linkagefields.forEach((v) => { v.linkageProperty = {}; diff --git a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx index 81c2b6ae6..7b14385c7 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx @@ -43,12 +43,8 @@ export const linkageMergeAction = async ({ ...field.linkageProperty, required: requiredResult, }; - return new Promise((resolve) => { - setTimeout(() => { - field.required = last(field.linkageProperty.required); - }); - resolve(void 0); - }); + field.required = last(field.linkageProperty.required); + break; case ActionType.InRequired: if (await conditionAnalyses({ rules: condition, variables, localVariables })) { requiredResult.push(false); @@ -57,12 +53,8 @@ export const linkageMergeAction = async ({ ...field.linkageProperty, required: requiredResult, }; - return new Promise((resolve) => { - setTimeout(() => { - field.required = last(field.linkageProperty.required); - }); - resolve(void 0); - }); + field.required = last(field.linkageProperty.required); + break; case ActionType.Visible: case ActionType.None: case ActionType.Hidden: @@ -73,12 +65,8 @@ export const linkageMergeAction = async ({ ...field.linkageProperty, display: displayResult, }; - return new Promise((resolve) => { - setTimeout(() => { - field.display = last(displayResult); - }); - resolve(void 0); - }); + field.display = last(displayResult); + break; case ActionType.Editable: case ActionType.ReadOnly: case ActionType.ReadPretty: @@ -89,12 +77,8 @@ export const linkageMergeAction = async ({ ...field.linkageProperty, pattern: patternResult, }; - return new Promise((resolve) => { - setTimeout(() => { - field.pattern = last(patternResult); - }); - resolve(void 0); - }); + field.pattern = last(patternResult); + break; case ActionType.Value: if (isConditionEmpty(condition) || (await conditionAnalyses({ rules: condition, variables, localVariables }))) { if (value?.mode === 'express') {