wtt
2026-01-07 1ce2a5eea6140cb576cbb6494a00a5f1934973a8
components/blueToothConnector/blueToothConnector.vue
@@ -32,6 +32,7 @@
</template>
<script>
    import printerMeta from "../../static/json/printerMeta.json";
   import {
      CommonUtils
   } from '../../utils/common';
@@ -50,6 +51,7 @@
      getAddress
   } from '../../utils/auth';
   import blueToothTool from '@/plugins/BluetoothTool.js';
import { nextTick } from "vue";
   export default {
      name: "blueToothPrinterConnector",
      data() {
@@ -95,12 +97,8 @@
               },
               fail: async (e) => {
                  console.error(e)
                  switch (e.code) {
                     case "10009":
                        this.showToast("此设备不支持设备搜索功能!");
                        break;
                     default:
                        console.error(e);
                  if(e.errCode == 10009) {
                     this.showToast('此设备不支持设备搜索功能!');
                  }
               }
            })
@@ -183,15 +181,16 @@
            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();
@@ -203,33 +202,22 @@
               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