|
@@ -361,17 +361,25 @@
|
|
|
></l-echart>
|
|
|
</view>
|
|
|
|
|
|
- <alarModel
|
|
|
+ <!-- <alarModel
|
|
|
v-if="isInitAlarm"
|
|
|
:clientIdProp="clientIdProp"
|
|
|
@sendChange="receptionChange"
|
|
|
@sendHealth="receptHealth"
|
|
|
+ /> -->
|
|
|
+
|
|
|
+ <alarModel
|
|
|
+ v-if="isInitAlarm"
|
|
|
+ @sendChange="receptionChange"
|
|
|
+ @sendHealth="receptHealth"
|
|
|
/>
|
|
|
</view>
|
|
|
</template>
|
|
|
<script>
|
|
|
import * as echarts from "../../uni_modules/lime-echart/static/echarts.min";
|
|
|
|
|
|
+import mqtt from "../../utils/mqtt";
|
|
|
+
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -473,6 +481,8 @@ export default {
|
|
|
},
|
|
|
index: 0,
|
|
|
loopTimer: null,
|
|
|
+ mqttClienTwoFlag: false,
|
|
|
+ mqttClientOne: false,
|
|
|
};
|
|
|
},
|
|
|
computed: {},
|
|
@@ -735,13 +745,7 @@ export default {
|
|
|
this.breathRate = val;
|
|
|
this.setEcharts(val);
|
|
|
},
|
|
|
- getToday() {
|
|
|
- const today = new Date();
|
|
|
- const year = today.getFullYear();
|
|
|
- const month = today.getMonth() + 1;
|
|
|
- const day = today.getDate();
|
|
|
- this.todayDate = `${year}年${month}月${day}日`;
|
|
|
- },
|
|
|
+
|
|
|
// echarts图表模块
|
|
|
|
|
|
getOption(list) {
|
|
@@ -836,9 +840,6 @@ export default {
|
|
|
this.breathRpmList = [];
|
|
|
}
|
|
|
this.breathRpmList.push(val);
|
|
|
- // if (this.breathRpmList.length > 60) {
|
|
|
- // this.breathRpmList = this.breathRpmList.shift();
|
|
|
- // }
|
|
|
if (!this.chartInstance) return;
|
|
|
const option = this.getOption(this.breathRpmList);
|
|
|
this.chartInstance.setOption(option, { notMerge: true });
|
|
@@ -877,12 +878,229 @@ export default {
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
+ // 订阅mqtt实时点位
|
|
|
+ connectMqtt() {
|
|
|
+ if (this.mqttClienTwoFlag) {
|
|
|
+ console.log("主题已订阅");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const THRESHOLD = 2;
|
|
|
+ const params = {
|
|
|
+ keepalive: 6000,
|
|
|
+ clean: true,
|
|
|
+ connectTimeout: 30 * 1000,
|
|
|
+ clientId:
|
|
|
+ "wx_mqtt_" + Math.random().toString(16).substring(2, 8),
|
|
|
+ username: "admin",
|
|
|
+ password: "public",
|
|
|
+ // 微信小程序特定配置
|
|
|
+ wsOptions: {
|
|
|
+ WebSocket: function (url) {
|
|
|
+ return wx.connectSocket({
|
|
|
+ url: url,
|
|
|
+ header: {
|
|
|
+ "content-type": "application/json",
|
|
|
+ },
|
|
|
+ protocols: ["mqtt"],
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ reconnectPeriod: 0,
|
|
|
+ rejectUnauthorized: false,
|
|
|
+ };
|
|
|
+ let clientTwo = "";
|
|
|
+ let selectedService = uni.getStorageSync("sercviceChoice");
|
|
|
+ if (!selectedService || selectedService == "aloneServe") {
|
|
|
+ if (__wxConfig.envVersion == "develop") {
|
|
|
+ clientTwo = mqtt.connect(
|
|
|
+ "wxs://data.radar-power.com:8084/mqtt",
|
|
|
+ params
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (__wxConfig.envVersion == "trial") {
|
|
|
+ clientTwo = mqtt.connect(
|
|
|
+ "wxs://data.radar-power.com:8084/mqtt",
|
|
|
+ params
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 存储client引用以便后续操作
|
|
|
+ this.mqttClientOne = clientTwo;
|
|
|
+ clientTwo.on("connect", () => {
|
|
|
+ console.log("MQTT连接成功");
|
|
|
+ this.mqttClienTwoFlag = true;
|
|
|
+ let userId = uni.getStorageSync("userId");
|
|
|
+ if (this.clientIdProp !== null) {
|
|
|
+ clientTwo.subscribe(
|
|
|
+ `/dev/${this.clientIdProp}/dsp_data`,
|
|
|
+ (err) => {
|
|
|
+ if (err) {
|
|
|
+ console.error("订阅clientId失败", err);
|
|
|
+ } else {
|
|
|
+ console.log(
|
|
|
+ `成功订阅设备主题: /dev/${this.clientIdProp}/dsp_data`
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ console.log(this.clientIdProp);
|
|
|
+ });
|
|
|
+ clientTwo.on("disconnect", () => {
|
|
|
+ console.log("MQTT不在连接");
|
|
|
+ });
|
|
|
+ clientTwo.on("error", (err) => {
|
|
|
+ this.mqttClienTwoFlag = false;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.connectMqtt();
|
|
|
+ }, 1000);
|
|
|
+ });
|
|
|
+
|
|
|
+ clientTwo.on("reconnect", () => {});
|
|
|
+
|
|
|
+ clientTwo.on("close", () => {});
|
|
|
+
|
|
|
+ clientTwo.on("message", (topic, message) => {
|
|
|
+ console.log(JSON.parse(message.toString()), "8870");
|
|
|
+ // 处理点位消息
|
|
|
+ if (this.clientIdProp !== null) {
|
|
|
+ this.handleMessage(topic, message, this.clientIdProp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ handleMessage(topic, message, clientId) {
|
|
|
+ // 清除不活动定时器
|
|
|
+ clearTimeout(this.inactivityTimer);
|
|
|
+ this.inactivityTimer = setTimeout(() => {
|
|
|
+ this.targetPoints = {};
|
|
|
+ }, 1500);
|
|
|
+
|
|
|
+ // 验证topic格式
|
|
|
+ const match = topic.match(/^\/dev\/(.+)\/dsp_data$/);
|
|
|
+ if (!match || match[1] !== clientId) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const data = JSON.parse(message.toString());
|
|
|
+ if (data.health) {
|
|
|
+ if (
|
|
|
+ data.health.breath_rpm ||
|
|
|
+ data.health.breath_rpm === 0
|
|
|
+ ) {
|
|
|
+ this.receptHealth(Math.floor(data.health.breath_rpm));
|
|
|
+ // this.$emit(
|
|
|
+ // "sendHealth",
|
|
|
+ // Math.floor(data.health.breath_rpm)
|
|
|
+ // );
|
|
|
+ } else {
|
|
|
+ // this.$emit("sendHealth", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.processTrackerData(data.tracker_targets);
|
|
|
+ } catch (e) {
|
|
|
+ console.error("MQTT消息解析失败", e);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ processTrackerData(arr) {
|
|
|
+ if (Array.isArray(arr) && arr.length > 0 && Array.isArray(arr[0])) {
|
|
|
+ this.targetPoints = {};
|
|
|
+ const currentIds = new Set();
|
|
|
+ const newTargetPoints = {};
|
|
|
+ // 处理每个追踪目标
|
|
|
+ arr.forEach((item) => {
|
|
|
+ if (!Array.isArray(item) || item.length < 4) return;
|
|
|
+
|
|
|
+ const [x, y, z, id] = item;
|
|
|
+ currentIds.add(id.toString());
|
|
|
+
|
|
|
+ // 处理新点或更新现有点
|
|
|
+ if (!this.targetPoints[id]) {
|
|
|
+ newTargetPoints[id] = this.createNewTargetPoint(
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ z,
|
|
|
+ id
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ newTargetPoints[id] = this.updateExistingTargetPoint(
|
|
|
+ this.targetPoints[id],
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ z,
|
|
|
+ 2
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 移除不存在的点
|
|
|
+ Object.keys(this.targetPoints).forEach((id) => {
|
|
|
+ if (!currentIds.has(id)) {
|
|
|
+ delete this.targetPoints[id];
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新目标点
|
|
|
+ this.targetPoints = {
|
|
|
+ ...this.targetPoints,
|
|
|
+ ...newTargetPoints,
|
|
|
+ };
|
|
|
+ if (Array.isArray(this.targetPoints)) {
|
|
|
+ this.targetPoints = this.targetPoints.filter(
|
|
|
+ (item) => item !== null && item !== undefined
|
|
|
+ );
|
|
|
+ }
|
|
|
+ console.log("当前目标点11111", this.targetPoints);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ createNewTargetPoint(x, y, z, id) {
|
|
|
+ return {
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ z,
|
|
|
+ id,
|
|
|
+ displayX: x,
|
|
|
+ displayY: y,
|
|
|
+ lastX: x,
|
|
|
+ lastY: y,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ updateExistingTargetPoint(existingPoint, x, y, z, THRESHOLD) {
|
|
|
+ const dx = x - existingPoint.lastX;
|
|
|
+ const dy = y - existingPoint.lastY;
|
|
|
+ const distance = Math.sqrt(dx * dx + dy * dy);
|
|
|
+
|
|
|
+ if (distance > THRESHOLD) {
|
|
|
+ return {
|
|
|
+ ...existingPoint,
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ z,
|
|
|
+ lastX: x,
|
|
|
+ lastY: y,
|
|
|
+ displayX: x,
|
|
|
+ displayY: y,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return existingPoint;
|
|
|
+ },
|
|
|
+
|
|
|
+ closemqtTwo() {
|
|
|
+ this.mqttClienTwoFlag = false;
|
|
|
+ if (this.mqttClientOne) {
|
|
|
+ this.mqttClientOne.end();
|
|
|
+ this.mqttClientOne = null;
|
|
|
+ console.log("MQTT连接已断开");
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
|
|
|
onShow() {
|
|
|
this.clientIdProp = uni.getStorageSync("clientIDetail");
|
|
|
this.isInitAlarm = true;
|
|
|
- this.getToday();
|
|
|
+ this.todayDate = this.$time(new Date(), 2);
|
|
|
+ this.connectMqtt();
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
const devItem = this.parseDeviceItem(options.devItem);
|
|
@@ -899,11 +1117,13 @@ export default {
|
|
|
this.isInitAlarm = false;
|
|
|
this.inactivityTimer = null;
|
|
|
this.autoPlayinterval = null;
|
|
|
+ this.closemqtTwo();
|
|
|
},
|
|
|
onHide() {
|
|
|
this.inactivityTimer = null;
|
|
|
this.autoPlayinterval = null;
|
|
|
this.isInitAlarm = false;
|
|
|
+ this.closemqtTwo();
|
|
|
},
|
|
|
};
|
|
|
</script>
|