From 00a363f1ef1e2ded9f7a8e933cd89d863458a3b4 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期三, 06 八月 2025 10:09:06 +0800
Subject: [PATCH] 修改工序出站汇报单前保存
---
components/blueToothConnector/blueToothConnector.vue | 180 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 146 insertions(+), 34 deletions(-)
diff --git a/components/blueToothConnector/blueToothConnector.vue b/components/blueToothConnector/blueToothConnector.vue
index 9b86d0f..d642203 100644
--- a/components/blueToothConnector/blueToothConnector.vue
+++ b/components/blueToothConnector/blueToothConnector.vue
@@ -2,7 +2,15 @@
<view>
<!-- 钃濈墮杩炴帴鐘舵�� MAC鍦板潃 -->
<view class="connection-status">
- <view>杩炴帴鐘舵�侊細</view>
+ <view style="display: flex; flex-direction: row; gap: 20rpx;padding: 20rpx;">
+ <view style="width: 5rem;">杩炴帴璁惧: </view>
+ <view v-if="$printer.isConnected() === false">鏃�</view>
+ <view v-else="$printer.isConnected() === true"
+ style="flex: 1;display: inline-flex;flex-direction: row;justify-content: space-between;">
+ <view>{{ $printer.connectedDevice().name }}</view>
+ <view>{{ $printer.connectedDevice().address }}</view>
+ </view>
+ </view>
</view>
<!-- 鎿嶄綔鍖� -->
<view class="buttons">
@@ -10,19 +18,23 @@
<button class="btn-d" @click="closeBluetooth()">鏂紑杩炴帴</button>
</view>
<!-- 璁惧鍒楄〃 -->
- <view v-for="(device, index) in discoveredDevices" :key="device.address">
- <uni-card :title="device.name" :extra="connectedDeviceId === device.address?'宸茶繛鎺�':'鏈繛鎺�'"
- style="margin: 10px;">
- <view class="operation-zone">
- <button class="op1" size="mini" plain @click="connectBT(device)">杩炴帴璁惧</button>
- </view>
- </uni-card>
- </view>
+ <scroll-view scroll-y="true" style="height: calc(80vh - 8rem);">
+ <view v-for="(device, index) in discoveredDevices" :key="device.address">
+ <uni-card :title="device.name" :extra="connectedDeviceId === device.address?'宸茶繛鎺�':'鏈繛鎺�'"
+ style="margin: 10px;">
+ <view class="operation-zone">
+ <button class="op1" size="mini" plain @click="connectBT(device)">杩炴帴璁惧</button>
+ </view>
+ </uni-card>
+ </view>
+ </scroll-view>
</view>
</template>
<script>
- import bluetoothTool from '@/plugins/BluetoothTool.js'
+ import {
+ CommonUtils
+ } from '../../utils/common';
import permission from '@/plugins/permission.js'
import {
InputImage
@@ -34,12 +46,19 @@
FakeConnectedDevice,
WriteOptions,
} from '@psdk/frame-father';
+ import {
+ getAddress
+ } from '../../utils/auth';
+ import blueToothTool from '@/plugins/BluetoothTool.js';
+import { nextTick } from "vue";
export default {
- name: "blueToothConnector",
+ name: "blueToothPrinterConnector",
data() {
return {
discoveredDevices: [], // 鏌ヨ鍒扮殑璁惧
- connectedDeviceId: ""
+ connectedDeviceId: "",
+ readSuccess: false,
+ clock: null,
};
},
methods: {
@@ -73,19 +92,16 @@
console.log('start discovery devices');
this.discoveredDevices = [];
console.log(res)
- bluetoothTool.discoveryNewDevice();
+ blueToothTool.discoveryNewDevice();
},
fail: async (e) => {
console.error(e)
- switch (e.code) {
- case "10009":
- this.showToast("姝よ澶囦笉鏀寔璁惧鎼滅储鍔熻兘!");
- break;
- default:
- console.error(e);
+ if(e.errCode == 10009) {
+ this.showToast('姝よ澶囦笉鏀寔璁惧鎼滅储鍔熻兘!');
}
}
})
+
},
onDevice(device) {
console.log("鐩戝惉瀵绘壘鍒版柊璁惧鐨勪簨浠�---------------")
@@ -107,19 +123,24 @@
uni.showLoading({
title: '杩炴帴涓�'
});
- bluetoothTool.connDevice(device.address, (result) => {
- console.log(result)
+ blueToothTool.connDevice(device.address, (result) => {
+ console.log("璁惧MAC鍦板潃: ", device.address)
+ console.log("printer锛�", vm.$printer._connectedDevice)
uni.hideLoading()
if (result) {
// // console.log(result);
- bluetoothTool.cancelDiscovery();
+ blueToothTool.cancelDiscovery();
// console.log(vm.$printer)
vm.$printer.init(new FakeConnectedDevice());
vm.connectedDeviceId = device.address;
+ vm.$printer._connectedDevice.address = device.address
+ vm.$printer._connectedDevice.name = device.name
+ console.log("printer锛�", vm.$printer._connectedDevice)
uni.showToast({
icon: 'none',
title: '杩炴帴鎴愬姛'
})
+
} else {
uni.showToast({
icon: 'none',
@@ -130,45 +151,136 @@
},
stopSearchBT() {
console.log("鍋滄鎼滃闄勮繎鐨勮摑鐗欏鍥磋澶�---------------")
- bluetoothTool.cancelDiscovery();
+ blueToothTool.cancelDiscovery();
},
closeBluetooth() {
console.log("鍋滄钃濈墮杩炴帴")
const vm = this;
if (vm.connectedDeviceId != '') {
- bluetoothTool.closeBtSocket();
+ blueToothTool.closeBtSocket();
vm.connectedDeviceId = "";
+ vm.$printer._connectedDevice = null
}
+
+ },
+ showToast(msg, status = "none") {
+ uni.showToast({
+ title: msg,
+ icon: status,
+ duration: 2000
+ });
+ },
+ async checkReadSuccess(count) {
+ // 鎵归噺鎻掑叆鏃讹紝濡傛灉鍓嶄竴娆″彂閫佹垚鍔燂紝鍒欐竻闄ゅ墠涓�娆$殑鏃堕挓
+ if (this.clock != null) {
+ this.clock.stop();
+ this.clock = null;
+ }
+ let that = this
+ return new Promise((resolve, reject) => {
+ let currentCount = 0;
+ that.clock = new CommonUtils.timeClock(() => {
+ console.log(that.readSuccess)
+ currentCount++;
+ if (that.readSuccess == true) {
+ that.clock.stop();
+ resolve(true);
+ } else if (currentCount >= count) {
+ that.clock.stop();
+ reject(new Error('璇诲彇瓒呮椂'));
+ }
+ }, 2000);
+
+ // 鍚姩鏃堕挓
+ that.clock.start();
+ });
+ },
+ async sendMessage(cmd) {
+ cmd = Array.from(this.uint8ArrayToSignedArray(cmd))
+ uni.showLoading({
+ 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)
+ }
+ that.checkReadSuccess(5)
+ .then((res) => {
+ if (res === true) {
+ toast('鍙戦�佹垚鍔�!!!')
+ resolve(true)
+ }
+ })
+ .catch((err) => {
+ toast('璁惧寮傚父,璇锋鏌ヨ澶囩姸鎬�...')
+ reject(false)
+ })
+ .finally(() => {
+ that.readSuccess = false
+ })
+ })
+
+ },
+ uint8ArrayToSignedArray(uint8Array) {
+ let signedArray = new Array(uint8Array.length);
+ for (let i = 0; i < uint8Array.length; i++) {
+ if (uint8Array[i] >= 128) {
+ signedArray[i] = uint8Array[i] - 256;
+ } else {
+ signedArray[i] = uint8Array[i];
+ }
+ }
+ return signedArray;
},
},
async mounted() {
//#ifdef APP-PLUS
// 钃濈墮
- bluetoothTool.init({
+ console.log("钃濈墮鍒濆鍖�")
+ blueToothTool.init({
listenBTStatusCallback: (state) => {
if (state == 'STATE_ON') {
console.log(state);
+ }
+ if (state == 'STATE_OFF') {
+ console.log(state);
+ this.closeBluetooth()
}
},
discoveryDeviceCallback: this.onDevice,
discoveryFinishedCallback: function() {
console.log("鎼滅储瀹屾垚");
},
- readDataCallback: function(dataByteArr) {
- /* if(that.receiveDataArr.length >= 200) {
- that.receiveDataArr = [];
- }
- that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr); */
+ readDataCallback: (dataByteArr) => {
+ // if(that.receiveDataArr.length >= 200) {
+ // that.receiveDataArr = [];
+ // }
+ // that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr);
+ this.readSuccess = true
console.log("璇诲彇瀹屾垚" + dataByteArr);
},
connExceptionCallback: function(e) {
console.log(e);
}
});
-
- // 鏌ョ湅杩炴帴璁惧
- let pariedDevices = bluetoothTool.getPairedDevices()
- console("宸查厤瀵硅澶�", pariedDevices)
+
+ if (this.$printer.isConnected()) {
+ this.connectedDeviceId = this.$printer.connectedDevice().address
+ }
//#endif
},
}
--
Gitblit v1.9.1