|
@@ -16,7 +16,7 @@ import { useHistory } from 'umi';
|
|
|
import { getMenuPathByCode } from '@/utils/menu';
|
|
import { getMenuPathByCode } from '@/utils/menu';
|
|
|
import { cloneDeep } from 'lodash';
|
|
import { cloneDeep } from 'lodash';
|
|
|
|
|
|
|
|
-const defaultBranches = [
|
|
|
|
|
|
|
+export const defaultBranches = [
|
|
|
{
|
|
{
|
|
|
when: [
|
|
when: [
|
|
|
{
|
|
{
|
|
@@ -72,6 +72,7 @@ export default observer(() => {
|
|
|
const triggerType = location?.query?.triggerType || '';
|
|
const triggerType = location?.query?.triggerType || '';
|
|
|
const id = location?.query?.id || '';
|
|
const id = location?.query?.id || '';
|
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
|
|
|
+ const [form] = Form.useForm()
|
|
|
|
|
|
|
|
const FormModelInit = () => {
|
|
const FormModelInit = () => {
|
|
|
FormModel.current = {
|
|
FormModel.current = {
|
|
@@ -116,8 +117,9 @@ export default observer(() => {
|
|
|
branches = branches.map((bItem: ActionBranchesProps, bIndex: number) => {
|
|
branches = branches.map((bItem: ActionBranchesProps, bIndex: number) => {
|
|
|
if (!bItem.key) {
|
|
if (!bItem.key) {
|
|
|
bItem.key = `branches_${new Date().getTime() + bIndex}`;
|
|
bItem.key = `branches_${new Date().getTime() + bIndex}`;
|
|
|
- if (bItem.then && bItem.then) {
|
|
|
|
|
- bItem.then = bItem.then.map((tItem) => {
|
|
|
|
|
|
|
+ if (bItem.then && bItem.then.length) {
|
|
|
|
|
+ bItem.then = bItem.then.map((tItem,tIndex) => {
|
|
|
|
|
+ tItem.key = `then_${new Date().getTime() + tIndex}`;
|
|
|
if (tItem.actions) {
|
|
if (tItem.actions) {
|
|
|
tItem.actions = tItem.actions.map((aItem, index) => {
|
|
tItem.actions = tItem.actions.map((aItem, index) => {
|
|
|
aItem.key = `${aItem.executor}_${new Date().getTime() + index}`;
|
|
aItem.key = `${aItem.executor}_${new Date().getTime() + index}`;
|
|
@@ -127,7 +129,7 @@ export default observer(() => {
|
|
|
return tItem;
|
|
return tItem;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- if (bItem.when) {
|
|
|
|
|
|
|
+ if (bItem.when && bItem.when.length) {
|
|
|
bItem.when = bItem.when.map((wItem, index) => {
|
|
bItem.when = bItem.when.map((wItem, index) => {
|
|
|
wItem.key = `when_${new Date().getTime() + index}`;
|
|
wItem.key = `when_${new Date().getTime() + index}`;
|
|
|
if (wItem.terms) {
|
|
if (wItem.terms) {
|
|
@@ -143,27 +145,31 @@ export default observer(() => {
|
|
|
return bItem;
|
|
return bItem;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- branches.push({
|
|
|
|
|
- when: [],
|
|
|
|
|
- key: 'branckes_2',
|
|
|
|
|
- shakeLimit: {
|
|
|
|
|
- enabled: false,
|
|
|
|
|
- time: 0,
|
|
|
|
|
- threshold: 0,
|
|
|
|
|
- alarmFirst: false,
|
|
|
|
|
- },
|
|
|
|
|
- then: [],
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (branches[0]?.when?.length) {
|
|
|
|
|
+ branches.push({
|
|
|
|
|
+ when: [],
|
|
|
|
|
+ key: 'branckes_2',
|
|
|
|
|
+ shakeLimit: {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ time: 0,
|
|
|
|
|
+ threshold: 0,
|
|
|
|
|
+ alarmFirst: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ then: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
FormModel.current = {
|
|
FormModel.current = {
|
|
|
...resp.result,
|
|
...resp.result,
|
|
|
};
|
|
};
|
|
|
FormModel.current.options = { ...defaultOptions, ...resp.result.options };
|
|
FormModel.current.options = { ...defaultOptions, ...resp.result.options };
|
|
|
FormModel.current.trigger = resp.result.trigger || {};
|
|
FormModel.current.trigger = resp.result.trigger || {};
|
|
|
FormModel.current.branches = branches;
|
|
FormModel.current.branches = branches;
|
|
|
|
|
+
|
|
|
|
|
+ form.setFieldValue('description', resp.result.description)
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- }, [id]);
|
|
|
|
|
|
|
+ }, [id, form]);
|
|
|
|
|
|
|
|
const triggerRender = (type: string) => {
|
|
const triggerRender = (type: string) => {
|
|
|
FormModel.current.trigger!.type = type;
|
|
FormModel.current.trigger!.type = type;
|
|
@@ -192,6 +198,7 @@ export default observer(() => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const submit = useCallback(() => {
|
|
const submit = useCallback(() => {
|
|
|
|
|
+ const baseData = form.getFieldsValue()
|
|
|
const FormData = cloneDeep(FormModel.current);
|
|
const FormData = cloneDeep(FormModel.current);
|
|
|
const { options, branches } = FormData;
|
|
const { options, branches } = FormData;
|
|
|
if (options?.terms) {
|
|
if (options?.terms) {
|
|
@@ -207,6 +214,11 @@ export default observer(() => {
|
|
|
if (branches) {
|
|
if (branches) {
|
|
|
FormData.branches = branches.filter((item) => !!item.then.length || !!item.when.length);
|
|
FormData.branches = branches.filter((item) => !!item.then.length || !!item.when.length);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (baseData) {
|
|
|
|
|
+ FormData.description = baseData.description
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
service.updateScene(FormData).then((res) => {
|
|
service.updateScene(FormData).then((res) => {
|
|
|
if (res.status === 200) {
|
|
if (res.status === 200) {
|
|
|
onlyMessage('操作成功', 'success');
|
|
onlyMessage('操作成功', 'success');
|
|
@@ -219,7 +231,7 @@ export default observer(() => {
|
|
|
return (
|
|
return (
|
|
|
<PageContainer>
|
|
<PageContainer>
|
|
|
<Card>
|
|
<Card>
|
|
|
- <Form name="timer" layout={'vertical'}>
|
|
|
|
|
|
|
+ <Form name="timer" layout={'vertical'} form={form}>
|
|
|
{triggerRender(triggerType)}
|
|
{triggerRender(triggerType)}
|
|
|
<Form.Item
|
|
<Form.Item
|
|
|
label={<TitleComponent style={{ fontSize: 14 }} data={'说明'} />}
|
|
label={<TitleComponent style={{ fontSize: 14 }} data={'说明'} />}
|