This commit is contained in:
Iruka 2025-01-02 20:28:11 +08:00
parent 4940286f57
commit 7384169e72
4 changed files with 97 additions and 18 deletions

View File

@ -152,10 +152,10 @@
},
//Mqtt
mqttMsgHandler(topic, data) {
// console.error("mqttMsgHandler:", {
// topic: topic,
// data: JSON.parse(data),
// });
console.error("mqttMsgHandler:", {
topic: topic,
data: JSON.parse(data),
});
this.dc.handleMessage(topic, JSON.parse(data));
this.sendMsgEvent("mqtt", {
type: "msg",

View File

@ -26,13 +26,15 @@
<uni-col :span="12">
<view class="flex-text global-font-size-1">
<view class="flex-text-one">/硬件版本</view>
<view>{{ item.softVer}} / {{ item.deviceVersion}}</view>
<view>{{ dataObj[item.deviceCode]?.sv || item.softVer}} /
{{ dataObj[item.deviceCode]?.dv || item.deviceVersion}}
</view>
</view>
</uni-col>
<uni-col :span="12">
<view class="flex-text global-font-size-1">
<view class="flex-text-one">频段</view>
<view>{{ item.rolaFrequency}}</view>
<view>{{ dataObj[item.deviceCode]?.lf || item.rolaFrequency}}</view>
</view>
</uni-col>
<uni-col :span="8">
@ -90,8 +92,9 @@
return {
landId: null,
dataList: [],
topics: [],
dc: getApp().dc, //
dataObj: {},
topics: [],
rolaFrequency: {
item: null,
old: null,
@ -117,6 +120,32 @@
list.push(lfObj);
}
this.rolaFrequency.range = list;
const that = this;
getApp().addMsgEvent("mqtt", "mqtt_devOps_station", function(e) {
if (e.type == "state") {
// that.mqttConnected = e.connected;
} else if (e.type == "msg") {
if (e.topic.includes("jsy/iot/deviceConfig/1/")) {
const arr = e.topic.split("/");
const deviceCode = arr[4];
let obj = that.dataObj[deviceCode] || {};
if (e.data.type == "gsc") {
obj = Object.assign(obj, {
dv: e.data.data.dv,
sv: e.data.data.sv,
lf: e.data.data.lf,
})
}
if (e.data.type == "lf") {
obj = Object.assign(obj, {
lf: e.data.data,
})
}
that.dataObj[deviceCode] = obj;
console.error("this.dataObj:", that.dataObj);
}
}
});
},
onShow() {},
mounted() {},
@ -127,23 +156,15 @@
queryList(pageNo, pageSize) {
DevOpsApi.getStationList(this.landId).then(res => {
console.error("res:", res);
// /${productKey}/${deviceName}/user/postConfig
this.$refs.paging.completeByTotal(res.rows);
this.mqttSubscribes(res.rows);
});
},
mqttSubscribes(rows) {
if (rows && rows.length) {
const shortTopic = [
"jsy/iot/deviceConfig/", //
]
let topic = [];
rows.forEach(item => {
shortTopic.forEach(i => {
topic.push(i + `${item.deviceTypeId}/${item.deviceCode}`);
});
topic.push(`jsy/iot/deviceConfig/${item.deviceTypeId}/${item.deviceCode}`);
});
this.topics = topic;
getApp().mqttSubscribes(this.topics);

View File

@ -33,13 +33,17 @@
<uni-col :span="12">
<view class="flex-text global-font-size-1">
<view class="flex-text-one">频段</view>
<view>{{ item.device.deviceExtendValve.rolaFrequency }}</view>
<view>
{{ dataObj[item.device.deviceCode]?.lf || item.device.deviceExtendValve.rolaFrequency}}
</view>
</view>
</uni-col>
<uni-col :span="12">
<view class="flex-text global-font-size-1">
<view class="flex-text-one">/硬件版本</view>
<view>{{ item.device.softVer || '-'}} / {{ item.device.deviceVersion || '-' }}</view>
<view>{{ dataObj[item.device.deviceCode]?.sv || item.device.softVer}} /
{{ dataObj[item.device.deviceCode]?.dv || item.device.deviceVersion }}
</view>
</view>
</uni-col>
<uni-col :span="12">
@ -100,6 +104,8 @@
},
dataList: [],
dc: getApp().dc, //
dataObj: {},
topics: [],
rolaFrequency: {
item: null,
old: null,
@ -131,15 +137,64 @@
list.push(lfObj);
}
this.rolaFrequency.range = list;
const that = this;
getApp().addMsgEvent("mqtt", "mqtt_devOps_valve", function(e) {
if (e.type == "state") {
// that.mqttConnected = e.connected;
} else if (e.type == "msg") {
if (e.topic.includes("jsy/iot/deviceConfig/2/") || e.topic.includes(
"jsy/iot/deviceConfig/13/")) {
const arr = e.topic.split("/");
const deviceCode = arr[4];
let obj = that.dataObj[deviceCode] || {};
if (e.data.type == "gvc") {
obj = Object.assign(obj, {
dv: e.data.data.dv,
sv: e.data.data.sv,
lf: e.data.data.lf,
})
}
that.dataObj[deviceCode] = obj;
console.error("this.dataObj:", that.dataObj);
}
if (e.topic.includes("jsy/iot/valveUpdateLoraRes/")) {
const arr = e.topic.split("/");
const deviceCode = arr[3];
let obj = that.dataObj[deviceCode] || {};
if (e.data.type == "vlf" && e.data.res == 1) {
obj = Object.assign(obj, {
lf: e.data.data,
})
}
that.dataObj[deviceCode] = obj;
console.error("this.dataObj:", that.dataObj);
}
}
});
},
onShow() {},
mounted() {},
onUnload() {
getApp().mqttUnsubscribes(this.topics);
},
methods: {
queryList(pageNo, pageSize) {
DevOpsApi.getStationValvelist(this.queryParams.landId, this.queryParams.stationId).then(res => {
this.$refs.paging.completeByTotal(res.rows);
this.mqttSubscribes(res.rows);
});
},
mqttSubscribes(rows) {
if (rows && rows.length) {
let topic = [];
rows.forEach(item => {
topic.push(`jsy/iot/deviceConfig/${item.device.deviceTypeId}/${item.device.deviceCode}`);//
topic.push(`jsy/iot/valveUpdateLoraRes/${item.device.deviceCode}`);//
});
this.topics = topic;
getApp().mqttSubscribes(this.topics);
}
},
//
restart(item) {
console.error("重启:", item);

View File

@ -807,6 +807,9 @@ class deviceControl {
* @param {Object} data
*/
handleMessage(topic, data) {
if(!topic.includes("jsy/iot/push/")){
return;
}
const that = this;
if (data.time < that.dataObj[data.deviceCode].time) {
return;