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

@ -0,0 +1,231 @@
<template>
<view>
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
class="offscreen-canvas"></canvas>
</view>
</template>
<script>
export default {
name: "textToDotMatrix",
props: {
txts: {
type: Array,
default: () => [],
validator: (value) => value.every(item => typeof item === 'string')
},
fontSize: {
type: Number,
default: 16,
validator: (value) => value > 0 && value <= 100
},
bgColor: {
type: String,
default: "#ffffff"
},
color: {
type: String,
default: "#000000"
}
},
data() {
return {
// 当前Canvas的宽高动态调整
currentCanvasWidth: 0,
currentCanvasHeight: 0,
// Canvas上下文复用
ctx: null
};
},
computed: {
validTxts() {
return this.txts.filter(line => line.trim() !== '');
}
},
mounted() {
// 初始化Canvas上下文只创建一次
this.ctx = uni.createCanvasContext('reusableCanvas', this);
},
methods: {
/**
* 估算单行文本所需的Canvas宽度
*/
calcLineWidth(textLine) {
return textLine.length * 16;
},
/**
* 清除Canvas内容
*/
clearCanvas() {
this.ctx.setFillStyle(this.bgColor);
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
},
/**
* 复用单个Canvas处理所有文本行
*/
async drawAndGetPixels() {
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 convertCharToMatrix = (imageData, item) => {
// console.log("imgOldData=", imageData)
let matrix = [];
let arr = [];
for (let y = 0; y < 16; y++) {
for (let x = 0; x < 16; x++) {
// 计算像素在imageData中的索引 (RGBA格式)
let index = (y * 16 + x) * 4;
let red = imageData[index];
// 黑色像素R值较低视为1白色视为0
let isBlack = red < 128 ? 1 : 0;
arr.push(isBlack);
}
}
let firstHalf = arr.slice(0, arr.length / 2); // [1, 2, ..., 128]
let secondHalf = arr.slice(arr.length / 2); // [129, 130, ..., 256]
for (let i = 0; i < 16; i++) {
let tmp = [];
for (let index = i; index < firstHalf.length; index += 16) {
tmp.push(firstHalf[index]);
}
tmp = tmp.reverse();
matrix.push(binaryToHex(tmp));
}
for (let i = 0; i < 16; i++) {
let tmp = [];
for (let index = i; index < secondHalf.length; index += 16) {
tmp.push(secondHalf[index]);
}
tmp = tmp.reverse();
matrix.push(binaryToHex(tmp));
}
console.log("matrix=", matrix);
return matrix;
}
let drawTxt = async (textLine) => {
let result = {};
let ctx = this.ctx;
// 1. 动态调整Canvas尺寸
this.currentCanvasWidth = this.calcLineWidth(textLine);
this.currentCanvasHeight = 16;
// 2. 清空Canvas绘制背景
this.clearCanvas();
// 3. 设置文字样式
ctx.setFillStyle(this.color);
ctx.setTextBaseline('middle');
// ctx.setTextAlign('center')
ctx.setFontSize(this.fontSize);
ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
// 4. 绘制当前行文本
let currentX = 0;
let currentY = this.fontSize / 2;
for (let j = 0; j < textLine.length; j++) {
let char = textLine[j];
ctx.fillText(char, currentX, currentY);
// 按实际字符宽度计算间距
let charWidth = ctx.measureText(char).width;
currentX += charWidth;
}
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
await new Promise((resolve, reject) => {
ctx.draw(false, () => {
uni.canvasGetImageData({
canvasId: 'reusableCanvas',
x: 0,
y: 0,
width: this.currentCanvasWidth,
height: this.currentCanvasHeight,
success: res => {
result = {
line: textLine,
pixelData: res.data,
width: this.currentCanvasWidth,
height: this.currentCanvasHeight
};
resolve();
},
fail: err => {
// console.error(`处理第${i+1}行失败:`, err);
reject(err)
}
});
});
});
return result;
}
let arr = [];
// 循环处理每行文本
for (let i = 0; i < this.validTxts.length; i++) {
let linePixls = [];
let item = this.validTxts[i];
console.log("item=", item);
for (var j = 0; j < item.length; j++) {
let result = await drawTxt(item[j]);
linePixls.push(convertCharToMatrix(result.pixelData, item));
}
console.log("hexs=", linePixls.join(","));
arr.push(linePixls);
}
return arr;
}
}
};
</script>
<style>
.offscreen-canvas {
position: fixed;
left: -9999px;
top: -9999px;
visibility: hidden;
}
</style>

View File

@ -2,7 +2,7 @@
const config = { const config = {
// 开发环境 // 开发环境
development: { development: {
BASE_URL: 'https://www.cnxhyc.com/jq', BASE_URL: 'http://192.168.110.56:8000',
API_PREFIX: '', API_PREFIX: '',
// MQTT 配置 // MQTT 配置
MQTT_HOST: 'www.cnxhyc.com', MQTT_HOST: 'www.cnxhyc.com',

View File

@ -1,9 +1,9 @@
<template> <template>
<view> <view>
<canvas id="splashCanvas" canvas-id="splashCanvas" style="width: 160px; height: 80px; z-index: 9999;position: fixed; visibility: hidden;"></canvas> <canvas id="splashCanvas" canvas-id="splashCanvas" :style="{'width':width+'px','height':height+'px'}" style=" z-index: 9999;position: fixed; visibility: hidden;"></canvas>
<qf-image-cropper :src="src" :showAngle="false" :width="1600" :height="800" fileType="jpg" <qf-image-cropper :src="src" :showAngle="false" :width="cropWidth" :height="cropHeight" fileType="jpg"
@crop="handleCrop" :gpu="true"> @crop="handleCrop" :gpu="true">
</qf-image-cropper> </qf-image-cropper>
</view> </view>
@ -18,17 +18,29 @@
data() { data() {
return { return {
src: "", src: "",
Statu: false Statu: false,
width:160,
height:80
} }
}, },
computed:{
cropWidth(){
return this.width*10;
}
,
cropHeight(){
return this.height*10;
}
},
onLoad: function(option) { onLoad: function(option) {
const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
var these = this; var these = this;
eventChannel.on('checkImg', (data)=> { eventChannel.on('checkImg', (rec)=> {
console.log("我收到你的消息了,消息内容是:" + JSON.stringify(data)); console.log("我收到你的消息了,消息内容是:" + JSON.stringify(rec));
this.src = data.data; this.src = rec.data;
console.log("我收到你的消息了,消息内容是:",data); this.width=rec.width?rec.width:160;
this.height=rec.height?rec.height:80;
}) })
}, },
methods: { methods: {
@ -43,7 +55,7 @@
const ctx = uni.createCanvasContext('splashCanvas', this); const ctx = uni.createCanvasContext('splashCanvas', this);
ctx.drawImage( ctx.drawImage(
e.tempFilePath, e.tempFilePath,
0,0,160,80 0,0,these.width,these.height
); );
setTimeout(() => { setTimeout(() => {
ctx.draw(false, ()=>{ ctx.draw(false, ()=>{
@ -52,8 +64,8 @@
canvasId: 'splashCanvas', canvasId: 'splashCanvas',
x: 0, x: 0,
y: 0, y: 0,
width: 160, width: these.width,
height: 80, height: these.height,
success: (res) => { success: (res) => {
// 处理像素数据并发送 // 处理像素数据并发送
@ -81,8 +93,7 @@
<style> <style>
.canvas { .canvas {
width: 1600px;
height: 800px;
border: 1px solid #ccc; border: 1px solid #ccc;
} }
</style> </style>

View File

@ -1,7 +1,7 @@
<template> <template>
<view class="content contentBg"> <view class="content contentBg">
<view class="eq"> <view class="eq">
<view class="leftImg"> <view class="leftImg" @click.stop="previewImg(formData.img)">
<image class="img" :src="formData.img" mode="aspectFit"></image> <image class="img" :src="formData.img" mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
@ -410,6 +410,15 @@
} }
}, },
methods: { methods: {
previewImg(img){
if(!img){
return;
}
uni.previewImage({
urls:[img]
})
},
getDevice: function() { getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList); // console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData); // console.log("formData=", these.formData);

View File

@ -1,7 +1,7 @@
<template> <template>
<view class="content contentBg"> <view class="content contentBg">
<view class="eq"> <view class="eq">
<view class="leftImg"> <view class="leftImg" @click.stop="previewImg(formData.img)">
<image class="img" :src="formData.img" mode="aspectFit"></image> <image class="img" :src="formData.img" mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
@ -367,6 +367,15 @@
} }
}, },
methods: { methods: {
previewImg(img){
if(!img){
return;
}
uni.previewImage({
urls:[img]
})
},
getWarnStyle(index) { getWarnStyle(index) {
let className = ""; let className = "";
switch (this.formData.warnLevel) { switch (this.formData.warnLevel) {
@ -590,6 +599,7 @@
borderColor: "#e034344d", borderColor: "#e034344d",
buttonBgColor: "#E03434", buttonBgColor: "#E03434",
buttonText: '去连接', buttonText: '去连接',
buttonTextColor:'#FFFFFFde',
okCallback: function() { okCallback: function() {
uni.navigateTo({ uni.navigateTo({

View File

@ -4,7 +4,7 @@
:rightIcons="Status.navbar.icons" @icon-click="handleRightClick"></custom-navbar> :rightIcons="Status.navbar.icons" @icon-click="handleRightClick"></custom-navbar>
<view class="eq" :style="{marginTop:Status.navbar.height+'px'}"> <view class="eq" :style="{marginTop:Status.navbar.height+'px'}">
<view class="leftImg"> <view class="leftImg" @click.stop="previewImg(device['devicePic'])">
<image class="img" :src="device['devicePic']" mode="aspectFit"></image> <image class="img" :src="device['devicePic']" mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
@ -524,6 +524,15 @@
}, },
methods: { methods: {
previewImg(img){
if(!img){
return;
}
uni.previewImage({
urls:[img]
})
},
showBleUnConnect() { showBleUnConnect() {
this.Status.bleLinkCnt++; this.Status.bleLinkCnt++;
if(this.Status.bleLinkCnt>3){ if(this.Status.bleLinkCnt>3){
@ -537,7 +546,7 @@
buttonText: '去连接', buttonText: '去连接',
showCancel: true, showCancel: true,
cancelCallback: () => { cancelCallback: () => {
this.closePop(); // this.closePop();
}, },
okCallback: function() { okCallback: function() {
console.log("1111"); console.log("1111");
@ -1200,7 +1209,7 @@
message.deviceId = these.device.id; message.deviceId = these.device.id;
message.deviceImei = these.device.deviceImei; message.deviceImei = these.device.deviceImei;
let requestSend = () => { let requestSend = (callback) => {
message.isBluetooth = false; message.isBluetooth = false;
api.sendSos(message).then((res) => { api.sendSos(message).then((res) => {
@ -1211,12 +1220,18 @@
code: 200, code: 200,
msg: '操作成功' msg: '操作成功'
}); });
if(callback){
callback();
}
} else { } else {
return this.sendMQ(json); return this.sendMQ(json);
} }
}).then((res) => { }).then((res) => {
console.log("res=", res); console.log("res=", res);
if(callback){
callback();
}
}).catch((ex) => { }).catch((ex) => {
console.log("ex=", ex); console.log("ex=", ex);
these.showPop({ these.showPop({
@ -1234,7 +1249,7 @@
} }
let bleSendCmd = () => { let bleSendCmd = (callback) => {
let f = this.getDevice(); let f = this.getDevice();
let buffer = null; let buffer = null;
if (f) { if (f) {
@ -1255,53 +1270,59 @@
these.setBleFormData(); these.setBleFormData();
message.isBluetooth = true; message.isBluetooth = true;
api.sendSos(message); api.sendSos(message);
if(callback){
callback();
}
}).catch((ex) => { }).catch((ex) => {
//使用4G发送 //使用4G发送
console.log("蓝牙发送失败,转4g发送", ex); console.log("蓝牙发送失败,转4g发送", ex);
requestSend(); requestSend(callback);
}); });
} else { } else {
console.log("找不到蓝牙设备"); console.log("找不到蓝牙设备");
requestSend(); requestSend(callback);
these.showBleUnConnect(); these.showBleUnConnect();
} }
} }
let OpenSOS = () => { let OpenSOS = () => {
these.formData.qzwarn = true; //标记为强制报警了 let execSos=()=>{
these.formData.qzwarn = true; //标记为强制报警了
these.Status.staticWarn.time = 180;
this.formData.SOS = type; these.Status.staticWarn.time = 180;
this.formData.SOS = type;
let loopFunc = () => {
if (these.Status.staticWarn.inteval === null) { let loopFunc = () => {
return; if (these.Status.staticWarn.inteval === null) {
return;
}
if (these.Status.staticWarn.time === 0) {
clearInterval(these.Status.staticWarn.inteval);
these.Status.staticWarn.inteval = null;
these.formData.qzwarn = false;
these.formData.SOS = 'close';
these.CloseWarn(false);
return;
}
these.Status.staticWarn.time = these.Status.staticWarn
.time - 1;
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
console.log("111111");
this.showQzWarn(this.Status.Pop.okCallback);
}
} }
if (these.Status.staticWarn.time === 0) { these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000);
clearInterval(these.Status.staticWarn.inteval);
these.Status.staticWarn.inteval = null;
these.formData.qzwarn = false;
these.formData.SOS = 'close';
these.CloseWarn(false);
return;
}
these.Status.staticWarn.time = these.Status.staticWarn
.time - 1;
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
console.log("111111");
this.showQzWarn(this.Status.Pop.okCallback);
}
} }
these.Status.staticWarn.inteval = setInterval(() => {
loopFunc();
}, 1000);
bleSendCmd(); bleSendCmd(execSos);
} }

View File

@ -1,7 +1,7 @@
<template> <template>
<view class="content contentBg"> <view class="content contentBg">
<view class="eq"> <view class="eq">
<view class="leftImg"> <view class="leftImg" @click.stop="previewImg(formData.img)">
<image class="img" :src="formData.img" mode="aspectFit"></image> <image class="img" :src="formData.img" mode="aspectFit"></image>
</view> </view>
<view class="rightTxt"> <view class="rightTxt">
@ -83,7 +83,7 @@
<text class="usrtitle fleft">人员信息登记</text> <text class="usrtitle fleft">人员信息登记</text>
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view> <view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></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" /> :color="'#000000'" :fontSize="14" />
</view> </view>
@ -124,8 +124,8 @@
:borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor" :borderColor="Status.Pop.borderColor" :textColor="Status.Pop.textColor"
:buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor" :buttonBgColor="Status.Pop.buttonBgColor" :buttonTextColor="Status.Pop.buttonTextColor"
:iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText" :iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText"
@buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle" @buttonClick="HidePop" @closePop="closePop" :visiblePrompt="Status.Pop.visiblePrompt"
v-model="Status.Pop.modelValue" /> :promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" />
<!-- 下方菜单 --> <!-- 下方菜单 -->
<BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick" <BottomSlideMenuPlus :config="Status.BottomMenu" @close="closeMenu" @itemClick="handleItemClick"
@ -143,7 +143,7 @@
</template> </template>
<script> <script>
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue'; import textToDotMatrix from '@/components/TextToHex/textToDotMatrix.vue';
import bleTool from '@/utils/BleHelper.js'; import bleTool from '@/utils/BleHelper.js';
import usrApi from '@/api/670/HBY670.js' import usrApi from '@/api/670/HBY670.js'
import { import {
@ -161,7 +161,7 @@
export default { export default {
components: { components: {
TextToHexV1 textToDotMatrix
}, },
data() { data() {
return { return {
@ -182,7 +182,7 @@
promptTitle: '设备名称', promptTitle: '设备名称',
modelValue: '', modelValue: '',
visibleClose: false, visibleClose: false,
okCallback:null okCallback: null
}, },
BottomMenu: { BottomMenu: {
show: false, show: false,
@ -410,6 +410,15 @@
} }
}, },
methods: { methods: {
previewImg(img) {
if (!img) {
return;
}
uni.previewImage({
urls: [img]
})
},
getDevice: function() { getDevice: function() {
// console.log("LinkedList=", ble.data.LinkedList); // console.log("LinkedList=", ble.data.LinkedList);
// console.log("formData=", these.formData); // console.log("formData=", these.formData);
@ -567,180 +576,83 @@
return; 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) => { return new Promise((resolve, reject) => {
// 总数据包数 // 总数据包数
const totalPackets = 7; const totalPackets = 3;
let currentPacket = 1; let currentPacket = 1;
let childPacket = 1;
let totalChildPacket = 9;
// 发送单个数据包 // 发送单个数据包
const sendNextPacket = () => { const sendNextPacket = () => {
if (currentPacket > totalPackets) { if (currentPacket > totalPackets) {
setTimeout(() => { setTimeout(() => {
hideLoading(these); hideLoading(these);
these.Status.BottomMenu.show = false; these.Status.BottomMenu.show = false;
these.showPop({ these.showPop({
message: "上传成功", message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png", iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor: '#BBE600', borderColor: '#BBE600',
buttonBgColor: '#BBE600' buttonBgColor: '#BBE600'
}); });
resolve(); resolve();
}, 20000) }, 0)
return; 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 start = 0;
let bufferSize = packetData.length * 2; let bufferSize = 343; //总共1029字节3包正好每包343字节
//FA 09 04 00 1024字节 FF
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 buffer = new ArrayBuffer(bufferSize);
var dataView = new DataView(buffer); var dataView = new DataView(buffer);
if (childPacket == 1) { if (currentPacket == 1) {
dataView.setUint8(0, 0xFA); // 帧头 dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, 0x09); // 帧头 dataView.setUint8(1, 0x09); // 帧头
dataView.setUint8(2, 0x10); // 帧头 dataView.setUint8(2, 0x04); // 帧头
dataView.setUint8(3, 0x04); // 帧头 dataView.setUint8(3, 0x00); // 帧头
dataView.setUint8(4, 0xFC); // 帧头
dataView.setUint8(5, 0x09); // 帧头
for (let i = 0; i < packetData.length; i++) {
dataView.setUint8(6, 0x00); // 图序号,图片固定0视频的话要写序号 dataView.setUint8(4 + i, parseInt(packetData[i],16));
dataView.setUint8(7, currentPacket); //子包序号 }
} }
if (currentPacket == totalPackets) {
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); dataView.setUint8(bufferSize - 1, 0xFF);
} }
//发送数据包 //发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
1000) 30)
.then(() => { .then(() => {
let curr = childPacket + (currentPacket - 1) *
totalChildPacket;
console.log("第" + currentPacket + "大包,第" + childPacket +
"小包发送完成,总计:" + curr);
updateLoading(these, { updateLoading(these, {
text: "正在发送" + curr + "/63" text: "正在发送" + currentPacket + "/"+totalPackets
}) })
if (childPacket == 9) { currentPacket++;
currentPacket++;
childPacket = 1; setTimeout(sendNextPacket, 100);
} else {
childPacket++;
}
setTimeout(sendNextPacket, 1000);
}).catch(err => { }).catch(err => {
if (err.code == 10007) { if (err.code == 10007) {
setTimeout(sendNextPacket, 1000); setTimeout(sendNextPacket, 100);
return; return;
} }
console.log("发送数据包失败了", err); console.log("发送数据包失败了", err);
these.Status.BottomMenu.show = false; these.Status.BottomMenu.show = false;
these.showPop({ these.showPop({
message: "发送数据包失败了" + err.msg, message: "发送数据包失败了" + err.msg,
@ -748,13 +660,14 @@
borderColor: "#e034344d", borderColor: "#e034344d",
buttonBgColor: "#E03434", buttonBgColor: "#E03434",
}); });
hideLoading(these); hideLoading(these);
reject(err); reject(err);
}); });
} }
// 开始发送数据 // 开始发送数据
sendNextPacket(); sendNextPacket();
}); });
} }
@ -770,13 +683,115 @@
events: { events: {
ImgCutOver: function(data) { 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, { showLoading(these, {
text: "正在发送0/52" text: "正在发送0/3"
}); });
these.Status.BottomMenu.show = false; these.Status.BottomMenu.show = false;
setTimeout(function() { setTimeout(function() {
processAndSendImageData(data.piexls).catch(( sendImagePackets(matrix).catch((
ex) => { ex) => {
console.log("出现异常", ex); console.log("出现异常", ex);
}); });
@ -786,7 +801,9 @@
}, },
success(ev) { success(ev) {
ev.eventChannel.emit('checkImg', { ev.eventChannel.emit('checkImg', {
data: res.tempFiles[0].path data: res.tempFiles[0].path,
width: 64,
height: 32
}) })
}, },
fail(ex) { fail(ex) {
@ -973,12 +990,12 @@
}, },
closePop: function() { closePop: function() {
this.Status.Pop.showPop = false; this.Status.Pop.showPop = false;
if (this.Status.Pop.cancelCallback) { if (this.Status.Pop.cancelCallback) {
this.Status.Pop.cancelCallback(); this.Status.Pop.cancelCallback();
} }
}, },
HidePop: function() { HidePop: function() {
console.log("1111"); console.log("1111");
if (this.Status.Pop.clickEvt == 'SendUsr') { if (this.Status.Pop.clickEvt == 'SendUsr') {
@ -1135,21 +1152,6 @@
return level1.flat(Infinity); return level1.flat(Infinity);
}); });
console.log("result=", result); 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 h3dic = [0x06, 0x07, 0x08];
let pros = []; let pros = [];
let flag = true; let flag = true;