|
@@ -1,4 +1,4 @@
|
|
|
-import { observer } from '@formily/react';
|
|
|
|
|
|
|
+import { observer, Observer } from '@formily/react';
|
|
|
import { useState, useEffect } from 'react';
|
|
import { useState, useEffect } from 'react';
|
|
|
import { FormModel } from '@/pages/rule-engine/Scene/Save';
|
|
import { FormModel } from '@/pages/rule-engine/Scene/Save';
|
|
|
import { PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
import { PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
@@ -6,6 +6,7 @@ import type { ActionBranchesProps, TermsType } from '@/pages/rule-engine/Scene/t
|
|
|
import Term from './term';
|
|
import Term from './term';
|
|
|
import Actions from '@/pages/rule-engine/Scene/Save/action';
|
|
import Actions from '@/pages/rule-engine/Scene/Save/action';
|
|
|
import classNames from 'classnames';
|
|
import classNames from 'classnames';
|
|
|
|
|
+import { set } from 'lodash';
|
|
|
|
|
|
|
|
interface BranchesItemProps {
|
|
interface BranchesItemProps {
|
|
|
name: number;
|
|
name: number;
|
|
@@ -16,10 +17,11 @@ interface BranchesItemProps {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default observer((props: BranchesItemProps) => {
|
|
export default observer((props: BranchesItemProps) => {
|
|
|
- const [deleteVisible, setDeleteVisible] = useState(false);
|
|
|
|
|
const [when, setWhen] = useState<TermsType[]>([]);
|
|
const [when, setWhen] = useState<TermsType[]>([]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ console.log('branchItem', props.data.when);
|
|
|
|
|
+
|
|
|
if (props.data.when) {
|
|
if (props.data.when) {
|
|
|
setWhen(props.data.when);
|
|
setWhen(props.data.when);
|
|
|
}
|
|
}
|
|
@@ -27,12 +29,14 @@ export default observer((props: BranchesItemProps) => {
|
|
|
|
|
|
|
|
const addWhen = (index: number) => {
|
|
const addWhen = (index: number) => {
|
|
|
const lastBranch = FormModel.current.branches![index].when;
|
|
const lastBranch = FormModel.current.branches![index].when;
|
|
|
- FormModel.current.options?.terms.push({
|
|
|
|
|
- terms: [],
|
|
|
|
|
|
|
+ FormModel.current.options?.when.push({
|
|
|
|
|
+ terms: [{ terms: [] }],
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
lastBranch.push({
|
|
lastBranch.push({
|
|
|
terms: [
|
|
terms: [
|
|
|
{
|
|
{
|
|
|
|
|
+ type: 'and',
|
|
|
column: undefined,
|
|
column: undefined,
|
|
|
value: undefined,
|
|
value: undefined,
|
|
|
key: 'params_1',
|
|
key: 'params_1',
|
|
@@ -47,9 +51,9 @@ export default observer((props: BranchesItemProps) => {
|
|
|
when: [],
|
|
when: [],
|
|
|
key: `branch_${new Date().getTime()}`,
|
|
key: `branch_${new Date().getTime()}`,
|
|
|
shakeLimit: {
|
|
shakeLimit: {
|
|
|
- enabled: true,
|
|
|
|
|
- time: 1,
|
|
|
|
|
- threshold: 1,
|
|
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ time: 0,
|
|
|
|
|
+ threshold: 0,
|
|
|
alarmFirst: false,
|
|
alarmFirst: false,
|
|
|
},
|
|
},
|
|
|
then: [],
|
|
then: [],
|
|
@@ -60,57 +64,57 @@ export default observer((props: BranchesItemProps) => {
|
|
|
return (
|
|
return (
|
|
|
<div className="actions-terms-warp">
|
|
<div className="actions-terms-warp">
|
|
|
<div className="actions-terms-title">{props.isFrist ? '当' : '否则'}</div>
|
|
<div className="actions-terms-title">{props.isFrist ? '当' : '否则'}</div>
|
|
|
- <div
|
|
|
|
|
- className={classNames('actions-terms-options', { border: !props.isFrist })}
|
|
|
|
|
- onMouseOver={() => setDeleteVisible(true)}
|
|
|
|
|
- onMouseOut={() => setDeleteVisible(false)}
|
|
|
|
|
- >
|
|
|
|
|
- {!props.isFrist && props.data.when?.length ? (
|
|
|
|
|
- <div
|
|
|
|
|
- className={classNames('terms-params-delete denger', { show: deleteVisible })}
|
|
|
|
|
- onClick={props.onDelete}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <div className={classNames('actions-terms-options', { border: !props.isFrist })}>
|
|
|
|
|
+ {!props.isFrist && props.data.when.length ? (
|
|
|
|
|
+ <div className={classNames('terms-params-delete denger show')} onClick={props.onDelete}>
|
|
|
<DeleteOutlined />
|
|
<DeleteOutlined />
|
|
|
</div>
|
|
</div>
|
|
|
) : null}
|
|
) : null}
|
|
|
<div className="actions-terms-list">
|
|
<div className="actions-terms-list">
|
|
|
- {when.length ? (
|
|
|
|
|
- when.map((item, dIndex) => (
|
|
|
|
|
- <Term
|
|
|
|
|
- pName={[props.name, 'when']}
|
|
|
|
|
- name={dIndex}
|
|
|
|
|
- data={item}
|
|
|
|
|
- key={item.key}
|
|
|
|
|
- paramsOptions={props.paramsOptions}
|
|
|
|
|
- isLast={dIndex === when!.length - 1}
|
|
|
|
|
- onValueChange={(data) => {
|
|
|
|
|
- FormModel.current.branches![props.name].when[dIndex] = {
|
|
|
|
|
- ...FormModel.current.branches![props.name].when[dIndex],
|
|
|
|
|
- ...data,
|
|
|
|
|
- };
|
|
|
|
|
- }}
|
|
|
|
|
- onLabelChange={(options) => {
|
|
|
|
|
- FormModel.current.options!.terms[props.name] = options;
|
|
|
|
|
- }}
|
|
|
|
|
- onDelete={() => {
|
|
|
|
|
- FormModel.current.branches![props.name].when.splice(dIndex, 1);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- ))
|
|
|
|
|
- ) : (
|
|
|
|
|
- <span
|
|
|
|
|
- style={{
|
|
|
|
|
- fontSize: 14,
|
|
|
|
|
- color: '#2F54EB',
|
|
|
|
|
- cursor: 'pointer',
|
|
|
|
|
- padding: props.isFrist ? '16px 0' : 0,
|
|
|
|
|
- }}
|
|
|
|
|
- onClick={() => addWhen(props.name)}
|
|
|
|
|
- >
|
|
|
|
|
- {' '}
|
|
|
|
|
- <PlusCircleOutlined style={{ padding: 4 }} /> 添加过滤条件
|
|
|
|
|
- </span>
|
|
|
|
|
- )}
|
|
|
|
|
|
|
+ <Observer>
|
|
|
|
|
+ {() =>
|
|
|
|
|
+ when.length ? (
|
|
|
|
|
+ when.map((item, dIndex) => (
|
|
|
|
|
+ <Term
|
|
|
|
|
+ whenName={props.name}
|
|
|
|
|
+ pName={[props.name, 'when']}
|
|
|
|
|
+ name={dIndex}
|
|
|
|
|
+ data={item}
|
|
|
|
|
+ key={item.key}
|
|
|
|
|
+ paramsOptions={props.paramsOptions}
|
|
|
|
|
+ isLast={dIndex === when!.length - 1}
|
|
|
|
|
+ onValueChange={(data) => {
|
|
|
|
|
+ console.log('onValueChange2', data);
|
|
|
|
|
+ // FormModel.current.branches![props.name].when[dIndex] = {
|
|
|
|
|
+ // ...FormModel.current.branches![props.name].when[dIndex],
|
|
|
|
|
+ // ...data,
|
|
|
|
|
+ // };
|
|
|
|
|
+ set(FormModel.current.branches!, [props.name, 'when', dIndex], data);
|
|
|
|
|
+ }}
|
|
|
|
|
+ onLabelChange={(options) => {
|
|
|
|
|
+ FormModel.current.options!.terms[props.name] = options;
|
|
|
|
|
+ }}
|
|
|
|
|
+ onDelete={() => {
|
|
|
|
|
+ FormModel.current.branches![props.name].when.splice(dIndex, 1);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ ))
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <span
|
|
|
|
|
+ style={{
|
|
|
|
|
+ fontSize: 14,
|
|
|
|
|
+ color: '#2F54EB',
|
|
|
|
|
+ cursor: 'pointer',
|
|
|
|
|
+ padding: props.isFrist ? '16px 0' : 0,
|
|
|
|
|
+ }}
|
|
|
|
|
+ onClick={() => addWhen(props.name)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {' '}
|
|
|
|
|
+ <PlusCircleOutlined style={{ padding: 4 }} /> 添加过滤条件
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ </Observer>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="actions-branchs">
|
|
<div className="actions-branchs">
|
|
|
<Actions openShakeLimit={true} name={props.name} thenOptions={props.data.then} />
|
|
<Actions openShakeLimit={true} name={props.name} thenOptions={props.data.then} />
|