hear 3 лет назад
Родитель
Сommit
3b4119ea61

+ 26 - 5
src/pages/device/Instance/Detail/Parsing/index.tsx

@@ -34,6 +34,8 @@ const Parsing = (props: Props) => {
   // const [data, setData] = useState<any>({});
   const [readOnly, setReadOnly] = useState<boolean>(true);
   const [topTitle, setTopTitle] = useState<string>();
+  const [disabled, setDisabled] = useState<boolean>(false);
+  const [isTest, setIsTest] = useState<boolean>(false);
 
   const editorDidMountHandle = (editor: any) => {
     editor.getAction('editor.action.formatDocument').run();
@@ -115,12 +117,12 @@ const Parsing = (props: Props) => {
     service.testCode(dataTest).then((res) => {
       if (res.status === 200) {
         setLoading(false);
-        onlyMessage('调试成功');
+        // onlyMessage('调试成功');
         setResultValue(res?.result);
-        console.log(res.result);
+        // console.log(res.result);
       } else {
         setLoading(false);
-        onlyMessage('调试失败', 'error');
+        // onlyMessage('调试失败', 'error');
       }
     });
   };
@@ -163,6 +165,14 @@ const Parsing = (props: Props) => {
     }
   }, []);
 
+  useEffect(() => {
+    if (value === '' && simulation === '') {
+      setDisabled(true);
+    } else {
+      setDisabled(false);
+    }
+  }, [value, simulation]);
+
   return (
     <Card className="parsing" style={{ minHeight }}>
       <div>
@@ -340,7 +350,12 @@ const Parsing = (props: Props) => {
               <div style={{ fontWeight: 600, fontSize: 14, marginTop: 10 }}>运行结果</div>
               <Input.TextArea
                 autoSize={{ minRows: 5 }}
-                style={{ marginTop: 10 }}
+                style={
+                  resultValue
+                    ? { marginTop: 10, borderColor: `${resultValue.success ? 'green' : 'red'}` }
+                    : { marginTop: 10 }
+                }
+                status={''}
                 value={
                   resultValue.success
                     ? JSON.stringify(resultValue.outputs?.[0])
@@ -356,7 +371,7 @@ const Parsing = (props: Props) => {
           <Button
             type="primary"
             loading={loading}
-            disabled={value !== '' && !simulation}
+            disabled={disabled}
             onClick={() => {
               if (type === 'MQTT') {
                 if (topic !== '') {
@@ -371,6 +386,7 @@ const Parsing = (props: Props) => {
                     provider: 'jsr223',
                     payload: simulation,
                   });
+                  setIsTest(true);
                 } else {
                   message.error('请输入topic');
                 }
@@ -387,6 +403,7 @@ const Parsing = (props: Props) => {
                     },
                     payload: simulation,
                   });
+                  setIsTest(true);
                 } else {
                   message.error('请输入url');
                 }
@@ -401,6 +418,10 @@ const Parsing = (props: Props) => {
           key={'update'}
           style={{ marginLeft: 10 }}
           isPermission={permission.update}
+          disabled={!isTest}
+          tooltip={{
+            title: isTest ? '' : '请先调试',
+          }}
           onClick={() => {
             if (props.tag === 'device') {
               saveDeviceCode(props.data.productId, props.data.id, {

+ 2 - 1
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/ObjModel.tsx

@@ -34,7 +34,8 @@ export default (props: Props) => {
       zIndex={1050}
       onCancel={() => props.close()}
       onOk={() => {
-        props.ok(value);
+        props.ok(JSON.parse(value));
+        console.log(value, JSON.parse(value));
       }}
     >
       <div

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

@@ -326,9 +326,9 @@ export default observer((props: Props) => {
           }}
           ok={(param) => {
             if (props.onChange) {
-              props.onChange(param);
+              props.onChange(JSON.stringify(param));
             }
-            setValue(param);
+            setValue(JSON.stringify(param));
             setObjVisable(false);
           }}
         />

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

@@ -473,7 +473,7 @@ export default observer((props: Props) => {
       if (isVariable) {
         form.setFieldsValue({ selector: 'variable' });
       }
-      console.log(isVariable);
+      // console.log(isVariable);
     }
   }, [DeviceModel.productDetail, builtInList]);
 

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

@@ -65,7 +65,7 @@ export default observer((props: Props) => {
   const next = () => {
     if (
       (DeviceModel.current === 0 && DeviceModel.productId) ||
-      (DeviceModel.current === 1 && DeviceModel.deviceId)
+      (DeviceModel.current === 1 && (DeviceModel.deviceId || DeviceModel.selector === 'tag'))
     ) {
       return (DeviceModel.current += 1);
     } else {
@@ -240,7 +240,7 @@ export default observer((props: Props) => {
                   }
                 });
               }
-              return DeviceModel.deviceId
+              return DeviceModel.deviceId || DeviceModel.selector === 'tag'
                 ? (DeviceModel.current = 2)
                 : onlyMessage('请选择设备', 'error');
             } else {

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

@@ -246,7 +246,7 @@ export default (props: ItemProps) => {
           <div>
             <AIcon type={typeIconMap[data!.device!.message!.messageType]} />
             {data?.options?.type}
-            {data.options?.taglist.map((item: any) => (
+            {data.options?.taglist?.map((item: any) => (
               <span>
                 {item.type}
                 {item.name}