1
0
forked from dyf/APP

merge upstream

This commit is contained in:
2025-11-17 09:38:17 +08:00
2 changed files with 305 additions and 161 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<view> <view>
<canvas canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight" <canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
class="offscreen-canvas"></canvas> class="offscreen-canvas"></canvas>
</view> </view>
</template> </template>
@ -27,16 +27,6 @@
color: { color: {
type: String, type: String,
default: "#000000" default: "#000000"
},
// 二值化阈值0~1越大越细默认偏清晰
threshold: {
type: Number,
default: 0.45
},
// 是否启用轻度笔画修复3x3 膨胀);默认关闭以避免变粗
sharpen: {
type: Boolean,
default: false
} }
}, },
data() { data() {
@ -58,16 +48,6 @@
this.ctx = uni.createCanvasContext('reusableCanvas', this); this.ctx = uni.createCanvasContext('reusableCanvas', this);
}, },
methods: { methods: {
/**
* 外部可调用:复位画布为纯背景并立即提交
*/
async resetCanvas() {
if (!this.ctx) return;
this.clearCanvas();
await new Promise((resolve) => {
this.ctx.draw(true, () => setTimeout(resolve, 30));
});
},
/** /**
* 估算单行文本所需的Canvas宽度 * 估算单行文本所需的Canvas宽度
*/ */
@ -79,8 +59,6 @@
* 清除Canvas内容 * 清除Canvas内容
*/ */
clearCanvas() { clearCanvas() {
// 先清除,再用背景色填充,确保无残留
this.ctx.clearRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
this.ctx.setFillStyle(this.bgColor); this.ctx.setFillStyle(this.bgColor);
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight); this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
}, },
@ -89,11 +67,6 @@
* 复用单个Canvas处理所有文本行 * 复用单个Canvas处理所有文本行
*/ */
async drawAndGetPixels() { async drawAndGetPixels() {
// 发送前:确保画布处于干净背景态
await this.resetCanvas();
// 超采样比例(提高分辨率再降采样,减少模糊)
const SCALE = 3;
const PADDING_X = 1 * SCALE; // 左侧预留像素,避免首字裁剪
let binaryToHex = (binaryArray) => { let binaryToHex = (binaryArray) => {
if (!Array.isArray(binaryArray) || binaryArray.length !== 8) { if (!Array.isArray(binaryArray) || binaryArray.length !== 8) {
throw new Error("输入必须是包含8个元素的二进制数组"); throw new Error("输入必须是包含8个元素的二进制数组");
@ -117,107 +90,25 @@
return hexString; return hexString;
} }
let convertCharToMatrix = (drawResult, item) => { let convertCharToMatrix = (imageData, item) => {
// 设备端使用13x13点阵渲染保持输出13列×13行但只在内部采样12×12保留右侧与底部1像素缓冲
const charWidth = 13; const charWidth = 13;
const charHeight = 13; const charHeight = 12;
const effectiveWidth = 12; // 仅采样前12列 const pixels = [];
const effectiveHeight = 12; // 仅采样前12行 for (let i = 0; i < imageData.length; i += 4) {
const { pixelData, width, height } = drawResult; const R = imageData[i];
// 将高分辨率像素降采样为13x13的布尔矩阵 pixels.push(R < 128 ? 1 : 0);
const target = new Array(charWidth * charHeight).fill(0);
const threshold = Math.max(0.2, Math.min(0.8, this.threshold || 0.45));
// 确保采样区域严格对齐从PADDING_X开始只采样12列右侧预留1px12行底部预留1px
// 字符实际绘制区域从PADDING_X开始宽度为12*SCALE
const charStartX = PADDING_X;
const charEndX = PADDING_X + effectiveWidth * SCALE; // 仅采样到第12列
for (let y = 0; y < charHeight; y++) {
for (let x = 0; x < charWidth; x++) {
// 超出有效采样区域第13列或第13行直接置0作为缓冲
if (x >= effectiveWidth || y >= effectiveHeight) {
target[y * charWidth + x] = 0;
continue;
}
let onCount = 0;
let total = 0;
// 采样区域字符从PADDING_X开始绘制每列宽度为SCALE
const startX = PADDING_X + x * SCALE;
const startY = y * SCALE;
for (let sy = 0; sy < SCALE; sy++) {
for (let sx = 0; sx < SCALE; sx++) {
const px = startX + sx;
const py = startY + sy;
// 边界检查确保不超出Canvas边界且不超出字符实际绘制区域
if (px < 0 || py < 0 || px >= width || py >= height) {
// 边界外视为背景(黑色)
continue;
}
// 额外检查:确保不采样到字符右侧的残留区域
if (px >= charEndX) {
// 超出字符区域,视为背景
continue;
}
const idx = (py * width + px) * 4;
const R = pixelData[idx];
const G = pixelData[idx + 1];
const B = pixelData[idx + 2];
const A = pixelData[idx + 3] || 255;
// 计算亮度
const luminance = 0.299 * R + 0.587 * G + 0.114 * B;
const alpha = A / 255;
// 背景是黑色,文字是白色,所以判断亮色(>=128为文字点
if (luminance >= 128 && alpha > 0.5) onCount++;
total++;
}
}
// 当亮色占比超过阈值时判为1至少需要采样到一些像素
target[y * charWidth + x] = (total > 0 && onCount / total >= threshold) ? 1 : 0;
}
}
// 轻度笔画修复:可选 3x3 膨胀(启用时阈值更严格,避免变粗)
if (this.sharpen) {
const dilated = target.slice();
for (let y = 0; y < effectiveHeight; y++) {
for (let x = 0; x < effectiveWidth; x++) {
const idx = y * charWidth + x;
if (target[idx] === 1) continue;
let neighbors = 0;
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx < 0 || ny < 0 || nx >= effectiveWidth || ny >= effectiveHeight) continue;
if (target[ny * charWidth + nx] === 1) neighbors++;
}
}
// 使用更严格的邻居门限,避免整体变粗
if (neighbors >= 5) {
dilated[idx] = 1;
}
}
}
for (let i = 0; i < target.length; i++) target[i] = dilated[i];
} }
const lowBytes = new Array(charWidth).fill(0); const lowBytes = new Array(charWidth).fill(0);
const highBytes = new Array(charWidth).fill(0); const highBytes = new Array(charWidth).fill(0);
// 按列打包每列13行分成上下两字节低字节0-7行8行高字节8-12行5行
for (let col = 0; col < charWidth; col++) { for (let col = 0; col < charWidth; col++) {
for (let row = 0; row < charHeight; row++) { for (let row = 0; row < charHeight; row++) {
const pixel = target[row * charWidth + col]; const pixel = pixels[row * charWidth + col];
if (pixel === 1) { if (pixel === 1) {
if (row < 8) { if (row < 8) {
// 低字节0-7行从低位到高位
lowBytes[col] |= (1 << row); lowBytes[col] |= (1 << row);
} else { } else {
// 高字节8-12行从低位到高位使用5位剩余3位未使用
highBytes[col] |= (1 << (row - 8)); highBytes[col] |= (1 << (row - 8));
} }
} }
@ -230,32 +121,34 @@
let result = {}; let result = {};
let ctx = this.ctx; let ctx = this.ctx;
// 1. 动态调整Canvas尺寸(高分辨率) // 1. 动态调整Canvas尺寸
// 设备端使用13x13点阵渲染 this.currentCanvasWidth = 13;
this.currentCanvasWidth = 13 * SCALE + PADDING_X; this.currentCanvasHeight = 12;
this.currentCanvasHeight = 13 * SCALE;
// 2. 清空Canvas绘制背景 // 2. 清空Canvas绘制背景
this.clearCanvas(); this.clearCanvas();
// 3. 设置文字样式(整数像素对齐,顶部基线,避免首字裁剪) // 3. 设置文字样式
ctx.setFillStyle(this.color); ctx.setFillStyle(this.color);
ctx.setTextBaseline('top'); ctx.setTextBaseline('middle');
ctx.setTextAlign('left'); // ctx.setTextAlign('center')
const fs = Math.max(1, Math.round(this.fontSize)) * SCALE; ctx.setFontSize(this.fontSize);
ctx.setFontSize(fs); ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
ctx.font = `${fs}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
// 4. 绘制单个字符(每个字符独立绘制在固定位置) // 4. 绘制当前行文本
// 确保字符始终从PADDING_X开始绘制Y坐标为0保证采样一致性 let currentX = 0;
const charX = PADDING_X; let currentY = this.fontSize / 2 + 1;
const charY = 0; for (let j = 0; j < textLine.length; j++) {
ctx.fillText(textLine, charX, charY); let char = textLine[j];
ctx.fillText(char, currentX, currentY);
// 按实际字符宽度计算间距
let charWidth = ctx.measureText(char).width;
currentX += charWidth;
}
// 5. 异步绘制并获取像素数据(串行处理避免冲突) // 5. 异步绘制并获取像素数据(串行处理避免冲突)
const grabPixels = () => new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
// 立即绘制并给一点缓冲时间,避免取像素过早 ctx.draw(false, () => {
ctx.draw(true, () => {
setTimeout(() => { setTimeout(() => {
uni.canvasGetImageData({ uni.canvasGetImageData({
canvasId: 'reusableCanvas', canvasId: 'reusableCanvas',
@ -272,22 +165,14 @@
}; };
resolve(); resolve();
}, },
fail: err => reject(err) fail: err => {
}); // console.error(`处理第${i+1}行失败:`, err);
}, 70); reject(err)
});
});
await grabPixels();
// 一次性校验:若像素全黑或明显异常,重绘重取一次
let nonZero = false;
for (let i = 0; i < result.pixelData.length; i += 4) {
if (result.pixelData[i] || result.pixelData[i+1] || result.pixelData[i+2]) { nonZero = true; break; }
}
if (!nonZero) {
await new Promise(r => setTimeout(r, 50));
await grabPixels();
} }
});
}, 100);
});
});
return result; return result;
} }
@ -299,23 +184,13 @@
let item = this.validTxts[i]; let item = this.validTxts[i];
// console.log("item=", item); // console.log("item=", item);
for (var j = 0; j < item.length; j++) { for (var j = 0; j < item.length; j++) {
let char = item[j]; let result = await drawTxt(item[j]);
let result = await drawTxt(char); linePixls.push(convertCharToMatrix(result.pixelData, item));
let matrix = convertCharToMatrix(result, item);
// 调试:打印每个字符的点阵数据
console.log(`[点阵生成] 字符"${char}" 点阵数据:`, matrix.map(b => '0x' + b.toString(16).padStart(2, '0')).join(' '));
linePixls.push(matrix);
// 在字符间增加轻微延时,避免相邻提取竞争(尤其是末字符)
await new Promise(r => setTimeout(r, 20));
} }
// console.log("hexs=", linePixls.join(",")); // console.log("hexs=", linePixls.join(","));
arr.push(linePixls); arr.push(linePixls);
// 每行结束再等一会,提高末字符稳定性
await new Promise(r => setTimeout(r, 40));
} }
// 发送后:再次清空画布,避免残留影响下一次
await this.resetCanvas();
return arr; return arr;
} }
} }
@ -327,5 +202,6 @@
position: fixed; position: fixed;
left: -9999px; left: -9999px;
top: -9999px; top: -9999px;
visibility: hidden;
} }
</style> </style>

268
et --hard id Normal file
View File

@ -0,0 +1,268 @@
commit c14da42ce5e3a1ce49d73681df28e66982dedba2 (HEAD -> main)
Author: fengerli <528575642@qq.com>
Date: Mon Nov 17 08:55:48 2025 +0800
210页面开发
commit dadad6ed194f88dceff90dcaa6c20d6513bf0282 (origin/main, origin/HEAD)
Author: fengerli <528575642@qq.com>
Date: Wed Nov 12 09:51:35 2025 +0800
添加token过期跳转到登录页
commit 426fdeddee783a8a551d683fb88d6ce2d6a9b9a1
Merge: 968d7a6 f835e25
Author: fengerli <528575642@qq.com>
Date: Sat Nov 8 10:33:20 2025 +0800
Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
commit 968d7a613dfa6c8be53520c99c01d1a889110b13
Author: fengerli <528575642@qq.com>
Date: Sat Nov 8 10:33:00 2025 +0800
6075页面功能开发
commit f835e25bbb7497f6545713cade4b032de17e11d1
Merge: b8ce162 012eca6
Author: dyf <974332738@qq.com>
Date: Sat Nov 8 10:32:38 2025 +0800
Merge pull request 'new-20250827 一些小优化' (#22) from liubiao/APP:new-20250827 into main
Reviewed-on: http://47.107.152.87:3000/dyf/APP/pulls/22
commit 012eca69853acd92a2bab85721ed99c85e0b7969
Merge: 623a474 b8ce162
Author: liub <itliubiao@qq.com>
Date: Fri Nov 7 13:08:05 2025 +0800
Merge branch 'new-20250827' of http://47.107.152.87:3000/liubiao/APP into new-20250827
# Conflicts:
# pages.json
# pages/100/HBY100.vue
# pages/6075/BJQ6075.vue
# pages/7305/BJQ7305.vue
# utils/BleReceive.js
commit 623a47466a6fef7c3fe40cfe5c1d52f85ac8d478
Author: liub <itliubiao@qq.com>
Date: Fri Nov 7 12:16:10 2025 +0800
合并线上代码
commit 2493bb7113fd21e64836ed912ff9ff72ed0fcd1e
Author: liub <itliubiao@qq.com>
Date: Fri Nov 7 11:57:35 2025 +0800
完成100
commit b8ce1621b45e40c3ff14d5d0ddaed3b362526d58
Merge: c81a4d1 27d212e
Author: fengerli <528575642@qq.com>
Date: Thu Nov 6 08:47:45 2025 +0800
Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
commit c81a4d1903eb32ed784b97e33d29076e46fb1531
Author: fengerli <528575642@qq.com>
Date: Thu Nov 6 08:46:27 2025 +0800
6075设备控制页
commit 27d212e7dc9dcf61f361bd633482d5f26cde4886
Author: 微微一笑 <709648985@qq.com>
Date: Wed Nov 5 19:18:05 2025 +0800
继续优化7305
commit 9037ef6ac31cfdcbe273c47ed79b75bfccbf2877
Merge: a30a631 2b72cc1
Author: 微微一笑 <709648985@qq.com>
Date: Wed Nov 5 11:17:11 2025 +0800
Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
commit a30a631ea647b0a0615e0c78d06de90f872d4990
Author: 微微一笑 <709648985@qq.com>
Date: Wed Nov 5 11:17:08 2025 +0800
改成13*13符合设备端
commit 2b72cc1a5cbe2a9e5923a262ea6cafe0413cbc1c
Merge: 77be45f a0c883f
Author: fengerli <528575642@qq.com>
Date: Wed Nov 5 11:13:35 2025 +0800
Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
commit 77be45f1f3bf43dd7c5184a6ba196da7d5a92a02
Author: fengerli <528575642@qq.com>
Date: Wed Nov 5 11:13:32 2025 +0800
6075
commit a0c883f4e3dfafa6805090eaebaffec811f50aec
Author: 微微一笑 <709648985@qq.com>
Date: Wed Nov 5 10:22:17 2025 +0800
优化蓝牙连接7305同步状态
commit 9313ec01060e32c7160f61e6a557ed53a4277e86
Merge: ca6345e d06cd6c
Author: fengerli <528575642@qq.com>
Date: Wed Nov 5 08:48:15 2025 +0800
Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
commit ca6345ee3e8572415e1c3454f4fe9f696da8c303
Author: fengerli <528575642@qq.com>
Date: Wed Nov 5 08:48:13 2025 +0800
6075页面开发
commit d06cd6cdfdf94321f5257891a85516b066ff8014
Author: 微微一笑 <709648985@qq.com>
Date: Tue Nov 4 19:30:47 2025 +0800
修复复杂字体渲染设备端乱序问题
commit 2218ca06501de44ad9ffdb7fbbb09d0733a5ba9e
Author: 微微一笑 <709648985@qq.com>
Date: Sat Nov 1 17:32:03 2025 +0800
修改输入框文本
commit 500b461bdd86a7c352e11af1e4827f9f1bb33ebb
Author: 微微一笑 <709648985@qq.com>
Date: Sat Nov 1 17:21:45 2025 +0800
修复7305设备上报问题
commit 3526f28d067bbcfb1f91bd2f86faa478f5f23794
Author: 微微一笑 <709648985@qq.com>
Date: Fri Oct 31 15:35:03 2025 +0800
修复蓝牙传输数据
commit 3eeffdb62c82e61a3de86766e4ac1c075bf28287
Merge: 317c762 bd56ca9
Author: fengerli <528575642@qq.com>
Date: Fri Oct 31 11:15:39 2025 +0800
Merge branch 'liubiao-new-20250827'
commit 317c762edc62551c2045415b0f4e598b0772a622
Author: fengerli <528575642@qq.com>
Date: Fri Oct 31 11:13:07 2025 +0800
7305文件报错
commit c39cbcb34d1929b2abb177f59538aaaae34dd292
Author: liub <itliubiao@qq.com>
Date: Thu Oct 30 11:10:57 2025 +0800
蓝牙开始、结束搜索添加状态判定
commit bd56ca997bb95078cf9b1ff7e32791af34dc3670 (liubiao-new-20250827)
Author: liub <itliubiao@qq.com>
Date: Mon Oct 27 13:00:34 2025 +0800
修复7305标签未闭合问题
commit cf60414d7686194f35f41e6f1cf1dfe8f6e89765
Author: liub <itliubiao@qq.com>
Date: Mon Oct 27 11:51:38 2025 +0800
蓝牙断开连接变成异步操作
commit 61ed91695f15decff77a9fec9d7af3f7fae0226a
Author: liub <itliubiao@qq.com>
Date: Mon Oct 27 10:52:17 2025 +0800
蓝牙模块添加在web平台默认成功方便调试功能,4877功能完成
commit d37ccfeabc9324872b686eb581ce33246fc1bb5d
Author: liub <itliubiao@qq.com>
Date: Fri Oct 24 17:21:18 2025 +0800
完成BJQ4877功能开发
commit 0909d9f023c6e3db7d65c025954b2626d6f1615f
Merge: 1d8b3b4 b20a93d
Author: liubiao <3909916335@qq.com>
Date: Fri Oct 24 11:46:02 2025 +0800
merge upstream
commit b20a93dd2854fef472eca51fd2a2934cba43ec59
Author: 微微一笑 <709648985@qq.com>
Date: Fri Oct 24 11:42:56 2025 +0800
修复传输时序问题
commit 1d8b3b4a9a7ed1030ce97b1ebb9121e1ceed365a
Merge: a5c6faa fa64e7f
Author: liub <itliubiao@qq.com>
Date: Fri Oct 24 11:08:32 2025 +0800
修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
# Conflicts:
# pages/7305/BJQ7305.vue
commit a5c6faa9dac8cadbaf6ea9d745e43bca9d48395c
Author: liub <itliubiao@qq.com>
Date: Fri Oct 24 11:04:36 2025 +0800
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
* 修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
commit 15ba241317a9ecc46bbb7022b4ec3638bfa00a4e
Author: liub <itliubiao@qq.com>
Date: Fri Oct 24 11:00:35 2025 +0800
修复蓝牙设备6155/7305全局弹窗与详情弹窗重复出现的问题
commit fa64e7f1fc9eb4b24e9bf6eab269e718299aabce
Merge: 0033649 1de958d
Author: liubiao <3909916335@qq.com>
Date: Fri Oct 24 10:57:08 2025 +0800
merge upstream
commit 45328120c1b552b483b325cad2511ab274305006
Author: liub <itliubiao@qq.com>
Date: Fri Oct 24 10:56:37 2025 +0800
修复6155/7305全局订阅与详情订阅重复弹窗
commit 1de958df20014e6a858d1a0da9e277766518c96c
Author: 微微一笑 <709648985@qq.com>
Date: Fri Oct 24 10:29:46 2025 +0800
修复优化7305设备屏幕点阵取模兼容设备端填坑
commit 0033649677964eb94ea930ba76f5f1a9020cffa3
Author: liub <itliubiao@qq.com>
Date: Thu Oct 23 16:36:48 2025 +0800
修改蓝牙接收数据处理逻辑改成配置式避免if无限增多
commit 738ce209a60