Commit 92718ac9 by liangjianmin

安卓丢包

parent c8a648b2
......@@ -5,11 +5,11 @@
<view class="form-box column rowCenter verCenter">
<view class="input-box row verCenter">
<text class="iconfont icon-riqi"></text>
<input type="text" class="uni-input" placeholder="请输入登录账号" v-model="account" placeholder-style="color: #6E767A;"/>
<input type="text" class="uni-input" placeholder="请输入登录账号" v-model="account" placeholder-style="color: #6E767A;" />
</view>
<view class="input-box row verCenter">
<text class="iconfont icon-a-riqi1"></text>
<input type="password" class="uni-input" placeholder="请输入登录密码" v-model="passwd" placeholder-style="color: #6E767A;"/>
<input type="password" class="uni-input" placeholder="请输入登录密码" v-model="passwd" placeholder-style="color: #6E767A;" />
</view>
<button class="btn row rowCenter verCenter" @click="submit()">登录</button>
</view>
......@@ -23,8 +23,8 @@ import { API } from '@/util/api.js';
export default {
data() {
return {
account: '',
passwd: ''
account: 'admin@ichunt.com',
passwd: '123456789'
};
},
onLoad(options) {},
......@@ -52,7 +52,7 @@ export default {
return false;
}
this.request(API.login, 'POST', { account: this.account, passwd: this.passwd },true).then(res => {
this.request(API.login, 'POST', { account: this.account, passwd: this.passwd }, true).then(res => {
if (res.err_code === 0) {
uni.setStorageSync('token', res.data.token);
uni.navigateBack({
......
......@@ -36,14 +36,6 @@
<view class="label">{{ text }}</view>
<input type="number" v-model="form.label_num" placeholder-style="font-size:24rpx;color:#404547;" class="uni-input" placeholder="请输入" />
</view>
<!-- <view class="box row verCenter">
<view class="label">放置托盘</view>
<view class="el-select row verCenter">
<picker @change="bindPickerChange" :value="index" :range="traySelectOption" range-key="tray_sn">
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
</picker>
</view>
</view> -->
</view>
<view class="btn row rowCenter verCenter" @click="submit()">提交打印</view>
</view>
......@@ -51,6 +43,7 @@
<script>
import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js';
const ToBase64 = require('../../util/base64gb2312.js');
export default {
......@@ -71,6 +64,7 @@ export default {
sendData64: '',
printLabelData: [],
print_text: '总箱数',
platform: '',
form: {
erp_order_sn_pre: '',
print_type: 1,
......@@ -81,6 +75,8 @@ export default {
};
},
onLoad(option) {
this.platform = getPlatform();
//停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({
success: res => {
......@@ -147,7 +143,6 @@ export default {
});
return false;
}
if (!this.form.erp_order_sn_pre) {
uni.showToast({
icon: 'error',
......@@ -185,7 +180,6 @@ export default {
});
return false;
}
this.request(API.printLabel, 'POST', this.form, false).then(res => {
if (res.err_code === 0) {
this.printLabelData = res.data;
......@@ -208,7 +202,7 @@ export default {
uni.showLoading({
title: '打印中...'
});
console.log('第' + this.print_number + '次打印');
console.log('第' + this.print_number + '次开始打印start...');
let data = [];
if (this.printLabelData.length > 0) {
data.push('! 60 200 200 300 1\r\n');
......@@ -230,10 +224,8 @@ export default {
data.push('FORM\r\n');
data.push('PRINT\r\n');
}
let arrayBuffer = uni.base64ToArrayBuffer(ToBase64.encode64gb2312(data.join('')));
this.sendData64 = arrayBuffer;
this.writeBLECharacteristicValue();
console.log(data.join(''));
this.cutCommand(data.join(''));
} catch (e) {
uni.hideLoading();
uni.showModal({
......@@ -245,57 +237,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() {
let that = this;
uni.writeBLECharacteristicValue({
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: this.sendData64,
success: res => {
this.print_number++;
console.log('打印张数:' + this.print_number);
if (this.print_number < this.printLabelData.length) {
this.sendDataChange();
} else {
writeBLECharacteristicValue(times) {
var sendData64 = this.sendData64;
if (sendData64.length >= times) {
uni.writeBLECharacteristicValue({
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristics,
value: sendData64[times - 1],
success: res => {
this.writeBLECharacteristicValue(++times);
},
fail() {
uni.hideLoading();
//清空数据
that.print_number = 0;
that.printLabelData = [];
that.sendData64 = '';
uni.showModal({
title: '提示',
content: '打印成功,请查看标签打印机',
content: '打印失败,请检查打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
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();
//清空数据
this.print_number = 0;
this.printLabelData = [];
this.sendData64 = '';
uni.showModal({
title: '提示',
content: '打印失败,请检查打印机',
content: '打印成功,请查看标签打印机',
showCancel: false,
confirmText: '关闭',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
});
}
},
change(index, type) {
if (type == 'erp_order_sn_pre') {
......
//const API_BASE = 'https://api.ichunt.com';
const API_BASE = 'http://api.liexin.com'
const API_BASE = 'https://api.ichunt.com';
//const API_BASE = 'http://api.liexin.com'
const API = {
/**
* 上传数据
......
......@@ -47,7 +47,7 @@ const request = (url = '', type = 'GET', param = {}, Loading) => {
* 平台判断
*/
const getPlatform = () => {
let platform = uni.getSystemInfoSync().platform
let platform = uni.getSystemInfoSync().platform;
if (platform == 'ios') {
platform = 'ios';
} else if (platform == 'android') {
......
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