From 96973dca40a1815e9727160e6b2e6dee839b9f8d Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期三, 31 十二月 2025 13:06:14 +0800
Subject: [PATCH] 质量模具模块页面优化
---
components/blueToothConnector/blueToothConnector.vue | 86 +++++++++++++++++++++---------------------
1 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/components/blueToothConnector/blueToothConnector.vue b/components/blueToothConnector/blueToothConnector.vue
index 893395c..b8d00cf 100644
--- a/components/blueToothConnector/blueToothConnector.vue
+++ b/components/blueToothConnector/blueToothConnector.vue
@@ -32,6 +32,7 @@
</template>
<script>
+ import printerMeta from "../../static/json/printerMeta.json";
import {
CommonUtils
} from '../../utils/common';
@@ -50,13 +51,15 @@
getAddress
} from '../../utils/auth';
import blueToothTool from '@/plugins/BluetoothTool.js';
+import { nextTick } from "vue";
export default {
name: "blueToothPrinterConnector",
data() {
return {
discoveredDevices: [], // 鏌ヨ鍒扮殑璁惧
connectedDeviceId: "",
- readSuccess: false
+ readSuccess: false,
+ clock: null,
};
},
methods: {
@@ -94,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('姝よ澶囦笉鏀寔璁惧鎼滅储鍔熻兘!');
}
}
})
@@ -173,22 +172,28 @@
});
},
async checkReadSuccess(count) {
+ // 鎵归噺鎻掑叆鏃讹紝濡傛灉鍓嶄竴娆″彂閫佹垚鍔燂紝鍒欐竻闄ゅ墠涓�娆$殑鏃堕挓
+ if (this.clock != null) {
+ this.clock.stop();
+ this.clock = null;
+ }
let that = this
return new Promise((resolve, reject) => {
let currentCount = 0;
- let clock = new CommonUtils.timeClock(() => {
+ that.clock = new CommonUtils.timeClock(() => {
+ console.log(that.readSuccess)
currentCount++;
- if (this.readSuccess == true) {
- clock.stop();
+ if (that.readSuccess == true) {
+ that.clock.stop();
resolve(true);
} else if (currentCount >= count) {
- clock.stop();
+ that.clock.stop();
reject(new Error('璇诲彇瓒呮椂'));
}
- }, 2000);
+ }, printerMeta['timeoutPerMillSecond']);
// 鍚姩鏃堕挓
- clock.start();
+ that.clock.start();
});
},
async sendMessage(cmd) {
@@ -196,34 +201,29 @@
uni.showLoading({
title: "鍙戦�佷腑..."
})
- console.log("msg: " + cmd);
- let toast = (msg) => {
- uni.showToast({
- icon: 'none',
- title: msg,
- duration: 2000
- })
- setTimeout(() => {
- uni.hideLoading()
- }, 3000)
- }
-
- const result = blueToothTool.sendByteData(cmd);
- if (!result) {
- return toast("鍙戦�佸け璐�,璇烽噸璇�...")
- }
- this.checkReadSuccess(5)
- .then((res) => {
- if(res === true) {
- toast('鍙戦�佹垚鍔�!!!')
+ // console.log("msg: " + cmd);
+ let that = this
+ return new Promise((resolve, reject) => {
+ const result = blueToothTool.sendByteData(cmd);
+ if (!result) {
+ this.clock.stop();
+ reject("鍙戦�佸け璐�,璇烽噸璇�...")
}
+ that.checkReadSuccess(printerMeta['timeoutCount'])
+ .then((res) => {
+ if (res === true) {
+ resolve(true)
+ }
+ })
+ .catch((err) => {
+ this.clock.stop();
+ reject('璁惧寮傚父,璇锋鏌ヨ澶囩姸鎬�...')
+ })
+ .finally(() => {
+ that.readSuccess = false
+ })
})
- .catch((err) => {
- toast('璁惧寮傚父,璇锋鏌ヨ澶囩姸鎬�...')
- })
- .finally(() => {
- this.readSuccess = false
- })
+
},
uint8ArrayToSignedArray(uint8Array) {
let signedArray = new Array(uint8Array.length);
@@ -256,10 +256,10 @@
console.log("鎼滅储瀹屾垚");
},
readDataCallback: (dataByteArr) => {
- /* if(that.receiveDataArr.length >= 200) {
- that.receiveDataArr = [];
- }
- that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr); */
+ // if(that.receiveDataArr.length >= 200) {
+ // that.receiveDataArr = [];
+ // }
+ // that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr);
this.readSuccess = true
console.log("璇诲彇瀹屾垚" + dataByteArr);
},
--
Gitblit v1.9.1