diff --git a/components/.DS_Store b/components/.DS_Store index 988d8bf..045bef0 100644 Binary files a/components/.DS_Store and b/components/.DS_Store differ diff --git a/components/kk-printer/index.vue b/components/kk-printer/index.vue index 81d1219..3a4f48f 100644 --- a/components/kk-printer/index.vue +++ b/components/kk-printer/index.vue @@ -6,14 +6,14 @@ - + 搜索设备 @@ -40,14 +40,14 @@ 信号强度: ({{Math.max(0, item.RSSI + 100)}}%) - + @@ -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; } } diff --git a/components/kk-printer/utils/bluetoolth.js b/components/kk-printer/utils/bluetoolth.js index 9175301..ee0862b 100644 --- a/components/kk-printer/utils/bluetoolth.js +++ b/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); + }); } } diff --git a/components/kk-printer/utils/printUtil-GBK.js b/components/kk-printer/utils/printUtil-GBK.js index 788d954..39d40cb 100644 --- a/components/kk-printer/utils/printUtil-GBK.js +++ b/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(); - /*********改自qiushuiwuhen(2002-9-16)********/ 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);} } diff --git a/components/kk-printer/utils/util.js b/components/kk-printer/utils/util.js index 39a3e2f..d088668 100644 --- a/components/kk-printer/utils/util.js +++ b/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++) { diff --git a/components/password-login-logistics/password-login-logistics.vue b/components/password-login-logistics/password-login-logistics.vue deleted file mode 100644 index d4f3441..0000000 --- a/components/password-login-logistics/password-login-logistics.vue +++ /dev/null @@ -1,106 +0,0 @@ - - - - \ No newline at end of file