打印增加中文编码
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
Component({
|
||||
mixins: [],
|
||||
data: {
|
||||
@@ -158,12 +160,17 @@ Component({
|
||||
const nameValue = typeof item.name === 'number'? item.name.toString() : item.name;
|
||||
const colorValue = typeof item.color_id_2[1] === 'number'? item.color_id_2[1].toString() : item.color_id_2[1];
|
||||
const codeValue = typeof value === 'number'? value.toString() : value;
|
||||
|
||||
// 拼接要打印的内容
|
||||
value = `name ${nameValue}.color ${colorValue}.code ${codeValue}`;
|
||||
// 去除中文和[]符号
|
||||
value = value.replace(/[\u4e00-\u9fa5\[\]]/g, '');
|
||||
allValuesToPrint.push(value);
|
||||
const nameValuereplace = nameValue.replace(/[\u4e00-\u9fa5\[\]]/g, '');
|
||||
// 拼接要打印的内容
|
||||
value = `货号: ${nameValuereplace}.色号: ${colorValue}.细码: ${codeValue}`;
|
||||
|
||||
// allValuesToPrint.push(value);
|
||||
allValuesToPrint.push({
|
||||
name: `货号: ${nameValuereplace}`,
|
||||
color: `色号: ${colorValue}`,
|
||||
code: `细码: ${codeValue}`
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -179,17 +186,21 @@ Component({
|
||||
// 计算总的数据块数量
|
||||
allValuesToPrint.forEach((code) => {
|
||||
const command = `
|
||||
SIZE 7,5
|
||||
SIZE 75 mm,60 mm
|
||||
GAP 2,0
|
||||
CLS
|
||||
QRCODE 20,150,H,5,A,0,"${code}"
|
||||
TEXT 20,350,"2",0,1,1,"${code}"
|
||||
QRCODE 20,150,H,5,A,0,"${code.name} ${code.color} ${code.code} 020-89061189"
|
||||
TEXT 200,100,"TSS32.BF2",0,1,1,"${code.name}"
|
||||
TEXT 200,200,"TSS32.BF2",0,1,1,"${code.color}"
|
||||
TEXT 200,300,"TSS32.BF2",0,1,1,"${code.code}"
|
||||
TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责"
|
||||
PRINT 1,1
|
||||
`;
|
||||
|
||||
|
||||
// const encoder = new TextEncoder('utf-8');
|
||||
// const commandBuffer = encoder.encode(command);
|
||||
const commandBuffer = Buffer.from(command, 'utf-8');
|
||||
// const commandBuffer = Buffer.from(command, 'utf8');
|
||||
const commandBuffer = iconv.encode(command, 'GB18030');
|
||||
const hexValue = Array.from(commandBuffer)
|
||||
.map(byte => byte.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
@@ -212,16 +223,22 @@ Component({
|
||||
|
||||
const currentCode = allValuesToPrint[index];
|
||||
const command = `
|
||||
SIZE 7,5
|
||||
SIZE 75 mm,60 mm
|
||||
GAP 2,0
|
||||
CLS
|
||||
QRCODE 20,150,H,5,A,0,"${currentCode}"
|
||||
TEXT 20,350,"2",0,1,1,"${currentCode}"
|
||||
QRCODE 20,150,H,5,A,0,"${currentCode.name} ${currentCode.color} ${currentCode.code} 020-89061189"
|
||||
TEXT 200,100,"TSS32.BF2",0,1,1,"${currentCode.name}"
|
||||
TEXT 200,200,"TSS32.BF2",0,1,1,"${currentCode.color}"
|
||||
TEXT 200,300,"TSS32.BF2",0,1,1,"${currentCode.code}"
|
||||
TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责"
|
||||
PRINT 1,1
|
||||
`;
|
||||
|
||||
// const encoder = new TextEncoder('utf-8');
|
||||
// const commandBuffer = encoder.encode(command);
|
||||
const commandBuffer = Buffer.from(command, 'utf-8');
|
||||
console.log("command",command)
|
||||
// const commandBuffer = Buffer.from(command, 'utf8');
|
||||
const commandBuffer = iconv.encode(command, 'GB18030');
|
||||
// 将二进制数据转换为 hex 编码
|
||||
const hexValue = Array.from(commandBuffer)
|
||||
.map(byte => byte.toString(16).padStart(2, '0'))
|
||||
|
||||
Reference in New Issue
Block a user