mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 21:28:34 +08:00
fix: linkage rule memory overflow (#2899)
* fix: linkage rule memory overflow * fix: linkage rule memory overflow * refactor: linkage rule * refactor: linkage rule
This commit is contained in:
parent
741e220fd3
commit
266a4ccb08
@ -61,17 +61,15 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
|
||||
useEffect(() => {
|
||||
const id = uid();
|
||||
form.addEffects(id, () => {
|
||||
linkageFields?.forEach((v) => {
|
||||
if (v) {
|
||||
//支持深层次子表单
|
||||
onFieldChange('*', (fieldPath: any) => {
|
||||
if (fieldPath.props.name === v && field.value) {
|
||||
props.onChange(null);
|
||||
setInnerValue(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (linkageFields?.length > 0) {
|
||||
//支持深层次子表单
|
||||
onFieldChange('*', (fieldPath: any) => {
|
||||
if (linkageFields.includes(fieldPath.props.name) && field.value) {
|
||||
props.onChange(null);
|
||||
setInnerValue(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
@ -1,6 +1,14 @@
|
||||
import { css } from '@emotion/css';
|
||||
import { FormLayout } from '@formily/antd-v5';
|
||||
import { createForm, Field, Form as FormilyForm, onFieldChange, onFieldInit, onFormInputChange } from '@formily/core';
|
||||
import {
|
||||
createForm,
|
||||
Field,
|
||||
Form as FormilyForm,
|
||||
onFieldChange,
|
||||
onFieldInit,
|
||||
onFieldReact,
|
||||
onFormInputChange,
|
||||
} from '@formily/core';
|
||||
import { FieldContext, FormContext, observer, RecursionField, useField, useFieldSchema } from '@formily/react';
|
||||
import { autorun } from '@formily/reactive';
|
||||
import { uid } from '@formily/shared';
|
||||
@ -111,12 +119,14 @@ const WithForm = (props: WithFormProps) => {
|
||||
if (h.targetFields?.length) {
|
||||
const fields = h.targetFields.join(',');
|
||||
onFieldInit(`*(${fields})`, (field: any, form) => {
|
||||
field['initProperty'] = {
|
||||
display: field.display,
|
||||
required: field.required,
|
||||
pattern: field.pattern,
|
||||
value: field.value || field.initialValue,
|
||||
};
|
||||
setTimeout(() => {
|
||||
field['initProperty'] = field?.['initProperty'] ?? {
|
||||
display: field.display,
|
||||
required: field.required,
|
||||
pattern: field.pattern,
|
||||
value: field.value || field.initialValue,
|
||||
};
|
||||
});
|
||||
});
|
||||
onFieldChange(`*(${fields})`, ['value', 'required', 'pattern', 'display'], (field: any) => {
|
||||
field.linkageProperty = {
|
||||
@ -127,9 +137,9 @@ const WithForm = (props: WithFormProps) => {
|
||||
// `onFieldReact` 有问题,没有办法被取消监听,所以这里用 `onFieldInit` 代替
|
||||
onFieldInit(`*(${fields})`, (field: any, form) => {
|
||||
disposes.push(
|
||||
autorun(() => {
|
||||
autorun(async () => {
|
||||
linkagefields.push(field);
|
||||
linkageMergeAction({
|
||||
await linkageMergeAction({
|
||||
operator: h.operator,
|
||||
value: h.value,
|
||||
field,
|
||||
|
@ -43,8 +43,12 @@ export const linkageMergeAction = async ({
|
||||
...field.linkageProperty,
|
||||
required: requiredResult,
|
||||
};
|
||||
field.required = last(field.linkageProperty?.required);
|
||||
break;
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
field.required = last(field.linkageProperty.required);
|
||||
});
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.InRequired:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
requiredResult.push(false);
|
||||
@ -53,8 +57,12 @@ export const linkageMergeAction = async ({
|
||||
...field.linkageProperty,
|
||||
required: requiredResult,
|
||||
};
|
||||
field.required = last(field.linkageProperty?.required);
|
||||
break;
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
field.required = last(field.linkageProperty.required);
|
||||
});
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.Visible:
|
||||
case ActionType.None:
|
||||
case ActionType.Hidden:
|
||||
@ -65,8 +73,12 @@ export const linkageMergeAction = async ({
|
||||
...field.linkageProperty,
|
||||
display: displayResult,
|
||||
};
|
||||
field.display = last(field.linkageProperty?.display);
|
||||
break;
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
field.display = last(displayResult);
|
||||
});
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.Editable:
|
||||
case ActionType.ReadOnly:
|
||||
case ActionType.ReadPretty:
|
||||
@ -77,8 +89,12 @@ export const linkageMergeAction = async ({
|
||||
...field.linkageProperty,
|
||||
pattern: patternResult,
|
||||
};
|
||||
field.pattern = last(field.linkageProperty.pattern);
|
||||
break;
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
field.pattern = last(patternResult);
|
||||
});
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.Value:
|
||||
if (
|
||||
isConditionEmpty(condition) ||
|
||||
|
Loading…
Reference in New Issue
Block a user