670控制中心,收到消息自动更新状态
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
<div class="device-page p-2">
|
||||
<!-- 头部信息栏 -->
|
||||
<div class="header-bar">
|
||||
<div>设备名称:{{ deviceDetail.deviceName }},IMEI:{{deviceDetail.deviceImei }}</div>
|
||||
<div>设备名称:{{ deviceDetail.deviceName }},IMEI:{{ deviceDetail.deviceImei }}</div>
|
||||
<div>设备型号:{{ deviceDetail.typeName }}</div>
|
||||
<div class="device-status">
|
||||
设备状态:
|
||||
@ -19,8 +19,8 @@
|
||||
<el-row :gutter="20" class="content-row" :class="deviceDetail.sta_ShakeBit == 1 || deviceDetail.staSOSGrade == 1 ? '' : 'displayNone'">
|
||||
<el-col :lg="24" :xs="24">
|
||||
<div class="staticRwo" :class="deviceDetail.sta_ShakeBit == 1 ? '' : 'displayNone'">设备静止报警中!</div>
|
||||
<div class="staticRwo" :class="(deviceDetail.staSOSGrade == 1 && Status.timeOut>0) ? '' : 'displayNone'" @click="showClose()">
|
||||
设备强制报警中<span v-show="Status.timeOut>0">,{{ Status.timeOut }}S</span>!
|
||||
<div class="staticRwo" :class="deviceDetail.staSOSGrade == 1 && Status.timeOut > 0 ? '' : 'displayNone'" @click="showClose()">
|
||||
设备强制报警中<span v-show="Status.timeOut > 0">,{{ Status.timeOut }}S</span>!
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@ -209,7 +209,6 @@ import strongLightActive from '@/assets/images/strong-light_HL.png';
|
||||
import floodLightDefault from '@/assets/images/flood-light.png';
|
||||
import floodLightActive from '@/assets/images/flood-light_HL.png';
|
||||
|
||||
|
||||
import di from '@/assets/images/di.png';
|
||||
import diAc from '@/assets/images/diAc.png';
|
||||
import high from '@/assets/images/high.png';
|
||||
@ -314,7 +313,7 @@ const staticModes = ref<any[]>([
|
||||
id: '2',
|
||||
name: '中档',
|
||||
icon: zhong, // 直接使用导入的变量
|
||||
activeIcon:zhongAc,
|
||||
activeIcon: zhongAc,
|
||||
|
||||
active: false
|
||||
},
|
||||
@ -394,7 +393,7 @@ const handleModeClick = async (id: string, type: string) => {
|
||||
|
||||
let dic = { promise: null, callback: null, key: '' };
|
||||
|
||||
//测试环境假装成功
|
||||
//测试环境假装成功
|
||||
dic.promise = Promise.resolve({ code: 200, msg: '操作成功' });
|
||||
|
||||
let arr = [];
|
||||
@ -427,39 +426,35 @@ const handleModeClick = async (id: string, type: string) => {
|
||||
dic.callback();
|
||||
}
|
||||
if (callback) {
|
||||
|
||||
callback();
|
||||
}
|
||||
|
||||
} else {
|
||||
proxy?.$modal.msgError(res.msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
if(type == 'sosMode' && Status.sosMode=== '1' && id==='0' && timer){
|
||||
if (type == 'sosMode' && Status.sosMode === '1' && id === '0' && timer) {
|
||||
showClose();
|
||||
return;
|
||||
}
|
||||
else if (type == 'sosMode' && id === '1' && timer==null) {
|
||||
} else if (type == 'sosMode' && id === '1' && timer == null) {
|
||||
ShowConfirm({
|
||||
title: '提示',
|
||||
text: '您确认开启180秒强制报警',
|
||||
cancelCallback: ()=>{
|
||||
timer=null;
|
||||
cancelCallback: () => {
|
||||
timer = null;
|
||||
},
|
||||
OkCallback: () => {
|
||||
sendCmd(function () {
|
||||
|
||||
Status.confirm.Visible = false;
|
||||
deviceDetail.value.staSOSGrade="1";
|
||||
deviceDetail.value.staSOSGrade = '1';
|
||||
Status.timeOut = 180;
|
||||
timer = setInterval(() => {
|
||||
if (Status.timeOut === 0) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
hideConfirm();
|
||||
handleModeClick('1','sosMode');
|
||||
deviceDetail.value.staSOSGrade="0";
|
||||
handleModeClick('1', 'sosMode');
|
||||
deviceDetail.value.staSOSGrade = '0';
|
||||
return;
|
||||
}
|
||||
|
||||
@ -478,26 +473,32 @@ const handleModeClick = async (id: string, type: string) => {
|
||||
};
|
||||
|
||||
const getList = () => {
|
||||
api.deviceRealTimeStatus(route.params.deviceId).then((res) => {
|
||||
if (res && res.code == 200) {
|
||||
let keys = Object.keys(res.data);
|
||||
keys.forEach((key) => {
|
||||
deviceDetail.value[key] = res.data[key];
|
||||
});
|
||||
Status.sosMode = res.data.staSOSGrade;
|
||||
Status.staticPower = res.data.staDetectGrade;
|
||||
Status.lightMode = res.data.staLightGrade;
|
||||
if(!deviceDetail.value.personnelInfo){
|
||||
deviceDetail.value.personnelInfo={
|
||||
'id': null,
|
||||
'deviceId': null,
|
||||
'name': null,
|
||||
'position': null,
|
||||
'unitName': null,
|
||||
'code': null
|
||||
return new Promise((resolve, reject) => {
|
||||
api
|
||||
.deviceRealTimeStatus(route.params.deviceId)
|
||||
.then((res) => {
|
||||
if (res && res.code == 200) {
|
||||
|
||||
let keys = Object.keys(res.data);
|
||||
keys.forEach((key) => {
|
||||
deviceDetail.value[key] = res.data[key];
|
||||
});
|
||||
Status.sosMode = res.data.staSOSGrade;
|
||||
Status.staticPower = res.data.staDetectGrade;
|
||||
Status.lightMode = res.data.staLightGrade;
|
||||
if (!deviceDetail.value.personnelInfo) {
|
||||
deviceDetail.value.personnelInfo = {
|
||||
'id': null,
|
||||
'deviceId': null,
|
||||
'name': null,
|
||||
'position': null,
|
||||
'unitName': null,
|
||||
'code': null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(resolve);
|
||||
});
|
||||
};
|
||||
|
||||
@ -563,8 +564,6 @@ const sendTextMessage = async () => {
|
||||
batchId: ''
|
||||
};
|
||||
|
||||
|
||||
|
||||
api.SendMessage(json).then((res) => {
|
||||
if (res.code === 200) {
|
||||
ElMessage.closeAll();
|
||||
@ -588,52 +587,63 @@ const lookMap = (row: any) => {
|
||||
function showClose() {
|
||||
Status.confirm.Visible = true;
|
||||
Status.confirm.OkTxt = '关闭';
|
||||
Status.confirm.OkCallback=()=>{
|
||||
clearInterval(timer);
|
||||
timer=null;
|
||||
handleModeClick('0','sosMode');
|
||||
deviceDetail.value.staSOSGrade="0";
|
||||
Status.confirm.OkCallback = () => {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
handleModeClick('0', 'sosMode');
|
||||
deviceDetail.value.staSOSGrade = '0';
|
||||
|
||||
Status.timeOut=0;
|
||||
Status.timeOut = 0;
|
||||
|
||||
hideConfirm();
|
||||
}
|
||||
};
|
||||
}
|
||||
// 处理设备消息
|
||||
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);
|
||||
|
||||
function parseDataMQ(json) {
|
||||
deviceDetail.value.staDetectGrade = json.sta_DetectGrade;
|
||||
deviceDetail.value.staLightGrade = json.sta_LightGrade;
|
||||
deviceDetail.value.staDetectResult = json.sta_DetectResult;
|
||||
deviceDetail.value.staSOSGrade = json.sta_SOSGrade;
|
||||
deviceDetail.value.sta_ShakeBit = json.sta_ShakeBit;
|
||||
deviceDetail.value.staPowerTime = json.sta_PowerTime;
|
||||
deviceDetail.value.staPowerPercent = json.sta_PowerPercent;
|
||||
deviceDetail.value.longitude = json.sta_longitude;
|
||||
deviceDetail.value.latitude = json.sta_latitude;
|
||||
deviceDetail.value.onlineStatus = 1;
|
||||
try {
|
||||
debugger;
|
||||
deviceDetail.value.staDetectGrade = json.sta_DetectGrade;
|
||||
deviceDetail.value.staLightGrade = json.sta_LightGrade;
|
||||
deviceDetail.value.staDetectResult = json.sta_DetectResult;
|
||||
deviceDetail.value.staSOSGrade = json.sta_SOSGrade;
|
||||
deviceDetail.value.sta_ShakeBit = json.sta_ShakeBit;
|
||||
deviceDetail.value.staPowerTime = json.sta_PowerTime;
|
||||
deviceDetail.value.staPowerPercent = json.sta_PowerPercent;
|
||||
deviceDetail.value.longitude = json.sta_longitude;
|
||||
deviceDetail.value.latitude = json.sta_latitude;
|
||||
deviceDetail.value.onlineStatus = 1;
|
||||
|
||||
Status.sosMode = json.sta_SOSGrade;
|
||||
Status.staticPower = json.sta_DetectGrade;
|
||||
Status.lightMode = json.sta_LightGrade;
|
||||
Status.sosMode = json.sta_SOSGrade;
|
||||
Status.staticPower = json.sta_DetectGrade;
|
||||
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) {
|
||||
centerDialogVisible.value = true;
|
||||
}
|
||||
|
||||
if (json.sta_PowerPercent < 20) {
|
||||
centerDialogVisible.value = true;
|
||||
}
|
||||
|
||||
if (json.sta_SOSGrade == 1 && json.sta_ShakeBit == 1) {
|
||||
confirm('设备SOS报警、静止预警中');
|
||||
return;
|
||||
}
|
||||
if (json.sta_SOSGrade == 1) {
|
||||
confirm('设备SOS报警中');
|
||||
}
|
||||
if (json.sta_ShakeBit == 1) {
|
||||
confirm('设备静止报警中');
|
||||
}
|
||||
if (json.sta_SOSGrade == 1 && json.sta_ShakeBit == 1) {
|
||||
confirm('设备SOS报警、静止预警中');
|
||||
return;
|
||||
}
|
||||
if (json.sta_SOSGrade == 1) {
|
||||
confirm('设备SOS报警中');
|
||||
}
|
||||
if (json.sta_ShakeBit == 1) {
|
||||
confirm('设备静止报警中');
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
if (keys.indexOf('sta_DetectGrade') > -1) {
|
||||
@ -646,6 +656,7 @@ onMounted(async () => {
|
||||
await getList(); // 先获取设备信息
|
||||
// 连接mqtt
|
||||
onConnect(async () => {
|
||||
|
||||
const deviceImei = deviceDetail.value.deviceImei;
|
||||
if (!deviceImei) {
|
||||
return;
|
||||
@ -659,6 +670,7 @@ onMounted(async () => {
|
||||
});
|
||||
// 2. 注册消息接收回调(核心:处理设备发送的消息)
|
||||
onMessage((msg) => {
|
||||
|
||||
console.log('收到新消息:', {
|
||||
主题: msg.topic,
|
||||
内容: msg.payload,
|
||||
@ -666,7 +678,7 @@ onMounted(async () => {
|
||||
QoS: msg.qos
|
||||
});
|
||||
// 在这里处理消息(根据实际业务逻辑)
|
||||
handleDeviceMessage(msg);
|
||||
handleDeviceMessage(msg.payload);
|
||||
});
|
||||
onError((err) => {
|
||||
console.error('MQTT连接失败原因:', err.message); // 关键:打印连接失败的具体原因
|
||||
@ -747,7 +759,7 @@ window.hideConfirm = function () {
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.p-2{
|
||||
.p-2 {
|
||||
background: rgba(247, 248, 252, 1);
|
||||
min-height: 100vh;
|
||||
box-sizing: border-box;
|
||||
|
||||
Reference in New Issue
Block a user