From bbae990ed1f4574fa954753faeae159052d03fba Mon Sep 17 00:00:00 2001
From: llj <132905093+newwwwwwtree@users.noreply.github.com>
Date: 星期二, 27 一月 2026 16:14:06 +0800
Subject: [PATCH] 待我审核增加销售订单,采购订单
---
components/blueToothConnector/blueToothConnector.vue | 234 +++++++++++++++++++++++++---------------------------------
1 files changed, 100 insertions(+), 134 deletions(-)
diff --git a/components/blueToothConnector/blueToothConnector.vue b/components/blueToothConnector/blueToothConnector.vue
index 2b9aba0..b8d00cf 100644
--- a/components/blueToothConnector/blueToothConnector.vue
+++ b/components/blueToothConnector/blueToothConnector.vue
@@ -6,7 +6,7 @@
<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;">
+ style="flex: 1;display: inline-flex;flex-direction: row;justify-content: space-between;">
<view>{{ $printer.connectedDevice().name }}</view>
<view>{{ $printer.connectedDevice().address }}</view>
</view>
@@ -18,19 +18,24 @@
<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 printerMeta from "../../static/json/printerMeta.json";
+ import {
+ CommonUtils
+ } from '../../utils/common';
import permission from '@/plugins/permission.js'
import {
InputImage
@@ -42,13 +47,19 @@
FakeConnectedDevice,
WriteOptions,
} from '@psdk/frame-father';
-import { getAddress } from '../../utils/auth';
+ 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: "",
+ readSuccess: false,
+ clock: null,
};
},
methods: {
@@ -82,16 +93,12 @@
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('姝よ澶囦笉鏀寔璁惧鎼滅储鍔熻兘!');
}
}
})
@@ -117,24 +124,24 @@
uni.showLoading({
title: '杩炴帴涓�'
});
- bluetoothTool.connDevice(device.address, (result) => {
+ blueToothTool.connDevice(device.address, (result) => {
console.log("璁惧MAC鍦板潃: ", device.address)
- console.log("printer锛�",vm.$printer._connectedDevice)
+ 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)
+ console.log("printer锛�", vm.$printer._connectedDevice)
uni.showToast({
icon: 'none',
title: '杩炴帴鎴愬姛'
})
-
+
} else {
uni.showToast({
icon: 'none',
@@ -145,44 +152,16 @@
},
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
-
}
- },
- labelPrint() {
- // 鎵撳嵃
- // 妫�鏌ヨ摑鐗欒繛鎺�
- let btStatus = bluetoothTool.getBluetoothStatus()
- if (btStatus != true) {
- this.showToast("钃濈墮杩炴帴寮傚父!")
- return
- }
-
- // 妫�鏌ユ槸鍚﹁繛鎺ヨ澶�
- let pairedDevices = bluetoothTool.getPairedDevices()
- if (pairedDevices.length < 1) {
- this.showToast("鏃犺澶囪繛鎺�!")
- return
- }
-
- // 妫�鏌ヨ〃鍗曢」鏄惁鏈夌┖鍊�
- for (var key in this.hform) {
- if (this.hform[key] == "") {
- // todo 鎻愮ず琛ㄥ崟椤逛笉鑳戒负绌�
- this.showToast("琛ㄥ崟涓嶈兘鏈夌┖鍊�!")
- return
- }
- }
- this.printWrite()
-
},
showToast(msg, status = "none") {
@@ -192,7 +171,60 @@
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('璇诲彇瓒呮椂'));
+ }
+ }, printerMeta['timeoutPerMillSecond']);
+
+ // 鍚姩鏃堕挓
+ that.clock.start();
+ });
+ },
+ async sendMessage(cmd) {
+ cmd = Array.from(this.uint8ArrayToSignedArray(cmd))
+ uni.showLoading({
+ title: "鍙戦�佷腑..."
+ })
+ // 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
+ })
+ })
+
+ },
uint8ArrayToSignedArray(uint8Array) {
let signedArray = new Array(uint8Array.length);
for (let i = 0; i < uint8Array.length; i++) {
@@ -204,105 +236,39 @@
}
return signedArray;
},
- async printWrite(type = "cpcl") {
- const vm = this;
- console.log("寮�濮嬫墦鍗�------------------")
- switch (type) {
- case "cpcl":
- await vm.writeCpclModel();
- break;
- }
- },
- async writeCpclModel() {
- const vm = this;
- try {
- const cpcl = await vm.$printer.cpcl().clear()
- .page(new CPage({
- width: 608,
- height: 260
- }))
- .text(new CText({
- x: 54,
- y: 40,
- content: "鐗╂枡浠g爜: " + vm.hform.HMaterCode,
- font: CFont.TSS24
- }))
- .text(new CText({
- x: 54,
- y: 80,
- content: "鍚� 绉�: " + vm.hform.HMaterName,
- font: CFont.TSS24
- }))
- .text(new CText({
- x: 54,
- y: 120,
- content: "瑙勬牸鍨嬪彿: " + vm.hform.HMaterType,
- font: CFont.TSS24
- }))
- .text(new CText({
- x: 54,
- y: 160,
- content: "鏁� 閲�: " + vm.hform.HNumber,
- font: CFont.TSS24
- }))
- .bar(new CBar({
- x: 120,
- y: 200,
- lineWidth: 1,
- height: 80,
- content: vm.hform.HBarCode,
- codeRotation: CCodeRotation.ROTATION_0,
- codeType: CCodeType.CODE128
- }))
- .form(new CForm()) //鏍囩绾搁渶瑕佸姞瀹氫綅鎸囦护
- .print();
- console.log(cpcl.command().string());
- var binary = cpcl.command().binary();
- await this.sendMessage(Array.from(this.uint8ArrayToSignedArray(binary)));
- } catch (e) {
- console.error(e);
- uni.showToast({
- title: '澶辫触',
- });
- }
- },
- async sendMessage(cmd) {
- console.log(cmd);
- const result = bluetoothTool.sendByteData(cmd);
- uni.showToast({
- icon: 'none',
- title: result ? '鍙戦�佹垚鍔燂紒' : '鍙戦�佸け璐�...'
- })
- },
},
async mounted() {
//#ifdef APP-PLUS
// 钃濈墮
console.log("钃濈墮鍒濆鍖�")
- bluetoothTool.init({
+ 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);
}
});
-
- console.log(this.$printer)
- if(this.$printer.isConnected()){
+
+ if (this.$printer.isConnected()) {
this.connectedDeviceId = this.$printer.connectedDevice().address
}
//#endif
--
Gitblit v1.9.1