|
@@ -41,8 +41,8 @@
|
|
|
</view>
|
|
|
</template>
|
|
|
<script>
|
|
|
+import MqttService from "../../utils/globalMqtt.js";
|
|
|
import config from "../../data/config.js";
|
|
|
-import mqtt from "../../utils/mqtt";
|
|
|
import {
|
|
|
getSnTicket,
|
|
|
authorize,
|
|
@@ -74,7 +74,6 @@ const getEnvVersionForVoip = (function () {
|
|
|
return _map[envVersion];
|
|
|
};
|
|
|
})();
|
|
|
-
|
|
|
export default {
|
|
|
comments: {
|
|
|
name: "alarModel",
|
|
@@ -637,114 +636,147 @@ export default {
|
|
|
console.log("接收到消息:", topic, data);
|
|
|
},
|
|
|
},
|
|
|
- // mounted() {
|
|
|
- // this.connectMQTTwo();
|
|
|
- // },
|
|
|
-
|
|
|
- // onShow() {
|
|
|
- // console.log("开始接受消息", "99999");
|
|
|
- // },
|
|
|
mounted() {
|
|
|
- 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");
|
|
|
- // 处理点位消息
|
|
|
+ // 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);
|
|
|
+ // 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);
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ let userId = uni.getStorageSync("userId");
|
|
|
+ const topic = `/mps/wx_${userId}/notice`;
|
|
|
+ this.unsubscribeFn = MqttService.subscribe(
|
|
|
+ "CMD",
|
|
|
+ topic,
|
|
|
+ (topic, message) => {
|
|
|
+ const data = JSON.parse(message);
|
|
|
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;
|
|
|
+ // VOIP 相关逻辑
|
|
|
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.nowTime = `${now.getFullYear()}-${String(
|
|
|
+ now.getMonth() + 1
|
|
|
+ ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
+ 2,
|
|
|
+ "0"
|
|
|
+ )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
+ now.getMinutes()
|
|
|
+ ).padStart(2, "0")}`;
|
|
|
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);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
+ console.log("处理后的 CMD 数据:", data);
|
|
|
+ }
|
|
|
+ );
|
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|
|
|
- this.closemqtt();
|
|
|
+ if (this.unsubscribeCmd) {
|
|
|
+ this.unsubscribeCmd();
|
|
|
+ this.unsubscribeCmd = null;
|
|
|
+ console.log("CMD 订阅已取消");
|
|
|
+ }
|
|
|
},
|
|
|
};
|
|
|
</script>
|