| | |
| | | </template> |
| | | |
| | | <script> |
| | | import printerMeta from "../../static/json/printerMeta.json"; |
| | | import { |
| | | CommonUtils |
| | | } from '../../utils/common'; |
| | |
| | | getAddress |
| | | } from '../../utils/auth'; |
| | | import blueToothTool from '@/plugins/BluetoothTool.js'; |
| | | import { nextTick } from "vue"; |
| | | export default { |
| | | name: "blueToothPrinterConnector", |
| | | data() { |
| | |
| | | }, |
| | | fail: async (e) => { |
| | | console.error(e) |
| | | switch (e.code) { |
| | | case "10009": |
| | | this.showToast("此设备不支持设备搜索功能!"); |
| | | break; |
| | | default: |
| | | console.error(e); |
| | | if(e.errCode == 10009) { |
| | | this.showToast('此设备不支持设备搜索功能!'); |
| | | } |
| | | } |
| | | }) |
| | |
| | | return new Promise((resolve, reject) => { |
| | | let currentCount = 0; |
| | | that.clock = new CommonUtils.timeClock(() => { |
| | | console.log(that.readSuccess) |
| | | currentCount++; |
| | | if (this.readSuccess == true) { |
| | | if (that.readSuccess == true) { |
| | | that.clock.stop(); |
| | | resolve(true); |
| | | } else if (currentCount >= count) { |
| | | that.clock.stop(); |
| | | reject(new Error('读取超时')); |
| | | } |
| | | }, 2000); |
| | | }, printerMeta['timeoutPerMillSecond']); |
| | | |
| | | // 启动时钟 |
| | | that.clock.start(); |
| | |
| | | title: "发送中..." |
| | | }) |
| | | // console.log("msg: " + cmd); |
| | | let toast = (msg) => { |
| | | uni.showToast({ |
| | | icon: 'none', |
| | | title: msg, |
| | | duration: 2000 |
| | | }) |
| | | setTimeout(() => { |
| | | uni.hideLoading() |
| | | }, 3000) |
| | | } |
| | | let that = this |
| | | return new Promise((resolve, reject) => { |
| | | const result = blueToothTool.sendByteData(cmd); |
| | | if (!result) { |
| | | toast("发送失败,请重试...") |
| | | reject(false) |
| | | this.clock.stop(); |
| | | reject("发送失败,请重试...") |
| | | } |
| | | that.checkReadSuccess(5) |
| | | that.checkReadSuccess(printerMeta['timeoutCount']) |
| | | .then((res) => { |
| | | if (res === true) { |
| | | toast('发送成功!!!') |
| | | resolve(true) |
| | | } |
| | | }) |
| | | .catch((err) => { |
| | | toast('设备异常,请检查设备状态...') |
| | | reject(false) |
| | | this.clock.stop(); |
| | | reject('设备异常,请检查设备状态...') |
| | | }) |
| | | .finally(() => { |
| | | that.readSuccess = false |