wangfukang 3 years ago
parent
commit
be0356f73e
  1. BIN
      components/.DS_Store
  2. 133
      components/kk-printer/index.vue
  3. 24
      components/kk-printer/utils/bluetoolth.js
  4. 5
      components/kk-printer/utils/printUtil-GBK.js
  5. 25
      components/kk-printer/utils/util.js
  6. 106
      components/password-login-logistics/password-login-logistics.vue

BIN
components/.DS_Store

Binary file not shown.

133
components/kk-printer/index.vue

@ -6,14 +6,14 @@
<view class="kk-shadow" :class="isShowSearch?'show':''" @tap="handleSearchClose">
<view class="kk-modal" @tap.stop="doNothing">
<view class="kk-search-device">
<view class="kk-filter-wrap">
<!-- <view class="kk-filter-wrap">
<view class="filter-title">根据SRRI过滤设备</view>
<slider @change="handleSRRIChange" max='-20' min='-100' value="-95" show-value/>
</view>
<view class="kk-filter-wrap">
<view class="filter-title">根据蓝牙名过滤</view>
<input type="text" placeholder-class="kk-placeholder-class" placeholder="请输入蓝牙名字或设备ID搜索" v-model="filterName" />
</view>
</view> -->
<view class="kk-btn-wrap">
<view class="kk-btn-item confirm-btn" @tap="searchBtnTap" v-if="!isSearching">
搜索设备
@ -40,14 +40,14 @@
<text>信号强度:</text>
<text>({{Math.max(0, item.RSSI + 100)}}%)</text>
</view>
<view class="deviceid">
<!-- <view class="deviceid">
<text>设备ID:</text>
<text>{{item.deviceId}}</text>
</view>
<view class="advmac" v-if="item.advMac">
<text>advMac:</text>
<text>{{item.advMac}}</text>
</view>
</view> -->
</view>
</view>
</view>
@ -123,7 +123,6 @@
let devices = this.devicesList;
let name = this.filterName;
let rssi = this.filterRSSI;
console.log(devices,name,rssi)
//按RSSI过滤
let filterDevices1 = devices.filter((item)=>{
return item.RSSI > rssi
@ -165,82 +164,45 @@
blesdk.openBlue().then((res)=>{
//获取已连接设备
blesdk.getConnectedBluetoothDevices().then((res)=>{
if(this.iosNo){
let datalen=20;
// #ifdef APP-PLUS
if (plus.os.name != 'Android')
{
datalen=180;
}
// #endif
this.isPrinting = true;
this.$emit('onPrint');
this.$nextTick(()=>{
if(this.bufferData!=''){
let buffer = gbk.strToGBKByte(this.bufferData)
let opt = {
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.writeId,
value:buffer,
lasterSuccess: this.onPrintSuccess,
onceLength:datalen
}
console.log("开始打印了")
blesdk.sendDataToDevice(opt);
this.isPrinting = false;
//打印成功跳转页面
if(uni.getStorageSync('deviceId') != '' && uni.getStorageSync('serviceId') != ''){
if(res.devices.length==0){
blesdk.createBLEConnection(uni.getStorageSync('deviceId'), this.onConnectSuccess, this.onConnectFail);
}else{
let datalen=20;
// #ifdef APP-PLUS
if (plus.os.name != 'Android')
{
datalen=180;
}
// #endif
})
return
}
if(uni.getStorageSync('deviceId') != '' && uni.getStorageSync('serviceId') != ''){
console.log('第二次进入')
let datalen=20;
// #ifdef APP-PLUS
if (plus.os.name != 'Android')
{
datalen=180;
this.isPrinting = true;
this.$emit('onPrint');
this.$nextTick(()=>{
if(this.bufferData!=''){
let buffer = gbk.strToGBKByte(this.bufferData)
let opt = {
deviceId: uni.getStorageSync('deviceId'),
serviceId: uni.getStorageSync('serviceId'),
characteristicId: uni.getStorageSync('writeId'),
value:buffer,
lasterSuccess: this.onPrintSuccess,
onceLength:datalen
}
blesdk.sendDataToDevice(opt);
this.isPrinting = false;
//打印成功跳转页面
}
})
}
// #endif
this.isPrinting = true;
this.$emit('onPrint');
this.$nextTick(()=>{
if(this.bufferData!=''){
let buffer = gbk.strToGBKByte(this.bufferData)
let opt = {
deviceId: uni.getStorageSync('deviceId'),
serviceId: uni.getStorageSync('serviceId'),
characteristicId: uni.getStorageSync('writeId'),
value:buffer,
lasterSuccess: this.onPrintSuccess,
onceLength:datalen
}
console.log("开始打印了")
blesdk.sendDataToDevice(opt);
this.isPrinting = false;
//打印成功跳转页面
}
})
}else{
console.log('首次进入')
console.log("没有设备连接")
this.iosNo = true
this.isShowSearch = true
}
// //若没有已连接设备,弹框搜索设备
// if(res.devices.length == 0){
// }else{
// }
}).catch((err)=>{
blesdk.catchToast(err);
})
@ -275,9 +237,7 @@
let name = device.name;
this.deviceId = deviceId;
uni.setStorageSync('deviceId',deviceId);
// uni.setStorageSync('k_curDeviceName',name);plus.bluetooth.onBluetoothDeviceFound
uni.onBLEConnectionStateChange(function(res){
console.log('连接',res)
if(res.connected){
// plus.nativeUI.toast('设备'+ res.deviceId + '已连接',{
@ -289,46 +249,49 @@
// })
}
})
blesdk.createBLEConnection(deviceId, this.onConnectSuccess, this.onConnectFail);
blesdk.createBLEConnection(deviceId, this.onConnectSuccess, this.onConnectFail);
this.devicesList == []
},
onConnectSuccess(res){
this.stopSearchBtnTap()
blesdk.getBLEDeviceServices(this.deviceId, this.onGetServicesSuccess, this.onGetServicesFail);
},
onConnectFail(err){
console.log('链接失败',err)
onConnectFail(err){
blesdk.closeBLEConnection(uni.getStorageSync('deviceId'));
this.isShowSearch = true
uni.removeStorageSync('deviceId')
uni.removeStorageSync('serviceId')
uni.removeStorageSync('writeId')
uni.removeStorageSync('readId')
// uni.
},
onGetServicesSuccess(res){
console.log('获取服务',res)
this.services = res.serviceId;
blesdk.getDeviceCharacteristics(this.deviceId, this.services, this.onGetCharacterSuccess, this.onGetCharacterFail);
blesdk.getDeviceCharacteristics(uni.getStorageSync('deviceId')?uni.getStorageSync('deviceId'):this.deviceId, uni.getStorageSync('services')?uni.getStorageSync('services'):this.services, this.onGetCharacterSuccess, this.onGetCharacterFail);
},
onGetServicesFail(err){
console.log('获取服务失败')
},
onGetCharacterSuccess(res){
console.log('获取特征值成功',res)
this.serviceId = res.serviceId;
this.writeId = res.writeId;
this.readId = res.readId;
uni.setStorageSync('serviceId',res.serviceId)
uni.setStorageSync('writeId',res.writeId)
uni.setStorageSync('readId',res.readId)
this.isShowSearch = false;
this.isShowSearch = false;
this.handlePrintTap()
},
onGetCharacterFail(err){
console.log('特征值获取失败')
},
onPrintSuccess(){
this.isPrinting = false;
this.$u.route('/pages/toll/toll',{
roomcode:this.roomcode,CustName:this.CustName,id:this.roomid})
console.log('打印成功')
this.$emit('onPrintSuccess')
},
onPrintFail(){
console.log('打印失败')
this.isPrinting = false;
}
}

24
components/kk-printer/utils/bluetoolth.js

@ -31,14 +31,12 @@ export function openBlue() {
}
export function startBluetoothDevicesDiscovery(option) {
console.log('开始蓝牙扫描');
uniAsyncPromise('startBluetoothDevicesDiscovery', option).then((res) => {
console.log('正在搜寻蓝牙设备', res);
});
}
export function getConnectedBluetoothDevices(option) {
console.log('开始获取已连接设备');
return uniAsyncPromise('getConnectedBluetoothDevices', option)
}
//二、
@ -65,7 +63,6 @@ export function onfindBlueDevices(getDevices) {
*/
export function stopBlueDevicesDiscovery() {
//监听寻找到新设备的事件
console.log('停止蓝牙扫描');
return uniAsyncPromise('stopBluetoothDevicesDiscovery').then((res) => {
console.log('停止搜寻蓝牙设备', res);
});
@ -81,7 +78,6 @@ export function stopBlueDevicesDiscovery() {
*/
export function createBLEConnection(deviceId, sucess, fail) {
//连接蓝牙设备
console.log('连接蓝牙设备', deviceId);
uniAsyncPromise("createBLEConnection", {
deviceId
})
@ -94,21 +90,15 @@ export function createBLEConnection(deviceId, sucess, fail) {
});
})
.catch(res => {
console.log('连接设备异常' + res);
console.log('连接设备异常' + JSON.stringify(res));
fail && fail({
res: res,
});
})
/*.finally(res=>{
console.log('连接成功');
sucess && sucess({
res: res,
});
});*/
}
export function closeBLEConnection(deviceId) {
console.log('断开蓝牙设备', deviceId);
uniAsyncPromise("closeBLEConnection", {
deviceId
})
@ -118,9 +108,6 @@ export function closeBLEConnection(deviceId) {
.catch(res => {
console.log('断开设备异常' + res);
})
/*.finally(res=>{
console.log('BLEDisconnect complete', res);
}); */
}
//四、连接成功后, 获取蓝牙设备的service服务
@ -130,7 +117,7 @@ export function getBLEDeviceServices(deviceId, success, fail) {
//加延迟避免取不到service
setTimeout(()=>{
uniAsyncPromise("getBLEDeviceServices", {
deviceId:deviceId
deviceId: uni.getStorageSync('deviceId')?uni.getStorageSync('deviceId'):deviceId
})
.then(res => {
console.log('服务', res);
@ -264,8 +251,7 @@ export function sendDataToDevice(options) {
...options,
value: options.value.slice(0, byteLength > speed ? speed : byteLength),
})
.then((res) => {
console.log("发送信息到蓝牙成功")
.then((res) => {
if (byteLength > speed) {
sendDataToDevice({
...options,
@ -276,7 +262,7 @@ export function sendDataToDevice(options) {
}
})
.catch((res) => {
console.log(res);
});
}
}

5
components/kk-printer/utils/printUtil-GBK.js

@ -130,7 +130,6 @@ function toUTF8Array(str) {
//字符串转GBK十六进制内码
function strToGBKHex(str) {
var ch, pos, val, ret = "", strSpecial = "!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%";
console.log('GBK123');
for (var i = 0; i < str.length; i++) {
ch = str.charAt(i);
val = str.charCodeAt(i);
@ -139,11 +138,9 @@ function strToGBKHex(str) {
ret += ("%" + (0xB0 + parseInt(pos / 94)).toString(16) + "%" + (0xA1 + pos % 94).toString(16)).toUpperCase();
}
else if ((pos = GBfh.indexOf(ch)) != -1){
console.log('GBfh'+ch)
ret += ("%" + (0xA1 + parseInt(pos / 94)).toString(16) + "%" + (0xA1 + pos % 94).toString(16)).toUpperCase();
}
else if ((pos = GBK_A940.indexOf(ch)) != -1){
console.log(pos)
ret += ("%" + (0xA9).toString(16) + "%" + (0x40 + pos).toString(16)).toUpperCase();
}
else if (strSpecial.indexOf(ch) != -1) {
@ -191,12 +188,10 @@ function stringToByte(str) {
function strToGBKByte(str) {
var bytes = new Array();
/*********改自<a href="http://blog.csdn.net/qiushuiwuhen/article/details/14112">qiushuiwuhen(2002-9-16)</a>********/
var ch, pos, val, strSpecial = "!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%";
for (var i = 0; i < str.length; i++) {
ch = str.charAt(i);
val = str.charCodeAt(i);
//console.log(ch, val)
if (val >= 0x4e00 && val < 0x9FA5) {
if ((pos = GBhz.indexOf(ch)) != -1){ bytes.push(0xB0 + parseInt(pos / 94)); bytes.push(0xA1 + pos % 94);}
}

25
components/kk-printer/utils/util.js

@ -16,31 +16,6 @@ const formatNumber = n => {
return n[1] ? n : '0' + n
}
/*
const hexStringToBuff = str => { //str='中国:WXHSH'
const buffer = new ArrayBuffer((sumStrLength(str)) * 4)
const dataView = new DataView(buffer)
var data = str.toString();
var p = 0; //ArrayBuffer 偏移量
for (var i = 0; i < data.length; i++) {
if (isCN(data[i])) { //是中文
//调用GBK 转码
var t = gbk.encode(data[i]);
for (var j = 0; j < 2; j++) {
//var code = t[j * 2] + t[j * 2 + 1];
var code = t[j * 3 + 1] + t[j * 3 + 2];
var temp = parseInt(code, 16)
//var temp = strToHexCharCode(code);
dataView.setUint8(p++, temp)
}
} else {
var temp = data.charCodeAt(i);
dataView.setUint8(p++, temp)
}
}
return buffer;
}
*/
function toUnicode(s) {
var str = "";
for (var i = 0; i < s.length; i++) {

106
components/password-login-logistics/password-login-logistics.vue

@ -1,106 +0,0 @@
<template>
<view>
<view class="main">
<view class="code">
<uni-easyinput v-model="username" :placeholder="plad" />
<com-zw />
<uni-easyinput v-model="password" :maxlength="25" placeholder="请输入密码" type="password" />
<com-zw />
</view>
<u-button type="primary" @tap.stop="confirm">登录</u-button>
</view>
</view>
</template>
<script>
import {
mapMutations,
mapActions
} from 'vuex';
export default {
name: "phone-verify-logistics",
props: {
ret: {
type: Object,
default () {
return {}
}
},
plad: {
type: String,
default: '请输入手机号'
},
},
data() {
return {
captchaId: '',
captchaImg: '',
username: '13122678567',
password: '123456',
}
},
created() {
this.getCaptchaImg();
},
methods: {
...mapMutations(['login']),
...mapActions(['getUserInfo']),
getCaptchaImg() {
this.tui.request("/common/captcha/init", "GET", null).then((res) => {
if (res.code == 200) {
this.captchaId = res.result
this.captchaImg = this.tui.interfaceUrl() + '/common/captcha/draw/' + this
.captchaId
}
}).catch((res) => {})
},
async confirm(form) { // 提
this.tui.request("/app/logitics/login", "POST", {
username: this.username,
password: this.password,
saveLogin: true
}, true, true).then((res) => {
console.log(res)
if (res.code == 200) {
uni.setStorageSync("hiver_token", res.result.lcomToken)
uni.setStorageSync("transCompany", res.result.logiticsCompany.id)
// let state = {
// token: res.result
// }
// this.login(state)
// this.getUserInfo()
this.tui.toast('登录成功', 2000, true)
setTimeout(() => {
uni.reLaunch({
url: '/pages/other/logistics'
// url: '/pages/index/index'
})
}, 200)
// if (res.result.type > 2) {
// setTimeout(() => {
// uni.reLaunch({
// // url: '/pages/index/logistics'
// url: '/pages/index/index'
// })
// }, 200)
// } else {
// setTimeout(() => {
// uni.reLaunch({
// url: '/pages/index/index'
// // url: '/pages/index/logistics'
// })
// }, 200)
// }
// } else {
// this.tui.toast(res.message)
// return
}
}).catch((res) => {})
},
}
}
</script>
<style lang="scss" scoped>
@import '@/scss/phone-verify.scss';
</style>
Loading…
Cancel
Save