瀏覽代碼

fix: 功能调用

Wzyyy98 3 年之前
父節點
當前提交
b5e75bbbfb

+ 51 - 0
src/pages/rule-engine/Scene/Save/action/DeviceOutput/actions/ObjModel.tsx

@@ -0,0 +1,51 @@
+import { Modal } from 'antd';
+import { useEffect, useRef, useState } from 'react';
+import MonacoEditor from 'react-monaco-editor';
+
+interface Props {
+  value: any;
+  close: () => void;
+  ok: (data: any) => void;
+}
+
+export default (props: Props) => {
+  const monacoRef = useRef<any>();
+
+  const [value, setValue] = useState<any>(props.value);
+
+  const editorDidMountHandle = (editor: any) => {
+    monacoRef.current = editor;
+    editor.getAction('editor.action.formatDocument').run();
+    editor.onDidContentSizeChange?.(() => {
+      editor.getAction('editor.action.formatDocument').run();
+    });
+  };
+
+  useEffect(() => {
+    setValue(props?.value || '');
+  }, [props.value]);
+
+  return (
+    <Modal
+      visible
+      title="编辑"
+      width={700}
+      onCancel={() => props.close()}
+      onOk={() => {
+        props.ok(value);
+      }}
+    >
+      <MonacoEditor
+        width={'100%'}
+        height={400}
+        theme="vs-dark"
+        language={'json'}
+        value={value}
+        onChange={(newValue) => {
+          setValue(newValue);
+        }}
+        editorDidMount={editorDidMountHandle}
+      />
+    </Modal>
+  );
+};

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

@@ -4,15 +4,21 @@ import { DataNode } from 'antd/es/tree';
 import { Input, InputNumber, Select, Tree } from 'antd';
 import MTimePicker from '../../../components/ParamsSelect/components/MTimePicker';
 import moment from 'moment';
+import { EditOutlined, EnvironmentOutlined } from '@ant-design/icons';
+import AMap from '@/components/GeoPoint/AMap';
+import ObjModel from './ObjModel';
 
 interface Props {
   value: any;
   type: string;
   onChange?: (data: any, format?: any) => void;
+  record: any;
 }
 
 export default (props: Props) => {
   const [value, setValue] = useState<any>(null);
+  const [visible, setVisible] = useState<boolean>(false);
+  const [objVisiable, setObjVisable] = useState<boolean>(false);
   const treeData: DataNode[] = [
     {
       title: 'parent 1',
@@ -62,12 +68,26 @@ export default (props: Props) => {
           <InputNumber
             value={value}
             onChange={(e: any) => {
-              setValue(e);
+              onChange(e);
             }}
             style={{ width: '100%' }}
             placeholder={'请输入'}
           />
         );
+      case 'enum':
+        return (
+          <Select
+            value={value}
+            style={{ width: '100%', textAlign: 'left' }}
+            options={props.record.options || []}
+            fieldNames={{ label: 'text', value: 'value' }}
+            placeholder={'请选择'}
+            mode="multiple"
+            onChange={(e) => {
+              onChange(e);
+            }}
+          />
+        );
       case 'boolean':
         return (
           <Select
@@ -77,7 +97,43 @@ export default (props: Props) => {
               { label: 'true', value: true },
               { label: 'false', value: false },
             ]}
-            placeholder={'请选择' + name}
+            placeholder={'请选择'}
+            onChange={(e) => {
+              onChange(e);
+            }}
+          />
+        );
+      case 'geoPoint':
+        return (
+          <Input
+            value={value}
+            style={{ width: '100%', textAlign: 'left' }}
+            addonAfter={
+              <EnvironmentOutlined
+                onClick={() => {
+                  setVisible(true);
+                }}
+              />
+            }
+            placeholder={'请选择'}
+            onChange={(e) => {
+              onChange(e);
+            }}
+          />
+        );
+      case 'object':
+        return (
+          <Input
+            value={value}
+            style={{ width: '100%', textAlign: 'left' }}
+            addonAfter={
+              <EditOutlined
+                onClick={() => {
+                  setObjVisable(true);
+                }}
+              />
+            }
+            placeholder={'请选择'}
             onChange={(e) => {
               onChange(e);
             }}
@@ -99,7 +155,7 @@ export default (props: Props) => {
         return (
           <Input
             value={value}
-            placeholder={'请输入' + name}
+            placeholder={'请输入'}
             onChange={(e) => {
               setValue(e.target.value);
               if (props.onChange) {
@@ -150,6 +206,37 @@ export default (props: Props) => {
           setValue(val);
         }}
       />
+      {visible && (
+        <AMap
+          value={value}
+          close={() => {
+            setVisible(false);
+          }}
+          ok={(param) => {
+            if (props.onChange) {
+              props.onChange(param);
+            }
+            setValue(param);
+            setVisible(false);
+          }}
+        />
+      )}
+
+      {objVisiable && (
+        <ObjModel
+          value={value}
+          close={() => {
+            setObjVisable(false);
+          }}
+          ok={(param) => {
+            if (props.onChange) {
+              props.onChange(param);
+            }
+            setValue(param);
+            setObjVisable(false);
+          }}
+        />
+      )}
     </div>
   );
 };

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

@@ -61,7 +61,7 @@ export default (props: FunctionCallProps) => {
 
   const getItemNode = (record: any) => {
     const type = record.type;
-    return <TypeModel value={record.value} type={type} />;
+    return <TypeModel value={record.value} type={type} record={record} />;
   };
 
   const columns: ProColumns<FunctionTableDataType>[] = [