Ver código fonte

feat: 上报页面新增用户 暂定 结束 开始

jinx 2 dias atrás
pai
commit
77a624f980
3 arquivos alterados com 223 adições e 88 exclusões
  1. 24 2
      src/api.js
  2. 141 28
      src/views/Report/index.vue
  3. 58 58
      src/views/Report/tagCoordinateList.json

+ 24 - 2
src/api.js

@@ -38,9 +38,9 @@ export function resetWholeData(sceneCode) {
   });
 }
 export function reportTagInfo(data) {
-      console.error("reporting", data);
+  console.error("reporting", data);
 
-  const url = `https://test.4dkankan.com/openDevice/ingest/${data.sceneNum}`;
+  const url = `https://test.4dkankan.com/openDevice/ingest/${data.num}`;
 
   return axios.post(url, data).then((res) => {
     if (res?.data?.code === 200 || res?.status === 200) {
@@ -50,3 +50,25 @@ export function reportTagInfo(data) {
     }
   });
 }
+export function startReport(data) {
+  const url = `https://test.4dkankan.com/openDevice/start`;
+
+  return axios.post(url, data).then((res) => {
+    if (res?.data?.code === 200 || res?.status === 200) {
+      return res?.data?.msg || "start report success";
+    } else {
+      throw res?.data?.msg || "start report failed";
+    }
+  });
+}
+export function stopReport(data) {
+  const url = `https://test.4dkankan.com/openDevice/end`;
+
+  return axios.post(url, data).then((res) => {
+    if (res?.data?.code === 200 || res?.status === 200) {
+      return res?.data?.msg || "stop report success";
+    } else {
+      throw res?.data?.msg || "stop report failed";
+    }
+  });
+}

+ 141 - 28
src/views/Report/index.vue

@@ -1,8 +1,23 @@
 <template>
   <div class="report-page">
     <h2 class="title">Report</h2>
-    <div style="width: 200px; margin: 10px 0">
-      <el-input v-model="sceneNum" placeholder="请输入场景码"></el-input>
+    <div style="width: 100%; margin: 10px 0">
+      <div style="display: flex">
+        <span>场景码:</span>
+        <el-input
+          style="width: 200px"
+          v-model="num"
+          placeholder="请输入场景码"
+        ></el-input>
+      </div>
+      <div style="display: flex; margin-top: 10px">
+        <span>用户:</span>
+        <el-input
+          style="width: 200px"
+          v-model="userId"
+          placeholder="请输入用户ID"
+        ></el-input>
+      </div>
     </div>
     <div class="category-tabs">
       <el-button
@@ -37,9 +52,20 @@
 
       <el-button
         class="report-btn stop-btn"
+        type="warning"
+        plain
+        :disabled="reportStatus === 'idle'"
+        @click="onPauseReport()"
+      >
+        <span class="btn-content">
+          <span class="btn-name">{{ reportStatus === "paused" ? "继续" : "暂停" }}</span>
+        </span>
+      </el-button>
+      <el-button
+        class="report-btn stop-btn"
         type="danger"
         plain
-        :disabled="!activeReportItem"
+        :disabled="reportStatus === 'idle'"
         @click="onStopReport()"
       >
         <span class="btn-content">
@@ -52,9 +78,12 @@
       </div> -->
     </div>
 
-    <p v-if="activeReportItem" class="status-text">
-      Reporting: {{ activeReportItem.name }} #{{ activeReportItem.id }} (every
-      1s)
+    <p v-if="reportStatus !== 'idle' && activeReportItem" class="status-text">
+      {{ reportStatus === "paused" ? "Paused" : "Reporting" }}:
+      {{ activeReportItem.name }} #{{ activeReportItem.id }} (every 1s)
+    </p>
+    <p v-else-if="reportStatus !== 'idle'" class="status-text">
+      {{ reportStatus === "paused" ? "Paused" : "Reporting" }}: 未选择点位
     </p>
 
     <div v-if="lastReportedItem" class="report-result">
@@ -66,7 +95,7 @@
 
 <script>
 import { ElMessage } from "element-plus";
-import { reportTagInfo } from "@/api.js";
+import { reportTagInfo, startReport, stopReport } from "@/api.js";
 import tagCoordinateList from "./tagCoordinateList.json";
 import reportInfoStream from "./reportInfoStream.js";
 
@@ -84,7 +113,9 @@ export default {
       servicesData: null,
       floors: [],
       activeFloor: "",
-      sceneNum: "SG-t-rQ14yS9VjVp",
+      num: "SG-t-rQ14yS9VjVp",
+      userId: null,
+      reportStatus: "idle", // idle | running | paused
     };
   },
   computed: {
@@ -103,6 +134,10 @@ export default {
     this.unsubErr && this.unsubErr();
   },
   mounted() {
+    if (this.$route.query.userId) {
+      this.userId = this.$route.query.userId;
+    }
+    console.error(this.$route.query);
     const floorList = Array.from(
       new Set(this.tagList.map((item) => item.floor).filter(Boolean)),
     );
@@ -154,6 +189,13 @@ export default {
         this.reportTimer = null;
       }
     },
+    buildReportPayload(item) {
+      return {
+        ...item,
+        num: this.num,
+        userId: this.userId,
+      };
+    },
     sendReportOnce() {
       if (!this.activeReportItem || this.isRequesting) {
         return;
@@ -162,10 +204,11 @@ export default {
       const item = this.activeReportItem;
       this.reportingId = item.id;
       this.isRequesting = true;
-      item.sceneNum = this.sceneNum;
-      reportTagInfo(item)
+      const payload = this.buildReportPayload(item);
+
+      reportTagInfo(payload)
         .then(() => {
-          this.lastReportedItem = item;
+          this.lastReportedItem = payload;
         })
         .catch((err) => {
           ElMessage({
@@ -178,33 +221,103 @@ export default {
           this.reportingId = null;
         });
     },
-    onReport(item) {
-      const switched =
-        !this.activeReportItem || this.activeReportItem.id !== item.id;
-      this.activeReportItem = item;
-
+    startPolling({ immediate = false } = {}) {
       this.clearReportTimer();
-      this.sendReportOnce();
+      if (immediate) {
+        this.sendReportOnce();
+      }
       this.reportTimer = setInterval(() => {
         this.sendReportOnce();
       }, 1000);
+    },
+    async onReport(item) {
+      if (!this.userId) {
+        ElMessage({
+          message: "请输入用户id",
+          type: "warning",
+        });
+        return;
+      }
+      if (!this.num) {
+        ElMessage({
+          message: "请输入场景码",
+          type: "warning",
+        });
+        return;
+      }
+      this.activeReportItem = item;
+
+      // First click: start session + polling
+      if (this.reportStatus === "idle") {
+        try {
+          await startReport({
+            num: this.num,
+            userId: this.userId,
+          });
+          this.reportStatus = "running";
+          this.startPolling({ immediate: true });
+        } catch (err) {
+          ElMessage({
+            message: err?.message || err || "startReport failed",
+            type: "error",
+          });
+        }
+        return;
+      }
 
-      if (switched) {
-        // ElMessage({
-        //   message: `start reporting ${item.name} #${item.id}`,
-        //   type: 'success',
-        // })
+      // paused: click any point button to resume polling
+      if (this.reportStatus === "paused") {
+        this.reportStatus = "running";
+        this.startPolling({ immediate: true });
+        return;
       }
+
+      // running: switch item and keep polling
+      this.startPolling({ immediate: true });
+
+      // (switched toast intentionally omitted)
     },
-    onStopReport() {
+    onPauseReport() {
+      if (this.reportStatus === "idle") {
+        return;
+      }
+
+      if (this.reportStatus === "running") {
+        this.clearReportTimer();
+        this.reportStatus = "paused";
+        ElMessage({ message: "report paused", type: "info" });
+        return;
+      }
+
+      // paused -> running
+      this.reportStatus = "running";
+      this.startPolling({ immediate: true });
+      ElMessage({ message: "report resumed", type: "success" });
+    },
+    async onStopReport() {
+      if (this.reportStatus === "idle") {
+        return;
+      }
+
       this.clearReportTimer();
-      this.activeReportItem = null;
       this.reportingId = null;
       this.isRequesting = false;
-      ElMessage({
-        message: "report stopped",
-        type: "info",
-      });
+
+      try {
+        await stopReport({
+          num: this.num,
+          userId: this.userId,
+        });
+      } catch (err) {
+        ElMessage({
+          message: err?.message || err || "stopReport failed",
+          type: "error",
+        });
+      } finally {
+        this.reportStatus = "idle";
+        this.activeReportItem = null;
+        ElMessage({ message: "report stopped", type: "info" });
+      }
     },
   },
 };

+ 58 - 58
src/views/Report/tagCoordinateList.json

@@ -8,7 +8,7 @@
     "pos": {
       "x": 12.762330136903149,
       "y": 0.020076632139445244,
-      "z": -0.7266
+      "z": -2.7266
     }
   },
   {
@@ -20,7 +20,7 @@
     "pos": {
       "x": 10.629505770574077,
       "y": 6.802374869195827,
-      "z": -0.9888
+      "z": -2.9888
     }
   },
   {
@@ -32,7 +32,7 @@
     "pos": {
       "x": 6.42187596861534,
       "y": -4.177731905625157,
-      "z": -0.5812
+      "z": -2.5812
     }
   },
   {
@@ -44,7 +44,7 @@
     "pos": {
       "x": 6.352335283580645,
       "y": -0.08353091640323823,
-      "z": -0.5825
+      "z": -2.5825
     }
   },
   {
@@ -56,7 +56,7 @@
     "pos": {
       "x": 4.282527668517008,
       "y": 3.404146254747082,
-      "z": -0.8355
+      "z": -2.8355
     }
   },
   {
@@ -68,7 +68,7 @@
     "pos": {
       "x": 0.2757547342686526,
       "y": 1.5837282156495454,
-      "z": -0.6465
+      "z": -2.6465
     }
   },
   {
@@ -80,7 +80,7 @@
     "pos": {
       "x": -5.646683760456344,
       "y": 0.739674958263142,
-      "z": -0.6422
+      "z": -2.6422
     }
   },
   {
@@ -92,7 +92,7 @@
     "pos": {
       "x": -5.523911624508015,
       "y": -6.408123506414033,
-      "z": -0.5935
+      "z": -2.5935
     }
   },
   {
@@ -104,7 +104,7 @@
     "pos": {
       "x": -11.634290449812912,
       "y": 2.01906157920439,
-      "z": -0.6628
+      "z": -2.6628
     }
   },
   {
@@ -116,7 +116,7 @@
     "pos": {
       "x": -11.488327430210164,
       "y": -4.578667764056485,
-      "z": -0.5859
+      "z": -2.5859
     }
   },
   {
@@ -128,7 +128,7 @@
     "pos": {
       "x": -17.645647049094368,
       "y": 1.88337619954559,
-      "z": -0.6721
+      "z": -2.6721
     }
   },
   {
@@ -140,7 +140,7 @@
     "pos": {
       "x": -17.520563972506743,
       "y": -5.110514553104488,
-      "z": -0.6087
+      "z": -2.6087
     }
   },
   {
@@ -152,7 +152,7 @@
     "pos": {
       "x": -23.675095035698355,
       "y": 3.2207891201789303,
-      "z": -0.7256
+      "z": -2.7256
     }
   },
   {
@@ -164,7 +164,7 @@
     "pos": {
       "x": 12.523649888926261,
       "y": 3.6814196024856747,
-      "z": -0.7106
+      "z": -1.7106
     }
   },
   {
@@ -176,7 +176,7 @@
     "pos": {
       "x": 16.500870804578806,
       "y": 4.0647172298303165,
-      "z": -1.2296
+      "z": -2.7296
     }
   },
   {
@@ -188,7 +188,7 @@
     "pos": {
       "x": 16.553070725002893,
       "y": 2.725159381788062,
-      "z": -2.5375
+      "z": -4.0375
     }
   },
   {
@@ -200,7 +200,7 @@
     "pos": {
       "x": 13.643899228571161,
       "y": 2.800065521446407,
-      "z": -3.7038
+      "z": -5.2038
     }
   },
   {
@@ -212,7 +212,7 @@
     "pos": {
       "x": 12.055875912036592,
       "y": 5.844237072956483,
-      "z": -5.6591
+      "z": -6.1591
     }
   },
   {
@@ -224,7 +224,7 @@
     "pos": {
       "x": 8.454271098571557,
       "y": 3.0290766514024177,
-      "z": -5.2572
+      "z": -5.7572
     }
   },
   {
@@ -236,7 +236,7 @@
     "pos": {
       "x": 2.399155958144253,
       "y": 2.3886710679018788,
-      "z": -4.6943
+      "z": -6.6943
     }
   },
   {
@@ -248,7 +248,7 @@
     "pos": {
       "x": 4.445661164025403,
       "y": -1.5959441750220134,
-      "z": -5.2577
+      "z": -7.2577
     }
   },
   {
@@ -260,7 +260,7 @@
     "pos": {
       "x": 6.316903493034541,
       "y": -5.727910321345538,
-      "z": -4.8311
+      "z": -6.8311
     }
   },
   {
@@ -272,7 +272,7 @@
     "pos": {
       "x": 0.402346953883731,
       "y": -6.252086556440688,
-      "z": -5.3246
+      "z": -5.8246
     }
   },
   {
@@ -284,7 +284,7 @@
     "pos": {
       "x": -4.05543024914224,
       "y": -5.572942776686306,
-      "z": -4.7656
+      "z": -6.7656
     }
   },
   {
@@ -296,7 +296,7 @@
     "pos": {
       "x": -4.313593884421408,
       "y": 1.6103321981914094,
-      "z": -4.7252
+      "z": -6.7252
     }
   },
   {
@@ -308,7 +308,7 @@
     "pos": {
       "x": -11.584317211995293,
       "y": 5.898932534353025,
-      "z": -5.0799
+      "z": -6.5799
     }
   },
   {
@@ -320,7 +320,7 @@
     "pos": {
       "x": -10.471849529251259,
       "y": 1.4610891923073237,
-      "z": -4.9244
+      "z": -6.9244
     }
   },
   {
@@ -332,7 +332,7 @@
     "pos": {
       "x": -14.912348300776669,
       "y": 1.8849501109095952,
-      "z": -4.8831
+      "z": -6.8831
     }
   },
   {
@@ -344,7 +344,7 @@
     "pos": {
       "x": -20.02896182421652,
       "y": 4.12693153782853,
-      "z": -5.0237
+      "z": -6.5237
     }
   },
   {
@@ -356,7 +356,7 @@
     "pos": {
       "x": -19.942047127209047,
       "y": -0.10706897136764215,
-      "z": -5.5467
+      "z": -7.0467
     }
   },
   {
@@ -368,7 +368,7 @@
     "pos": {
       "x": -16.356942176392025,
       "y": -3.8548943321622353,
-      "z": -5.2182
+      "z": -6.2182
     }
   },
   {
@@ -380,7 +380,7 @@
     "pos": {
       "x": -11.685545338397079,
       "y": -2.069712329172339,
-      "z": -5.1611
+      "z": -6.1611
     }
   },
   {
@@ -392,7 +392,7 @@
     "pos": {
       "x": -10.36163766073829,
       "y": -5.545165917266754,
-      "z": -4.98
+      "z": -6.98
     }
   },
   {
@@ -404,7 +404,7 @@
     "pos": {
       "x": -5.706760891708474,
       "y": -6.325240148145387,
-      "z": -5.5375
+      "z": -6.5375
     }
   },
   {
@@ -416,7 +416,7 @@
     "pos": {
       "x": 16.027600141895782,
       "y": 2.7320479614605016,
-      "z": 0.8624
+      "z": -0.6376
     }
   },
   {
@@ -428,7 +428,7 @@
     "pos": {
       "x": 16.2517550213854,
       "y": 4.093109610639161,
-      "z": 2.7665
+      "z": 1.2665000000000002
     }
   },
   {
@@ -440,7 +440,7 @@
     "pos": {
       "x": 16.270360807444206,
       "y": 4.097679886277495,
-      "z": 6.5167
+      "z": 5.0167
     }
   },
   {
@@ -452,7 +452,7 @@
     "pos": {
       "x": 16.009587209712333,
       "y": 2.7727206394972908,
-      "z": 4.7122
+      "z": 3.2122
     }
   },
   {
@@ -464,7 +464,7 @@
     "pos": {
       "x": 15.870916175650951,
       "y": 2.8196739822984624,
-      "z": 8.3978
+      "z": 6.8978
     }
   },
   {
@@ -476,7 +476,7 @@
     "pos": {
       "x": 16.19654687455847,
       "y": 4.166414938755257,
-      "z": 10.3245
+      "z": 8.8245
     }
   },
   {
@@ -488,7 +488,7 @@
     "pos": {
       "x": 9.188735346792575,
       "y": 1.6072084398041069,
-      "z": 10.0813
+      "z": 8.0813
     }
   },
   {
@@ -500,7 +500,7 @@
     "pos": {
       "x": 6.325451357843287,
       "y": 0.16848416334835933,
-      "z": 10.6554
+      "z": 8.6554
     }
   },
   {
@@ -512,7 +512,7 @@
     "pos": {
       "x": 0.3280485331331535,
       "y": -0.5709536197903704,
-      "z": 10.7468
+      "z": 8.7468
     }
   },
   {
@@ -524,7 +524,7 @@
     "pos": {
       "x": -5.661980678427771,
       "y": -0.7260584863276928,
-      "z": 10.6792
+      "z": 8.6792
     }
   },
   {
@@ -536,7 +536,7 @@
     "pos": {
       "x": -11.655284211422043,
       "y": -0.5721011231917611,
-      "z": 10.7152
+      "z": 8.7152
     }
   },
   {
@@ -548,7 +548,7 @@
     "pos": {
       "x": -17.629952099456457,
       "y": -0.9918684137582539,
-      "z": 10.714
+      "z": 8.714
     }
   },
   {
@@ -560,7 +560,7 @@
     "pos": {
       "x": -23.389054192461728,
       "y": -2.3096036276880314,
-      "z": 10.0036
+      "z": 9.0036
     }
   },
   {
@@ -572,7 +572,7 @@
     "pos": {
       "x": -11.581752226657345,
       "y": -3.2691985408198967,
-      "z": 10.7532
+      "z": 8.7532
     }
   },
   {
@@ -584,7 +584,7 @@
     "pos": {
       "x": -12.935643448747442,
       "y": -10.005416142913178,
-      "z": 10.2906
+      "z": 8.2906
     }
   },
   {
@@ -596,7 +596,7 @@
     "pos": {
       "x": -5.599435637462419,
       "y": -3.2324307997358033,
-      "z": 10.6931
+      "z": 8.6931
     }
   },
   {
@@ -608,7 +608,7 @@
     "pos": {
       "x": -6.104624243715159,
       "y": -5.879173346471542,
-      "z": 10.4785
+      "z": 8.4785
     }
   },
   {
@@ -620,7 +620,7 @@
     "pos": {
       "x": 0.3893905753896256,
       "y": -3.0445008873391894,
-      "z": 10.7815
+      "z": 8.7815
     }
   },
   {
@@ -632,7 +632,7 @@
     "pos": {
       "x": -0.8968289175102542,
       "y": -5.779834604051655,
-      "z": 10.4932
+      "z": 8.4932
     }
   },
   {
@@ -644,7 +644,7 @@
     "pos": {
       "x": 2.3870513990494393,
       "y": -9.639885680010366,
-      "z": 10.8763
+      "z": 8.8763
     }
   },
   {
@@ -656,7 +656,7 @@
     "pos": {
       "x": 5.321677088930896,
       "y": -6.420066974872126,
-      "z": 10.6196
+      "z": 8.6196
     }
   },
   {
@@ -668,7 +668,7 @@
     "pos": {
       "x": 2.6536347353798813,
       "y": -1.7673779816210742,
-      "z": 10.1908
+      "z": 9.1908
     }
   },
   {
@@ -680,7 +680,7 @@
     "pos": {
       "x": -8.934738270159002,
       "y": -9.889385843043714,
-      "z": 10.8527
+      "z": 8.8527
     }
   },
   {
@@ -692,7 +692,7 @@
     "pos": {
       "x": -9.21755445433687,
       "y": -1.74440707007014,
-      "z": -5.2716
+      "z": -6.2716
     }
   }
 ]