打印增加中文编码
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({
|
Component({
|
||||||
mixins: [],
|
mixins: [],
|
||||||
data: {
|
data: {
|
||||||
@ -158,12 +160,17 @@ Component({
|
|||||||
const nameValue = typeof item.name === 'number'? item.name.toString() : item.name;
|
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 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;
|
const codeValue = typeof value === 'number'? value.toString() : value;
|
||||||
|
|
||||||
// 拼接要打印的内容
|
|
||||||
value = `name ${nameValue}.color ${colorValue}.code ${codeValue}`;
|
|
||||||
// 去除中文和[]符号
|
// 去除中文和[]符号
|
||||||
value = value.replace(/[\u4e00-\u9fa5\[\]]/g, '');
|
const nameValuereplace = nameValue.replace(/[\u4e00-\u9fa5\[\]]/g, '');
|
||||||
allValuesToPrint.push(value);
|
// 拼接要打印的内容
|
||||||
|
value = `货号: ${nameValuereplace}.色号: ${colorValue}.细码: ${codeValue}`;
|
||||||
|
|
||||||
|
// allValuesToPrint.push(value);
|
||||||
|
allValuesToPrint.push({
|
||||||
|
name: `货号: ${nameValuereplace}`,
|
||||||
|
color: `色号: ${colorValue}`,
|
||||||
|
code: `细码: ${codeValue}`
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -179,17 +186,21 @@ Component({
|
|||||||
// 计算总的数据块数量
|
// 计算总的数据块数量
|
||||||
allValuesToPrint.forEach((code) => {
|
allValuesToPrint.forEach((code) => {
|
||||||
const command = `
|
const command = `
|
||||||
SIZE 7,5
|
SIZE 75 mm,60 mm
|
||||||
GAP 2,0
|
GAP 2,0
|
||||||
CLS
|
CLS
|
||||||
QRCODE 20,150,H,5,A,0,"${code}"
|
QRCODE 20,150,H,5,A,0,"${code.name} ${code.color} ${code.code} 020-89061189"
|
||||||
TEXT 20,350,"2",0,1,1,"${code}"
|
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
|
PRINT 1,1
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// const encoder = new TextEncoder('utf-8');
|
// const encoder = new TextEncoder('utf-8');
|
||||||
// const commandBuffer = encoder.encode(command);
|
// 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)
|
const hexValue = Array.from(commandBuffer)
|
||||||
.map(byte => byte.toString(16).padStart(2, '0'))
|
.map(byte => byte.toString(16).padStart(2, '0'))
|
||||||
.join('');
|
.join('');
|
||||||
@ -212,16 +223,22 @@ Component({
|
|||||||
|
|
||||||
const currentCode = allValuesToPrint[index];
|
const currentCode = allValuesToPrint[index];
|
||||||
const command = `
|
const command = `
|
||||||
SIZE 7,5
|
SIZE 75 mm,60 mm
|
||||||
GAP 2,0
|
GAP 2,0
|
||||||
CLS
|
CLS
|
||||||
QRCODE 20,150,H,5,A,0,"${currentCode}"
|
QRCODE 20,150,H,5,A,0,"${currentCode.name} ${currentCode.color} ${currentCode.code} 020-89061189"
|
||||||
TEXT 20,350,"2",0,1,1,"${currentCode}"
|
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
|
PRINT 1,1
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// const encoder = new TextEncoder('utf-8');
|
// const encoder = new TextEncoder('utf-8');
|
||||||
// const commandBuffer = encoder.encode(command);
|
// 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 编码
|
// 将二进制数据转换为 hex 编码
|
||||||
const hexValue = Array.from(commandBuffer)
|
const hexValue = Array.from(commandBuffer)
|
||||||
.map(byte => byte.toString(16).padStart(2, '0'))
|
.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">
|
<view class="nav-container">
|
||||||
<navigator open-type="navigate" url="/pages/deal/saleOrder/saleOrder" hover-class="navigator-hover" class="nav-button">销售</navigator>
|
<navigator open-type="navigate" url="/pages/deal/saleOrder/saleOrder" hover-class="navigator-hover" class="nav-button">销售</navigator>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@ -4,7 +4,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
},
|
},
|
||||||
onReady() {
|
onReady() {
|
||||||
// 页面加载完成
|
// 页面加载完成
|
||||||
|
|||||||
@ -3,7 +3,7 @@ Page({
|
|||||||
items: []
|
items: []
|
||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
// console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
||||||
dd.getStorage({
|
dd.getStorage({
|
||||||
key: 'saleOrderlines',
|
key: 'saleOrderlines',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
|||||||
@ -16,7 +16,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
},
|
},
|
||||||
onReady() {
|
onReady() {
|
||||||
// 页面加载完成
|
// 页面加载完成
|
||||||
|
|||||||
@ -4,7 +4,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
const objectKey = query.objectKey;
|
const objectKey = query.objectKey;
|
||||||
if (objectKey) {
|
if (objectKey) {
|
||||||
dd.getStorage({
|
dd.getStorage({
|
||||||
|
|||||||
@ -12,7 +12,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
// console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
const loginInfo = dd.getStorageSync({
|
const loginInfo = dd.getStorageSync({
|
||||||
key: 'loginInfo'
|
key: 'loginInfo'
|
||||||
}).data;
|
}).data;
|
||||||
|
|||||||
@ -4,7 +4,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
},
|
},
|
||||||
onReady() {
|
onReady() {
|
||||||
// 页面加载完成
|
// 页面加载完成
|
||||||
|
|||||||
@ -9,8 +9,7 @@ Page({
|
|||||||
Uid: null, //登录获取的信息保存本地设备
|
Uid: null, //登录获取的信息保存本地设备
|
||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// // 页面加载
|
||||||
console.info(`胜佳Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
// 检查本地缓存中是否有登录信息 要四个不为空才渲染//
|
// 检查本地缓存中是否有登录信息 要四个不为空才渲染//
|
||||||
const loginInfo = dd.getStorageSync({
|
const loginInfo = dd.getStorageSync({
|
||||||
key: 'loginInfo'
|
key: 'loginInfo'
|
||||||
@ -37,7 +36,7 @@ Page({
|
|||||||
type:'success',
|
type:'success',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -85,7 +84,7 @@ Page({
|
|||||||
type: 'none',
|
type: 'none',
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -113,7 +112,7 @@ Page({
|
|||||||
type: 'none',
|
type: 'none',
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -180,7 +179,7 @@ Page({
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
resolve(uid);
|
resolve(uid);
|
||||||
@ -204,7 +203,7 @@ Page({
|
|||||||
type: 'none',
|
type: 'none',
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -283,7 +282,6 @@ Page({
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -292,7 +290,6 @@ Page({
|
|||||||
type: 'none',
|
type: 'none',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -303,7 +300,6 @@ Page({
|
|||||||
type: 'none',
|
type: 'none',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
success() {
|
success() {
|
||||||
console.log('toast end');
|
|
||||||
},
|
},
|
||||||
fail() {
|
fail() {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
|
|||||||
@ -4,7 +4,6 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad(query) {
|
onLoad(query) {
|
||||||
// 页面加载
|
// 页面加载
|
||||||
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
|
|
||||||
},
|
},
|
||||||
onReady() {
|
onReady() {
|
||||||
// 页面加载完成
|
// 页面加载完成
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export default function jsonrpc(loginInfo, data) {
|
|||||||
},
|
},
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log(`响应状态码: ${res.status}`);
|
console.log('res',res);
|
||||||
if (res.status < 200 || res.status >= 300) {
|
if (res.status < 200 || res.status >= 300) {
|
||||||
reject(new Error(`HTTP error! status: ${res.status}`));
|
reject(new Error(`HTTP error! status: ${res.status}`));
|
||||||
return;
|
return;
|
||||||
@ -25,7 +25,7 @@ export default function jsonrpc(loginInfo, data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ObjectData = result.result;
|
const ObjectData = result.result;
|
||||||
console.log('获取订单数据成功:', ObjectData);
|
// console.log('获取订单数据成功:', ObjectData);
|
||||||
resolve(ObjectData);
|
resolve(ObjectData);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user