Browse Source

fix: 场景联动

Wzyyy98 3 năm trước cách đây
mục cha
commit
3fbe7d1e08

+ 21 - 0
src/global.less

@@ -160,6 +160,7 @@ input[type='tel'] {
 #driver-page-overlay {
   opacity: 0.35 !important;
 }
+
 .ant-pagination-mini .ant-pagination-jump-prev,
 .ant-pagination-mini .ant-pagination-jump-next {
   display: none;
@@ -169,3 +170,23 @@ input[type='tel'] {
   display: flex;
   justify-content: flex-end;
 }
+
+.ant-formily-array-table
+  .ant-table
+  td
+  .ant-formily-item:not(.ant-formily-item-feedback-layout-popover)
+  .ant-formily-item-help {
+  position: inherit;
+  top: 100%;
+  z-index: 1;
+  width: 100%;
+  margin-top: 3px;
+  padding: 3px;
+  font-size: 12px;
+  background: #fff;
+  border-radius: 3px;
+  box-shadow: 0 0 10px #eee;
+  transform: translateY(0);
+  opacity: 1;
+  animation: none;
+}

+ 24 - 6
src/pages/device/Instance/Detail/MapChannel/index.tsx

@@ -1,7 +1,7 @@
 import useDomFullHeight from '@/hooks/document/useDomFullHeight';
 import { createForm, Field, FormPath, onFieldReact } from '@formily/core';
 import { FormProvider, createSchemaField } from '@formily/react';
-import { Badge, Button, Card, Tooltip } from 'antd';
+import { Badge, Button, Card, Spin, Tooltip } from 'antd';
 import { useEffect, useState } from 'react';
 import { FormItem, ArrayTable, Editable, Select } from '@formily/antd';
 import PermissionButton from '@/components/PermissionButton';
@@ -28,6 +28,7 @@ const MapChannel = (props: Props) => {
   const [properties, setProperties] = useState<any>([]);
   const [channelList, setChannelList] = useState<any>([]);
   const [visible, setVisible] = useState<boolean>(false);
+  const [loading, setLoading] = useState<boolean>(false);
 
   const Render = (propsName: any) => {
     const text = properties.find((item: any) => item.metadataId === propsName.value);
@@ -62,6 +63,7 @@ const MapChannel = (props: Props) => {
           title: '确认解绑',
           disabled: !record(index)?.id,
           onConfirm: async () => {
+            setLoading(true);
             remove(record(index)?.id);
           },
         }}
@@ -369,6 +371,7 @@ const MapChannel = (props: Props) => {
   };
 
   useEffect(() => {
+    setLoading(true);
     service
       .getChannel({
         paging: false,
@@ -418,14 +421,23 @@ const MapChannel = (props: Props) => {
           //删除物模型
           const items = array.filter((item: any) => item.metadataName);
           setProperties(items);
+          setTimeout(() => {
+            setLoading(false);
+          }, 500);
           const delList = array.filter((a: any) => !a.metadataName).map((b: any) => b.id);
           //删除后解绑
           if (delList && delList.length !== 0) {
             service.removeMap('device', data.id, delList);
+            setTimeout(() => {
+              setLoading(false);
+            }, 500);
           }
         }
       });
     } else {
+      setTimeout(() => {
+        setLoading(false);
+      }, 500);
       setEmpty(true);
     }
   }, [reload]);
@@ -448,6 +460,7 @@ const MapChannel = (props: Props) => {
             <Button
               type="primary"
               onClick={async () => {
+                setLoading(true);
                 const value: any = await form.submit();
                 const arr = value.requestList.filter((i: any) => i.channelId);
                 if (arr && arr.length !== 0) {
@@ -459,11 +472,16 @@ const MapChannel = (props: Props) => {
               保存
             </Button>
           </div>
-          <div className="array-table">
-            <FormProvider form={form}>
-              <SchemaField schema={schema} scope={{ useAsyncDataSource, getCollector, getPoint }} />
-            </FormProvider>
-          </div>
+          <Spin spinning={loading}>
+            <div className="array-table">
+              <FormProvider form={form}>
+                <SchemaField
+                  schema={schema}
+                  scope={{ useAsyncDataSource, getCollector, getPoint }}
+                />
+              </FormProvider>
+            </div>
+          </Spin>
         </>
       )}
       {visible && (

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

@@ -132,7 +132,6 @@ export default observer((props: Props) => {
             fieldNames={{ label: 'text', value: 'value' }}
             placeholder={'请选择'}
             onChange={(e, options: any) => {
-              console.log(options?.text);
               setValue(e);
               setLabelValue(options?.text);
               // DeviceModel.propertiesValue = options?.text

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

@@ -63,7 +63,7 @@ export default (props: Props) => {
   }, [props.properties]);
 
   useEffect(() => {
-    if (props.onChange && propertiesValue) {
+    if (props.onChange) {
       const obj = {
         [propertiesId || 0]: {
           value: propertiesValue,
@@ -127,7 +127,7 @@ export default (props: Props) => {
             }}
             onChange={(value, sources, text) => {
               // console.log(value, sources);
-              console.log(text);
+              // console.log(text);
               ref.current = text;
               setPropertiesValue(value);
               setSource(sources);

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

@@ -174,6 +174,7 @@ export default observer((props: Props) => {
               () => ({
                 validator(_, value) {
                   const isValue = Object.values(value)?.[0];
+                  // console.log('-------',isValue,value)
                   if (isValue) {
                     return Promise.resolve();
                   }
@@ -188,19 +189,16 @@ export default observer((props: Props) => {
               branchGroup={props.branchGroup}
               thenName={props.thenName}
               onColumns={(col, text) => {
-                // console.log('col',col,[col])
                 DeviceModel.columns = [col];
                 DeviceModel.actionName = text;
-                // console.log(text)
               }}
               onChange={(value, text, valueLable) => {
                 const item = value[Object.keys(value)?.[0]]?.value;
-                // console.log(`valueLable`,valueLable)
                 DeviceModel.propertiesName = text;
                 if (valueLable) {
                   DeviceModel.propertiesValue = valueLable;
                 } else {
-                  DeviceModel.propertiesValue = item;
+                  DeviceModel.propertiesValue = `${item}`;
                 }
               }}
               onRest={(value: any) => {

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

@@ -9,6 +9,7 @@ import './index.less';
 import DeviceModel from './model';
 import { onlyMessage } from '@/utils/util';
 import { ActionsDeviceProps } from '../../../typings';
+import { service as api } from '@/pages/device/Instance/index';
 
 export const service = new Service<any>('');
 
@@ -112,17 +113,14 @@ export default observer((props: Props) => {
     const _type = value.message.messageType;
     if (_type === 'INVOKE_FUNCTION') {
       _options.type = '执行';
-      // _options.properties = value.message.functionId;
       _options.properties = DeviceModel.propertiesName;
     }
     if (_type === 'READ_PROPERTY') {
       _options.type = '读取';
       _options.properties = DeviceModel.propertiesName;
-      // _options.name = DeviceModel.selectorValues[0].name;
     }
     if (_type === 'WRITE_PROPERTY') {
       _options.type = '设置';
-      // _options.properties = Object.keys(value.message.properties)?.[0];
       _options.properties = DeviceModel.propertiesName;
       _options.propertiesValue = DeviceModel.propertiesValue;
       _options.columns = DeviceModel.columns;
@@ -140,13 +138,13 @@ export default observer((props: Props) => {
       }));
       // console.log(_options.taglist, 'taglist')
     }
-    // console.log(DeviceModel.propertiesValue,_options);
+    console.log(DeviceModel.propertiesValue, _options);
     props.save(item, _options);
     init();
   };
 
   useEffect(() => {
-    console.log(props.value);
+    // console.log(props.value);
     if (props.value) {
       DeviceModel.selector = props.value.selector;
       DeviceModel.productId = props.value.productId;
@@ -158,6 +156,9 @@ export default observer((props: Props) => {
           ? props.value.selectorValues?.map((item: any) => item.value)[0]
           : 'deviceId';
     }
+    return () => {
+      init();
+    };
   }, [props.value]);
 
   return (
@@ -216,6 +217,13 @@ export default observer((props: Props) => {
                 ? (DeviceModel.current = 1)
                 : onlyMessage('请选择产品', 'error');
             } else if (value === 2) {
+              if (DeviceModel.deviceId) {
+                api.detail(DeviceModel.deviceId).then((res) => {
+                  if (res.status === 200) {
+                    DeviceModel.deviceDetail = res.result || {};
+                  }
+                });
+              }
               return DeviceModel.deviceId
                 ? (DeviceModel.current = 2)
                 : onlyMessage('请选择设备', 'error');

+ 1 - 1
src/pages/rule-engine/Scene/Save/action/DeviceOutput/model.ts

@@ -23,7 +23,7 @@ type ModelType = {
   relationName: string;
   message: any;
   propertiesName: string;
-  propertiesValue: string;
+  propertiesValue: string | any;
   columns: string[];
   actionName: string;
 };

+ 4 - 0
src/pages/rule-engine/Scene/Save/action/notify/index.tsx

@@ -63,6 +63,10 @@ export default observer((props: Props) => {
       ...props.value,
       options: { ...props.options },
     };
+    return () => {
+      NotifyModel.current = 0;
+      NotifyModel.notify = {};
+    };
   }, [props.value, props.options]);
 
   const renderComponent = (type: string) => {