1
0
forked from dyf/APP

018A初步完成

This commit is contained in:
liub
2026-04-14 15:19:05 +08:00
parent d82ae6445e
commit 01ff9c7a05
43 changed files with 2626 additions and 892 deletions

View File

@ -31,7 +31,7 @@
<view class="battery-v1">
<image src="/static/images/common/time.png" class="dlIMG" mode="aspectFit"></image>
<view>
<view class="battery-v2">{{ deviceInfo.batteryRemainingTime || '0' }}分钟</view>
<view class="battery-v2">{{remainTime}}</view>
<view class="battery-v3">续航时间</view>
</view>
</view>
@ -54,13 +54,13 @@
</view>
<view class="info-row" v-if="itemInfo.deviceMac" @click="bleStatuToggle">
<text class="info-label">蓝牙状态</text>
<text class="info-value status-running" :class="formData.bleStatu?'green':'red'" >
<text class="info-value status-running" :class="formData.bleStatu?'green':'red'">
{{getbleStatu}}
</text>
</view>
<view class="info-row" v-if="itemInfo.deviceMac" @click="bleStatuToggle">
<text class="info-label">充电状态</text>
<text class="info-value status-running" >
<text class="info-value status-running">
{{deviceInfo.chargeState != 0?'充电中':'未充电'}}
</text>
</view>
@ -112,7 +112,7 @@
</view>
</view>
</view>
<view class="mode-v1" v-if="hasPermission('2')">
<view class="mode-v1" v-if="hasPermission('2')" :class="{'active':isLaserOn}">
<view class="mode-v2" @click="lasermode">
<image src="/static/images/6170/jg.png" class="setIMG" mode="aspectFit"></image>
<view>
@ -121,17 +121,20 @@
</view>
</view>
</view>
<view class="mode-v1" :class="{'active':itemInfo.alarmStatus===1 || itemInfo.alarmStatus==='1'}" >
<view class="mode-v1"
:class="{'active':itemInfo.alarmStatus===1 || itemInfo.alarmStatus==='1'}">
<view class="mode-v2" @click="warnToggle">
<image v-show="itemInfo.alarmStatus!=1" src="/static/images/common/sg.png" class="setIMG" mode="aspectFit"></image>
<image v-show="itemInfo.alarmStatus==1" src="/static/images/common/sgActive.png" class="setIMG" mode="aspectFit"></image>
<image v-show="itemInfo.alarmStatus!=1" src="/static/images/common/sg.png"
class="setIMG" mode="aspectFit"></image>
<image v-show="itemInfo.alarmStatus==1" src="/static/images/common/sgActive.png"
class="setIMG" mode="aspectFit"></image>
<view>
<view class="battery-v2">{{itemInfo.alarmStatus==1?'解除报警':'强制报警'}}</view>
<view class="battery-v2">{{itemInfo.alarmStatus==1?'解除报警':'强制报警'}}</view>
</view>
</view>
</view>
<view class="mode-v1" v-if="hasPermission('3')">
<view class="mode-v2" @click="uploadStartup">
<image src="/static/images/common/path7.png" class="setIMG" mode="aspectFit"></image>
@ -147,7 +150,7 @@
<!-- 人员信息登记 -->
<view class="form-section" v-if="hasPermission('4')">
<TextToHexV2 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
:color="'#000000'" :fontSize="14" :returnType="10" />
:color="'#000000'" :fontSize="12" :returnType="10" />
<view class="mode-buttons">
<view class="section-title">人员信息登记</view>
@ -161,17 +164,16 @@
<view class="form-row">
<text class="form-label">单位</text>
<input class="form-input" placeholder="请输入单位" v-model="personnelInfo.unitName"
:maxlength="15" />
:maxlength="8" />
</view>
<view class="form-row">
<text class="form-label">姓名</text>
<input class="form-input" placeholder="请输入姓名" v-model="personnelInfo.name"
:maxlength="15" />
<input class="form-input" placeholder="请输入姓名" v-model="personnelInfo.name" :maxlength="8" />
</view>
<view class="form-row">
<text class="form-label">职位</text>
<input class="form-input" placeholder="请输入职位" v-model="personnelInfo.position"
:maxlength="15" />
:maxlength="8" />
</view>
<view class="form-row">
<text class="form-label">ID</text>
@ -180,7 +182,7 @@
</view>
</view>
</view>
<!-- 人员信息登记 -->
<!-- 发送信息-->
<view class="form-section" v-if="hasPermission('5')">
<view class="mode-buttons">
<view class="section-title">发送信息</view>
@ -193,7 +195,7 @@
</view>
<!-- 产品信息 -->
<ProParams :id="itemInfo.id"></ProParams>
</view>
<!-- 弹框 -->
<view class="agreement-mask" v-if="lightModeA" @click.stop="closePopup">
@ -276,15 +278,17 @@
<CustomPopup v-if="popupType === 'cancel'" :show="showPopupFlag"
popupBorder="1rpx solid rgba(224, 52, 52, 0.3)" :message="popupMessage"
icon="/static/images/6170/svg.png" :confirm-text="popupConfirmText" :show-cancel="true"
@confirm="onPopupConfirmPolice" confirmBtnBg="rgba(224, 52, 52, 1)" confirmBtnColor="#fff" />
@cancel="onPopupConfirm" @confirm="onPopupConfirmPolice" confirmBtnBg="rgba(224, 52, 52, 1)"
confirmBtnColor="#fff" />
<!-- 强制报警 -->
<CustomPopup v-if="popupType === 'openWarn'" :show="showPopupFlag"
popupBorder="1rpx solid rgba(224, 52, 52, 0.3)" :message="popupMessage"
icon="/static/images/6170/svg.png" :confirm-text="popupConfirmText" :show-cancel="true"
@confirm="OpenWarn(1)" confirmBtnBg="rgba(224, 52, 52, 1)" confirmBtnColor="#fff" />
@cancel="onPopupConfirm" @confirm="OpenWarn(1)" confirmBtnBg="rgba(224, 52, 52, 1)"
confirmBtnColor="#fff" />
<MsgBox ref="msgPop" />
<global-loading ref="loading" />
</view>
@ -306,7 +310,8 @@
MsgError,
MsgClose,
MsgWarning,
showPop
showPop,
MsgInfo
} from '@/utils/MsgPops.js';
import Common from '@/utils/Common.js';
@ -355,7 +360,7 @@
navTitle: "",
sliderValue: 25,
lightModeA: false,
currentMainMode: '强光',
currentMainMode: '关闭',
currentlaserMode: "关闭",
lightModeB: false,
lightModeC: false, //激光提示框
@ -402,7 +407,7 @@
rgb565Data: null,
selectedItemIndex: 0,
popupType: 'person', //弹框类型
isLaserOn: false,
isLaserOn: false, //激光开启状态
isSending: false,
isProcessing: false,
isPolling: false, // 轮询状态
@ -418,6 +423,9 @@
}
},
computed: {
remainTime() {
return Common.formatTime(this.deviceInfo.batteryRemainingTime);
},
computedDeviceId() {
return this.apiType === 'listA' ? this.deviceID : this.itemInfo.deviceId;
},
@ -442,7 +450,8 @@
}
},
methods: {
onReceive(deviceState){//蓝牙/Mq通用消息处理
onReceive(deviceState, parsedMessage) { //蓝牙/Mq通用消息处理
switch (deviceState[0]) {
// 1设备切换灯光实时返回
case 1:
@ -452,13 +461,21 @@
this.sliderValue = deviceState[2];
this.deviceInfo.batteryRemainingTime = deviceState[3];
break;
case 6:
if(deviceState[1]==50){
this.popupType = 'person';
this.showPopupFlag = true;
this.popupMessage = '信息发送成功';
uni.hideLoading();
}
break;
// 12为设备实时上报
case 12:
this.currentMainMode = this.getMainLightModeLabel(
deviceState[
1]);
this.currentMainMode = this.getMainLightModeLabel(deviceState[1]);
this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
this.deviceInfo.alarmStatus= deviceState[6];//报警状态
this.itemInfo.alarmStatus= deviceState[6];
if (this.deviceInfo) {
this.deviceInfo.batteryPercentage = deviceState[3]; //第4位电量百分比
this.deviceInfo.chargeState = deviceState[4]; //第5位为充电状态0没有充电1正在充电2为已充满
@ -501,19 +518,19 @@
});
return;
}
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:"+ex.msg,"确定",these);
MsgError("连接错误:" + ex.msg, "确定", these);
});
return;
}
},
getDevice: function() {
if (ble) {
@ -556,7 +573,7 @@
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: '去连接',
buttonTextColor: '#FFFFFFde',
buttonTextColor: '#FFFFFFde',
showCancel: true,
okCallback: function() {
console.log("1111");
@ -583,10 +600,15 @@
return;
}
let data = rec.ReceiveData(receive, device, pagePath, recArr);
console.log("蓝牙收到消息", data)
this.onReceive(data.state);
let keys = Object.keys(data);
if (keys.length && "state" in data) {
this.onReceive(data.state, receive.str);
} else {
console.log("不是状态数据,丢弃", data);
}
},
bleStateBreak() {
if (this.Status.pageHide) {
return;
@ -620,7 +642,7 @@
text: ex.msg
})
these.formData.bleStatu = 'err';
MsgError("连接错误:"+ex.msg,"确定",these);
MsgError("连接错误:" + ex.msg, "确定", these);
}).finally(() => {
setTimeout(() => {
hideLoading(these);
@ -737,60 +759,62 @@
});
},
onSliderChanging(e) {
if (!this.cardRect) return;
let value = e.detail.value;
if (value < 10) {
value = 10;
}
this.sliderValue = value; // 实时更新UI
const now = Date.now();
// 使用节流防止指令发送过于频繁
if (now - this.lastBrightnessTime > 200) { // 200毫秒节流
this.lastBrightnessTime = now;
return;
// const now = Date.now();
// // 使用节流防止指令发送过于频繁
// if (now - this.lastBrightnessTime > 200) { // 200毫秒节流
// this.lastBrightnessTime = now;
let mqSend = () => {
// let mqSend = () => {
// 增加轻微的震动反馈,提升手感
uni.vibrateShort({
type: 'light'
});
// // 增加轻微的震动反馈,提升手感
// uni.vibrateShort({
// type: 'light'
// });
let data = {
deviceId: this.computedDeviceId,
instructValue: this.sliderValue + '.00',
deviceImei: this.itemInfo.deviceImei,
}
lightBrightnessSettings(data).then((res) => {
if (res.code !== 200) {
// 可以在这里处理错误但滑动中不建议用toast
}
})
}
// let data = {
// deviceId: this.computedDeviceId,
// instructValue: this.sliderValue + '.00',
// deviceImei: this.itemInfo.deviceImei,
// }
// lightBrightnessSettings(data).then((res) => {
// if (res.code !== 200) {
// // 可以在这里处理错误但滑动中不建议用toast
// }
// })
// }
if (ble && this.itemInfo.deviceMac) {
let f = this.getDevice();
if (f) {
let json = {
instruct: [5, 0, 0, 0, 0]
};
json.instruct[1] = parseInt(this.sliderValue);
// if (ble && this.itemInfo.deviceMac) {
// let f = this.getDevice();
// if (f) {
// let json = {
// instruct: [5, 0, 0, 0, 0]
// };
// json.instruct[1] = parseInt(this.sliderValue);
ble.sendString(f.deviceId, json).then(res => {
// ble.sendString(f.deviceId, json).then(res => {
}).catch(ex => {
mqSend();
});
} else {
mqSend();
}
return;
} else {
mqSend();
}
}
// }).catch(ex => {
// mqSend();
// });
// } else {
// mqSend();
// }
// return;
// } else {
// mqSend();
// }
// }
},
onSliderChangeEnd(e) {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
let value = e.detail.value;
if (value < 10) {
value = 10;
@ -847,6 +871,10 @@
}
},
selectMode(type) {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
this.modeType = type;
this.lightModeA = true;
if (type === 'main') {
@ -906,7 +934,10 @@
},
// 灯光模式的确认
handleSumbit() {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
if (this.selectedItemIndex === null) return;
const selectedItem = this.items[this.selectedItemIndex];
@ -928,8 +959,13 @@
};
lightModeSettings(data).then((res) => {
if (res.code == 200) {
this.currentMainMode = this.pendingMainMode;
this.selectedItemIndex = selectedItem;
this.currentMainMode = this.getMainLightModeLabel(selectedItem.instructValue);
this.isLaserOn = false; //第3位表示当时激光灯档位
this.currentlaserMode = "关闭";
uni.showToast({
title: res.msg,
icon: 'none'
@ -959,8 +995,11 @@
json.instruct[1] = parseInt(selectedItem.instructValue);
ble.sendString(f.deviceId, json).then(res => {
console.log("ble send success",json);
console.log("ble send success", json);
this.lightModeA = false;
this.currentMainMode = this.getMainLightModeLabel(selectedItem.instructValue);
this.isLaserOn = false;
this.currentlaserMode = "关闭";
}).catch(ex => {
console.error("ble send fail,mqsending....")
mqSend();
@ -976,15 +1015,23 @@
},
// 激光模式
lasermode() {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
this.lightModeC = true
},
// 激光确认框提交
handleBtn() {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
const instructValue = this.isLaserOn ? 0 : 1;
let mqSend = () => {
@ -1011,6 +1058,10 @@
// 更新状态
this.isLaserOn = !this.isLaserOn;
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
this.currentMainMode = this.getMainLightModeLabel(0);
this.lightModeC = false;
} else {
uni.showToast({
@ -1035,6 +1086,8 @@
this.lightModeC = false;
this.isLaserOn = !this.isLaserOn;
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
this.currentMainMode = this.getMainLightModeLabel(0);
}).catch(ex => {
mqSend();
});
@ -1052,7 +1105,12 @@
},
// 上传开机画面
uploadStartup() {
this.lightModeB = true
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
this.lightModeB = true;
this.selectedImage=null;
},
// 上传开机画面
checkImgUpload() {
@ -1102,6 +1160,10 @@
});
return;
}
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
let mqSend = () => {
if (this.deviceInfo.onlineStatus !== 1) {
@ -1264,9 +1326,9 @@
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x02); // 帧类型:开机画面
dataView.setUint8(2, currentPacket); // 包序号
dataView.setUint16(3, packetData.length*2,false); // 包t长度
dataView.setUint16(3, packetData.length * 2, false); // 包t长度
// 填充数据每个RGB565值占2字节
for (let i = 0; i < packetData.length; i++) {
@ -1338,11 +1400,11 @@
});
}
setTimeout(()=> {
setTimeout(() => {
sendImagePackets().catch(() => {
}).finally(()=>{
this.lightModeB=false;
}).finally(() => {
this.lightModeB = false;
});
}, 0)
}
@ -1373,6 +1435,11 @@
},
// 发送人员信息
sendPersonnelInfo() {
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
let mqSend = async () => {
if (this.isSending) return;
const requiredFields = [{
@ -1532,9 +1599,9 @@
hideLoading();
return;
}
let packData = combinedData[curr - 1];
let array = {
instruct: [2, curr].concat(combinedData[curr - 1])
instruct: [2, curr, packData.length].concat(packData)
};
@ -1574,15 +1641,17 @@
setTimeout(() => {
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(
results => {
console.log("results=", results);
if (results[0].status == 'rejected') {
MsgError(results[0].reason.code + ':' + results[0].reason.msg, '',
these);
setTimeout(() => {
hideLoading(these)
}, 500);
return;
}
if (results[1].status == 'rejected') {
MsgError("无法完成文字取模", '', these);
return;
}
@ -1615,32 +1684,36 @@
this.showPopupFlag = true;
// this.popupConfirmText="";
},
OpenWarn(val){//开启/解除强制报警
debugger;
OpenWarn(val) { //开启/解除强制报警
debugger;
const topic = `B/${this.itemInfo.deviceImei}`;
let message={"instruct":[7,val,0,0,0,0]};
message=JSON.stringify(message);
let flag=this.mqttClient.publish(topic, message, {
let message = {
"instruct": [7, val, 0, 0, 0, 0]
};
message = JSON.stringify(message);
let flag = this.mqttClient.publish(topic, message, {
qos: 1
});
if(flag){
this.itemInfo.alarmStatus=val;
}else{
MsgError("操作没有成功",'确定',this);
if (flag) {
this.itemInfo.alarmStatus = val;
this.deviceInfo.alarmStatus = val;
} else {
MsgError("操作没有成功", '确定', this);
}
this.showPopupFlag = false;
this.onPopupConfirm();
},
warnToggle(){
if(this.itemInfo.alarmStatus==1){
warnToggle() {
if (this.itemInfo.alarmStatus == 1) {
this.popupType = 'cancel';
this.popupMessage = '确认解除报警状态';
}else{
} else {
this.popupType = 'openWarn';
this.popupMessage = '确认开启报警状态';
}
this.showPopupFlag = true;
// this.popupConfirmText="开启";
@ -1650,25 +1723,25 @@
// val=0;
// msg="确认解除强制报警?";
// }
// let mqSend=()=>{
// const topic = `B/${this.itemInfo.deviceImei}`;
// let message={"instruct":[7,val,0,0,0,0]};
// message=JSON.stringify(message);
// let flag=this.mqttClient.publish(topic, message, {
// qos: 1
// });
// if(flag){
// this.itemInfo.alarmStatus=val;
// }
// }
},
// 解除报警逻辑
async onPopupConfirmPolice() {
if (this.deviceInfo.onlineStatus !== 1) {
@ -1676,7 +1749,7 @@
// title: '设备已离线',
// icon: 'none'
// });
this.OpenWarn(0);//走mq直发
this.OpenWarn(0); //走mq直发
return;
}
this.isPolling = true; // 标记开始轮询
@ -1701,14 +1774,18 @@
// title: registerRes.msg,
// icon: 'none'
// })
this.OpenWarn(0);
return
}
this.itemInfo.alarmStatus=0;
this.itemInfo.alarmStatus = 0;
this.deviceInfo.alarmStatus = 0;
uni.hideLoading();
this.showPopupFlag = false
// 4. 获取设备状态FunctionAccessBatchStatusRule 批量
let deviceImei = this.itemInfo.deviceImei
let typeName = this.itemInfo.typeName
const statusRes = await getdeviceSTatus({
getdeviceSTatus({
functionMode: 2,
batchId,
typeName: 'FunctionAccessBatchStatusRule',
@ -1716,22 +1793,26 @@
interval: 500
},
deviceRealTimeStatus
);
if (statusRes.data.functionAccess === 'OK') {
uni.showToast({
title: statusRes.msg,
icon: 'none'
});
uni.$emit('deviceStatusUpdate', {});
this.showPopupFlag = false
if (this.apiType === 'listA') {
this.fetchDeviceDetail(this.computedDeviceId)
} else {
// 分享权限详情
this.fetchSharedDeviceDetail(this.itemInfo.id)
}
).then(statusRes => {
if (statusRes.data.functionAccess === 'OK') {
uni.showToast({
title: statusRes.msg,
icon: 'none'
});
uni.$emit('deviceStatusUpdate', {});
if (this.apiType === 'listA') {
this.fetchDeviceDetail(this.computedDeviceId)
} else {
// 分享权限详情
this.fetchSharedDeviceDetail(this.itemInfo.id)
}
}
}).catch(ex => {
console.error("出现错误", ex);
});
}
} catch (error) {
uni.showToast({
title: error.message,
@ -1751,6 +1832,12 @@
});
return;
}
if (this.deviceInfo.alarmStatus == 1) {
MsgError('请先解除强制报警', '', these);
return;
}
// 防重复提交
if (this.isSending) return;
if (!this.messageToSend) {
@ -1801,9 +1888,9 @@
);
// 只有当状态为'OK'时才显示成功弹窗
if (statusRes.data.functionAccess === 'OK') {
this.popupType = 'person';
this.showPopupFlag = true;
this.popupMessage = '信息发送成功';
// this.popupType = 'person';
// this.showPopupFlag = true;
// this.popupMessage = '信息发送成功';
}
} catch (error) {
uni.showToast({
@ -1899,7 +1986,7 @@
}
}
},
// 发送mqtt查询设备信息
queryDeviceStatus() {
if (this.mqttClient && this.mqttClient.isConnected()) {
@ -1955,14 +2042,30 @@
this.mqttClient.subscribe(statusTopic, (payload) => {
try {
console.log(`收到来自 ${statusTopic} 的消息:`, payload);
console.log("typeof payload=", typeof payload);
const parsedMessage = typeof payload === 'string' ? JSON.parse(
payload) :
payload;
const deviceState = parsedMessage.state; // 直接取 state 数组
// 切换主灯光模式,亮度值设备同步
if (!deviceState) return;
this.onReceive(deviceState);
payload) : payload;
let keys = Object.keys(parsedMessage);
if("sta_BreakNews" in parsedMessage){
console.error("收到确认消息")
if(parsedMessage.sta_BreakNews=='I get it'){
MsgSuccess("用户已确认收到紧急通知","",this);
}
}
else if (keys.length && "state" in parsedMessage) {
const deviceState = parsedMessage.state; // 直接取 state 数组
// 切换主灯光模式,亮度值设备同步
if (!deviceState || !deviceState instanceof Array) {
return;
}
this.onReceive(deviceState, parsedMessage);
}else{
console.error("丢弃的消息",payload)
}
} catch (error) {
console.log('解析MQTT消息失败:', error, '原始消息:', payload);
}
@ -1999,10 +2102,10 @@
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(
res => {
these.formData.bleStatu = true;
}).catch(ex=>{
these.formData.bleStatu = 'err';
MsgError("连接错误:"+ex.msg,"确定",these);
});
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
});
}
}
@ -2022,8 +2125,8 @@
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
this.formData.bleStatu = true;
}).catch(ex=>{
MsgError("连接错误:"+ex.msg,"确定",these);
}).catch(ex => {
MsgError("连接错误:" + ex.msg, "确定", these);
});
}
},
@ -2261,8 +2364,9 @@
box-sizing: border-box;
border: 1rpx solid #00000000;
}
.mode-v1.active{
border:1rpx solid #bbe600 !important;
.mode-v1.active {
border: 1rpx solid #bbe600 !important;
}
.mode-v2 {