|
@@ -1,10 +1,11 @@
|
|
|
-import { useState } from 'react';
|
|
|
|
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
import { AddButton } from '@/pages/rule-engine/Scene/Save/components/Buttons';
|
|
import { AddButton } from '@/pages/rule-engine/Scene/Save/components/Buttons';
|
|
|
import Modal from '../Modal/add';
|
|
import Modal from '../Modal/add';
|
|
|
import './index.less';
|
|
import './index.less';
|
|
|
import type { ActionsType } from '@/pages/rule-engine/Scene/typings';
|
|
import type { ActionsType } from '@/pages/rule-engine/Scene/typings';
|
|
|
import Item from './Item';
|
|
import Item from './Item';
|
|
|
import type { ParallelType } from './Item';
|
|
import type { ParallelType } from './Item';
|
|
|
|
|
+import { FormModel } from '../..';
|
|
|
interface ListProps {
|
|
interface ListProps {
|
|
|
type: ParallelType;
|
|
type: ParallelType;
|
|
|
actions: ActionsType[];
|
|
actions: ActionsType[];
|
|
@@ -12,30 +13,20 @@ interface ListProps {
|
|
|
|
|
|
|
|
export default (props: ListProps) => {
|
|
export default (props: ListProps) => {
|
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
|
|
|
+ const [actions, setActions] = useState<ActionsType[]>(props.actions);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setActions(props.actions);
|
|
|
|
|
+ }, [props.actions]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="action-list-content">
|
|
<div className="action-list-content">
|
|
|
- {props.actions.map((item, index) => (
|
|
|
|
|
|
|
+ {actions.map((item, index) => (
|
|
|
<Item name={index} data={item} type={props.type} key={item.key} />
|
|
<Item name={index} data={item} type={props.type} key={item.key} />
|
|
|
))}
|
|
))}
|
|
|
<AddButton
|
|
<AddButton
|
|
|
onClick={() => {
|
|
onClick={() => {
|
|
|
setVisible(true);
|
|
setVisible(true);
|
|
|
- // const addItem: ActionsType = {
|
|
|
|
|
- // executor: 'device',
|
|
|
|
|
- // device: {
|
|
|
|
|
- // selector: 'all',
|
|
|
|
|
- // source: 'fixed'
|
|
|
|
|
- // },
|
|
|
|
|
- // key: `${props.type}_${props.actions.length}`
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // if (props.type === 'serial') {
|
|
|
|
|
- // addItem.terms = []
|
|
|
|
|
- // }
|
|
|
|
|
- // console.log(addItem);
|
|
|
|
|
-
|
|
|
|
|
- // FormModel?.actions?.push(addItem)
|
|
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
点击配置执行动作
|
|
点击配置执行动作
|
|
@@ -43,10 +34,28 @@ export default (props: ListProps) => {
|
|
|
{visible && (
|
|
{visible && (
|
|
|
<Modal
|
|
<Modal
|
|
|
name={props.actions.length + 1}
|
|
name={props.actions.length + 1}
|
|
|
- data={{}}
|
|
|
|
|
|
|
+ data={{
|
|
|
|
|
+ key: `${props.type}_${props.actions.length}`,
|
|
|
|
|
+ }}
|
|
|
close={() => {
|
|
close={() => {
|
|
|
setVisible(false);
|
|
setVisible(false);
|
|
|
}}
|
|
}}
|
|
|
|
|
+ save={(data: any) => {
|
|
|
|
|
+ const { type, ...extra } = data;
|
|
|
|
|
+ const item: ActionsType = {
|
|
|
|
|
+ ...extra,
|
|
|
|
|
+ executor: data.type === 'trigger' || data.type === 'relieve' ? 'alarm' : data.type,
|
|
|
|
|
+ key: data.key,
|
|
|
|
|
+ alarm: {
|
|
|
|
|
+ mode: data.type,
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ const index = FormModel?.actions.findIndex((i) => {
|
|
|
|
|
+ return i.key === item.key ? item : i;
|
|
|
|
|
+ });
|
|
|
|
|
+ FormModel.actions[index] = { ...item };
|
|
|
|
|
+ setVisible(false);
|
|
|
|
|
+ }}
|
|
|
/>
|
|
/>
|
|
|
)}
|
|
)}
|
|
|
</div>
|
|
</div>
|