打印增加中文编码
This commit is contained in:
parent
c415939ef1
commit
dd72d79bb1
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"iconv-lite": "^0.6.3"
|
||||
}
|
||||
}
|
||||
@ -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'))
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
<view class="page-section">
|
||||
<view class="page-section-demo">
|
||||
<text> v1.0.11 </text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="nav-container">
|
||||
<navigator open-type="navigate" url="/pages/deal/saleOrder/saleOrder" hover-class="navigator-hover" class="nav-button">销售</navigator>
|
||||
</view>
|
||||
|
||||
@ -4,7 +4,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
},
|
||||
onReady() {
|
||||
// 页面加载完成
|
||||
|
||||
@ -3,7 +3,7 @@ Page({
|
||||
items: []
|
||||
},
|
||||
onLoad(query) {
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
// console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
dd.getStorage({
|
||||
key: 'saleOrderlines',
|
||||
success: (res) => {
|
||||
|
||||
@ -16,7 +16,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
},
|
||||
onReady() {
|
||||
// 页面加载完成
|
||||
|
||||
@ -4,7 +4,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
const objectKey = query.objectKey;
|
||||
if (objectKey) {
|
||||
dd.getStorage({
|
||||
|
||||
@ -12,7 +12,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
// console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
const loginInfo = dd.getStorageSync({
|
||||
key: 'loginInfo'
|
||||
}).data;
|
||||
|
||||
@ -4,7 +4,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
},
|
||||
onReady() {
|
||||
// 页面加载完成
|
||||
|
||||
@ -9,8 +9,7 @@ Page({
|
||||
Uid: null, //登录获取的信息保存本地设备
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`胜佳Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
// // 页面加载
|
||||
// 检查本地缓存中是否有登录信息 要四个不为空才渲染//
|
||||
const loginInfo = dd.getStorageSync({
|
||||
key: 'loginInfo'
|
||||
@ -37,7 +36,7 @@ Page({
|
||||
type:'success',
|
||||
duration: 1000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -85,7 +84,7 @@ Page({
|
||||
type: 'none',
|
||||
duration: 3000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -113,7 +112,7 @@ Page({
|
||||
type: 'none',
|
||||
duration: 3000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -180,7 +179,7 @@ Page({
|
||||
type: 'success',
|
||||
duration: 3000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
|
||||
}
|
||||
});
|
||||
resolve(uid);
|
||||
@ -204,7 +203,7 @@ Page({
|
||||
type: 'none',
|
||||
duration: 3000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -283,7 +282,6 @@ Page({
|
||||
type: 'success',
|
||||
duration: 1000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
},
|
||||
});
|
||||
} else {
|
||||
@ -292,7 +290,6 @@ Page({
|
||||
type: 'none',
|
||||
duration: 1000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -303,7 +300,6 @@ Page({
|
||||
type: 'none',
|
||||
duration: 1000,
|
||||
success() {
|
||||
console.log('toast end');
|
||||
},
|
||||
fail() {
|
||||
console.log(error.message);
|
||||
|
||||
@ -4,7 +4,6 @@ Page({
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||
},
|
||||
onReady() {
|
||||
// 页面加载完成
|
||||
|
||||
@ -12,7 +12,7 @@ export default function jsonrpc(loginInfo, data) {
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
success: (res) => {
|
||||
console.log(`响应状态码: ${res.status}`);
|
||||
console.log('res',res);
|
||||
if (res.status < 200 || res.status >= 300) {
|
||||
reject(new Error(`HTTP error! status: ${res.status}`));
|
||||
return;
|
||||
@ -25,7 +25,7 @@ export default function jsonrpc(loginInfo, data) {
|
||||
return;
|
||||
}
|
||||
const ObjectData = result.result;
|
||||
console.log('获取订单数据成功:', ObjectData);
|
||||
// console.log('获取订单数据成功:', ObjectData);
|
||||
resolve(ObjectData);
|
||||
},
|
||||
fail: (err) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user