sun-chaochao 3 лет назад
Родитель
Сommit
ce20e28512

BIN
public/images/device/device-number.png


+ 8 - 0
src/global.less

@@ -131,3 +131,11 @@ ol {
   text-align: left;
   text-overflow: ellipsis;
 }
+
+// fuck chrome
+input[type='text'],
+input[type='password'],
+input[type='number'],
+input[type='tel'] {
+  box-shadow: inset 0 0 0 100vw white !important;
+}

+ 3 - 2
src/hooks/route/useHistory.tsx

@@ -1,9 +1,9 @@
 import { useHistory } from 'umi';
 import { useEffect, useState } from 'react';
 import type { LocationState, Path } from 'history';
-import { model } from '@formily/reactive';
+import { observable } from '@formily/reactive';
 
-export const historyStateModel = model<{ state: any }>({ state: {} });
+export const historyStateModel = observable<{ state: any }>({ state: {} });
 
 const useHistories = () => {
   const umiHistory = useHistory();
@@ -14,6 +14,7 @@ const useHistories = () => {
     if (state) {
       historyStateModel.state[location] = state;
     }
+
     umiHistory.push(location, state);
   };
 

+ 1 - 1
src/locales/zh-CN/pages.ts

@@ -37,7 +37,7 @@ export default {
   'pages.data.option.invoke': '执行',
   'pages.data.option.cancel': '取消',
   'pages.data.option.view': '查看',
-  'pages.searchTable.new': '新',
+  'pages.searchTable.new': '新',
   'pages.searchTable.titleStatus': '状态',
   'pages.searchTable.titleStatus.all': '全部',
   'pages.searchTable.titleStatus.normal': '正常',

+ 2 - 0
src/pages/device/Product/index.tsx

@@ -84,6 +84,8 @@ const Product = observer(() => {
 
   useEffect(() => {
     const { state } = location;
+    console.log(state);
+
     if (state && state.save) {
       setCurrent(undefined);
       setVisible(true);

+ 1 - 1
src/pages/device/components/Metadata/Base/index.tsx

@@ -208,7 +208,7 @@ const BaseMetadata = observer((props: Props) => {
           >
             {intl.formatMessage({
               id: 'pages.searchTable.new',
-              defaultMessage: '新',
+              defaultMessage: '新',
             })}
           </PermissionButton>,
         ]}

+ 3 - 3
src/pages/home/comprehensive/index.tsx

@@ -95,7 +95,7 @@ const Comprehensive = () => {
       img: require('/public/images/home/guide-home1.png'),
       english: 'CREATE PRODUCT',
       auth: !!productPermission.add,
-      url: 'device/Product',
+      url: getMenuPathByCode('device/Product'),
       param: {
         save: true,
       },
@@ -106,7 +106,7 @@ const Comprehensive = () => {
       english: 'CREATE DEVICE',
       img: require('/public/images/home/guide-home2.png'),
       auth: !!devicePermission.add,
-      url: 'device/Instance',
+      url: getMenuPathByCode('device/Instance'),
       param: {
         save: true,
       },
@@ -117,7 +117,7 @@ const Comprehensive = () => {
       english: 'RULE ENGINE',
       img: require('/public/images/home/guide-home3.png'),
       auth: !!rulePermission.add,
-      url: 'rule-engine/Instance',
+      url: getMenuPathByCode('rule-engine/Instance'),
       param: {
         save: true,
       },

+ 2 - 0
src/pages/home/device/index.tsx

@@ -100,6 +100,8 @@ const Device = () => {
                 '产品是设备的集合,通常指一组具有相同功能的设备。物联设备必须通过产品进行接入方式配置。',
               onClick: () => {
                 const path = getMenuPathByCode('device/Product');
+                console.log(path);
+
                 if (path && !!productPermission.add) {
                   history.push(`${path}`, {
                     save: true,

+ 43 - 33
src/pages/rule-engine/Scene/Save/Explanation.tsx

@@ -2,7 +2,7 @@
 import styles from './Explanation.less';
 import { ExclamationCircleFilled } from '@ant-design/icons';
 
-export default () => {
+export default ({ type }: { type: string }) => {
   return (
     <div className={styles.doc} style={{ marginLeft: 12 }}>
       <h1>1.概述</h1>
@@ -11,39 +11,42 @@ export default () => {
       </div>
       <div>场景联动的规则可用于告警规则的引用,达到触发条件时将生成对应的告警记录。</div>
       <h1>2.配置说明</h1>
-      <h2>1、触发方式</h2>
-      <div>
-        包含<b>手动触发</b>、<b>定时触发</b>、<b>设备触发</b>3种方式
-      </div>
-      <h3>a. 手动触发</h3>
-      <div>适用于第三方平台向物联网平台下发指令控制设备。</div>
-      <div>
-        <b>例如:</b>用户通过智能家居APP开启或关闭设备。
-      </div>
-
-      <h3>b. 定时触发</h3>
-      <div>
-        <b>例如:</b>每天早上9点打开空调,并将空调开到26度。
-      </div>
+      {type === 'manual' && (
+        <>
+          <h2>1. 手动触发</h2>
+          <div>适用于第三方平台向物联网平台下发指令控制设备。</div>
+          <div>
+            <b>例如:</b>用户通过智能家居APP开启或关闭设备。
+          </div>
+        </>
+      )}
+      {type === 'timer' && (
+        <>
+          <h2>1. 定时触发</h2>
+          <div>
+            适用于第三方平台向物联网平台下发指令控制设备。支持按周、按月、按Corn表达式3种方式配置频率。
+          </div>
+          <div>
+            <b>例如:</b>每天早上9点打开空调,并将空调开到26度。
+          </div>
+        </>
+      )}
+      {type === 'device' && (
+        <>
+          <h2>1. 设备触发</h2>
+          <div>
+            适用于多个不同设备间执行动作的联动。选择具体设备时支持指定产品下属的固定设备、全部设备或选择产品下归属于具体部门的设备
+          </div>
+          <div>
+            <b>例如:</b>打开综合办部门房间门的时候,打开电灯、空调。
+          </div>
+        </>
+      )}
 
-      <h3>c. 设备触发</h3>
+      <h2>2.执行动作:</h2>
       <div>
-        适用于多个不同设备间执行动作的联动。选择具体设备时支持指定产品下属的固定设备、全部设备或选择产品下归属于具体部门的设备
+        支持消息通知、设备输出、延迟执行3种方式,延迟执行只在执行动作为串行时显示。另外串行模式下,多个执行动作间可以通过条件过滤判断时候继续执行后续动作。
       </div>
-      <div>
-        <b>例如:</b>打开综合办部门房间门的时候,打开电灯、空调。
-      </div>
-
-      <h2>2、触发条件</h2>
-      <div>
-        选择设备触发时,可对设备触发条件进行详细配置。触发条件支持多组条件,条件之间支持并且/或者的关系配置。每一个分组内可以添加多个条件,条件之间支持并且/或者的关系配置。
-      </div>
-      <div>
-        触发条件支持以属性指标(需在产品物模型tab页进行属性指标定义,定义后在对应设备的运行状态页填写阈值)作为判断阈值。
-      </div>
-
-      <h2>3、执行动作</h2>
-      <div>支持消息通知、设备输出、延迟执行3种方式,延迟执行只在执行动作为串行时显示。</div>
       <h3>a.消息通知</h3>
       <div>
         通过系统外的渠道给相关人员发送对应的通知模板内容。若钉钉消息、微信企业消息的通知模板中没有定义固定通知人,可在当前页面进行配置。同时“收信人”字段支持同步平台与微信、钉钉用户映射关系(对应类型的通知配置列表页配置),实现选择平台用户即可通知到对应的微信、钉钉用户。
@@ -57,7 +60,7 @@ export default () => {
         设备下线时,以微信或钉钉的方式通知该“设备负责人”(需管理员先在“关系配置”菜单中定义设备与用户的关系,然后到设备实例信息页面填写值)。
       </div>
 
-      <h3>b.设备输出</h3>
+      <h3>b.设备输出:</h3>
       <div>
         联动其他设备进行功能调用、读取属性、设置属性操作。
         选择设备时支持固定设备、按标签(需在设备物模型中自定义配置)、按关系(需管理员先在“关系配置”菜单中定义设备与用户的关系,然后到设备实例信息页面填写值)3种方式。
@@ -71,9 +74,16 @@ export default () => {
         {`温度传感器>30度时,与该设备相同“设备负责人”(自定义关系名)的空调执行打开操作。即可实现张三的温度传感器>30度时自动打开张三的空调,李四的温度传感器>30度时自动打开李四的空调。`}
       </div>
 
-      <h3>c.延迟执行</h3>
+      <h3>c.延迟执行:</h3>
       <div>设置延时时间后,设备执行动作将保持当前状态,时间结束后再执行下一条动作。</div>
       <div>房间门打开时,摄像头开启录像,延迟执行5s后,停止录像。</div>
+
+      <h3>d.条件过滤:</h3>
+      <div>根据当前动作执行是否成功,判断是否执行后续动作</div>
+      <div>
+        <b>例如:</b>
+        房间门打开时,执行打开空调,如果打开空调失败,给维修人员发送微信通知。
+      </div>
     </div>
   );
 };

+ 31 - 34
src/pages/rule-engine/Scene/Save/action/VariableItems/builtIn.tsx

@@ -32,40 +32,6 @@ export default (props: BuiltInProps) => {
 
   const [builtInList, setBuiltInList] = useState<any[]>([]);
 
-  useEffect(() => {
-    console.log(props.parallel);
-    // if (source === 'upper' && props.trigger) {
-    //   getBuiltInList({ ...props.trigger });
-    // }
-    if (source === 'upper') {
-      if (props.parallel === false) {
-        const data = props.form.getFieldsValue();
-        const params = props.name - 1 >= 0 ? { action: props.name - 1 } : undefined;
-        queryBuiltInParams(data, params).then((res: any) => {
-          if (res.status === 200) {
-            const actionParams = res.result.filter(
-              (item: any) => item.id === `action_${props.name}`,
-            );
-            const _data = props.name === 0 ? res.result : BuiltInParamsHandleTreeData(actionParams);
-            setBuiltInList(_data);
-          }
-        });
-      } else {
-        queryBuiltInParams({ ...props.trigger }).then((res: any) => {
-          if (res.status === 200) {
-            setBuiltInList(BuiltInParamsHandleTreeData(res.result));
-          }
-        });
-      }
-    }
-  }, [source, props.trigger, props.parallel]);
-
-  useEffect(() => {
-    setSource(props.value?.source);
-    setValue(props.value?.value);
-    setUpperKey(props.value?.upperKey);
-  }, [props.value]);
-
   const onChange = (_source: string = 'fixed', _value?: any, _upperKey?: string) => {
     const obj: ChangeType = {
       source: _source,
@@ -81,6 +47,37 @@ export default (props: BuiltInProps) => {
     }
   };
 
+  const sourceChangeEvent = () => {
+    onChange(source, undefined);
+    const data = props.form.getFieldsValue();
+    const params = props.name - 1 >= 0 ? { action: props.name - 1 } : undefined;
+    queryBuiltInParams(data, params).then((res: any) => {
+      if (res.status === 200) {
+        const actionParams = res.result.filter((item: any) => item.id === `action_${props.name}`);
+        const _data = props.name === 0 ? res.result : BuiltInParamsHandleTreeData(actionParams);
+        setBuiltInList(_data);
+      }
+    });
+  };
+
+  useEffect(() => {
+    if (source === 'upper') {
+      sourceChangeEvent();
+    }
+  }, [source, props.trigger, props.parallel]);
+
+  useEffect(() => {
+    if (props.trigger?.trigger?.device?.productId && source === 'upper') {
+      sourceChangeEvent();
+    }
+  }, [props.trigger?.trigger?.device?.productId, source]);
+
+  useEffect(() => {
+    setSource(props.value?.source);
+    setValue(props.value?.value);
+    setUpperKey(props.value?.upperKey);
+  }, [props.value]);
+
   const itemOnChange = useCallback(
     (_value: any) => {
       onChange(source, _value);

+ 42 - 10
src/pages/rule-engine/Scene/Save/action/action.tsx

@@ -34,8 +34,6 @@ interface ActionProps {
 
 export default observer((props: ActionProps) => {
   const { name } = props;
-  console.log('name', name);
-  console.log('isLast', props.isLast);
   const [type1, setType1] = useState('');
   // 消息通知
   const [notifyType, setNotifyType] = useState('');
@@ -47,6 +45,8 @@ export default observer((props: ActionProps) => {
   const [properties, setProperties] = useState([]); // 物模型-属性
   const [functionList, setFunctionList] = useState([]); // 物模型-功能
 
+  const [productId, setProductId] = useState('');
+
   const [isFiltering, setIsFiltering] = useState(false);
 
   const { data: messageType, run: queryMessageTypes } = useRequest(queryMessageType, {
@@ -123,11 +123,10 @@ export default observer((props: ActionProps) => {
 
   const handleInit = useCallback(async (data: any) => {
     if (data) {
-      console.log('actions ', data);
       if (data.executor) {
         setType1(data.executor);
       }
-      console.log(data.terms);
+
       if (data.terms) {
         // 显示过滤条件
         setIsFiltering(true);
@@ -146,6 +145,26 @@ export default observer((props: ActionProps) => {
     handleInit(props.actionItemData);
   }, [props.actionItemData]);
 
+  useEffect(() => {
+    if (
+      props.actionItemData?.executor &&
+      props.actionItemData?.executor === 'delay' &&
+      props.parallel === true
+    ) {
+      props.onRemove();
+    }
+  }, [props.parallel]);
+
+  useEffect(() => {
+    if (productId) {
+      const actions = props.form.getFieldValue('actions');
+      if (actions[name].device?.message?.properties) {
+        actions[name].device.message.properties = undefined;
+        props.form.setFieldsValue({ actions });
+      }
+    }
+  }, [productId]);
+
   const MessageNodes = (
     <>
       <Col span={7}>
@@ -276,11 +295,18 @@ export default observer((props: ActionProps) => {
             rules={[{ required: true, message: '请选择执行条件' }]}
           >
             <Select
-              options={[
-                { label: '消息通知', value: 'notify' },
-                { label: '设备输出', value: 'device' },
-                { label: '延迟执行', value: 'delay' },
-              ]}
+              options={
+                !props.parallel
+                  ? [
+                      { label: '消息通知', value: 'notify' },
+                      { label: '设备输出', value: 'device' },
+                      { label: '延迟执行', value: 'delay' },
+                    ]
+                  : [
+                      { label: '消息通知', value: 'notify' },
+                      { label: '设备输出', value: 'device' },
+                    ]
+              }
               placeholder={'请选择执行条件'}
               style={{ width: '100%' }}
             />
@@ -298,6 +324,7 @@ export default observer((props: ActionProps) => {
             onFunctionChange={setFunctionList}
             restField={props.restField}
             parallel={props.parallel}
+            onProductIdChange={setProductId}
           />
         )}
         {type1 === 'delay' && (
@@ -348,8 +375,10 @@ export default observer((props: ActionProps) => {
                   name={name}
                   properties={properties}
                   type={props.triggerType}
+                  trigger={props.trigger}
                   form={props.form}
                   parallel={props.parallel}
+                  productId={productId}
                 />
               </Form.Item>
             </Col>
@@ -361,6 +390,7 @@ export default observer((props: ActionProps) => {
                 name={name}
                 form={props.form}
                 data={props.actionItemData.terms}
+                productId={productId}
               />
             </Row>
           )}
@@ -387,6 +417,7 @@ export default observer((props: ActionProps) => {
                 name={name}
                 form={props.form}
                 data={props.actionItemData.terms}
+                productId={productId}
               />
             </Row>
           )}
@@ -400,7 +431,7 @@ export default observer((props: ActionProps) => {
             name={[name, 'device', 'message', 'inputs']}
             rules={[{ required: true, message: '请输入功能值' }]}
           >
-            <FunctionCall functionData={functionList} />
+            <FunctionCall functionData={functionList} productId={productId} />
           </Form.Item>
           <Row gutter={24}>
             {parallelNode}
@@ -409,6 +440,7 @@ export default observer((props: ActionProps) => {
                 name={name}
                 form={props.form}
                 data={props.actionItemData.terms}
+                productId={productId}
               />
             )}
           </Row>

+ 45 - 5
src/pages/rule-engine/Scene/Save/action/device/ConditionalFiltering.tsx

@@ -8,6 +8,7 @@ interface ConditionalFilteringProps {
   name: number;
   form: FormInstance;
   data?: any;
+  productId: string;
 }
 
 export default (props: ConditionalFilteringProps) => {
@@ -85,7 +86,6 @@ export default (props: ConditionalFilteringProps) => {
   const getBuiltItemById = useCallback(
     (id: string) => {
       const builtItem: any = getItemByChildren(id, builtInList);
-      console.log(builtItem, id);
       if (builtItem) {
         setType(builtItem.type);
         setTermTypes(builtItem.termTypes);
@@ -95,7 +95,7 @@ export default (props: ConditionalFilteringProps) => {
     [builtInList],
   );
 
-  useEffect(() => {
+  const getBuiltInParamsData = () => {
     const data = props.form.getFieldsValue();
     queryBuiltInParams(data, { action: props.name }).then((res: any) => {
       if (res.status === 200) {
@@ -105,16 +105,32 @@ export default (props: ConditionalFilteringProps) => {
         setBuiltInList(handleTreeData(actionParams));
       }
     });
-  }, []);
+  };
 
   useEffect(() => {
-    console.log('Conditional', builtInList);
     if (props.data && props.data[0] && props.data[0].column && builtInList && builtInList.length) {
       getBuiltItemById(props.data[0].column);
     }
   }, [props.data, builtInList]);
 
-  console.log(props.data, props.name);
+  useEffect(() => {
+    if (props.productId) {
+      getBuiltInParamsData();
+      const actions = props.form.getFieldValue('actions');
+      if (actions?.[props.name].terms?.[0]) {
+        actions[props.name].terms[0] = {
+          column: undefined,
+          termType: undefined,
+          value: {
+            source: 'fixed',
+            value: undefined,
+          },
+        };
+      }
+      setSource('fixed');
+    }
+  }, [props.productId]);
+
   return (
     <>
       <Col span={4}>
@@ -175,6 +191,30 @@ export default (props: ConditionalFilteringProps) => {
                 style={{ width: 120 }}
                 onSelect={(v: any) => {
                   setSource(v);
+                  if (
+                    ['nbtw', 'btw'].includes(
+                      props.data && props.data[0] && props.data[0].termType,
+                    ) &&
+                    source === 'fixed'
+                  ) {
+                    props.form.setFields([
+                      {
+                        name: [props.name, 'terms', 0, 'value', 'value', 0],
+                        value: undefined,
+                      },
+                      {
+                        name: [props.name, 'terms', 0, 'value', 'value', 1],
+                        value: undefined,
+                      },
+                    ]);
+                  } else {
+                    props.form.setFields([
+                      {
+                        name: [props.name, 'terms', 0, 'value', 'value'],
+                        value: undefined,
+                      },
+                    ]);
+                  }
                 }}
               />
             </Form.Item>

+ 63 - 38
src/pages/rule-engine/Scene/Save/action/device/WriteProperty/index.tsx

@@ -14,6 +14,8 @@ interface WritePropertyProps {
   onChange?: (value?: any) => void;
   parallel?: boolean;
   name: number;
+  trigger?: any;
+  productId: string;
 }
 
 export default (props: WritePropertyProps) => {
@@ -51,57 +53,80 @@ export default (props: WritePropertyProps) => {
     if (props.onChange) {
       props.onChange({
         [key || 0]: {
-          value,
+          value: value,
           source: _source,
         },
       });
     }
   };
 
+  const sourceChangeEvent = () => {
+    onChange(propertiesKey, undefined, source);
+    const params = props.name - 1 >= 0 ? { action: props.name - 1 } : undefined;
+    const data = props.form.getFieldsValue();
+    queryBuiltInParams(data, params).then((res: any) => {
+      if (res.status === 200) {
+        const actionParams = res.result.filter((item: any) => item.id === `action_${props.name}`);
+        const _data = props.name === 0 ? res.result : handleTreeData(actionParams);
+        setBuiltInList(_data);
+      }
+    });
+    // if (props.parallel === false) {
+    //   // 串行
+    // } else {
+    //   // 并行
+    //   queryBuiltInParams({
+    //     trigger: { type: props.type },
+    //   }).then((res: any) => {
+    //     if (res.status === 200) {
+    //       setBuiltInList(handleTreeData(res.result));
+    //     }
+    //   });
+    // }
+  };
+
   useEffect(() => {
     if (source === 'upper') {
-      onChange(propertiesKey, undefined, source);
-      if (props.parallel === false) {
-        // 串行
-        const params = props.name - 1 >= 0 ? { action: props.name - 1 } : undefined;
-        const data = props.form.getFieldsValue();
-        queryBuiltInParams(data, params).then((res: any) => {
-          if (res.status === 200) {
-            const actionParams = res.result.filter(
-              (item: any) => item.id === `action_${props.name}`,
-            );
-            const _data = props.name === 0 ? res.result : handleTreeData(actionParams);
-            setBuiltInList(_data);
-          }
-        });
-      } else {
-        // 并行
-        queryBuiltInParams({
-          trigger: { type: props.type },
-        }).then((res: any) => {
-          if (res.status === 200) {
-            setBuiltInList(handleTreeData(res.result));
-          }
-        });
-      }
+      sourceChangeEvent();
     }
   }, [source, props.type, props.parallel]);
 
   useEffect(() => {
-    if (props.value && props.properties && props.properties.length) {
-      if (0 in props.value) {
-        setPropertiesValue(props.value[0]);
-      } else {
-        Object.keys(props.value).forEach((key: string) => {
-          setPropertiesKey(key);
-          setPropertiesValue(props.value[key].value);
-          setSource(props.value[key].source);
-          const propertiesItem = props.properties.find((item: any) => item.id === key);
-          if (propertiesItem) {
-            setPropertiesType(propertiesItem.valueType.type);
-          }
-        });
+    if (props.trigger?.trigger?.device?.productId && source === 'upper') {
+      sourceChangeEvent();
+    }
+  }, [props.trigger?.trigger?.device?.productId, source]);
+
+  useEffect(() => {
+    if (props.productId) {
+      setPropertiesKey(undefined);
+      onChange('undefined', undefined, source);
+    }
+  }, [props.productId]);
+
+  useEffect(() => {
+    if (props.value) {
+      if (props.properties && props.properties.length) {
+        if (0 in props.value) {
+          setPropertiesValue(props.value[0]);
+        } else if ('undefined' in props.value) {
+          setPropertiesKey(undefined);
+          setPropertiesValue(undefined);
+        } else {
+          Object.keys(props.value).forEach((key: string) => {
+            setPropertiesKey(key);
+            setPropertiesValue(props.value[key].value);
+            setSource(props.value[key].source);
+            const propertiesItem = props.properties.find((item: any) => item.id === key);
+            if (propertiesItem) {
+              setPropertiesType(propertiesItem.valueType.type);
+            }
+          });
+        }
       }
+    } else {
+      setPropertiesKey(undefined);
+      setPropertiesValue(undefined);
     }
   }, [props.value, props.properties]);
 

+ 11 - 0
src/pages/rule-engine/Scene/Save/action/device/functionCall.tsx

@@ -17,6 +17,7 @@ interface FunctionCallProps {
   value?: any;
   onChange?: (data: any) => void;
   name?: string;
+  productId?: string;
 }
 
 export default (props: FunctionCallProps) => {
@@ -44,9 +45,19 @@ export default (props: FunctionCallProps) => {
           return item;
         }),
       });
+    } else {
+      formRef.current?.setFieldsValue({
+        table: [],
+      });
     }
   }, [props.value, props.functionData]);
 
+  useEffect(() => {
+    if (props.productId && props.onChange) {
+      props.onChange([]);
+    }
+  }, [props.productId]);
+
   const getItemNode = (record: any) => {
     const type = record.type;
     const name = record.name;

+ 17 - 7
src/pages/rule-engine/Scene/Save/action/device/index.tsx

@@ -17,6 +17,7 @@ interface DeviceProps {
   onMessageTypeChange: (type: string) => void;
   onFunctionChange: (functionItem: any) => void;
   parallel?: boolean;
+  onProductIdChange: (id: string) => void;
 }
 
 enum SourceEnum {
@@ -87,12 +88,20 @@ export default (props: DeviceProps) => {
     } else {
       setSourceList(DefaultSourceOptions);
     }
-    props.form?.setFields([
-      {
-        name: ['actions', name, 'device', 'selector'],
-        value: SourceEnum.fixed,
-      },
-    ]);
+    const actions = props.form?.getFieldValue('actions');
+
+    if (actions[name] && actions[name].device) {
+      if (actions[name].device.selector) {
+        actions[name].device.selector = SourceEnum.fixed;
+      }
+      if (actions[name].device.selectorValues) {
+        actions[name].device.selectorValues = undefined;
+      }
+    }
+    props.form?.setFieldsValue({
+      actions,
+    });
+    setSelector(SourceEnum.fixed);
   }, [props.triggerType]);
 
   useEffect(() => {
@@ -102,6 +111,8 @@ export default (props: DeviceProps) => {
         handleMetadata(productItem.metadata);
       }
     }
+
+    props.onProductIdChange(productId);
   }, [productId]);
 
   useEffect(() => {
@@ -134,7 +145,6 @@ export default (props: DeviceProps) => {
   }, []);
 
   useEffect(() => {
-    console.log('actions-device', props.value);
     const deviceData = props.value;
     if (deviceData) {
       setProductId(deviceData.productId);

+ 20 - 10
src/pages/rule-engine/Scene/Save/index.tsx

@@ -52,7 +52,7 @@ export default () => {
   const history = useHistory();
 
   const { getOtherPermission } = PermissionButton.usePermission('rule-engine/Scene');
-  const [triggerType, setTriggerType] = useState('');
+  const [triggerType, setTriggerType] = useState('device');
 
   const [loading, setLoading] = useState(false);
   const [parallel, setParallel] = useState(true); // 是否并行
@@ -62,6 +62,7 @@ export default () => {
   const [triggerValue, setTriggerValue] = useState<any>([]);
   const [triggerDatas, setTriggerDatas] = useState<any>({});
   const [actionParams, setActionParams] = useState<any>(undefined);
+  const [actionDataCount, setActionDataCount] = useState(0);
 
   const [actionsData, setActionsData] = useState<any[]>([]);
   const [isEdit, setIsEdit] = useState(false);
@@ -224,9 +225,6 @@ export default () => {
               layout={'vertical'}
               preserve={false}
               className={'scene-save'}
-              initialValues={{
-                actions: [undefined],
-              }}
               onValuesChange={(changeValue, allValues) => {
                 if (changeValue.trigger) {
                   if (changeValue.trigger.device) {
@@ -258,7 +256,7 @@ export default () => {
                     setActionParams({ trigger: allValues.trigger }); // 用于内置参数请求
                   }
                 }
-
+                console.log('scene save', allValues);
                 if (allValues.actions) {
                   setActionsData(allValues.actions);
                 }
@@ -288,6 +286,7 @@ export default () => {
                 <Form.Item
                   name={['trigger', 'type']}
                   rules={[{ required: true, message: '请选择触发方式' }]}
+                  initialValue={'device'}
                 >
                   <TriggerWay onSelect={setTriggerType} disabled={isEdit} />
                 </Form.Item>
@@ -357,7 +356,10 @@ export default () => {
                             name={name}
                             trigger={actionParams}
                             triggerType={triggerType}
-                            onRemove={() => remove(name)}
+                            onRemove={() => {
+                              remove(name);
+                              setActionDataCount(actionDataCount - 1);
+                            }}
                             onMove={(type) => {
                               if (type === 'up') {
                                 move(name, name - 1);
@@ -365,13 +367,21 @@ export default () => {
                                 move(name, name + 1);
                               }
                             }}
-                            actionItemData={actionsData.length && actionsData[name]}
-                            isLast={!actionsData.length || actionsData.length - 1 === name}
+                            actionItemData={actionDataCount && actionsData[name]}
+                            isLast={!actionDataCount || actionDataCount - 1 === name}
                             parallel={parallel}
                           />
                         ))}
                         <Form.Item noStyle>
-                          <Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}>
+                          <Button
+                            type="dashed"
+                            onClick={() => {
+                              add();
+                              setActionDataCount(actionDataCount + 1);
+                            }}
+                            block
+                            icon={<PlusOutlined />}
+                          >
                             新增
                           </Button>
                         </Form.Item>
@@ -409,7 +419,7 @@ export default () => {
             </Form>
           </Col>
           <Col span={8}>
-            <Explanation />
+            <Explanation type={triggerType} />
           </Col>
         </Row>
       </Card>