|
@@ -1,20 +1,46 @@
|
|
|
import { useState } from 'react';
|
|
import { useState } from 'react';
|
|
|
import type { TermsType } from '@/pages/rule-engine/Scene/typings';
|
|
import type { TermsType } from '@/pages/rule-engine/Scene/typings';
|
|
|
-import { Popover } from 'antd';
|
|
|
|
|
|
|
+import { DropdownButton } from '@/pages/rule-engine/Scene/Save/components/Buttons';
|
|
|
import { CloseOutlined, PlusOutlined } from '@ant-design/icons';
|
|
import { CloseOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
import classNames from 'classnames';
|
|
import classNames from 'classnames';
|
|
|
|
|
+import { observer } from '@formily/react';
|
|
|
|
|
+import { FormModel } from '@/pages/rule-engine/Scene/Save';
|
|
|
|
|
+import { get, set } from 'lodash';
|
|
|
import './index.less';
|
|
import './index.less';
|
|
|
|
|
|
|
|
interface ParamsItemProps {
|
|
interface ParamsItemProps {
|
|
|
data: TermsType;
|
|
data: TermsType;
|
|
|
|
|
+ pName: (number | string)[];
|
|
|
name: number;
|
|
name: number;
|
|
|
isLast: boolean;
|
|
isLast: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export default (props: ParamsItemProps) => {
|
|
|
|
|
|
|
+export default observer((props: ParamsItemProps) => {
|
|
|
const [deleteVisible, setDeleteVisible] = useState(false);
|
|
const [deleteVisible, setDeleteVisible] = useState(false);
|
|
|
|
|
+ const [paramOptions] = useState([]);
|
|
|
|
|
+ const [termTypeOptions] = useState([]);
|
|
|
|
|
+ const [valueOptions] = useState([]);
|
|
|
|
|
|
|
|
- const deleteItem = () => {};
|
|
|
|
|
|
|
+ const deleteItem = () => {
|
|
|
|
|
+ const data = get(FormModel.branches, [...props.pName, 'terms']);
|
|
|
|
|
+ const indexOf = data?.findIndex((item: TermsType) => item.key === props.data.key);
|
|
|
|
|
+ if (indexOf !== undefined && indexOf !== -1) {
|
|
|
|
|
+ data!.splice(indexOf, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ set(FormModel.branches!, [...props.pName, 'terms'], data);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const addItem = () => {
|
|
|
|
|
+ const key = 'params_' + new Date().getTime();
|
|
|
|
|
+ const data = get(FormModel.branches, [...props.pName, 'terms']);
|
|
|
|
|
+ data?.push({
|
|
|
|
|
+ type: 'and',
|
|
|
|
|
+ column: undefined,
|
|
|
|
|
+ value: undefined,
|
|
|
|
|
+ termType: undefined,
|
|
|
|
|
+ key,
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="terms-params-item">
|
|
<div className="terms-params-item">
|
|
@@ -23,31 +49,39 @@ export default (props: ParamsItemProps) => {
|
|
|
onMouseOver={() => setDeleteVisible(true)}
|
|
onMouseOver={() => setDeleteVisible(true)}
|
|
|
onMouseOut={() => setDeleteVisible(false)}
|
|
onMouseOut={() => setDeleteVisible(false)}
|
|
|
>
|
|
>
|
|
|
- <Popover trigger={'click'} content={<span>1231</span>}>
|
|
|
|
|
- <div className="params-button parameter">请选择参数</div>
|
|
|
|
|
- </Popover>
|
|
|
|
|
- <Popover trigger={'click'} content={<span>1231</span>}>
|
|
|
|
|
- <div className="params-button termType">操作符</div>
|
|
|
|
|
- </Popover>
|
|
|
|
|
- <Popover trigger={'click'} content={<span>1231</span>}>
|
|
|
|
|
- <div className="params-button termsValue">参数值</div>
|
|
|
|
|
- </Popover>
|
|
|
|
|
- <div className={classNames('button-delete', { show: deleteVisible })}>
|
|
|
|
|
|
|
+ <DropdownButton
|
|
|
|
|
+ options={paramOptions}
|
|
|
|
|
+ type="param"
|
|
|
|
|
+ placeholder="请选择参数"
|
|
|
|
|
+ ></DropdownButton>
|
|
|
|
|
+ <DropdownButton
|
|
|
|
|
+ options={termTypeOptions}
|
|
|
|
|
+ type="termType"
|
|
|
|
|
+ placeholder="操作符"
|
|
|
|
|
+ ></DropdownButton>
|
|
|
|
|
+ <DropdownButton options={valueOptions} type="value" placeholder="参数值"></DropdownButton>
|
|
|
|
|
+ <div className={classNames('button-delete', { show: deleteVisible })} onClick={deleteItem}>
|
|
|
<CloseOutlined />
|
|
<CloseOutlined />
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
{!props.isLast ? (
|
|
{!props.isLast ? (
|
|
|
- <div className="term-type-warp" onClick={deleteItem}>
|
|
|
|
|
- <Popover trigger={'click'} content={<span>1231</span>}>
|
|
|
|
|
- <div className="params-button term-type">参数值</div>
|
|
|
|
|
- </Popover>
|
|
|
|
|
|
|
+ <div className="term-type-warp">
|
|
|
|
|
+ <DropdownButton
|
|
|
|
|
+ options={[
|
|
|
|
|
+ { title: '并且', key: 'and' },
|
|
|
|
|
+ { title: '或者', key: 'or' },
|
|
|
|
|
+ ]}
|
|
|
|
|
+ isTree={false}
|
|
|
|
|
+ type="type"
|
|
|
|
|
+ value="and"
|
|
|
|
|
+ ></DropdownButton>
|
|
|
</div>
|
|
</div>
|
|
|
) : (
|
|
) : (
|
|
|
- <div className="term-add">
|
|
|
|
|
|
|
+ <div className="term-add" onClick={addItem}>
|
|
|
<PlusOutlined style={{ fontSize: 12, paddingRight: 4 }} />
|
|
<PlusOutlined style={{ fontSize: 12, paddingRight: 4 }} />
|
|
|
<span>条件</span>
|
|
<span>条件</span>
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
-};
|
|
|
|
|
|
|
+});
|