1
0
forked from dyf/APP

650添加应答,app图标添加

This commit is contained in:
liub
2025-09-15 11:55:44 +08:00
parent 6ee45f6868
commit 9c9c684ab6
27 changed files with 31504 additions and 7864 deletions

View File

@ -1,11 +1,11 @@
<template>
<view class="content">
<canvas canvas-id="flashCanvas"
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
<view>
重发包序号:{{reSendNumber}}
</view>
<view>
<text>发送间隔</text>
@ -13,7 +13,7 @@
</view>
<view>
<button @click="checkVideo">选择视频</button>
<!-- <button @click="CutImg">发送</button> -->
<button @click="uploadVideo">发送</button>
</view>
@ -28,8 +28,8 @@
</view>
</template>
<script>
import Common from '@/utils/Common';
<script>
import Common from '@/utils/Common';
export default {
data() {
@ -51,7 +51,7 @@ import Common from '@/utils/Common';
videoWidth: 320,
videoHeight: 160,
videoDuration: 2,
reSendNumber:null,
hexArray: []
}
@ -64,7 +64,17 @@ import Common from '@/utils/Common';
this.serviceId = data.serviceId;
this.writeCharacteristicId = data.writeCharacteristicId;
this.notifyCharacteristicId = data.notifyCharacteristicId;
})
});
eventChannel.on('ReSendVideo', (data) => {
//重新发送某一包
this.reSendNumber = data.videoNo;
setTimeout(() => {
this.shotVideoClick(this.hexArray, 'rgb565', data.videoNo);
}, 0);
});
},
methods: {
checkVideo: function() {
@ -76,9 +86,12 @@ import Common from '@/utils/Common';
success: (res) => {
this.videoPath = res.tempFilePath;
this.imgs = [];
this.hexArray = [];
this.$refs.compARef.base64 = [];
this.videoWidth = res.width;
this.videoHeight = res.height;
this.videoDuration = res.duration;
@ -95,24 +108,24 @@ import Common from '@/utils/Common';
return;
}
if(!this.videoPath){
if (!this.videoPath) {
uni.showToast({
title: "请选择视频",
icon: 'fail'
})
return;
}
console.log("正在上传视频");
uni.showLoading({
title: "上传中"
});
let p2=new Promise((resolve,reject)=>{
let p2 = new Promise((resolve, reject) => {
let start = new Date();
console.log("Common.baseURL="+Common.baseURL);
console.log("Common.baseURL=" + Common.baseURL);
uni.uploadFile({
url:Common.baseURL+'video/upload',
url: Common.baseURL + 'video/upload',
filePath: this.videoPath,
name: 'file',
header: {
@ -138,28 +151,28 @@ import Common from '@/utils/Common';
uni.hideLoading();
resolve(res);
}
});
});
let p1=this.HoldYouHand();
Promise.all([p2,p1]).then((arr)=>{
if(arr[1]===true){
let res=arr[0];
let p1 = this.HoldYouHand();
Promise.all([p2, p1]).then((arr) => {
if (arr[1] === true) {
let res = arr[0];
res = JSON.parse(res.data);
if (res.data) {
this.hexArray = res.data;
uni.showLoading({
title: "正在发送"
});
setTimeout(() => {
this.shotVideoClick(res.data, 'rgb565');
}, 0)
} else {
console.log("res")
uni.showModal({
@ -167,24 +180,39 @@ import Common from '@/utils/Common';
title: '错误'
})
}
}else{
} else {
uni.showModal({
content:"与设备握手失败了",
title:"错误"
content: "与设备握手失败了",
title: "错误"
})
}
});
},
shotVideoClick: function(array, type) {
bleSendComplete() {
var str = "transmit complete"; //握手的协议字符串
let buffer = new ArrayBuffer(str.length);
let dataView = new DataView(buffer);
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
}
setTimeout(() => {
this.sendData(buffer).then(() => {
console.log("完成指令发送成功");
}).catch(err => {
console.log("完成指令发送失败");
});
}, 3000)
},
shotVideoClick: function(array, type, ReSendNo) {
//console.log("处理视频完成", array);
//console.log("type=" + type)
//console.log("array=", array);
this.imgs = array;
var sendImagePackets = (imageData) => {
return new Promise((resolve, reject) => {
@ -197,12 +225,25 @@ import Common from '@/utils/Common';
const totalPackets = 1536;
this.totalPackets = totalPackets;
let currentPacket = 1;
if (ReSendNo) {
console.log("11111");
this.progress = ReSendNo - 1;
this.currentPacket = ReSendNo - 1;
console.log("22222");
this.totalPackets = ReSendNo;
console.log("11111=",ReSendNo);
}
// 发送单个数据包
const sendNextPacket = () => {
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
if (currentPacket > totalPackets) {
this.isSending = false;
if (!ReSendNo) {
this.bleSendComplete();
} else {
// this.reSendNumber="";
}
resolve();
return;
@ -221,11 +262,11 @@ import Common from '@/utils/Common';
resolve();
return;
}
////console.log("111111");
console.log("111111");
const packetData = imageData.slice(startIndex, endIndex);
// 构建数据包
////console.log("packetData.length"+packetData.length);
console.log("packetData.length"+packetData.length);
const bufferSize = 506; // 头部5字节 + 数据部分
const buffer = new ArrayBuffer(bufferSize);
const dataView = new DataView(buffer);
@ -256,11 +297,16 @@ import Common from '@/utils/Common';
let inteval = parseInt(this.inteval ? this.inteval : 0);
this.sendData(buffer).then(() => {
if(ReSendNo){
this.isSending = false;
resolve();
return;
}
// 更新进度
this.currentPacket = currentPacket;
this.progress = Math.round((currentPacket / totalPackets) *
100);
//console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
currentPacket++;
@ -277,8 +323,8 @@ import Common from '@/utils/Common';
});
};
sendNextPacket();
@ -294,12 +340,13 @@ import Common from '@/utils/Common';
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff-s) / 60;
let m = (diff - s) / 60;
console.log("发送完成,耗时:" + m + "分" + s + "秒");
uni.showToast({
title: "发送完成,耗时:" + m + "分" + s + "秒",
icon: 'success'
})
uni.showModal({
content:"发送完成,耗时:" + m + "分" + s + "秒",
title:"提示"
});
}).catch((ex1) => {
//console.log("出现了异常", ex1)
}).finally(() => {
@ -312,17 +359,17 @@ import Common from '@/utils/Common';
},
HoldYouHand() {
var promise=new Promise((resolve,reject)=>{
try{
let start=new Date();
var promise = new Promise((resolve, reject) => {
try {
let start = new Date();
var str = "video transmit start"; //握手的协议字符串
console.log("开始握手:"+str)
console.log("开始握手:" + str)
// 1. 创建 ArrayBuffer 和 DataView
const buffer = new ArrayBuffer(str.length);
const dataView = new DataView(buffer);
// 2. 将字符串转换为 ASCII 码并写入 DataView
for (let i = 0; i < str.length; i++) {
dataView.setUint8(i, str.charCodeAt(i));
@ -330,31 +377,31 @@ import Common from '@/utils/Common';
//console.log("111111");
this.sendData(buffer).then(() => {
// 开始发送第一个包
setTimeout(()=>{
setTimeout(() => {
let end = new Date();
var diff = (end.getTime() - start.getTime()) / 1000;
let s = diff % 60;
let m = (diff - s) / 60;
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
resolve(true);
console.log("握手成功并完成2200ms等待,耗时" + m + "分" + s + "秒");
resolve(true);
}, 2200);
}).catch(err => {
//console.log("握手没有成功");
reject(err);
});
}catch(ex){
} catch (ex) {
reject(ex);
}
});
return promise;
},
sendData(buffer) {
////console.log("deviceId=" + this.connectedDeviceId);
@ -415,18 +462,8 @@ import Common from '@/utils/Common';
promise.then(resolve).catch(reject);
}
});
},
CutImg: function() {
if (this.imgs.length == 30) {
this.shotVideoClick(this.imgs, 'img');
return;
}
//console.log("开始处理视频")
uni.showLoading({
title: '开始处理'
});
this.$refs.compARef.shotVideoClick(0);
}
}
}
</script>
@ -469,4 +506,19 @@ import Common from '@/utils/Common';
align-items: center;
justify-content: center;
}
.splash-frame {
height: 320rpx;
width: 640rpx;
border: 2rpx solid #409eff;
border-radius: 8rpx;
overflow: hidden;
position: relative;
background-color: #f0f0f0;
}
.splash-frame image {
width: 100%;
height: 100%;
}
</style>