Просмотр исходного кода

fix: 场景联动及其他模块bug

wzyyy 3 лет назад
Родитель
Сommit
1f5b9c50c5

+ 1 - 1
src/components/SearchComponent/index.tsx

@@ -683,7 +683,7 @@ const SearchComponent = <T extends Record<string, any>>(props: Props<T>) => {
                 {item.name}
               </Typography.Text>
               <Popconfirm
-                title="确定删除"
+                title="确定删除"
                 onConfirm={async (e) => {
                   e?.stopPropagation();
                   const response = await service.history.remove(`${target}-search`, item.key);

+ 14 - 7
src/pages/device/Instance/Detail/index.tsx

@@ -29,6 +29,7 @@ import { onlyMessage } from '@/utils/util';
 import Parsing from './Parsing';
 import EdgeMap from './EdgeMap';
 import MapChannel from './MapChannel';
+import { service as api } from '../../Product/index';
 
 export const deviceStatus = new Map();
 deviceStatus.set('online', <Badge status="success" text={'在线'} />);
@@ -327,13 +328,19 @@ const InstanceDetail = observer(() => {
                 placement: 'topLeft',
               }}
               isPermission={!!getMenuPathByCode(MENUS_CODE['device/Product'])}
-              onClick={() => {
-                const url = getMenuPathByParams(
-                  MENUS_CODE['device/Product/Detail'],
-                  InstanceModel.detail?.productId,
-                );
-                if (url) {
-                  history.replace(url);
+              onClick={async () => {
+                if (InstanceModel.detail?.productId) {
+                  //为了判断资产权限
+                  const res = await api.detail(InstanceModel.detail?.productId);
+                  if (res.status === 200) {
+                    const url = getMenuPathByParams(
+                      MENUS_CODE['device/Product/Detail'],
+                      InstanceModel.detail?.productId,
+                    );
+                    if (url) {
+                      history.replace(url);
+                    }
+                  }
                 }
               }}
             >

+ 4 - 1
src/pages/device/Instance/Save/index.tsx

@@ -92,7 +92,10 @@ const Save = (props: Props) => {
         delete values.id;
       }
       setLoading(true);
-      const resp = (await service.update(values)) as any;
+      const resp =
+        props.model === 'add'
+          ? await service.update(values)
+          : await service.modify(values.id, values);
       setLoading(false);
       if (resp.status === 200) {
         onlyMessage('保存成功');

+ 12 - 15
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/TypeModel.tsx

@@ -1,5 +1,5 @@
 import ParamsSelect, { ItemProps } from '@/pages/rule-engine/Scene/Save/components/ParamsSelect';
-import { useEffect, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
 import { Input, InputNumber, Select, Tree } from 'antd';
 import MTimePicker from '../../../components/ParamsSelect/components/MTimePicker';
 import moment from 'moment';
@@ -36,14 +36,8 @@ export default observer((props: Props) => {
   const [builtInList, setBuiltInList] = useState<any[]>([]);
   const [labelValue, setLabelValue] = useState<any>('');
   const [open, setOpen] = useState<boolean>(false);
+  const optionMap = useRef<Map<string, any>>(new Map());
 
-  const filterLabel = (nodes: any[]) => {
-    let lable: any;
-    nodes.forEach((item) => {
-      lable = item.children?.find((it: any) => it.id === props.value);
-    });
-    return lable?.description;
-  };
   const filterParamsData = (type?: string, data?: any[]): any[] => {
     if (type && data) {
       return data.filter((item) => {
@@ -52,6 +46,7 @@ export default observer((props: Props) => {
           item.children = _children;
           return _children.length ? true : false;
         } else if (item.type === type) {
+          optionMap.current.set(item.id, item);
           return true;
         }
         return false;
@@ -69,14 +64,14 @@ export default observer((props: Props) => {
     };
     queryBuiltInParams(FormModel.current, _params).then((res: any) => {
       if (res.status === 200) {
+        optionMap.current.clear();
         const _data = BuiltInParamsHandleTreeData(res.result);
         const filterData = filterParamsData(props.type, _data);
-        // console.log('_data', _data);
-        // console.log('filterData', filterData);
-        // console.log('type',props.type)
         setBuiltInList(filterData);
-        const label = filterLabel(filterData);
-        setLabelValue(label);
+        if (props.value) {
+          const label = optionMap.current.get(props.value);
+          setLabelValue(label?.description);
+        }
       }
     });
   };
@@ -98,14 +93,16 @@ export default observer((props: Props) => {
   useEffect(() => {
     setValue(props.value);
     // setLabelValue(props.label);
-    // console.log('typemodel', props.value);
   }, [props.value]);
 
   useEffect(() => {
     setLabelValue(props.label);
-    console.log('-------', props.label);
   }, []);
 
+  useEffect(() => {
+    DeviceModel.actionName = labelValue;
+  }, [labelValue]);
+
   const renderNode = (type: string) => {
     switch (type) {
       case 'int':

+ 2 - 4
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/WriteProperty.tsx

@@ -28,7 +28,7 @@ export default (props: Props) => {
   const ref = useRef<any>('');
 
   useEffect(() => {
-    // console.log(props.value);
+    // console.log('props.value----',props.value,props.properties);
     if (props.value) {
       if (props.properties && props.properties.length) {
         if (0 in props.value) {
@@ -41,7 +41,6 @@ export default (props: Props) => {
             setPropertiesValue(props.value[key].value);
             setSource(props.value[key].source);
             const propertiesItem = props.properties.find((item: any) => item.id === key);
-            // console.log(propertiesItem,'11111111')
             if (propertiesItem) {
               setPropertiesType(propertiesItem.valueType.type);
               if (propertiesItem.valueType.type === 'enum') {
@@ -51,7 +50,6 @@ export default (props: Props) => {
                   (item: any) => item.value === props.value[key].value,
                 )?.text;
                 setLabel(text);
-                // console.log(text);
               }
             }
           });
@@ -63,7 +61,7 @@ export default (props: Props) => {
   }, [props.properties]);
 
   useEffect(() => {
-    if (props.onChange) {
+    if (props.onChange && propertiesValue) {
       const obj = {
         [propertiesId || 0]: {
           value: propertiesValue,

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

@@ -94,6 +94,7 @@ export default observer((props: Props) => {
     if (DeviceModel.message.functionId) {
       setFunctionId(DeviceModel.message.functionId);
     }
+    console.log('DeviceModel.message----------', DeviceModel.message);
   }, [DeviceModel.message]);
 
   useEffect(() => {
@@ -187,6 +188,7 @@ export default observer((props: Props) => {
           <Form.Item
             name={['message', 'properties']}
             label="设置属性"
+            required
             rules={[
               // { required: true, message: '请选择属性' },
               () => ({
@@ -212,7 +214,7 @@ export default observer((props: Props) => {
               }}
               onChange={(value, text, valueLable) => {
                 const item = value[Object.keys(value)?.[0]]?.value;
-                console.log(item);
+                // console.log(item);
                 DeviceModel.propertiesName = text;
                 if (valueLable) {
                   DeviceModel.propertiesValue = valueLable;

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

@@ -166,7 +166,7 @@ export default observer((props: Props) => {
     if (_options.selector === 'variable') {
       _options.name = DeviceModel.selectorValues?.[0]?.name;
     }
-    console.log('----------', item, _options, DeviceModel.propertiesValue);
+    // console.log('----------', item, _options, DeviceModel.propertiesValue);
     props.save(item, _options);
     init();
   };

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

@@ -66,7 +66,7 @@ export default (props: ShakeLimitProps) => {
       {enabled ? (
         <>
           <InputNumber
-            min={0}
+            min={1}
             max={100}
             precision={0}
             value={time}
@@ -76,7 +76,7 @@ export default (props: ShakeLimitProps) => {
           />
           <span>秒内发送</span>
           <InputNumber
-            min={0}
+            min={1}
             max={100}
             precision={0}
             value={threshold}

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

@@ -37,8 +37,8 @@ export const defaultBranches = [
     key: 'branches_1',
     shakeLimit: {
       enabled: false,
-      time: 0,
-      threshold: 0,
+      time: 1,
+      threshold: 1,
       alarmFirst: false,
     },
     then: [],

+ 2 - 2
src/pages/rule-engine/Scene/Save/terms/index.tsx

@@ -96,8 +96,8 @@ export default observer((props: Props) => {
       key: key,
       shakeLimit: {
         enabled: false,
-        time: 0,
-        threshold: 0,
+        time: 1,
+        threshold: 1,
         alarmFirst: false,
       },
       then: [],