فهرست منبع

chore(api): 适配“获取设备实时数据”接口

ccnnde 2 ماه پیش
والد
کامیت
1f22aba2a5
2فایلهای تغییر یافته به همراه36 افزوده شده و 1 حذف شده
  1. 5 1
      src/services/iot.ts
  2. 31 0
      src/views/Preview.vue

+ 5 - 1
src/services/iot.ts

@@ -7,8 +7,12 @@ export async function getDevices(){
     productId: '',
   };
   const ret: { records: any[]; total: number; type:number } = await axios.post(
-    '/api/iot/devices'
+    '/api/iot/devices',
     // '/api/iot/device/list'
+    {
+      pageIndex: 1,
+      pageSize: 1000
+    }
   );
   return ret;
 }

+ 31 - 0
src/views/Preview.vue

@@ -128,6 +128,7 @@ const open = async () => {
       if(!ret.data.width){ret.data.width= 1920};
       if(!ret.data.height){ret.data.height= 1080};
       meta2d.open(ret.data);
+      getRealTimeData()
     }
   } else {
     let data: any = await localforage.getItem(localStorageName);
@@ -149,6 +150,36 @@ const open = async () => {
   }
 };
 
+const getRealTimeData = () => {
+  meta2d.store.data.https = [
+    {
+      http: `${import.meta.env.VITE_BASE_API}/api-dashboard/api/iot/getRTDData`,
+      method: 'POST',
+      httpTimeInterval: 1000,
+      httpHeaders: {
+        'Content-Type': 'application/json',
+        Authorization: 'Bearer ' + import.meta.env.VITE_TEMP_TOKEN
+      },
+      body: {
+        dataPoint: meta2d.store.data.dataPoints
+      } as unknown as BodyInit
+    }
+  ]
+
+  meta2d.socketFn = (e) => {
+    const { data, code, msg } = JSON.parse(e)
+
+    if (code !== 0) {
+      console.error(msg)
+      return {}
+    }
+
+    return data
+  }
+
+  meta2d.connectHttp()
+}
+
 const opened = () => {
   meta2d.store.options.shadowColor = '#0000'
   meta2d.canvas.parentElement.style.background = meta2d.store.data.background|| meta2d.store.theme[meta2d.store.data.theme].background;