Forráskód Böngészése

fix: bug

Next wzy
hear 3 éve
szülő
commit
68260430cb

+ 43 - 21
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/TypeModel.tsx

@@ -1,6 +1,6 @@
 import ParamsSelect, { ItemProps } from '@/pages/rule-engine/Scene/Save/components/ParamsSelect';
 import { useEffect, useState } from 'react';
-import { Input, InputNumber, Select, Tree } from 'antd';
+import { Empty, Input, InputNumber, Select, Tree } from 'antd';
 import MTimePicker from '../../../components/ParamsSelect/components/MTimePicker';
 import moment from 'moment';
 import { EditOutlined, EnvironmentOutlined } from '@ant-design/icons';
@@ -26,22 +26,37 @@ export default (props: Props) => {
   const [source, setSource] = useState<string>(props.source || 'fixed');
   const [builtInList, setBuiltInList] = useState<any[]>([]);
   const [labelValue, setLabelValue] = useState<any>('');
+  const [dateOpen, setDateOpen] = useState<boolean>();
 
-  const filterTree = (nodes: any[]) => {
+  const filterLabel = (nodes: any[]) => {
     let lable: any;
     nodes.forEach((item) => {
       lable = item.children?.find((it: any) => it.id === props.value);
     });
     return lable?.description;
   };
+  const filterTree = (nodes: any[]) => {
+    if (!nodes?.length) {
+      return nodes;
+    }
+    return nodes.filter((it) => {
+      if (it.children.find((item: any) => item.type === props.type)) {
+        return true;
+      }
+      return false;
+    });
+  };
 
   const sourceChangeEvent = async () => {
     const params = props?.name - 1 >= 0 ? { action: props?.name - 1 } : undefined;
     queryBuiltInParams(FormModel.current, params).then((res: any) => {
       if (res.status === 200) {
         const _data = BuiltInParamsHandleTreeData(res.result);
-        setBuiltInList(_data);
-        const label = filterTree(_data);
+        const filterData = filterTree(_data);
+        // console.log('_data',_data,)
+        // console.log('type',props.type)
+        setBuiltInList(filterData);
+        const label = filterLabel(filterData);
         setLabelValue(label);
       }
     });
@@ -146,6 +161,9 @@ export default (props: Props) => {
       case 'date':
         return (
           <MTimePicker
+            onOpen={(param) => {
+              setDateOpen(param);
+            }}
             value={moment(value, 'HH:mm:ss')}
             onChange={(_: any, timeString: string) => {
               setValue(timeString);
@@ -182,22 +200,25 @@ export default (props: Props) => {
     {
       label: `内置参数`,
       key: 'upper',
-      content: (
-        <Tree
-          treeData={builtInList}
-          height={300}
-          defaultExpandAll
-          fieldNames={{ title: 'name', key: 'id' }}
-          onSelect={(selectedKeys, e) => {
-            // console.log(e.node);
-            setLabelValue(e.node.description);
-            setValue(selectedKeys[0]);
-            if (props.onChange) {
-              props.onChange(selectedKeys[0], source);
-            }
-          }}
-        />
-      ),
+      content:
+        builtInList.length !== 0 ? (
+          <Tree
+            treeData={builtInList}
+            height={300}
+            defaultExpandAll
+            fieldNames={{ title: 'name', key: 'id' }}
+            onSelect={(selectedKeys, e) => {
+              // console.log(e.node);
+              setLabelValue(e.node.description);
+              setValue(selectedKeys[0]);
+              if (props.onChange) {
+                props.onChange(selectedKeys[0], source);
+              }
+            }}
+          />
+        ) : (
+          <Empty />
+        ),
     },
   ];
 
@@ -207,18 +228,19 @@ export default (props: Props) => {
         style={{ width: '100%', height: '100%' }}
         inputProps={{
           placeholder: '请选择',
+          disabled: true,
         }}
         tabKey={source}
         itemList={itemList}
         value={value}
         onChange={(val: any, tabKey: any) => {
-          // console.log(val, tabKey);
           setValue(val);
           setSource(tabKey);
           if (props.onChange) {
             props.onChange(val, tabKey);
           }
         }}
+        open={dateOpen}
         type={props.type}
         labelValue={labelValue}
       />

+ 5 - 2
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/index.tsx

@@ -16,7 +16,6 @@ export default observer((props: Props) => {
   const [form] = Form.useForm();
   const [deviceMessageType, setDeviceMessageType] = useState('');
   const [properties, setProperties] = useState([]); // 物模型-属性
-  // const [propertiesId, setPropertiesId] = useState<string | undefined>(''); // 物模型-属性ID,用于串行
   const [functionList, setFunctionList] = useState<any>([]); // 物模型-功能
   const [functionId, setFunctionId] = useState('');
   const [functions, setFunctions] = useState([]);
@@ -80,7 +79,6 @@ export default observer((props: Props) => {
     if (DeviceModel.message.functionId) {
       setFunctionId(DeviceModel.message.functionId);
     }
-    // console.log(DeviceModel.message)
   }, [DeviceModel.message]);
 
   useEffect(() => {
@@ -108,6 +106,11 @@ export default observer((props: Props) => {
             onChange={(value: string) => {
               setDeviceMessageType(value);
               console.log(value);
+              form.setFieldsValue({
+                message: {
+                  properties: [],
+                },
+              });
             }}
           />
         </Form.Item>

+ 2 - 0
src/pages/rule-engine/Scene/Save/action/DeviceOutput/device/index.tsx

@@ -342,6 +342,8 @@ export default observer((props: Props) => {
             />
             <div>
               <ProTableCard<DeviceInstance>
+                noPadding
+                cardScrollY={460}
                 actionRef={actionRef}
                 columns={columns}
                 rowKey="id"

+ 1 - 1
src/pages/rule-engine/Scene/Save/action/DeviceOutput/index.tsx

@@ -132,7 +132,7 @@ export default observer((props: Props) => {
     <Modal
       title={'执行动作'}
       open
-      width={860}
+      width={880}
       onCancel={() => {
         props.cancel();
         DeviceModel.current = 0;

+ 3 - 0
src/pages/rule-engine/Scene/Save/action/DeviceOutput/product/index.tsx

@@ -223,6 +223,8 @@ export default observer((props: Props) => {
         }}
       >
         <ProTableCard<ProductItem>
+          noPadding
+          cardScrollY={460}
           actionRef={actionRef}
           columns={columns}
           rowKey="id"
@@ -237,6 +239,7 @@ export default observer((props: Props) => {
             onChange: (_, selectedRows) => {
               DeviceModel.productId = selectedRows.map((item) => item.id)?.[0];
               DeviceModel.productDetail = selectedRows?.[0];
+              DeviceModel.message = {};
             },
           }}
           request={(params) =>

+ 1 - 1
src/pages/rule-engine/Scene/Save/action/ListItem/List.tsx

@@ -20,7 +20,7 @@ export default (props: ListProps) => {
 
   useEffect(() => {
     setActions(props.actions);
-    console.log('list-change', props.actions);
+    // console.log('list-change', props.actions);
   }, [props.actions]);
 
   return (

+ 5 - 1
src/pages/rule-engine/Scene/Save/action/Modal/add.tsx

@@ -38,6 +38,7 @@ export default (props: Props) => {
               props.save(
                 {
                   type: 'device',
+                  executor: 'device',
                   key: props.data.key || `device_${new Date().getTime()}`,
                   device: {
                     ...data,
@@ -63,6 +64,7 @@ export default (props: Props) => {
               props.save(
                 {
                   ...data,
+                  executor: 'notify',
                   key: props.data.key || `notify_${new Date().getTime()}`,
                 },
                 option,
@@ -83,6 +85,7 @@ export default (props: Props) => {
               props.save(
                 {
                   type: 'delay',
+                  executor: 'delay',
                   key: props.data.key || `delay_${new Date().getTime()}`,
                   delay: {
                     ...data,
@@ -113,7 +116,8 @@ export default (props: Props) => {
         const values = await form.validateFields();
         setActionType(values.type);
         if (values.type === 'relieve' || values.type === 'trigger') {
-          props.save({ ...props.data, type: values.type });
+          console.log(values.type, props.data);
+          props.save({ ...props.data, type: values.type, executor: values.type });
         }
       }}
     >

+ 1 - 1
src/pages/rule-engine/Scene/Save/action/index.tsx

@@ -63,7 +63,7 @@ export default (props: ActionsProps) => {
                       parallel={false}
                       actions={parallelThens.length ? parallelThens[0].actions : []}
                       onAdd={(actionItem) => {
-                        console.log('parallelThens', parallelThens, actionItem);
+                        // console.log('parallelThens', parallelThens, actionItem);
                         if (parallelThens[0]) {
                           if (
                             parallelThens[0].actions.some((aItem) => aItem.key === actionItem.key)

+ 10 - 1
src/pages/rule-engine/Scene/Save/components/ParamsSelect/components/MTimePicker/index.tsx

@@ -3,7 +3,11 @@ import './index.less';
 import type { TimePickerProps } from 'antd/lib/time-picker';
 import { useEffect, useState } from 'react';
 
-export default (props: TimePickerProps) => {
+type Props = TimePickerProps & {
+  onOpen?: (open: boolean) => void;
+};
+
+export default (props: Props) => {
   const [myValue, setMyValue] = useState<any>(props.value || undefined);
 
   useEffect(() => {
@@ -23,6 +27,11 @@ export default (props: TimePickerProps) => {
         className={'manual-time-picker'}
         popupClassName={'my-manual-time-picker'}
         open
+        onOk={() => {
+          if (props.onOpen) {
+            props.onOpen(false);
+          }
+        }}
         // @ts-ignore
         getPopupContainer={(trigger) => {
           return trigger && trigger?.parentNode ? trigger.parentNode : document.body;

+ 1 - 1
src/pages/rule-engine/Scene/Save/components/ParamsSelect/index.less

@@ -28,7 +28,7 @@
   padding: 4px;
   background: #fff;
   border-radius: 2px;
-  box-shadow: 0 4px 18px #f3f3f3;
+  // box-shadow: 0 4px 18px #f3f3f3;
 
   .select-box-header-top {
     width: 100%;

+ 2 - 1
src/pages/rule-engine/Scene/Save/components/ParamsSelect/index.tsx

@@ -82,13 +82,14 @@ export default (props: Props) => {
         <Input
           suffix={<DownOutlined style={{ color: 'rgba(0, 0, 0, 0.25)' }} />}
           {...props.inputProps}
+          readOnly
           value={props.labelValue ? props.labelValue : value}
           onChange={(e) => {
             setValue(e.target.value);
             props.onChange(value, tabKey);
           }}
           onFocus={() => {
-            setOpen(true);
+            // setOpen(true);
             props.openChange?.(true);
           }}
         />