xujunjie пре 1 година
родитељ
комит
b50ca57627
2 измењених фајлова са 55 додато и 19 уклоњено
  1. 49 18
      src/pages/Controller/Device.js
  2. 6 1
      src/services/controller.js

+ 49 - 18
src/pages/Controller/Device.js

@@ -1,40 +1,71 @@
 import PageContent from '@/components/PageContent';
 import PageTitle from '@/components/PageTitle';
-import { queryDevice } from '@/services/controller';
+import { queryDevice, queryScanDuration } from '@/services/controller';
 import { UnityAction } from '@/utils/utils';
 import { useParams, useRequest } from '@umijs/max';
-import { Spin } from 'antd';
+import { useCallback, useEffect } from 'react';
 import styles from './index.less';
 
+let timer;
 function Hardware() {
   const { projectId } = useParams();
 
-  const { data, loading } = useRequest(queryDevice, {
+  const { data, run, loading } = useRequest(queryDevice, {
+    manual: true,
+    onSuccess(data) {
+      UnityAction.sendMsg('devLocate', JSON.stringify(data.list));
+    },
+  });
+
+  const { data: draw } = useRequest(queryScanDuration, {
     defaultParams: [projectId],
+    formatResult(res) {
+      return res.data.draw;
+    },
+  });
+
+  const getDeviceIconClassName = useCallback((status) => {
+    let statusClassName = '';
+    if (status == 2) {
+      statusClassName = styles.error;
+    } else if (status == 3) {
+      statusClassName = styles.offline;
+    }
+
+    return `${styles.icon} ${statusClassName}`;
   });
 
+  useEffect(() => {
+    if (!draw) return;
+    run(projectId);
+    timer = setInterval(() => {
+      run(projectId);
+    }, draw);
+    return () => clearInterval(timer);
+  }, [draw]);
+
   return (
     <PageContent closeable={false}>
       <PageTitle onReturn={() => UnityAction.sendMsg('menuItem', '智能管控')}>
         设备定位
       </PageTitle>
 
-      <Spin spinning={loading}>
-        {data?.list?.map((item) => (
-          <div
-            key={item.id}
-            className={`card-box ${styles.item}`}
-            style={{ justifyContent: 'space-between' }}
-          >
-            <div>
-              <i className={`${styles.icon} `}></i>
-              {item.name}
-            </div>
-
-            <div onClick={() => UnityAction.sendMsg('devLocate', item.code)}>定位</div>
+      {/* <Spin spinning={loading}> */}
+      {data?.list?.map((item) => (
+        <div
+          key={item.id}
+          className={`card-box ${styles.item}`}
+          style={{ justifyContent: 'space-between' }}
+        >
+          <div>
+            <i
+              className={getDeviceIconClassName(item.mobile_device_status)}
+            ></i>
+            {item.mobile_device_name}
           </div>
-        ))}
-      </Spin>
+        </div>
+      ))}
+      {/* </Spin> */}
     </PageContent>
   );
 }

+ 6 - 1
src/services/controller.js

@@ -11,7 +11,12 @@ export async function queryLightList(project_id) {
   });
 }
 export async function queryDevice(project_id) {
-  return request(`/api/iot/v1/lbs/mobile_device/list`, {
+  return request(`/api/iot/v1/lbs/mobile_device/location`, {
+    params: { project_id },
+  });
+}
+export async function queryScanDuration(project_id) {
+  return request(`/api/iot/v1/lbs/scan/duration`, {
     params: { project_id },
   });
 }