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

feat(merge): merge sc

fix: 告警配置修改
Lind 3 лет назад
Родитель
Сommit
d30c35a8fb

+ 29 - 26
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -84,7 +84,6 @@ const Status = observer((props: Props) => {
   const [productTemp, setProductTemp] = useState<any[]>([]);
   const [deviceTemp, setDeviceTemp] = useState<any[]>([]);
   const [gatewayTemp, setGatewayTemp] = useState<any>({});
-  const [productItem, setProductItem] = useState<any>({});
 
   const getDetail = (id: string) => {
     service.detail(id).then((response) => {
@@ -162,7 +161,6 @@ const Status = observer((props: Props) => {
       } else {
         service.queryProductState(InstanceModel.detail?.productId || '').then((resp) => {
           if (resp.status === 200) {
-            setProductItem(resp.result);
             if (resp.result.accessId) {
               service.queryGatewayState(resp.result.accessId).then((response: any) => {
                 if (response.status === 200) {
@@ -596,6 +594,7 @@ const Status = observer((props: Props) => {
     });
 
   const handleSearch = () => {
+    DiagnoseStatusModel.model = true;
     props.onChange('loading');
     DiagnoseStatusModel.list = [...initlist];
     DiagnoseStatusModel.status = {
@@ -640,6 +639,8 @@ const Status = observer((props: Props) => {
           .then(() => {
             diagnoseDeviceAuthConfig().then(() => {
               diagnoseDeviceAccess(gateway).then(() => {
+                DiagnoseStatusModel.model = false;
+                DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
                 if (InstanceModel.detail.state?.value !== 'online') {
                   props.onChange('error');
                 } else {
@@ -669,35 +670,37 @@ const Status = observer((props: Props) => {
   }, [devicePermission]);
 
   useEffect(() => {
-    const data = { ...DiagnoseStatusModel.status };
-    const flag = Object.keys(data).every((item: any) => {
-      return data[item]?.status === 'success';
-    });
-    if (flag && InstanceModel.detail.state?.value !== 'online') {
-      // 展示诊断建议
-      if (
-        gatewayTemp.provider !== 'mqtt-server-gateway' &&
-        gatewayList.includes(gatewayTemp.provider)
-      ) {
-        service.queryProcotolDetail(gatewayTemp.provider, gatewayTemp.transport).then((resp1) => {
+    if (!DiagnoseStatusModel.model) {
+      const data = { ...DiagnoseStatusModel.status };
+      const flag = Object.keys(data).every((item: any) => {
+        return data[item]?.status === 'success';
+      });
+      if (flag && InstanceModel.detail.state?.value !== 'online') {
+        // 展示诊断建议
+        if (
+          gatewayTemp.provider !== 'mqtt-server-gateway' &&
+          gatewayList.includes(gatewayTemp.provider)
+        ) {
+          service.queryProcotolDetail(gatewayTemp.provider, gatewayTemp.transport).then((resp1) => {
+            setDiagnoseData({
+              product: productTemp,
+              device: deviceTemp,
+              id: InstanceModel.detail?.productId,
+              provider: gatewayTemp.provider,
+              routes: resp1.result?.routes || [],
+            });
+            setDiagnoseVisible(true);
+          });
+        } else {
           setDiagnoseData({
             product: productTemp,
             device: deviceTemp,
-            id: productItem.id,
-            provider: gatewayTemp.provider,
-            routes: resp1.result?.routes || [],
+            id: InstanceModel.detail?.productId,
+            provider: gatewayTemp?.provider,
+            routes: [],
           });
           setDiagnoseVisible(true);
-        });
-      } else {
-        setDiagnoseData({
-          product: productTemp,
-          device: deviceTemp,
-          id: productItem.i,
-          provider: gatewayTemp?.provider,
-          routes: [],
-        });
-        setDiagnoseVisible(true);
+        }
       }
     }
   }, [DiagnoseStatusModel.status]);

+ 2 - 0
src/pages/device/Instance/Detail/Diagnose/Status/model.ts

@@ -26,6 +26,7 @@ export const DiagnoseStatusModel = model<{
     other?: StatusProps;
   };
   list: ListProps[];
+  model: boolean;
 }>({
   status: {
     config: {
@@ -85,4 +86,5 @@ export const DiagnoseStatusModel = model<{
       desc: '诊断设备状态是否已启用,未启用的状态将导致连接失败',
     },
   ],
+  model: true,
 });

+ 6 - 4
src/pages/link/AccessConfig/Detail/Access/index.tsx

@@ -61,6 +61,7 @@ const Access = (props: Props) => {
   ProcotoleMapping.set('mqtt-client-gateway', 'MQTT');
   ProcotoleMapping.set('mqtt-server-gateway', 'MQTT');
   ProcotoleMapping.set('tcp-server-gateway', 'TCP');
+  ProcotoleMapping.set('child-device', 'Gateway');
 
   const queryNetworkList = (id: string, params?: any) => {
     service.getNetworkList(MetworkTypeMapping.get(id), params).then((resp) => {
@@ -412,8 +413,8 @@ const Access = (props: Props) => {
                 onClick={() => {
                   const url = getMenuPathByCode(MENUS_CODE[`link/Protocol`]);
                   const tab: any = window.open(`${origin}/#${url}?save=true`);
-                  tab!.onTabSaveSuccess = (value: any) => {
-                    if (value) {
+                  tab!.onTabSaveSuccess = (resp: any) => {
+                    if (resp.status === 200) {
                       queryProcotolList(props.provider?.id);
                     }
                   };
@@ -461,8 +462,9 @@ const Access = (props: Props) => {
                         onClick={() => {
                           const url = getMenuPathByCode(MENUS_CODE[`link/Protocol`]);
                           const tab: any = window.open(`${origin}/#${url}?save=true`);
-                          tab!.onTabSaveSuccess = (value: any) => {
-                            if (value) {
+                          tab!.onTabSaveSuccess = (resp: any) => {
+                            if (resp.status === 200) {
+                              console.log(props.provider);
                               queryProcotolList(props.provider?.id);
                             }
                           };

+ 4 - 0
src/pages/link/Protocol/save/index.tsx

@@ -214,6 +214,10 @@ const Save = (props: Props) => {
         await service.modifyState(value.id, 'deploy');
       }
       props.reload();
+      if ((window as any).onTabSaveSuccess) {
+        (window as any).onTabSaveSuccess(response);
+        setTimeout(() => window.close(), 300);
+      }
     }
   };
 

+ 17 - 15
src/pages/notice/Config/SyncUser/index.tsx

@@ -65,22 +65,24 @@ const SyncUser = observer(() => {
           </Button>
         </Tooltip>,
         <Tooltip title={'解绑用户'} key="unbind">
-          <Button type="link">
-            <Popconfirm
-              title={'确认解绑'}
-              onConfirm={async () => {
-                if (record?.bindingId) {
-                  const resp = await service.syncUser.unBindUser(record.bindingId);
-                  if (resp.status === 200) {
-                    message.success('操作成功!');
-                    actionRef.current?.reload();
+          {record?.userId && (
+            <Button type="link">
+              <Popconfirm
+                title={'确认解绑'}
+                onConfirm={async () => {
+                  if (record?.bindingId) {
+                    const resp = await service.syncUser.unBindUser(record.bindingId);
+                    if (resp.status === 200) {
+                      message.success('操作成功!');
+                      actionRef.current?.reload();
+                    }
                   }
-                }
-              }}
-            >
-              <DisconnectOutlined />
-            </Popconfirm>
-          </Button>
+                }}
+              >
+                <DisconnectOutlined />
+              </Popconfirm>
+            </Button>
+          )}
         </Tooltip>,
       ],
     },

+ 1 - 1
src/pages/rule-engine/Alarm/Configuration/Save/index.less

@@ -2,7 +2,7 @@
   :global {
     .ant-radio-button-wrapper {
       height: 100%;
-      margin-right: 15px;
+      margin: 10px 15px 0 0;
     }
   }
 }

+ 61 - 12
src/pages/rule-engine/Alarm/Configuration/index.tsx

@@ -1,11 +1,12 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import SearchComponent from '@/components/SearchComponent';
-import { ActionType, ProColumns } from '@jetlinks/pro-table';
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { PermissionButton } from '@/components';
 import {
   CloseCircleOutlined,
   DeleteOutlined,
   EditOutlined,
+  LikeOutlined,
   PlayCircleOutlined,
   PlusOutlined,
 } from '@ant-design/icons';
@@ -22,6 +23,7 @@ const service = new Service('alarm/config');
 const Configuration = () => {
   const intl = useIntl();
   const [visible, setVisible] = useState<boolean>(false);
+  const actionRef = useRef<ActionType>();
 
   const [current, setCurrent] = useState<any>();
   const columns: ProColumns<ConfigurationItem>[] = [
@@ -55,8 +57,30 @@ const Configuration = () => {
       valueType: 'option',
       align: 'center',
       render: (_, record) => [
+        record.sceneTriggerType === 'manual' && (
+          <PermissionButton
+            key="trigger"
+            isPermission={true}
+            popConfirm={{
+              title: '确认手动触发?',
+              onConfirm: async () => {
+                await service._execute(record.sceneId);
+                message.success(
+                  intl.formatMessage({
+                    id: 'pages.data.option.success',
+                    defaultMessage: '操作成功!',
+                  }),
+                );
+                actionRef.current?.reload();
+              },
+            }}
+          >
+            <LikeOutlined />
+          </PermissionButton>
+        ),
         <PermissionButton
           isPermission={true}
+          key="edit"
           style={{ padding: 0 }}
           tooltip={{
             title: intl.formatMessage({
@@ -74,6 +98,7 @@ const Configuration = () => {
         </PermissionButton>,
         <PermissionButton
           isPermission={true}
+          key="action"
           style={{ padding: 0 }}
           popConfirm={{
             title: intl.formatMessage({
@@ -83,10 +108,11 @@ const Configuration = () => {
               defaultMessage: `确认${record.state.value === 'disable' ? '禁用' : '启用'}?`,
             }),
             onConfirm: async () => {
-              // await service.update({
-              //   id: record.id,
-              //   status: record.status ? 0 : 1,
-              // });
+              if (record.state?.value === 'disable') {
+                await service._enable(record.id);
+              } else {
+                await service._disable(record.id);
+              }
               setVisible(true);
               setCurrent(record);
               message.success(
@@ -95,7 +121,7 @@ const Configuration = () => {
                   defaultMessage: '操作成功!',
                 }),
               );
-              // actionRef.current?.reload();
+              actionRef.current?.reload();
             },
           }}
           tooltip={{
@@ -111,6 +137,7 @@ const Configuration = () => {
         <PermissionButton
           type="link"
           isPermission={true}
+          key="delete"
           style={{ padding: 0 }}
           popConfirm={{
             title: '确认删除?',
@@ -129,8 +156,6 @@ const Configuration = () => {
     },
   ];
 
-  const actionRef = useRef<ActionType>();
-
   const [param, setParam] = useState({});
 
   return (
@@ -154,6 +179,28 @@ const Configuration = () => {
           <AlarmConfig
             {...record}
             actions={[
+              record.sceneTriggerType === 'manual' && (
+                <PermissionButton
+                  key="trigger"
+                  isPermission={true}
+                  popConfirm={{
+                    title: '确认手动触发?',
+                    onConfirm: async () => {
+                      await service._execute(record.sceneId);
+                      message.success(
+                        intl.formatMessage({
+                          id: 'pages.data.option.success',
+                          defaultMessage: '操作成功!',
+                        }),
+                      );
+                      actionRef.current?.reload();
+                    },
+                  }}
+                >
+                  <LikeOutlined />
+                  手动触发
+                </PermissionButton>
+              ),
               <PermissionButton
                 isPermission={true}
                 key="edit"
@@ -176,10 +223,11 @@ const Configuration = () => {
                     defaultMessage: `确认${record.state.value === 'disable' ? '禁用' : '启用'}?`,
                   }),
                   onConfirm: async () => {
-                    // await service.update({
-                    //   id: record.id,
-                    //   status: record.status ? 0 : 1,
-                    // });
+                    if (record.state?.value === 'disable') {
+                      await service._enable(record.id);
+                    } else {
+                      await service._disable(record.id);
+                    }
                     setVisible(true);
                     setCurrent(record);
                     message.success(
@@ -199,6 +247,7 @@ const Configuration = () => {
                     defaultMessage: record.state.value === 'disable' ? '禁用' : '启用',
                   }),
                 }}
+                key="action"
                 type="link"
               >
                 {record.state.value === 'disable' ? (

+ 14 - 0
src/pages/rule-engine/Alarm/Configuration/service.ts

@@ -22,6 +22,20 @@ class Service extends BaseService<ConfigItem> {
         value: item.id,
       }));
     });
+
+  public _enable = (id: string) =>
+    request(`/${SystemConst.API_BASE}/alarm/config/${id}/_enable`, {
+      method: 'POST',
+    });
+
+  public _disable = (id: string) =>
+    request(`/${SystemConst.API_BASE}/alarm/config/${id}/_disable`, {
+      method: 'POST',
+    });
+  public _execute = (id: string) =>
+    request(`/${SystemConst.API_BASE}/scene/${id}/_execute`, {
+      method: 'POST',
+    });
 }
 
 export default Service;

+ 1 - 0
src/pages/rule-engine/Alarm/Configuration/typings.d.ts

@@ -7,4 +7,5 @@ type ConfigurationItem = {
   state: { text: string; value: string };
   description: string;
   id: string;
+  sceneTriggerType: string;
 };