1
0
forked from dyf/APP

650完成,670完成部分

This commit is contained in:
liub
2025-08-25 17:13:13 +08:00
parent 793fe7132b
commit bbf55c58f0
23 changed files with 16897 additions and 221 deletions

View File

@ -77,7 +77,7 @@
</view>
<view class="mode marginLeft fleft" :class="formData.cMode=='mode'?'':'active'"
v-on:click.stop="UploadOpenImg()">
v-on:click.stop="ShowUpload()">
<view class="leftImg">
<image class="img" src="/static/images/6155/DeviceDetail/open.png" mode="aspectFit"></image>
</view>
@ -89,19 +89,19 @@
<view class="clear"></view>
</view>
<view class="usrinfo">
<view @click="formData.usrToggle=!formData.usrToggle">
<view @click="Status.usrToggle=!Status.usrToggle">
<text class="usrtitle fleft">人员信息登记</text>
<view class="image fright" :style="{transform:formData.usrToggle?'rotate(0deg)':'rotate(180deg)' }">
<view class="image fright" :style="{transform:Status.usrToggle?'rotate(0deg)':'rotate(180deg)' }">
<image class="img" src="/static/images/6155/DeviceDetail/slideToggle.png" mode="aspectFit"></image>
</view>
<view class="clear"></view>
</view>
<view :class="formData.usrToggle?'':'displayNone'">
<view :class="Status.usrToggle?'':'displayNone'">
<view style="margin: 20rpx 0rpx;">
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="btnSend fright" v-on:click.stop="sendUsr(null)">发送</view>
<view class="clear"></view>
</view>
<view class="item">
@ -235,7 +235,7 @@
maskBgColor: '#00000066',
showClose: false
},
usrToggle: true,
},
formData: {
img: '/static/images/6155/DeviceDetail/equip.png',
@ -251,17 +251,14 @@
macAddress: '',
cMode: false,
modeCurr: 'low',
usrToggle: true,
company: '黄石消防支队',
name: '菜英俊',
job: '小队长',
id: 'HSXF01061',
iswarn: false
},
rgb565Data: [],
videoHexArray: []
}
},
@ -377,19 +374,41 @@
return className;
},
bleValueNotify: function(receive, device, path) { //订阅消息
let data = recei.ReceiveData(receive, device, pagePath);
console.log("收到设备的数据",data)
if (data) {
console.log("收到订阅消息", receive);
if ("staBlue_picture" in data) {
//重发图片
console.log("收到重新发送图片的命令");
this.checkImgUpload('img', data.staBlue_picture);
return;
} else if ("staBlue_text" in data) {
//重发文本
console.log("收到重新发送文本的命令");
this.sendUsr(data.staBlue_text);
return;
} else if ("staBlue_vidio" in data) {
//重发视频
console.log("收到重新发送视频的命令");
this.checkImgUpload('video', data.staBlue_vidio);
return;
} else if ("staBlue" in data) {
if (data.staBlue == "finish") {
console.log("收到设备回复,全部传输完成");
}
return;
}
let keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.formData[key] = data[key];
if(key in these.formData){
these.formData[key] = data[key];
}
}
if (these.formData.iswarn) {
these.showPop({
message: "环境存在漏电电源",
@ -398,7 +417,7 @@
buttonBgColor: "#E03434",
});
}
these.setBleFormData();
}
@ -412,8 +431,8 @@
},
getDevice: function() {
console.log("LinkedList=", ble.data.LinkedList);
console.log("formData=", these.formData);
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
});
@ -558,33 +577,22 @@
}
});
},
checkImgUpload: function() {
checkImgUpload: function(type, index) {
console.log("123213213213");
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const rgb565Data = ble.convertToRGB565(pixels);
// 分包发送
sendImagePackets(rgb565Data).then(resolve).catch(reject);
});
}
let f = these.getDevice();
// 分包发送图片数据
var sendImagePackets = function(imageData) {
var sendImagePackets = function(ReSendNo) {
return new Promise((resolve, reject) => {
// 总数据包数
const totalPackets = 52;
let totalPackets = 52;
let currentPacket = 1;
let f = these.getDevice();
if (ReSendNo) {
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
if (f) {
// 发送单个数据包
@ -597,6 +605,13 @@
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
});
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f.wirteCharactId);
},500);
}
resolve();
return;
@ -604,23 +619,23 @@
// 计算当前包的数据
let packetSize = 250;
if (currentPacket <= 51) {
packetSize = 250; // 前51个包每个500字节
} else {
packetSize = 50; // 最后一个包100字节
}
// if (currentPacket <= 51) {
// packetSize = 250; // 前51个包每个500字节
// } else {
// packetSize = 50; // 最后一个包100字节
// }
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData
const endIndex = Math.min(startIndex + packetSize, these.rgb565Data
.length);
if (startIndex > endIndex) {
return;
}
const packetData = imageData.slice(startIndex,
const packetData = these.rgb565Data.slice(startIndex,
endIndex);
// 构建数据包
const bufferSize = 5 + packetData.length * 2; // 头部5字节 + 数据部分
const bufferSize =505;// 5 + packetData.length * 2; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -644,6 +659,11 @@
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
}
if (currentPacket > 51) { //第52包补FF
for (var i = 105; i < bufferSize; i++) {
dataView.setUint8(i, 0xFF);
}
}
@ -681,7 +701,10 @@
});
}
if (ReSendNo) {
sendNextPacket(ReSendNo);
return;
}
// 开始牵手
these.HoldYouHand("picture transmit start", 120, f.deviceId, f.writeServiceId,
f.wirteCharactId).then(() => {
@ -713,8 +736,9 @@
});
these.Status.BottomMenu.show = false;
these.rgb565Data = ble.convertToRGB565(data);
setTimeout(function() {
processAndSendImageData(data).catch(() => {
sendImagePackets().catch(() => {
});
}, 0)
@ -730,6 +754,137 @@
});
}
let sendVideoPackets = (ReSendNo) => {
console.log("开始发送分片数据");
return new Promise((resolve, reject) => {
if (f) {
// 总数据包数
var totalPackets = 1536;
let currentPacket = 1;
console.log("发送数据准备中,总共" + totalPackets);
if (ReSendNo) {
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
this.totalPackets = totalPackets;
// 发送单个数据包
const sendNextVideoPacket = () => {
console.log("准备发送一段数据");
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f
.writeServiceId, f.wirteCharactId).then(()=>{
console.log("全部发送完毕")
}).catch((ex)=>{
console.log("出现异常",ex);
});
},500);
}
these.Status.BottomMenu.show = false;
hideLoading(these);
these.showPop({
showPop: true,
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
resolve();
return;
}
// 计算当前包的数据
let packetSize = 500;
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, these.videoHexArray
.length);
if (startIndex > endIndex) {
resolve();
return;
}
////console.log("111111");
const packetData = these.videoHexArray.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
let sortNo = currentPacket.toString(16).padStart(4, '0');
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x04); // 帧类型:开机画面
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
dataView.setUint8(4, 0x01);
dataView.setUint8(5, 0xF4);
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
let inteval = 50;
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 10).then(() => {
updateLoading(these, {
text: "正在发送:" + currentPacket + "/" +
totalPackets
})
currentPacket++;
console.log("发送一段成功,发送下一段");
setTimeout(sendNextVideoPacket, inteval);
}).catch(err => {
console.log("发送失败了");
if (err.code == '10007') { //遇到这个错误自动重新发送
console.log(err.errMsg + ",发送失败了,正在补偿:" +
currentPacket);
setTimeout(sendNextVideoPacket, inteval);
} else {
these.Status.BottomMenu.show = false;
hideLoading(these);
these.showPop({
showPop: true,
message: err.msg + ",发送失败了",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: "确定",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png"
});
reject(err);
return;
}
});
};
sendNextVideoPacket();
} else {
console.log("Fail.......")
}
});
}
var sendVideo = (videoPath) => {
let uploadVideo = () => {
@ -740,7 +895,7 @@
}
console.log("开始处理,正在上传");
let f = this.getDevice();
showLoading(these, {
text: "上传中"
});
@ -809,123 +964,13 @@
})
}
let f = these.getDevice();
console.log("f=", f);
let sendVideoPackets = (imageData) => {
console.log("开始发送分片数据");
return new Promise((resolve, reject) => {
if (f) {
// 总数据包数
const totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
console.log("发送数据准备中,总共" + totalPackets);
// 发送单个数据包
const sendNextVideoPacket = () => {
console.log("准备发送一段数据");
if (currentPacket > totalPackets) {
these.Status.BottomMenu.show = false;
hideLoading(these);
these.showPop({
showPop: true,
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
these.videoHexArray = [];
resolve();
return;
}
// 计算当前包的数据
let packetSize = 500;
// 创建数据包
const startIndex = (currentPacket - 1) * packetSize;
const endIndex = Math.min(startIndex + packetSize, imageData
.length);
if (startIndex > endIndex) {
resolve();
return;
}
////console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
let sortNo = currentPacket.toString(16).padStart(4, '0');
// 填充头部
dataView.setUint8(0, 0x55); // 帧头
dataView.setUint8(1, 0x04); // 帧类型:开机画面
dataView.setUint8(2, '0x' + sortNo.substring(0, 2)); // 包序号
dataView.setUint8(3, '0x' + sortNo.substring(2, 4)); // 包序号
dataView.setUint8(4, 0x01);
dataView.setUint8(5, 0xF4);
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6 + i, '0x' + packetData[i]);
}
let inteval = 50;
console.log("开始发送一段视频"); //
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 10).then(() => {
updateLoading(these, {
text: "正在发送:" + currentPacket + "/" +
totalPackets
})
currentPacket++;
console.log("发送一段成功,发送下一段");
setTimeout(sendNextVideoPacket, inteval);
}).catch(err => {
if (err.code == '10007') { //遇到这个错误自动重新发送
console.log(err.errMsg + ",发送失败了,正在补偿:" +
currentPacket);
setTimeout(sendNextVideoPacket, inteval);
} else {
these.Status.BottomMenu.show = false;
hideLoading(these);
these.showPop({
showPop: true,
message: err.msg + ",发送失败了",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText: "确定",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png"
});
reject(err);
return;
}
});
};
sendNextVideoPacket();
} else {
console.log("Fail.......")
}
});
}
let shotVideoClick = (array) => {
let shotVideoClick = () => {
console.log("正在开始发送");
sendVideoPackets(array).then(() => {
sendVideoPackets().then(() => {
console.log("发送完成");
}).catch((ex1) => {
@ -940,6 +985,14 @@
}
if (type) {
if (type == 'img') {
sendImagePackets(index);
} else if (type == 'video') {
sendVideoPackets(index);
}
return;
}
uni.chooseMedia({
count: 1,
mediaType: ['image', 'video'],
@ -968,16 +1021,9 @@
}
});
// uni.chooseImage({
// count: 1,
// sizeType: ['original', 'compressed'],
// sourceType: ['album'],
// success: function(res) {
// gotoCutImg(res.tempFiles[0].path);
// }
// });
},
UploadOpenImg: function() {
ShowUpload: function() {
//上传开机画面
this.Status.BottomMenu.menuItems = [];
this.Status.BottomMenu.title = "上传开机画面";
@ -1043,7 +1089,7 @@
}
these.Status.Pop.showPop = true;
},
sendUsr: function() {
sendUsr: function(ReSendNo) {
@ -1052,7 +1098,6 @@
this.formData.name,
this.formData.job,
this.formData.id
];
@ -1070,17 +1115,28 @@
text: "请稍候..."
});
var sendText = function() {
// 总数据包数
const totalPackets = textLines.length;
let totalPackets = textLines.length;
let currentPacket = 1;
// console.log("currentPacket=",currentPacket);
// console.log("ReSendNo=",ReSendNo);
if (ReSendNo) {
totalPackets = ReSendNo;
currentPacket = ReSendNo;
}
// console.log("currentPacket=",currentPacket);
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
if (!ReSendNo) {
setTimeout(()=>{
these.HoldYouHand("transmit complete", 0, f.deviceId, f.writeServiceId, f
.wirteCharactId);
},500);
}
these.showPop({
showPop: true, //是否显示弹窗
popType: 'custom',
@ -1107,9 +1163,9 @@
let arr = gbk.encode(text)
let gbkData = gbk.arr2hex(arr);
console.log(JSON.stringify(gbkData));
// 构建数据包
const bufferSize = 5 + text.length * 2; // 头部4字节 + 数据部分
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -1118,19 +1174,16 @@
dataView.setUint8(1, 0x03); // 帧类型:文字
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度
console.log("gbkData.length=" + gbkData.length)
// 填充数据
for (let i = 1; i <= text.length * 2; i++) {
const highNibble = gbkData[i * 2 - 2]; // 高4位
const lowNibble = gbkData[i * 2 - 1]; // 低4位如果是奇数长度补0
//console.log("i=" + i + "," + highNibble + lowNibble)
// 组合高低位并转换为字节值
const byteValue = parseInt(highNibble + lowNibble, 16);
dataView.setUint8(5 + i - 1, byteValue);
// 填充数据
let index = 0;
for (var i = 0; i < gbkData.length; i += 2) {
let value = parseInt(gbkData[i] + "" + gbkData[i + 1], 16);
dataView.setUint8(5 + index, value);
index++;
}
console.log("dataView.length=" + dataView.byteLength)
// 发送数据包
@ -1166,7 +1219,10 @@
}
if(ReSendNo){
sendText(ReSendNo);
return;
}
setTimeout(() => {
these.HoldYouHand("word transmit start", 120, f.deviceId, f.writeServiceId, f
.wirteCharactId).then(