|
@@ -645,47 +645,102 @@ export default {
|
|
|
// console.log("开始接受消息", "99999");
|
|
|
// },
|
|
|
mounted() {
|
|
|
- console.log("开始接受消息", "8870");
|
|
|
- // 通过全局 MQTT 客户端订阅主题或监听消息
|
|
|
- this.$mqttClient.on("message", (topic, message) => {
|
|
|
- console.log("接收到消息CMD:", JSON.parse(message.toString()));
|
|
|
- console.log(JSON.parse(message.toString()), "8870");
|
|
|
- // 处理点位消息
|
|
|
- let userId = uni.getStorageSync("userId");
|
|
|
- const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
- const match = topic.match(noticeMatch);
|
|
|
- if (!match) return;
|
|
|
- this.alarmModel = true;
|
|
|
- const data = JSON.parse(message.toString());
|
|
|
- this.clientId = data.clientId;
|
|
|
- this.devName = data.devName;
|
|
|
- this.sn = data.clientId;
|
|
|
- this.eventListId = data.eventListId;
|
|
|
- this.getVoipAuthor(this.clientId, userId);
|
|
|
- console.log(data, topic, "接收到消息222:");
|
|
|
- console.log(
|
|
|
- "接收到消息:",
|
|
|
- this.clientId,
|
|
|
- this.devName,
|
|
|
- this.sn,
|
|
|
- this.eventListId,
|
|
|
- data
|
|
|
- );
|
|
|
- const now = new Date();
|
|
|
- const year = now.getFullYear();
|
|
|
- const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
|
|
- const day = now.getDate().toString().padStart(2, "0");
|
|
|
- const hours = now.getHours().toString().padStart(2, "0");
|
|
|
- const minutes = now.getMinutes().toString().padStart(2, "0");
|
|
|
- const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
- this.nowTime = formattedTime;
|
|
|
- console.log("isWmpf:", isWmpf);
|
|
|
- if (!isWmpf) {
|
|
|
+ if (this.$mqttClient) {
|
|
|
+ console.log("开始接受mqtt消息111");
|
|
|
+ this.$mqttClient.on("message", (topic, message) => {
|
|
|
+ console.log(
|
|
|
+ "接收到消息CMD11111:",
|
|
|
+ JSON.parse(message.toString())
|
|
|
+ );
|
|
|
+ console.log(JSON.parse(message.toString()), "8870");
|
|
|
+ // 处理点位消息
|
|
|
+ let userId = uni.getStorageSync("userId");
|
|
|
+ const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
+ const match = topic.match(noticeMatch);
|
|
|
+ if (!match) return;
|
|
|
+ this.alarmModel = true;
|
|
|
+ const data = JSON.parse(message.toString());
|
|
|
+ this.clientId = data.clientId;
|
|
|
+ this.devName = data.devName;
|
|
|
+ this.sn = data.clientId;
|
|
|
+ this.eventListId = data.eventListId;
|
|
|
+ this.getVoipAuthor(this.clientId, userId);
|
|
|
+ console.log(data, topic, "接收到消息222:");
|
|
|
+ console.log(
|
|
|
+ "接收到消息:",
|
|
|
+ this.clientId,
|
|
|
+ this.devName,
|
|
|
+ this.sn,
|
|
|
+ this.eventListId,
|
|
|
+ data
|
|
|
+ );
|
|
|
+ const now = new Date();
|
|
|
+ const year = now.getFullYear();
|
|
|
+ const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
|
|
+ const day = now.getDate().toString().padStart(2, "0");
|
|
|
+ const hours = now.getHours().toString().padStart(2, "0");
|
|
|
+ const minutes = now.getMinutes().toString().padStart(2, "0");
|
|
|
+ const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
+ this.nowTime = formattedTime;
|
|
|
console.log("isWmpf:", isWmpf);
|
|
|
- this.getVoipDevices();
|
|
|
- }
|
|
|
- console.log("接收到消息:", topic, data);
|
|
|
- });
|
|
|
+ if (!isWmpf) {
|
|
|
+ console.log("isWmpf:", isWmpf);
|
|
|
+ this.getVoipDevices();
|
|
|
+ }
|
|
|
+ console.log("接收到消息:", topic, data);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.$once("mqtt-ready", () => {
|
|
|
+ console.log("开始接受mqtt消息222");
|
|
|
+ this.$mqttClient.on("message", (topic, message) => {
|
|
|
+ console.log(
|
|
|
+ "接收到消息CMD222:",
|
|
|
+ JSON.parse(message.toString())
|
|
|
+ );
|
|
|
+ console.log(JSON.parse(message.toString()), "8870");
|
|
|
+ // 处理点位消息
|
|
|
+ let userId = uni.getStorageSync("userId");
|
|
|
+ const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
+ const match = topic.match(noticeMatch);
|
|
|
+ if (!match) return;
|
|
|
+ this.alarmModel = true;
|
|
|
+ const data = JSON.parse(message.toString());
|
|
|
+ this.clientId = data.clientId;
|
|
|
+ this.devName = data.devName;
|
|
|
+ this.sn = data.clientId;
|
|
|
+ this.eventListId = data.eventListId;
|
|
|
+ this.getVoipAuthor(this.clientId, userId);
|
|
|
+ console.log(data, topic, "接收到消息222:");
|
|
|
+ console.log(
|
|
|
+ "接收到消息:",
|
|
|
+ this.clientId,
|
|
|
+ this.devName,
|
|
|
+ this.sn,
|
|
|
+ this.eventListId,
|
|
|
+ data
|
|
|
+ );
|
|
|
+ const now = new Date();
|
|
|
+ const year = now.getFullYear();
|
|
|
+ const month = (now.getMonth() + 1)
|
|
|
+ .toString()
|
|
|
+ .padStart(2, "0");
|
|
|
+ const day = now.getDate().toString().padStart(2, "0");
|
|
|
+ const hours = now.getHours().toString().padStart(2, "0");
|
|
|
+ const minutes = now
|
|
|
+ .getMinutes()
|
|
|
+ .toString()
|
|
|
+ .padStart(2, "0");
|
|
|
+ const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
+ this.nowTime = formattedTime;
|
|
|
+ console.log("isWmpf:", isWmpf);
|
|
|
+ if (!isWmpf) {
|
|
|
+ console.log("isWmpf:", isWmpf);
|
|
|
+ this.getVoipDevices();
|
|
|
+ }
|
|
|
+ console.log("接收到消息:", topic, data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|