Explorar o código

解决接口请求失败的问题

hongrunxia hai 10 meses
pai
achega
307cf3e8e5
Modificáronse 3 ficheiros con 49 adicións e 34 borrados
  1. 21 15
      api/api.js
  2. 1 1
      manifest.json
  3. 27 18
      pages/home/detail/autodoor/autodoor.vue

+ 21 - 15
api/api.js

@@ -1,5 +1,6 @@
 import { http } from "@/common/service/service.js";
 import configService from "@/common/service/config.service.js";
+import  buildURL from "@/common/luch-request/helpers/buildURL.js"
 const apiService = {
   /**
    * 登录
@@ -37,8 +38,9 @@ const apiService = {
   },
   //查询分页列表信息 通过分类查询 各类设备在app上是否展示的字段
   getShowColumList(params) {
-    const urlParams = new URLSearchParams(params);
-    const url = "/safety/ventanalyShowColum/list?" + urlParams.toString();
+    // const urlParams = new URLSearchParams(params);
+    // const url = "/safety/ventanalyShowColum/list?" + urlParams.toString();
+	const url = buildURL("/safety/ventanalyShowColum/list", params)
     return http.get(url);
   },
   //设备控制
@@ -50,31 +52,35 @@ const apiService = {
   },
   //根据设备id 查询该设备关联的视频流url
   getCameraById(params) {
-    const urlParams = new URLSearchParams(params);
-    const url = "/safety/ventanalyCamera/list?" + urlParams.toString();
+    // const urlParams = new URLSearchParams(params);
+    // const url = "/safety/ventanalyCamera/list?" + urlParams.toString();
+	const url = buildURL("/safety/ventanalyCamera/list", params)
     return http.get(url);
   },
   //如果上面这个接口返回code码  则使用这个接口获取url
   getCameraByCode(params) {
-    const urlParams = new URLSearchParams(params);
-    const url =
-      "/ventanaly-device/camera/queryByCameraCode?" + urlParams.toString();
+    // const urlParams = new URLSearchParams(params);
+    // const url =
+    //   "/ventanaly-device/camera/queryByCameraCode?" + urlParams.toString();
+	const url = buildURL("/ventanaly-device/camera/queryByCameraCode", params)
     return http.get(url);
   },
   //获取设备历史数据
   getDeviceHistory(params) {
-    const urlParams = new URLSearchParams(params);
-    const url =
-      "/ventanaly-device/safety/ventanalyMonitorData/listdays?" +
-      urlParams.toString();
+    // const urlParams = new URLSearchParams(params);
+    // const url =
+    //   "/ventanaly-device/safety/ventanalyMonitorData/listdays?" +
+    //   urlParams.toString();
+	const url = buildURL("/ventanaly-device/safety/ventanalyMonitorData/listdays", params)
     return http.get(url);
   },
   //获取操作历史
   getOpreateHistory(params) {
-    const urlParams = new URLSearchParams(params);
-    const url =
-      "/ventanaly-device/safety/ventanalyDevicesetLog/list?" +
-      urlParams.toString();
+    // const urlParams = new URLSearchParams(params);
+    // const url =
+    //   "/ventanaly-device/safety/ventanalyDevicesetLog/list?" +
+    //   urlParams.toString();
+	const url = buildURL("/ventanaly-device/safety/ventanalyDevicesetLog/list", params)
     return http.get(url);
   },
   /**

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
     "name" : "智能通风",
-    "appid" : "__UNI__8193760",
+    "appid" : "__UNI__2000523",
     "description" : "",
     "versionName" : "2.2.22",
     "versionCode" : 1,

+ 27 - 18
pages/home/detail/autodoor/autodoor.vue

@@ -241,6 +241,7 @@ import fanlocalAnimate from "../fanlocalAnimate/fanlocalAnimate2.vue";
 export default {
   data() {
     return {
+	  timer: undefined,
       tableData: [], //监测数据
       typeList: [], //展示字段
       itemId: "", // 初始化 itemId
@@ -283,24 +284,29 @@ export default {
     this.ndoorcount = 2;
   },
   components: { doorAnimate, windowAnimate,windrectAnimate,fanlocalAnimate },
-  created() {
-	this.getShowList(this.TabCur);
-    this.getDeviceInfo(this.itemId);
-    this.getVideoUrlById(this.itemId);
+  async created() {
+	await this.getShowList(this.TabCur);
+    await this.getDeviceInfo(this.itemId);
+    await this.getVideoUrlById(this.itemId);
   },
   mounted() {
-    this.startTimer();
+    this.startTimer(false);
   },
   methods: {
-    startTimer() {
-      this.timer = setInterval(() => {
+    startTimer(flag = true) {
+      this.timer = setTimeout(async() => {
         // 执行定时任务
-        this.getDeviceInfo(this.itemId);
-      }, 5000);
+		await this.getShowList(this.TabCur);
+        await this.getDeviceInfo(this.itemId);
+		if(this.timer){
+			this.startTimer()
+		}
+      }, !flag ? 0 : 2000);
     },
     stopTimer() {
       // 停止定时器
-      clearInterval(this.timer);
+      clearTimeout(this.timer);
+	  this.timer = undefined
     },
     // 返回上一个页面
     backPage() {
@@ -317,7 +323,7 @@ export default {
         pageNo: 1,
         pageSize: 100,
       };
-      new Promise((resolve, reject) => {
+      return new Promise((resolve, reject) => {
         api
           .getShowColumList(params)
           .then((response) => {
@@ -336,7 +342,7 @@ export default {
     //获取详情数据
     getDeviceInfo(ID) {
       let IDString = String(ID); // 将 ID 转换为字符串
-      new Promise((resolve, reject) => {
+      return new Promise((resolve, reject) => {
         api
           .getDeviceMonitor({ devicetype: this.TabCur, ids: IDString })
           .then((response) => {
@@ -344,6 +350,7 @@ export default {
 				var result = response.data.result.msgTxt[0].datalist[0];
               this.tableData =
                 result.readData;
+				console.log('监测数据------------>', result)
               if (this.tableData.frontGateOpen == "1") {
                 this.tableData.frontGateOpen = "打开";
               } else {
@@ -377,6 +384,7 @@ export default {
               this.windowAngle1 =
                 (this.tableData.rearArea / maxarea) * 100 * 0.9;
 			  this.$forceUpdate()
+			  resolve(null)
             } else {
               resolve(response);
             }
@@ -389,7 +397,7 @@ export default {
     //获取监控URL 通过ID获取
     getVideoUrlById(ID) {
       let IDString = String(ID); // 将 ID 转换为字符串
-      new Promise((resolve, reject) => {
+      return new Promise((resolve, reject) => {
         api
           .getCameraById({ deviceid: IDString })
           .then((response) => {
@@ -454,7 +462,7 @@ export default {
 };
 </script>
 
-<style>
+<style lang="scss">
 passwordPopup {
   height: 300rpx;
   background-color: #fff;
@@ -502,13 +510,14 @@ passwordPopup {
   border: 1rpx solid #000000;
   border-radius: 20rpx;
 }
-.flex-containe {
+.flex-container {
   display: flex;
   flex-direction: row;
   flex-wrap: wrap;
 }
 .itemback {
-  flex: 0 0 calc(33.33% - 10px); /* 使用calc函数计算每个项目的宽度,减去间距 */
+  width: calc(48% - 5px);
+  // flex: 0 0 calc(33.33% - 10px); /* 使用calc函数计算每个项目的宽度,减去间距 */
   margin: 5px; /* 间距设置为5px */
 }
 .datacardtime {
@@ -528,10 +537,10 @@ passwordPopup {
 }
 .datacard {
   display: flex;
-  width: 48%;
+  /* width: 48%; */
   flex: 1;
   margin: 1%;
-  float: left;
+  /* float: left; */
   height: 100rpx;
   text-align: center;
   background: linear-gradient(