|
|
@@ -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" });
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
};
|