批量报警,获取设备实时状态
This commit is contained in:
@ -249,14 +249,10 @@
|
|||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.onIntall()
|
this.onIntall()
|
||||||
// 绑定页面做了监听,新增成功,刷新页面
|
|
||||||
uni.$on('refreshDeviceList', () => {
|
|
||||||
this.onIntall()
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
// 组件销毁前移除监听器
|
// 组件销毁前移除监听器
|
||||||
uni.$off('refreshDeviceList');
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
<!-- 设备列表 -->
|
<!-- 设备列表 -->
|
||||||
<view class="allSelect" @click="selectAll"> 全选</view>
|
<view class="allSelect" @click="selectAll"> 全选</view>
|
||||||
<scroll-view class="device-list" scroll-y>
|
<scroll-view class="device-list" scroll-y>
|
||||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
<view class="device-card" v-for="(item, index) in deviceList" :key="index"
|
||||||
|
@click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||||
<!-- 复选框 -->
|
<!-- 复选框 -->
|
||||||
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
||||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||||
@ -88,6 +89,44 @@
|
|||||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||||
this.$forceUpdate()
|
this.$forceUpdate()
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 获取设备状态(带自动轮询)
|
||||||
|
* @param {number} val - 功能模式
|
||||||
|
* @param {string} batchId - 批次ID
|
||||||
|
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
||||||
|
*/
|
||||||
|
async getdeviceSTatus(val, batchId, interval =500) {
|
||||||
|
const checkStatus = async () => {
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
functionMode: val,
|
||||||
|
batchId: batchId,
|
||||||
|
typeName: this.sendInfo.typeName,
|
||||||
|
deviceImei: this.sendInfo.deviceImei
|
||||||
|
};
|
||||||
|
const res = await deviceRealTimeStatus(data);
|
||||||
|
if (res.code !== 200) {
|
||||||
|
throw new Error(res.msg || '请求失败');
|
||||||
|
}
|
||||||
|
switch (res.data.functionAccess) {
|
||||||
|
case 'OK':
|
||||||
|
return res; // 成功完成
|
||||||
|
case 'ACTIVE':
|
||||||
|
await new Promise(r => setTimeout(r, interval));
|
||||||
|
return checkStatus(); // 继续轮询
|
||||||
|
case 'FAILED':
|
||||||
|
throw new Error('设备操作失败');
|
||||||
|
case 'TIMEOUT':
|
||||||
|
throw new Error('设备响应超时');
|
||||||
|
default:
|
||||||
|
throw new Error('未知状态');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return checkStatus();
|
||||||
|
},
|
||||||
// 全选/取消全选
|
// 全选/取消全选
|
||||||
selectAll() {
|
selectAll() {
|
||||||
console.log('123');
|
console.log('123');
|
||||||
@ -158,18 +197,31 @@
|
|||||||
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
const deviceImeiList = selectedDevices.map(item => item.deviceImei);
|
||||||
const isAlarming = this.pendingAlarmAction == 1;
|
const isAlarming = this.pendingAlarmAction == 1;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: isAlarming ? '设备报警中...' : '解除报警中...',
|
title: isAlarming ? '设备报警中...' : '解除报警中...',
|
||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
|
// 2. 准备请求数据
|
||||||
|
const batchId = generateShortId();
|
||||||
const data = {
|
const data = {
|
||||||
deviceIds: deviceIds,
|
deviceIds: deviceIds,
|
||||||
typeName: this.sendInfo.typeName,
|
typeName: this.sendInfo.typeName,
|
||||||
deviceImeiList: deviceImeiList,
|
deviceImeiList: deviceImeiList,
|
||||||
|
batchId: batchId,
|
||||||
instructValue: this.pendingAlarmAction == 1 ? '1' : '0'
|
instructValue: this.pendingAlarmAction == 1 ? '1' : '0'
|
||||||
};
|
};
|
||||||
const registerRes = await deviceSendAlarmMessage(data);
|
const registerRes = await deviceSendAlarmMessage(data);
|
||||||
if (registerRes.code == 200) {
|
if (registerRes.code !== 200) {
|
||||||
|
uni.showToast({
|
||||||
|
title: registerRes.msg,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 4. 获取设备状态
|
||||||
|
const statusRes = await this.getdeviceSTatus(2, batchId);
|
||||||
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: statusRes.msg,
|
title: statusRes.msg,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@ -179,11 +231,6 @@
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}, 500)
|
}, 500)
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: registerRes.msg,
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -192,7 +239,6 @@
|
|||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
this.isSending = false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 点击确认状态
|
// 点击确认状态
|
||||||
@ -432,12 +478,15 @@
|
|||||||
border: 1px solid rgba(255, 255, 255, 0.87);
|
border: 1px solid rgba(255, 255, 255, 0.87);
|
||||||
background: rgba(18, 18, 18, 1);
|
background: rgba(18, 18, 18, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox.disabled {
|
.checkbox.disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
background-color: rgba(255, 255, 255, 0.1) !important;
|
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||||
border-color: rgba(255, 255, 255, 0.2) !important;
|
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||||
pointer-events: none; /* 阻止点击事件 */
|
pointer-events: none;
|
||||||
|
/* 阻止点击事件 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 可选:离线设备的卡片整体置灰 */
|
/* 可选:离线设备的卡片整体置灰 */
|
||||||
.device-card[data-offline="true"] {
|
.device-card[data-offline="true"] {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
|
@ -309,6 +309,7 @@
|
|||||||
lightModeB: false,
|
lightModeB: false,
|
||||||
lightModeC: false, //激光提示框
|
lightModeC: false, //激光提示框
|
||||||
items: [],
|
items: [],
|
||||||
|
pendingMainMode: null, // 选中的索引
|
||||||
isFormExpanded: true, // 默认展开
|
isFormExpanded: true, // 默认展开
|
||||||
deviceID: '',
|
deviceID: '',
|
||||||
itemInfo: {},
|
itemInfo: {},
|
||||||
@ -553,21 +554,38 @@
|
|||||||
toggleForm() {
|
toggleForm() {
|
||||||
this.isFormExpanded = !this.isFormExpanded;
|
this.isFormExpanded = !this.isFormExpanded;
|
||||||
},
|
},
|
||||||
|
// onItemClick(index) {
|
||||||
|
// const selectedItem = this.items[index];
|
||||||
|
// if (selectedItem.text === '激光') {
|
||||||
|
// this.lightModeC = true;
|
||||||
|
// } else {
|
||||||
|
// // 更新选中状态
|
||||||
|
// this.items = this.items.map((item, i) => ({
|
||||||
|
// ...item,
|
||||||
|
// selected: i === index
|
||||||
|
// }));
|
||||||
|
// this.currentMainMode = selectedItem.text;
|
||||||
|
// this.selectedItemIndex = index;
|
||||||
|
// // 强制更新视图(如果需要)
|
||||||
|
// this.$forceUpdate();
|
||||||
|
// }
|
||||||
|
// },
|
||||||
onItemClick(index) {
|
onItemClick(index) {
|
||||||
const selectedItem = this.items[index];
|
const item = this.items[index];
|
||||||
if (selectedItem.text === '激光') {
|
// 激光模式特殊处理
|
||||||
|
if (item.text === '激光') {
|
||||||
this.lightModeC = true;
|
this.lightModeC = true;
|
||||||
} else {
|
return;
|
||||||
// 更新选中状态
|
}
|
||||||
|
// 只更新临时选中状态
|
||||||
|
this.selectedItemIndex = index;
|
||||||
|
// UI高亮效果(不影响实际模式)
|
||||||
this.items = this.items.map((item, i) => ({
|
this.items = this.items.map((item, i) => ({
|
||||||
...item,
|
...item,
|
||||||
selected: i === index
|
selected: i === index
|
||||||
}));
|
}));
|
||||||
this.currentMainMode = selectedItem.text;
|
// 显示临时选中的模式名称(视觉反馈)
|
||||||
this.selectedItemIndex = index;
|
this.pendingMainMode = item.text;
|
||||||
// 强制更新视图(如果需要)
|
|
||||||
this.$forceUpdate();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// 灯光模式的确认
|
// 灯光模式的确认
|
||||||
handleSumbit() {
|
handleSumbit() {
|
||||||
@ -589,7 +607,6 @@
|
|||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
if (this.selectedItemIndex === null) return;
|
if (this.selectedItemIndex === null) return;
|
||||||
const selectedItem = this.items[this.selectedItemIndex];
|
const selectedItem = this.items[this.selectedItemIndex];
|
||||||
// 准备请求数据
|
|
||||||
let data = {
|
let data = {
|
||||||
deviceId: this.computedDeviceId,
|
deviceId: this.computedDeviceId,
|
||||||
instructValue: selectedItem.instructValue,
|
instructValue: selectedItem.instructValue,
|
||||||
@ -598,6 +615,9 @@
|
|||||||
};
|
};
|
||||||
lightModeSettings(data).then((res) => {
|
lightModeSettings(data).then((res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
|
// 只有确认成功才更新实际模式,选中模式
|
||||||
|
this.currentMainMode = this.pendingMainMode;
|
||||||
|
this.selectedItemIndex = selectedItem;
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.msg,
|
title: res.msg,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@ -914,20 +934,29 @@
|
|||||||
};
|
};
|
||||||
// 3.解除告警状态
|
// 3.解除告警状态
|
||||||
const registerRes = await deviceSendAlarmMessage(data);
|
const registerRes = await deviceSendAlarmMessage(data);
|
||||||
if (registerRes.code == 200) {
|
if (registerRes.code !== 200) {
|
||||||
|
uni.showToast({
|
||||||
|
title: registerRes.msg,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 4. 获取设备状态
|
||||||
|
const statusRes = await this.getdeviceSTatus(2, batchId);
|
||||||
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: statusRes.msg,
|
title: statusRes.msg,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
// 刷新详情接口
|
|
||||||
this.fetchDeviceDetail(this.computedDeviceId, true);
|
|
||||||
uni.$emit('deviceStatusUpdate', {});
|
uni.$emit('deviceStatusUpdate', {});
|
||||||
this.showPopupFlag = false
|
this.showPopupFlag = false
|
||||||
|
if (this.apiType === 'listA') {
|
||||||
|
this.fetchDeviceDetail(this.computedDeviceId)
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
// 分享权限详情
|
||||||
title: registerRes.message,
|
this.fetchSharedDeviceDetail(this.itemInfo.id)
|
||||||
icon: 'none'
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -1091,6 +1120,7 @@
|
|||||||
title: error.msg,
|
title: error.msg,
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
|
uni.hideLoading()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 操作说明
|
// 操作说明
|
||||||
@ -1187,15 +1217,18 @@
|
|||||||
this.deviceInfo.batteryRemainingTime = deviceState[5];
|
this.deviceInfo.batteryRemainingTime = deviceState[5];
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.fetchDeviceDetail(data.data.id, true).then(
|
|
||||||
() => {
|
|
||||||
if (this.deviceInfo.batteryPercentage <
|
if (this.deviceInfo.batteryPercentage <
|
||||||
20) {
|
20) {
|
||||||
this.popupType = 'bettery';
|
this.popupType = 'bettery';
|
||||||
this.popupMessage = '请及时充电';
|
this.popupMessage = '请及时充电';
|
||||||
this.showPopupFlag = true;
|
this.showPopupFlag = true;
|
||||||
}
|
}
|
||||||
});
|
if (this.apiType === 'listA') {
|
||||||
|
this.fetchDeviceDetail(data.data.id)
|
||||||
|
} else {
|
||||||
|
// 分享权限详情
|
||||||
|
this.fetchSharedDeviceDetail(data.data.id)
|
||||||
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
// 上报电量,在列表里面同步
|
// 上报电量,在列表里面同步
|
||||||
uni.$emit('deviceStatusUpdate', {
|
uni.$emit('deviceStatusUpdate', {
|
||||||
|
@ -82,7 +82,6 @@
|
|||||||
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
||||||
*/
|
*/
|
||||||
async getdeviceSTatus(val, batchId, interval = 800) {
|
async getdeviceSTatus(val, batchId, interval = 800) {
|
||||||
let retries = 0;
|
|
||||||
const checkStatus = async () => {
|
const checkStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const data = {
|
const data = {
|
||||||
|
Reference in New Issue
Block a user