1
0
forked from dyf/APP

更新100、670电量低的提示方式为监听式

This commit is contained in:
liub
2026-03-09 16:10:48 +08:00
parent 0aa012d9c7
commit 1eae2d1d91
7 changed files with 214 additions and 244 deletions

View File

@ -63,6 +63,10 @@ export function mapReverseGeocoding(data) {
})
}
export function deviceRealTimeStatus(){
return Promise.resolve({code:500});
export function deviceRealTimeStatus(params){
return request({
url: `/app/device/realTimeStatus`,
method: 'get',
data:params
})
}

View File

@ -2,7 +2,7 @@
"name" : "星汉物联",
"appid" : "__UNI__A21EF43",
"description" : "设备管控",
"versionName" : "1.0.18",
"versionName" : "1.0.19",
"versionCode" : 101,
"transformPx" : false,
/* 5+App */
@ -114,7 +114,8 @@
"xhdpi" : "unpackage/res/icons/48x48.png",
"xxhdpi" : "unpackage/res/icons/72x72.png"
}
}
},
"meizu" : {}
}
}
},

View File

@ -223,11 +223,11 @@
</view>
<view class="proinfo lamp">
<text class="title">产品信息</text>
<view class="itemcontent">
@ -245,18 +245,18 @@
</view>
</view>
</view>
<!-- 弹窗通知 -->
<MessagePopup :visible="Status.Pop.showPop" :type="Status.Pop.popType" :bgColor="Status.Pop.bgColor"
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" />
<!-- 下方菜单 -->
<!-- <BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
<MessagePopup :visible="Status.Pop.showPop" :type="Status.Pop.popType" :bgColor="Status.Pop.bgColor"
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
@buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText"
:showCancel="Status.Pop.showCancel" @cancelPop="closePop" />
<!-- 下方菜单 -->
<!-- <BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@btnClick="btnClick">
<view>
<view class="addIco">
@ -266,8 +266,8 @@
</view>
</view>
</BottomSlideMenuPlus> -->
<global-loading ref="loading" />
<global-loading ref="loading" />
</view>
</template>
@ -518,6 +518,11 @@
recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool();
this.$watch("formData.sta_battery", (newVal, oldVal) => {
if (newVal <= 20 && this.formData.sta_system==2) {
this.showMsg("设备电量低");
}
});
ble.addReceiveCallback(this.bleValueNotify, pagePath);
ble.addStateBreakCallback(this.bleStateBreak, pagePath);
@ -572,10 +577,10 @@
these.formData.bleStatu = false;
these.formData.deviceId = f.deviceId;
these.formData.bleStatu = 'connecting';
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex=>{
}).catch(ex => {
these.formData.bleStatu = 'err';
});
these.setBleFormData();
@ -592,17 +597,17 @@
this.Status.pageHide = false;
},
computed: {
getbleStatu(){
if(this.formData.bleStatu===true){
getbleStatu() {
if (this.formData.bleStatu === true) {
return '已连接';
}
if(this.formData.bleStatu==='connecting'){
if (this.formData.bleStatu === 'connecting') {
return '连接中';
}
if(this.formData.bleStatu==='dicconnect'){
if (this.formData.bleStatu === 'dicconnect') {
return '正在断开';
}
if(this.formData.bleStatu==='err'){
if (this.formData.bleStatu === 'err') {
return '连接异常';
}
return '未连接';
@ -1196,9 +1201,9 @@
return;
}
if (res.deviceId == these.formData.deviceId) {
if(res.device){
if (res.device) {
these.formData.bleStatu = 'connecting';
}else{
} else {
this.formData.bleStatu = false;
}
setTimeout(() => {
@ -1233,14 +1238,14 @@
showLoading(this, {
text: "蓝牙恢复可用,正在连接设备"
});
these.formData.bleStatu='connecting';
these.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
updateLoading(these, {
text: '连接成功'
});
}).catch(ex => {
these.formData.bleStatu='err';
these.formData.bleStatu = 'err';
updateLoading(these, {
text: ex.msg
})
@ -1313,9 +1318,10 @@
}
});
if (this.formData.sta_battery <= 20) {
this.showMsg("设备电量低");
}
},
getDevice: function() {
@ -1327,32 +1333,32 @@
return f;
},
bleStatuToggle(){
let f=this.getDevice();
if(!f){
bleStatuToggle() {
let f = this.getDevice();
if (!f) {
this.showBleUnConnect();
return;
}
if(this.formData.bleStatu===true){
this.formData.bleStatu='dicconnect';
ble.disconnectDevice(f.deviceId).finally(r=>{
this.formData.bleStatu=false;
if (this.formData.bleStatu === true) {
this.formData.bleStatu = 'dicconnect';
ble.disconnectDevice(f.deviceId).finally(r => {
this.formData.bleStatu = false;
});
return;
}
if(this.formData.bleStatu===false || this.formData.bleStatu==='err'){
this.formData.bleStatu='connecting';
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
this.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
}).catch(ex=>{
}).catch(ex => {
these.formData.bleStatu = 'err';
});
return;
}
},

View File

@ -411,7 +411,8 @@
staPowerTime: null,
staPowerPercent: null,
staDetectResult: null
}
},
inteval:50
}
},
computed: {
@ -994,179 +995,146 @@
}
let f = this.getDevice();
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const arr = Common.convertToRGB565(pixels, 'bgr');
var list = [];
let index = 0; // 用于追踪arr的当前位置
let packetSize = 2048;
let cSize = 248;
// 外层循环7个主要元素i从1到7
for (let i = 1; i < 8; i++) {
let secondLevel = [];
let secondCnt = 0;
// 中层循环每个主要元素包含9个子数组j从1到9
for (let j = 1; j < 10; j++) {
// 确定当前子数组的长度前8个是254第9个是64
let thirdLevel = [];
// 从arr中提取相应数量的元素
for (let k = 0; k < cSize && index < arr.length; k++) {
if (secondCnt == packetSize) {
break;
}
thirdLevel.push(arr[index]);
secondCnt++;
index++;
}
secondLevel.push(thirdLevel);
}
list.push(secondLevel);
}
console.log("list=", list);
let length = 0;
for (let i = 0; i < list.length; i++) {
const item = list[i];
let clength = 0;
for (let j = 0; j < item.length; j++) {
const element = item[j];
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
length += element.length;
clength += element.length;
}
}
// 分包发送
sendImagePackets(list).then(resolve).catch(reject);
});
}
// 分包发送图片数据
var sendImagePackets = function(imageData) {
var sendImagePackets = function(ReSendNo) {
return new Promise((resolve, reject) => {
// 总数据包数
const totalPackets = 7;
let totalPackets = 52;
let currentPacket = 1;
let childPacket = 1;
let totalChildPacket = 9;
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
setTimeout(() => {
if (ReSendNo) {
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
if (f) {
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
hideLoading(these);
MsgSuccess("上传成功", "确定", these);
these.closeAction();
these.showPop({
showPop: true,
message: "上传成功",
iconUrl: "/static/images/common/success.png",
});
setTimeout(()=>{
ble.sendString(f.deviceId, "transmit complete", f.writeServiceId, f
.wirteCharactId);
},1000);
these.rgb565Data = null;
resolve();
}, 3000)
return;
}
// 计算当前包的数据
let packetSize = 250;
// if (currentPacket <= 51) {
// packetSize = 250; // 前51个包每个500字节
// } else {
// packetSize = 50; // 最后一个包100字节
// }
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, these.rgb565Data
.length);
if (startIndex > endIndex) {
return;
}
const packetData = these.rgb565Data.slice(startIndex,
endIndex);
// 构建数据包
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x02); // 帧类型:开机画面
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
'0')); // 包序号
if (packetData.length == 250) {
dataView.setUint8(3, 0x01);
dataView.setUint8(4, 0xF4);
} else {
dataView.setUint8(3, 0x00);
dataView.setUint8(4, 0x64);
}
// 填充数据每个RGB565值占2字节
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
}
if (currentPacket > 51) { //第52包补FF
for (var i = 105; i < bufferSize; i++) {
dataView.setUint8(i, 0xFF);
}
}
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
10)
.then(() => {
updateLoading(these, {
text: "正在发送:" + currentPacket + "/" +
totalPackets
})
currentPacket++;
setTimeout(sendNextPacket, these.inteval);
}).catch(err => {
console.log("发送数据包失败了" + JSON.stringify(err));
if (err.code == '10007') {
setTimeout(sendNextPacket, these.inteval);
return;
}
these.closeAction();
these.showPop({
message: err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
hideLoading(these);
these.rgb565Data = null;
reject(err);
});
}
if (ReSendNo) {
sendNextPacket(ReSendNo);
return;
}
var packetData = imageData[currentPacket - 1][childPacket - 1];
let start = 0;
let bufferSize = packetData.length * 2;
if (currentPacket == 7) {
if (childPacket > 2 && childPacket < 9) {
bufferSize = 496;
} else if (childPacket == 9) {
bufferSize = 128;
}
}
if (childPacket == 1) {
bufferSize = bufferSize + 8
start = 8;
}
if (childPacket == 9) { //|| (currentPacket==7 && childPacket==3
bufferSize = bufferSize + 1
}
//FA 09 10 04 FC 09 [00] [01] + 4096字节+FF 数据格式
var buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer);
if (childPacket == 1) {
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, 0x10); // 帧头
dataView.setUint8(3, 0x04); // 帧头
dataView.setUint8(4, 0xFC); // 帧头
dataView.setUint8(5, 0x09); // 帧头
dataView.setUint8(6, 0x00); // 图序号,图片固定0视频的话要写序号
dataView.setUint8(7, currentPacket); //子包序号
}
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
}
console.log("packetData.length=", packetData.length);
console.log("bufferSize=", bufferSize)
if (childPacket == 9) { // || (currentPacket==7 && childPacket==3
dataView.setUint8(bufferSize - 1, 0xFF);
}
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, {
text: "正在发送" + curr + "/63"
})
if (childPacket == 9) {
currentPacket++;
childPacket = 1;
} else {
childPacket++;
}
setTimeout(sendNextPacket, 100);
}).catch(err => {
if (err.code == 10007) {
setTimeout(sendNextPacket, 100);
return;
}
console.log("发送数据包失败了", err);
showPop({
message: "发送数据包失败了" + err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
hideLoading(these);
reject(err);
// 开始牵手
ble.sendString(f.deviceId, "picture transmit start", f.writeServiceId,
f.wirteCharactId).then(() => {
setTimeout(sendNextPacket, 120);
}).catch((err) => {
console.log("握手没有成功");
these.showPop({
message: err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
hideLoading(these);
reject(err);
});
}
// 开始发送数据
sendNextPacket();
});
}
@ -1186,10 +1154,11 @@
});
these.rgb565Data = Common.convertToRGB565(data.piexls);
setTimeout(function() {
processAndSendImageData(data.piexls).catch((
ex) => {
console.log("出现异常", ex);
sendImagePackets().catch(() => {
});
}, 0)

View File

@ -486,10 +486,14 @@
},
onLoad: function() {
these = this;
recei = BleReceive.getBleReceive();
ble = BleTool.getBleTool();
this.$watch("formData.battary", (newVal, oldVal) => {
if (newVal <= 20 && this.formData.sta_system==2) {
this.showMsg("设备电量低");
}
});
ble.addReceiveCallback(these.bleValueNotify, pagePath);
@ -928,30 +932,16 @@
// console.log("收到文本回复", payload);
// // this.SendTxtMQ(json);
// }
if (keys.indexOf('sta_BreakNews') > -
1) { //紧急通知
if (json.sta_BreakNews ===
'I get it'
) // && this.Status.msgOkTime && this.Status.msgOkIntval){
{
these.showPop({
showPop: true,
message: "用户已确认收到紧急通知",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
// this.Status.msgOkTime=null
// clearInterval(this.Status.msgOkIntval);
}
}
// else {
// console.log("收到不能处理的数据", payload);
// }
if (keys.indexOf('sta_BreakNews') > -1) { //紧急通知
if(json.sta_BreakNews=='I get it'){
these.showPop({
showPop: true,
message: "用户已确认收到紧急通知",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
}
}
} catch (error) {
console.error("无法解析此消息", payload);
}

View File

@ -72,7 +72,6 @@
callback: this.scan
}],
title: '扫码'
},
},
formData: {
@ -208,7 +207,7 @@
this.qrCodeResult(cleanedResult, true, null);
},
fail: (err) => {
this.showMsg("扫码失败:" + err.errMsg, MsgType.error);
MsgError("扫码失败:" + err.errMsg,"确定",these);
}
});
},

View File

@ -187,7 +187,8 @@ import BleReceive from '@/utils/BleReceive';
navTitle: "我的设备",
deleteShow: false,
RenameModel: false,
menuItems: [{
menuItems: [
{
text: '扫一扫添加',
icon: '/static/images/common/scane.png',
action: 'scan'