Commit 8aa09097 by liangjianmin

bug

parent 92718ac9
...@@ -23,8 +23,8 @@ import { API } from '@/util/api.js'; ...@@ -23,8 +23,8 @@ import { API } from '@/util/api.js';
export default { export default {
data() { data() {
return { return {
account: 'admin@ichunt.com', account: '',
passwd: '123456789' passwd: ''
}; };
}, },
onLoad(options) {}, onLoad(options) {},
......
...@@ -219,7 +219,7 @@ export default { ...@@ -219,7 +219,7 @@ export default {
data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n'); data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n');
data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n'); data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n');
data.push('B QR 280 110 M 2 U 8\r\n'); data.push('B QR 280 110 M 2 U 8\r\n');
data.push('MA,' + this.printLabelData[this.print_number]['box_code'] + '|\r\n'); data.push('MA,' + this.printLabelData[this.print_number]['erp_order_sn'] + '|\r\n');
data.push('ENDQR\r\n'); data.push('ENDQR\r\n');
data.push('FORM\r\n'); data.push('FORM\r\n');
data.push('PRINT\r\n'); data.push('PRINT\r\n');
......
...@@ -64,6 +64,8 @@ export default { ...@@ -64,6 +64,8 @@ export default {
}; };
}, },
onLoad(option) { onLoad(option) {
this.platform = getPlatform();
//停止搜索,节省系统资源 //停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({ uni.stopBluetoothDevicesDiscovery({
success: res => { success: res => {
...@@ -187,7 +189,7 @@ export default { ...@@ -187,7 +189,7 @@ export default {
uni.showLoading({ uni.showLoading({
title: '打印中...' title: '打印中...'
}); });
console.log('第' + this.print_number + '次打印'); console.log('第' + this.print_number + '次开始打印start...');
let data = []; let data = [];
if (this.printLabelData.length > 0) { if (this.printLabelData.length > 0) {
data.push('! 60 200 200 300 1\r\n'); data.push('! 60 200 200 300 1\r\n');
...@@ -204,15 +206,13 @@ export default { ...@@ -204,15 +206,13 @@ export default {
data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n'); data.push('T 8 0 10 220 仓库代码:' + this.printLabelData[this.print_number].warehouse_code + '\r\n');
data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n'); data.push('T 8 0 10 260 流水号:' + this.printLabelData[this.print_number].wstyptll_id_sn + '\r\n');
data.push('B QR 280 110 M 2 U 8\r\n'); data.push('B QR 280 110 M 2 U 8\r\n');
data.push('MA,' + this.printLabelData[this.print_number].box_code + '|\r\n'); data.push('MA,' + this.printLabelData[this.print_number].erp_order_sn + '|\r\n');
data.push('ENDQR\r\n'); data.push('ENDQR\r\n');
data.push('FORM\r\n'); data.push('FORM\r\n');
data.push('PRINT\r\n'); data.push('PRINT\r\n');
} }
let arrayBuffer = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.join('')));
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join('')); console.log(data.join(''));
this.cutCommand(data.join(''));
} catch (e) { } catch (e) {
uni.hideLoading(); uni.hideLoading();
uni.showModal({ uni.showModal({
...@@ -224,57 +224,78 @@ export default { ...@@ -224,57 +224,78 @@ export default {
} }
}, },
/** /**
* 分批传输数据
*/
cutCommand: function(data) {
var packageLength = 15; //安卓不超过20个字节传输
var sendData64 = [];
if (this.platform == 'ios') {
packageLength = 40;
}
console.log('package长度:' + packageLength);
for (let i = 0; i < Math.ceil(data.length / packageLength); i++) {
sendData64[i] = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.substr(i * packageLength, packageLength)));
}
this.sendData64 = sendData64;
console.log(sendData64);
this.writeBLECharacteristicValue(1);
},
/**
* 写入二进制数据 * 写入二进制数据
*/ */
writeBLECharacteristicValue() { writeBLECharacteristicValue(times) {
let that = this; var sendData64 = this.sendData64;
uni.writeBLECharacteristicValue({ if (sendData64.length >= times) {
deviceId: this.deviceId, uni.writeBLECharacteristicValue({
serviceId: this.serviceId, deviceId: this.deviceId,
characteristicId: this.characteristics, serviceId: this.serviceId,
value: this.sendData64, characteristicId: this.characteristics,
success: res => { value: sendData64[times - 1],
this.print_number++; success: res => {
console.log('打印张数:' + this.print_number); this.writeBLECharacteristicValue(++times);
if (this.print_number < this.printLabelData.length) { },
this.sendDataChange(); fail() {
} else {
uni.hideLoading(); uni.hideLoading();
//清空数据
that.print_number = 0;
that.printLabelData = [];
that.sendData64 = '';
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '打印成功,请查看标签打印机', content: '打印失败,请检查打印机',
showCancel: false, showCancel: false,
confirmText: '关闭', confirmText: '关闭',
success: function(res) { success: function(res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消'); console.log('用户点击取消');
} }
} }
}); });
} }
}, });
fail() { } else {
this.print_number++;
console.log('第' + this.print_number + '次传输完成end');
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
uni.hideLoading(); uni.hideLoading();
//清空数据
this.print_number = 0;
this.printLabelData = [];
this.sendData64 = '';
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '打印失败,请检查打印机', content: '打印成功,请查看标签打印机',
showCancel: false, showCancel: false,
confirmText: '关闭', confirmText: '关闭',
success: function(res) { success: function(res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消'); console.log('用户点击取消');
} }
} }
}); });
} }
}); }
}, },
change(index, type) { change(index, type) {
if (type == 'erp_order_sn_pre') { if (type == 'erp_order_sn_pre') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment