|
@@ -417,125 +417,125 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
// mqtt相关方法
|
|
|
- connectMQTTwo() {
|
|
|
- if (this.mqttClientFlag) {
|
|
|
- console.log("主题已订阅");
|
|
|
- return;
|
|
|
- }
|
|
|
- const THRESHOLD = 2;
|
|
|
- const params = {
|
|
|
- keepalive: 6000,
|
|
|
- clean: true,
|
|
|
- connectTimeout: 30 * 1000,
|
|
|
- clientId:
|
|
|
- "xcx_mqtt_cmd1" +
|
|
|
- uni.getStorageSync("userId") +
|
|
|
- Math.random().toString(16).substring(2, 8),
|
|
|
- username: "lnradar",
|
|
|
- password: "lnradar",
|
|
|
- // 微信小程序特定配置
|
|
|
- wsOptions: {
|
|
|
- WebSocket: function (url) {
|
|
|
- return wx.connectSocket({
|
|
|
- url: url,
|
|
|
- header: {
|
|
|
- "content-type": "application/json",
|
|
|
- },
|
|
|
- protocols: ["mqtt"],
|
|
|
- });
|
|
|
- },
|
|
|
- },
|
|
|
- reconnectPeriod: 0,
|
|
|
- rejectUnauthorized: false, // 仅开发环境使用,生产环境应设为true或移除
|
|
|
- };
|
|
|
- let client = "";
|
|
|
- let selectedService = uni.getStorageSync("sercviceChoice");
|
|
|
- if (!selectedService || selectedService == "aloneServe") {
|
|
|
- if (__wxConfig.envVersion == "develop") {
|
|
|
- client = mqtt.connect(
|
|
|
- "wxs://cmd.radar-power.cn/mqtt/",
|
|
|
- params
|
|
|
- );
|
|
|
- }
|
|
|
- if (__wxConfig.envVersion == "trial") {
|
|
|
- client = mqtt.connect(
|
|
|
- "wxs://cmd.radar-power.cn/mqtt/",
|
|
|
- params
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- // 存储client引用以便后续操作
|
|
|
- this.mqttClientTwo = client;
|
|
|
- client.on("connect", () => {
|
|
|
- console.log("MQTT连接成功");
|
|
|
- this.mqttClientFlag = true;
|
|
|
- let userId = uni.getStorageSync("userId");
|
|
|
- client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
|
|
|
- if (err) {
|
|
|
- console.error("订阅失败", err);
|
|
|
- } else {
|
|
|
- console.log(
|
|
|
- `成功订阅设备主题: /mps/wx_${userId}/notice`
|
|
|
- );
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- client.on("disconnect", () => {
|
|
|
- console.log("MQTT不在连接");
|
|
|
- });
|
|
|
- client.on("error", (err) => {
|
|
|
- this.mqttClientFlag = false;
|
|
|
- setTimeout(() => {
|
|
|
- this.connectMQTTwo();
|
|
|
- }, 1000);
|
|
|
- });
|
|
|
+ // connectMQTTwo() {
|
|
|
+ // if (this.mqttClientFlag) {
|
|
|
+ // console.log("主题已订阅");
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // const THRESHOLD = 2;
|
|
|
+ // const params = {
|
|
|
+ // keepalive: 6000,
|
|
|
+ // clean: true,
|
|
|
+ // connectTimeout: 30 * 1000,
|
|
|
+ // clientId:
|
|
|
+ // "xcx_mqtt_cmd1" +
|
|
|
+ // uni.getStorageSync("userId") +
|
|
|
+ // Math.random().toString(16).substring(2, 8),
|
|
|
+ // username: "lnradar",
|
|
|
+ // password: "lnradar",
|
|
|
+ // // 微信小程序特定配置
|
|
|
+ // wsOptions: {
|
|
|
+ // WebSocket: function (url) {
|
|
|
+ // return wx.connectSocket({
|
|
|
+ // url: url,
|
|
|
+ // header: {
|
|
|
+ // "content-type": "application/json",
|
|
|
+ // },
|
|
|
+ // protocols: ["mqtt"],
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // reconnectPeriod: 0,
|
|
|
+ // rejectUnauthorized: false, // 仅开发环境使用,生产环境应设为true或移除
|
|
|
+ // };
|
|
|
+ // let client = "";
|
|
|
+ // let selectedService = uni.getStorageSync("sercviceChoice");
|
|
|
+ // if (!selectedService || selectedService == "aloneServe") {
|
|
|
+ // if (__wxConfig.envVersion == "develop") {
|
|
|
+ // client = mqtt.connect(
|
|
|
+ // "wxs://cmd.radar-power.cn/mqtt/",
|
|
|
+ // params
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // if (__wxConfig.envVersion == "trial") {
|
|
|
+ // client = mqtt.connect(
|
|
|
+ // "wxs://cmd.radar-power.cn/mqtt/",
|
|
|
+ // params
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // 存储client引用以便后续操作
|
|
|
+ // this.mqttClientTwo = client;
|
|
|
+ // client.on("connect", () => {
|
|
|
+ // console.log("MQTT连接成功");
|
|
|
+ // this.mqttClientFlag = true;
|
|
|
+ // let userId = uni.getStorageSync("userId");
|
|
|
+ // client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
|
|
|
+ // if (err) {
|
|
|
+ // console.error("订阅失败", err);
|
|
|
+ // } else {
|
|
|
+ // console.log(
|
|
|
+ // `成功订阅设备主题: /mps/wx_${userId}/notice`
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // client.on("disconnect", () => {
|
|
|
+ // console.log("MQTT不在连接");
|
|
|
+ // });
|
|
|
+ // client.on("error", (err) => {
|
|
|
+ // this.mqttClientFlag = false;
|
|
|
+ // setTimeout(() => {
|
|
|
+ // this.connectMQTTwo();
|
|
|
+ // }, 1000);
|
|
|
+ // });
|
|
|
|
|
|
- client.on("reconnect", () => {});
|
|
|
+ // client.on("reconnect", () => {});
|
|
|
|
|
|
- client.on("close", () => {});
|
|
|
+ // client.on("close", () => {});
|
|
|
|
|
|
- client.on("message", (topic, message) => {
|
|
|
- console.log(JSON.parse(message.toString()), "8870");
|
|
|
- // 处理点位消息
|
|
|
- let userId = uni.getStorageSync("userId");
|
|
|
+ // client.on("message", (topic, message) => {
|
|
|
+ // console.log(JSON.parse(message.toString()), "8870");
|
|
|
+ // // 处理点位消息
|
|
|
+ // let userId = uni.getStorageSync("userId");
|
|
|
|
|
|
- console.log("topic777777", userId);
|
|
|
+ // console.log("topic777777", 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);
|
|
|
- });
|
|
|
- },
|
|
|
+ // 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);
|
|
|
+ // });
|
|
|
+ // },
|
|
|
|
|
|
hanledList(type) {
|
|
|
this.$http
|