1
0
forked from dyf/APP

图片裁剪页面加入自定义尺寸,7305修改发送文字和图片的方式

This commit is contained in:
liub
2025-10-15 16:40:02 +08:00
parent 8689781e17
commit fe87727e2d
7 changed files with 502 additions and 218 deletions

View File

@ -1,7 +1,7 @@
<template>
<view class="content contentBg">
<view class="eq">
<view class="leftImg">
<view class="leftImg" @click.stop="previewImg(formData.img)">
<image class="img" :src="formData.img" mode="aspectFit"></image>
</view>
<view class="rightTxt">
@ -83,7 +83,7 @@
<text class="usrtitle fleft">人员信息登记</text>
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></view>
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
<textToDotMatrix class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
:color="'#000000'" :fontSize="14" />
</view>
@ -124,8 +124,8 @@
: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" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle"
v-model="Status.Pop.modelValue" />
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
:promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
<!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@ -143,7 +143,7 @@
</template>
<script>
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
import textToDotMatrix from '@/components/TextToHex/textToDotMatrix.vue';
import bleTool from '@/utils/BleHelper.js';
import usrApi from '@/api/670/HBY670.js'
import {
@ -161,7 +161,7 @@
export default {
components: {
TextToHexV1
textToDotMatrix
},
data() {
return {
@ -182,7 +182,7 @@
promptTitle: '设备名称',
modelValue: '',
visibleClose: false,
okCallback:null
okCallback: null
},
BottomMenu: {
show: false,
@ -410,6 +410,15 @@
}
},
methods: {
previewImg(img) {
if (!img) {
return;
}
uni.previewImage({
urls: [img]
})
},
getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData);
@ -567,180 +576,83 @@
return;
}
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const arr = ble.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(packetData) {
return new Promise((resolve, reject) => {
// 总数据包数
const totalPackets = 7;
const totalPackets = 3;
let currentPacket = 1;
let childPacket = 1;
let totalChildPacket = 9;
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
setTimeout(() => {
hideLoading(these);
these.Status.BottomMenu.show = false;
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
resolve();
}, 20000)
}, 0)
return;
}
var packetData = imageData[currentPacket - 1][childPacket - 1];
// if (packetData.length == 0) {
// hideLoading(these);
// these.Status.BottomMenu.show = false;
// these.showPop({
// message: "上传成功",
// iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
// });
// resolve();
// return;
// }
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 数据格式
let bufferSize = 343; //总共1029字节3包正好每包343字节
//FA 09 04 00 1024字节 FF
var buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer);
if (childPacket == 1) {
if (currentPacket == 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); //子包序号
dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, 0x04); // 帧头
dataView.setUint8(3, 0x00); // 帧头
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(4 + i, parseInt(packetData[i],16));
}
}
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
if (currentPacket == totalPackets) {
dataView.setUint8(bufferSize - 1, 0xFF);
}
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
1000)
30)
.then(() => {
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, {
text: "正在发送" + curr + "/63"
text: "正在发送" + currentPacket + "/"+totalPackets
})
if (childPacket == 9) {
currentPacket++;
childPacket = 1;
} else {
childPacket++;
}
setTimeout(sendNextPacket, 1000);
currentPacket++;
setTimeout(sendNextPacket, 100);
}).catch(err => {
if (err.code == 10007) {
setTimeout(sendNextPacket, 1000);
setTimeout(sendNextPacket, 100);
return;
}
console.log("发送数据包失败了", err);
these.Status.BottomMenu.show = false;
these.showPop({
message: "发送数据包失败了" + err.msg,
@ -748,13 +660,14 @@
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
hideLoading(these);
reject(err);
});
}
// 开始发送数据
sendNextPacket();
});
}
@ -770,13 +683,115 @@
events: {
ImgCutOver: function(data) {
let binaryToHex = (binaryArray) => {
if (!Array.isArray(binaryArray) || binaryArray
.length !== 8) {
throw new Error("输入必须是包含8个元素的二进制数组");
}
// 检查每个元素是否为0或1
if (!binaryArray.every(bit => bit === 0 || bit ===
1)) {
throw new Error("数组元素必须只能是0或1");
}
// 将二进制数组转换为十进制数
let decimalValue = 0;
for (let i = 0; i < 8; i++) {
// 计算每个位的权重并累加
decimalValue += binaryArray[i] * Math.pow(2,
7 - i);
}
// 将十进制转换为十六进制字符串并添加0x前缀
const hexString = "0x" + decimalValue.toString(16)
.padStart(2, '0').toUpperCase();
return hexString;
}
let imageData = data.piexls;
let arr = [];
for (let x = 0; x < imageData.length; x += 4) {
let R = imageData[x];
let G = imageData[x + 1];
let B = imageData[x + 2];
let A = imageData[x + 3];
if (A < 128) {
arr.push(0);
continue;
}
let grayVal = Math.floor(R * 0.299 + G * 0.587 + B *
0.114);
// console.log("RGBA", R + "," + G + "," + B + "," + A +
// ',' + grayVal);
arr.push(grayVal < 128 ? 1 : 0);
}
let f = arr.filter(v => {
return v === 1;
});
//如果有超过1/3的亮点,将进行反色处理
if (f.length > arr.length / 3) {
for (var r = 0; r < arr.length; r++) {
if (arr[r] === 0) {
arr[r] = 1;
} else {
arr[r] = 0;
}
}
}
// console.log("arr=", JSON.stringify(arr));
let matrix = [];
let size = 512;
let len = arr.length / size;
for (let j = 0; j < len; j++) {
let start = j * size;
let end = start + size;
let firstHalf = arr.slice(start, end);
let arr64 = [];
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 64; col++) {
let ind = col + row * 64;
if (col === 63) {
}
let val = firstHalf[ind];
if (arr64.length < col + 1) {
arr64.push([])
}
arr64[col].push(val);
if (arr64[col].length === 8) {
arr64[col] = arr64[col].reverse();
matrix.push(binaryToHex(arr64[col]));
}
}
}
}
console.log("matrix=", JSON.stringify(matrix));
showLoading(these, {
text: "正在发送0/52"
text: "正在发送0/3"
});
these.Status.BottomMenu.show = false;
setTimeout(function() {
processAndSendImageData(data.piexls).catch((
sendImagePackets(matrix).catch((
ex) => {
console.log("出现异常", ex);
});
@ -786,7 +801,9 @@
},
success(ev) {
ev.eventChannel.emit('checkImg', {
data: res.tempFiles[0].path
data: res.tempFiles[0].path,
width: 64,
height: 32
})
},
fail(ex) {
@ -973,12 +990,12 @@
},
closePop: function() {
this.Status.Pop.showPop = false;
if (this.Status.Pop.cancelCallback) {
this.Status.Pop.cancelCallback();
}
},
this.Status.Pop.showPop = false;
if (this.Status.Pop.cancelCallback) {
this.Status.Pop.cancelCallback();
}
},
HidePop: function() {
console.log("1111");
if (this.Status.Pop.clickEvt == 'SendUsr') {
@ -1135,21 +1152,6 @@
return level1.flat(Infinity);
});
console.log("result=", result);
// var str1="FA 06 01 00 FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 FF 81 03 ED BB DD B7 CB CF F3 C7 CD 39 BE FF FE FF C0 03 FE FB FD FB F3 F7 8F 87 FF FF FF FF FE FF FE FF FE FF C0 03 FF FB FD FB FD FB FD FB FD FB FB FB FB FF F7 F7 EF F7 9F 8F FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
// var str2="FA 07 01 00 FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EF 77 EF 73 EF 7F 80 01 EF 7F EF 7F EF 03 E7 3B 8E BB EE D7 EE EF ED E7 ED 9B 8B 7D FF FF FF FF FF FF F7 EF F7 F7 EF F7 DF FB FF FF FF FF FE FF 80 01 FE 7F FD BF FB DF F7 E7 9F F9 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
// var str3="FA 08 01 00 FF FF EF DF EC 01 EF FF AB FF AA 03 AA FB AE FB EE 03 EF DF EF DF EE DB ED DF ED DD EF 1F FF FF FF FF EF BF EF 87 81 77 EE F7 EC 03 81 7F EF 7F EF 7F EF 03 81 7F EF 7F EF 7D EF 7D EF 03 FF FF FF FF F9 F1 CF BF DF FF DF FF C1 FF DD 81 DD F7 DD F7 C1 F7 DF 77 FF 77 BF 77 BF 77 FF F7 FF FF FF FF FD FF FD FF FB FF FB FF F0 07 E7 F7 EF F7 D8 07 BF F7 FF F7 F8 07 FF F7 FF F7 FF C7 FF FF FF FF FF FF FF FF FF FF FE FF FE 7F FE 7F FE FF FD BF FD FF FB DF F7 EF EF F7 DF FB BF FD FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
// result=[arr1,arr2,arr3];
// console.log("result=",result);
let h3dic = [0x06, 0x07, 0x08];
let pros = [];
let flag = true;