Commit 92718ac9 by liangjianmin

安卓丢包

parent c8a648b2
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
<view class="form-box column rowCenter verCenter"> <view class="form-box column rowCenter verCenter">
<view class="input-box row verCenter"> <view class="input-box row verCenter">
<text class="iconfont icon-riqi"></text> <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>
<view class="input-box row verCenter"> <view class="input-box row verCenter">
<text class="iconfont icon-a-riqi1"></text> <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> </view>
<button class="btn row rowCenter verCenter" @click="submit()">登录</button> <button class="btn row rowCenter verCenter" @click="submit()">登录</button>
</view> </view>
...@@ -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: '', account: 'admin@ichunt.com',
passwd: '' passwd: '123456789'
}; };
}, },
onLoad(options) {}, onLoad(options) {},
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
return false; 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) { if (res.err_code === 0) {
uni.setStorageSync('token', res.data.token); uni.setStorageSync('token', res.data.token);
uni.navigateBack({ uni.navigateBack({
......
...@@ -36,14 +36,6 @@ ...@@ -36,14 +36,6 @@
<view class="label">{{ text }}</view> <view class="label">{{ text }}</view>
<input type="number" v-model="form.label_num" placeholder-style="font-size:24rpx;color:#404547;" class="uni-input" placeholder="请输入" /> <input type="number" v-model="form.label_num" placeholder-style="font-size:24rpx;color:#404547;" class="uni-input" placeholder="请输入" />
</view> </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>
<view class="btn row rowCenter verCenter" @click="submit()">提交打印</view> <view class="btn row rowCenter verCenter" @click="submit()">提交打印</view>
</view> </view>
...@@ -51,6 +43,7 @@ ...@@ -51,6 +43,7 @@
<script> <script>
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import { getPlatform } from '@/util/util.js';
const ToBase64 = require('../../util/base64gb2312.js'); const ToBase64 = require('../../util/base64gb2312.js');
export default { export default {
...@@ -71,6 +64,7 @@ export default { ...@@ -71,6 +64,7 @@ export default {
sendData64: '', sendData64: '',
printLabelData: [], printLabelData: [],
print_text: '总箱数', print_text: '总箱数',
platform: '',
form: { form: {
erp_order_sn_pre: '', erp_order_sn_pre: '',
print_type: 1, print_type: 1,
...@@ -81,6 +75,8 @@ export default { ...@@ -81,6 +75,8 @@ export default {
}; };
}, },
onLoad(option) { onLoad(option) {
this.platform = getPlatform();
//停止搜索,节省系统资源 //停止搜索,节省系统资源
uni.stopBluetoothDevicesDiscovery({ uni.stopBluetoothDevicesDiscovery({
success: res => { success: res => {
...@@ -147,7 +143,6 @@ export default { ...@@ -147,7 +143,6 @@ export default {
}); });
return false; return false;
} }
if (!this.form.erp_order_sn_pre) { if (!this.form.erp_order_sn_pre) {
uni.showToast({ uni.showToast({
icon: 'error', icon: 'error',
...@@ -185,7 +180,6 @@ export default { ...@@ -185,7 +180,6 @@ export default {
}); });
return false; return false;
} }
this.request(API.printLabel, 'POST', this.form, false).then(res => { this.request(API.printLabel, 'POST', this.form, false).then(res => {
if (res.err_code === 0) { if (res.err_code === 0) {
this.printLabelData = res.data; this.printLabelData = res.data;
...@@ -208,7 +202,7 @@ export default { ...@@ -208,7 +202,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');
...@@ -230,10 +224,8 @@ export default { ...@@ -230,10 +224,8 @@ export default {
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({
...@@ -245,57 +237,78 @@ export default { ...@@ -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() { writeBLECharacteristicValue(times) {
let that = this; var sendData64 = this.sendData64;
if (sendData64.length >= times) {
uni.writeBLECharacteristicValue({ uni.writeBLECharacteristicValue({
deviceId: this.deviceId, deviceId: this.deviceId,
serviceId: this.serviceId, serviceId: this.serviceId,
characteristicId: this.characteristics, characteristicId: this.characteristics,
value: this.sendData64, value: sendData64[times - 1],
success: res => { success: res => {
this.print_number++; this.writeBLECharacteristicValue(++times);
console.log('打印张数:' + this.print_number); },
if (this.print_number < this.printLabelData.length) { fail() {
this.sendDataChange();
} 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') {
......
//const API_BASE = 'https://api.ichunt.com'; const API_BASE = 'https://api.ichunt.com';
const API_BASE = 'http://api.liexin.com' //const API_BASE = 'http://api.liexin.com'
const API = { const API = {
/** /**
* 上传数据 * 上传数据
......
...@@ -47,7 +47,7 @@ const request = (url = '', type = 'GET', param = {}, Loading) => { ...@@ -47,7 +47,7 @@ const request = (url = '', type = 'GET', param = {}, Loading) => {
* 平台判断 * 平台判断
*/ */
const getPlatform = () => { const getPlatform = () => {
let platform = uni.getSystemInfoSync().platform let platform = uni.getSystemInfoSync().platform;
if (platform == 'ios') { if (platform == 'ios') {
platform = 'ios'; platform = 'ios';
} else if (platform == 'android') { } 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