670控制中心,收到消息自动更新状态
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
<el-row :gutter="20" class="content-row" :class="deviceDetail.sta_ShakeBit == 1 || deviceDetail.staSOSGrade == 1 ? '' : 'displayNone'">
|
<el-row :gutter="20" class="content-row" :class="deviceDetail.sta_ShakeBit == 1 || deviceDetail.staSOSGrade == 1 ? '' : 'displayNone'">
|
||||||
<el-col :lg="24" :xs="24">
|
<el-col :lg="24" :xs="24">
|
||||||
<div class="staticRwo" :class="deviceDetail.sta_ShakeBit == 1 ? '' : 'displayNone'">设备静止报警中!</div>
|
<div class="staticRwo" :class="deviceDetail.sta_ShakeBit == 1 ? '' : 'displayNone'">设备静止报警中!</div>
|
||||||
<div class="staticRwo" :class="(deviceDetail.staSOSGrade == 1 && Status.timeOut>0) ? '' : 'displayNone'" @click="showClose()">
|
<div class="staticRwo" :class="deviceDetail.staSOSGrade == 1 && Status.timeOut > 0 ? '' : 'displayNone'" @click="showClose()">
|
||||||
设备强制报警中<span v-show="Status.timeOut > 0">,{{ Status.timeOut }}S</span>!
|
设备强制报警中<span v-show="Status.timeOut > 0">,{{ Status.timeOut }}S</span>!
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -209,7 +209,6 @@ import strongLightActive from '@/assets/images/strong-light_HL.png';
|
|||||||
import floodLightDefault from '@/assets/images/flood-light.png';
|
import floodLightDefault from '@/assets/images/flood-light.png';
|
||||||
import floodLightActive from '@/assets/images/flood-light_HL.png';
|
import floodLightActive from '@/assets/images/flood-light_HL.png';
|
||||||
|
|
||||||
|
|
||||||
import di from '@/assets/images/di.png';
|
import di from '@/assets/images/di.png';
|
||||||
import diAc from '@/assets/images/diAc.png';
|
import diAc from '@/assets/images/diAc.png';
|
||||||
import high from '@/assets/images/high.png';
|
import high from '@/assets/images/high.png';
|
||||||
@ -427,10 +426,8 @@ const handleModeClick = async (id: string, type: string) => {
|
|||||||
dic.callback();
|
dic.callback();
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
proxy?.$modal.msgError(res.msg);
|
proxy?.$modal.msgError(res.msg);
|
||||||
}
|
}
|
||||||
@ -439,8 +436,7 @@ const handleModeClick = async (id: string, type: string) => {
|
|||||||
if (type == 'sosMode' && Status.sosMode === '1' && id === '0' && timer) {
|
if (type == 'sosMode' && Status.sosMode === '1' && id === '0' && timer) {
|
||||||
showClose();
|
showClose();
|
||||||
return;
|
return;
|
||||||
}
|
} else if (type == 'sosMode' && id === '1' && timer == null) {
|
||||||
else if (type == 'sosMode' && id === '1' && timer==null) {
|
|
||||||
ShowConfirm({
|
ShowConfirm({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
text: '您确认开启180秒强制报警',
|
text: '您确认开启180秒强制报警',
|
||||||
@ -449,9 +445,8 @@ const handleModeClick = async (id: string, type: string) => {
|
|||||||
},
|
},
|
||||||
OkCallback: () => {
|
OkCallback: () => {
|
||||||
sendCmd(function () {
|
sendCmd(function () {
|
||||||
|
|
||||||
Status.confirm.Visible = false;
|
Status.confirm.Visible = false;
|
||||||
deviceDetail.value.staSOSGrade="1";
|
deviceDetail.value.staSOSGrade = '1';
|
||||||
Status.timeOut = 180;
|
Status.timeOut = 180;
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
if (Status.timeOut === 0) {
|
if (Status.timeOut === 0) {
|
||||||
@ -459,7 +454,7 @@ const handleModeClick = async (id: string, type: string) => {
|
|||||||
timer = null;
|
timer = null;
|
||||||
hideConfirm();
|
hideConfirm();
|
||||||
handleModeClick('1', 'sosMode');
|
handleModeClick('1', 'sosMode');
|
||||||
deviceDetail.value.staSOSGrade="0";
|
deviceDetail.value.staSOSGrade = '0';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,8 +473,12 @@ const handleModeClick = async (id: string, type: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getList = () => {
|
const getList = () => {
|
||||||
api.deviceRealTimeStatus(route.params.deviceId).then((res) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
api
|
||||||
|
.deviceRealTimeStatus(route.params.deviceId)
|
||||||
|
.then((res) => {
|
||||||
if (res && res.code == 200) {
|
if (res && res.code == 200) {
|
||||||
|
|
||||||
let keys = Object.keys(res.data);
|
let keys = Object.keys(res.data);
|
||||||
keys.forEach((key) => {
|
keys.forEach((key) => {
|
||||||
deviceDetail.value[key] = res.data[key];
|
deviceDetail.value[key] = res.data[key];
|
||||||
@ -495,9 +494,11 @@ const getList = () => {
|
|||||||
'position': null,
|
'position': null,
|
||||||
'unitName': null,
|
'unitName': null,
|
||||||
'code': null
|
'code': null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
.finally(resolve);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -563,8 +564,6 @@ const sendTextMessage = async () => {
|
|||||||
batchId: ''
|
batchId: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
api.SendMessage(json).then((res) => {
|
api.SendMessage(json).then((res) => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
ElMessage.closeAll();
|
ElMessage.closeAll();
|
||||||
@ -592,19 +591,27 @@ function showClose() {
|
|||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
timer = null;
|
timer = null;
|
||||||
handleModeClick('0', 'sosMode');
|
handleModeClick('0', 'sosMode');
|
||||||
deviceDetail.value.staSOSGrade="0";
|
deviceDetail.value.staSOSGrade = '0';
|
||||||
|
|
||||||
Status.timeOut = 0;
|
Status.timeOut = 0;
|
||||||
|
|
||||||
hideConfirm();
|
hideConfirm();
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
// 处理设备消息
|
// 处理设备消息
|
||||||
const handleDeviceMessage = (payload: any) => {
|
const handleDeviceMessage = (payload: any) => {
|
||||||
let json = JSON.parse(payload);
|
let json = null;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(payload);
|
||||||
|
} catch (ex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let keys = Object.keys(json);
|
let keys = Object.keys(json);
|
||||||
|
|
||||||
function parseDataMQ(json) {
|
function parseDataMQ(json) {
|
||||||
|
try {
|
||||||
|
debugger;
|
||||||
deviceDetail.value.staDetectGrade = json.sta_DetectGrade;
|
deviceDetail.value.staDetectGrade = json.sta_DetectGrade;
|
||||||
deviceDetail.value.staLightGrade = json.sta_LightGrade;
|
deviceDetail.value.staLightGrade = json.sta_LightGrade;
|
||||||
deviceDetail.value.staDetectResult = json.sta_DetectResult;
|
deviceDetail.value.staDetectResult = json.sta_DetectResult;
|
||||||
@ -619,7 +626,9 @@ const handleDeviceMessage = (payload: any) => {
|
|||||||
Status.sosMode = json.sta_SOSGrade;
|
Status.sosMode = json.sta_SOSGrade;
|
||||||
Status.staticPower = json.sta_DetectGrade;
|
Status.staticPower = json.sta_DetectGrade;
|
||||||
Status.lightMode = json.sta_LightGrade;
|
Status.lightMode = json.sta_LightGrade;
|
||||||
|
console.log('Status=', Status);
|
||||||
|
console.log('sosModes=', sosModes.value);
|
||||||
|
console.log('sta_SOSGrade=', json.sta_SOSGrade);
|
||||||
if (json.sta_PowerPercent < 20) {
|
if (json.sta_PowerPercent < 20) {
|
||||||
centerDialogVisible.value = true;
|
centerDialogVisible.value = true;
|
||||||
}
|
}
|
||||||
@ -634,6 +643,7 @@ const handleDeviceMessage = (payload: any) => {
|
|||||||
if (json.sta_ShakeBit == 1) {
|
if (json.sta_ShakeBit == 1) {
|
||||||
confirm('设备静止报警中');
|
confirm('设备静止报警中');
|
||||||
}
|
}
|
||||||
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys.indexOf('sta_DetectGrade') > -1) {
|
if (keys.indexOf('sta_DetectGrade') > -1) {
|
||||||
@ -646,6 +656,7 @@ onMounted(async () => {
|
|||||||
await getList(); // 先获取设备信息
|
await getList(); // 先获取设备信息
|
||||||
// 连接mqtt
|
// 连接mqtt
|
||||||
onConnect(async () => {
|
onConnect(async () => {
|
||||||
|
|
||||||
const deviceImei = deviceDetail.value.deviceImei;
|
const deviceImei = deviceDetail.value.deviceImei;
|
||||||
if (!deviceImei) {
|
if (!deviceImei) {
|
||||||
return;
|
return;
|
||||||
@ -659,6 +670,7 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
// 2. 注册消息接收回调(核心:处理设备发送的消息)
|
// 2. 注册消息接收回调(核心:处理设备发送的消息)
|
||||||
onMessage((msg) => {
|
onMessage((msg) => {
|
||||||
|
|
||||||
console.log('收到新消息:', {
|
console.log('收到新消息:', {
|
||||||
主题: msg.topic,
|
主题: msg.topic,
|
||||||
内容: msg.payload,
|
内容: msg.payload,
|
||||||
@ -666,7 +678,7 @@ onMounted(async () => {
|
|||||||
QoS: msg.qos
|
QoS: msg.qos
|
||||||
});
|
});
|
||||||
// 在这里处理消息(根据实际业务逻辑)
|
// 在这里处理消息(根据实际业务逻辑)
|
||||||
handleDeviceMessage(msg);
|
handleDeviceMessage(msg.payload);
|
||||||
});
|
});
|
||||||
onError((err) => {
|
onError((err) => {
|
||||||
console.error('MQTT连接失败原因:', err.message); // 关键:打印连接失败的具体原因
|
console.error('MQTT连接失败原因:', err.message); // 关键:打印连接失败的具体原因
|
||||||
|
|||||||
Reference in New Issue
Block a user