fix: BUG修改

This commit is contained in:
kun 2024-05-28 15:55:39 +08:00
parent b5c0c58ca7
commit c1f79e2391
2 changed files with 98 additions and 1 deletions

View File

@ -2062,6 +2062,15 @@ import { VueCropper } from "vue-cropper";
import { apiUploadImage } from "@/assets/js/api/common";
import lrz from "lrz";
import mqtt from "mqtt";
var client = null;
const options = {
connectTimeout: 40000,
clientId: "mqttjs_" + Math.random().toString(16).substr(2, 8),
username: "root",
password: "123456",
clean: true,
};
export default {
components: {
VueCropper,
@ -2217,6 +2226,8 @@ export default {
radio: "",
showImgList: false,
imgFileList: [], //
topicName: "topic",
userId: "",
};
},
created() {
@ -2250,9 +2261,20 @@ export default {
this.getUGroupDevList();
this.getProjectConfig();
},
beforeDestroy() {
if (client) {
client.unsubscribe(this.topicName + this.userId, options);
client.end();
}
client = null;
},
mounted() {
this.userId = this.$store.state.userInfo.userId;
this.topicName = this.$store.state.userInfo.scope;
this.selectJobList();
this.getEnterpriseType();
client = mqtt.connect(mqttUrl, options);
this.mqttMSG();
},
computed: {
headers() {
@ -2262,6 +2284,33 @@ export default {
},
},
methods: {
// mqtt
mqttMSG() {
// mqtt +"/#" +workerId
client.on("connect", (e) => {
// console.log(':', this.topicName + this.userId)
client.subscribe(this.topicName + this.userId, { qos: 0 }, (error) => {
if (!error) {
// console.log('123')
} else {
console.log("订阅失败");
}
});
});
//
client.on("message", (topic, message) => {
// console.log(message);
this.getTableData();
});
//
// client.on("reconnect", (error) => {
// console.log(":", error);
// });
//
client.on("error", (error) => {
console.log("连接失败:", error);
});
},
//
saveImportFn() {
if (this.imgFileList.length == 0) {

View File

@ -2386,6 +2386,15 @@ import { VueCropper } from "vue-cropper";
import { apiUploadImage } from "@/assets/js/api/common";
import lrz from "lrz";
import mqtt from "mqtt";
var client = null;
const options = {
connectTimeout: 40000,
clientId: "mqttjs_" + Math.random().toString(16).substr(2, 8),
username: "root",
password: "123456",
clean: true,
};
export default {
components: {
VueCropper,
@ -2582,6 +2591,8 @@ export default {
pageSize: 10,
},
whoId: "",
topicName: "topic",
userId: "",
};
},
created() {
@ -2615,10 +2626,20 @@ export default {
this.getUGroupDevList();
this.getProjectConfig();
},
beforeDestroy() {
if (client) {
client.unsubscribe(this.topicName + this.userId, options);
client.end();
}
client = null;
},
mounted() {
// this.webSocket = new WebSocket("ws://127.0.0.1:1818");
this.userId = this.$store.state.userInfo.userId;
this.topicName = this.$store.state.userInfo.scope;
this.getEnterpriseType();
client = mqtt.connect(mqttUrl, options);
this.mqttMSG();
},
computed: {
headers() {
@ -2628,6 +2649,33 @@ export default {
},
},
methods: {
// mqtt
mqttMSG() {
// mqtt +"/#" +workerId
client.on("connect", (e) => {
// console.log(':', this.topicName + this.userId)
client.subscribe(this.topicName + this.userId, { qos: 0 }, (error) => {
if (!error) {
// console.log('123')
} else {
console.log("订阅失败");
}
});
});
//
client.on("message", (topic, message) => {
// console.log(message);
this.getTableData();
});
//
// client.on("reconnect", (error) => {
// console.log(":", error);
// });
//
client.on("error", (error) => {
console.log("连接失败:", error);
});
},
handleImportSuccess(response, file, fileList) {
console.log(response, file, fileList);
this.imgFileList = fileList;