fix: linkage rule enable effect in form (#1669)
This commit is contained in:
parent
7821af4024
commit
a529d9b7eb
@ -6,6 +6,7 @@ import { ConfigProvider, Spin } from 'antd';
|
|||||||
import React, { useEffect, useMemo } from 'react';
|
import React, { useEffect, useMemo } from 'react';
|
||||||
import { useActionContext } from '..';
|
import { useActionContext } from '..';
|
||||||
import { useAttach, useComponent } from '../..';
|
import { useAttach, useComponent } from '../..';
|
||||||
|
import { gridRowColWrap } from '../../../schema-initializer';
|
||||||
import { useProps } from '../../hooks/useProps';
|
import { useProps } from '../../hooks/useProps';
|
||||||
import { linkageMergeAction } from './utils';
|
import { linkageMergeAction } from './utils';
|
||||||
|
|
||||||
@ -69,8 +70,10 @@ const WithForm = (props) => {
|
|||||||
const { form } = props;
|
const { form } = props;
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { setFormValueChanged } = useActionContext();
|
const { setFormValueChanged } = useActionContext();
|
||||||
const linkageRules =
|
const linkageRules = useMemo(
|
||||||
(getLinkageRules(fieldSchema) || fieldSchema.parent?.['x-linkage-rules'])?.filter((k) => !k.disabled) || [];
|
() => (getLinkageRules(fieldSchema) || fieldSchema.parent?.['x-linkage-rules'])?.filter((k) => !k.disabled) || [],
|
||||||
|
[fieldSchema.properties?.grid?.['x-linkage-rules']],
|
||||||
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = uid();
|
const id = uid();
|
||||||
form.addEffects(id, () => {
|
form.addEffects(id, () => {
|
||||||
@ -114,36 +117,34 @@ const WithForm = (props) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (linkageRules.length > 0) {
|
const id = uid();
|
||||||
const id = uid();
|
const linkagefields = [];
|
||||||
const linkagefields = [];
|
const formGraph = form.getFormGraph();
|
||||||
const formGraph = form.getFormGraph();
|
form.addEffects(id, () => {
|
||||||
form.addEffects(id, () => {
|
return linkageRules.map((v, index) => {
|
||||||
return linkageRules.map((v, index) => {
|
return v.actions?.map((h) => {
|
||||||
return v.actions?.map((h) => {
|
if (h.targetFields) {
|
||||||
if (h.targetFields) {
|
const fields = h.targetFields.join(',');
|
||||||
const fields = h.targetFields.join(',');
|
return onFieldReact(`*(${fields})`, (field: any, form) => {
|
||||||
return onFieldReact(`*(${fields})`, (field: any, form) => {
|
linkagefields.push(field);
|
||||||
linkagefields.push(field);
|
linkageMergeAction(h, field, v.condition, form?.values);
|
||||||
linkageMergeAction(h, field, v.condition, form?.values);
|
if (index === linkageRules.length - 1) {
|
||||||
if (index === linkageRules.length - 1) {
|
setTimeout(() =>
|
||||||
setTimeout(() =>
|
linkagefields.map((v) => {
|
||||||
linkagefields.map((v) => {
|
v.linkageProperty = {};
|
||||||
v.linkageProperty = {};
|
}),
|
||||||
}),
|
);
|
||||||
);
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return () => {
|
});
|
||||||
form.removeEffects(id);
|
return () => {
|
||||||
form.clearFormGraph();
|
form.removeEffects(id);
|
||||||
form.setFormGraph(formGraph);
|
form.clearFormGraph();
|
||||||
};
|
form.setFormGraph(formGraph);
|
||||||
}
|
};
|
||||||
}, [linkageRules]);
|
}, [linkageRules]);
|
||||||
return fieldSchema['x-decorator'] === 'Form' ? <FormDecorator {...props} /> : <FormComponent {...props} />;
|
return fieldSchema['x-decorator'] === 'Form' ? <FormDecorator {...props} /> : <FormComponent {...props} />;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user