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/labelPrinterComponent/labelPrinterComponent.vue |  225 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 152 insertions(+), 73 deletions(-)

diff --git a/components/labelPrinterComponent/labelPrinterComponent.vue b/components/labelPrinterComponent/labelPrinterComponent.vue
index b77a503..2c408c5 100644
--- a/components/labelPrinterComponent/labelPrinterComponent.vue
+++ b/components/labelPrinterComponent/labelPrinterComponent.vue
@@ -1,10 +1,12 @@
 <template>
-	<view>
-		<uni-popup ref="popup" type="bottom" @close="popupCloseHandler">
-			<view style="height: 80vh; background-color: #fff;">
-				<blueToothConnectorVue></blueToothConnectorVue>
+	<view class="container" :hidden="isPopup === false">
+		<uni-popup ref="popup" type="bottom" popupshow @change="popupChange">
+			<view style="height: 80vh; background-color: #fff; padding-bottom: 2rem;">
+				<blueToothConnectorVue ref="bt"></blueToothConnectorVue>
 			</view>
 		</uni-popup>
+		<!-- 浣跨敤uni-popup绫荤殑缁勪欢鏃讹紝褰損opup涓嶆樉绀烘椂锛岀粍浠舵爲涓病鏈塸opup鍐呯殑妯$粍锛屾棤娉曚娇鐢╮ef璋冪敤妯$粍鍐呯殑鍑芥暟锛屾晠闇�瑕佸湪澶栭儴鎸傝浇涓�涓�忔槑鐨勭粍浠� -->
+		<blueToothConnectorVue style="display: none;position: absolute; bottom: 0;right: 0;" ref="bt2"></blueToothConnectorVue>
 	</view>
 </template>
 
@@ -25,11 +27,19 @@
 		Commander,
 	} from '@psdk/frame-father';
 	import blueToothConnectorVue from '../../components/blueToothConnector/blueToothConnector.vue';
+	import {
+		CStatus
+	} from '@psdk/cpcl';
+	import {
+		CommonUtils
+	} from '../../utils/common';
+import { nextTick } from "vue";
+
 	export default {
 		name: "lablePrinterComponent",
 		data() {
 			return {
-
+				isPopup: false,
 			};
 		},
 		props: {
@@ -46,97 +56,166 @@
 			blueToothConnectorVue
 		},
 		methods: {
-			openPopup(){
+			async openPopup() {
 				this.$refs.popup.open();
-			},
-			popupCloseHandler() {
+				// 鍦╬opup涓殑鎿嶄綔閽堝ref bt瀵瑰簲鐨勭粍浠讹紝闇�瑕佸皢bt缁勪欢鐨勭姸鎬佷笌bt2杩涜涓�娆″悓姝�
+				this.$nextTick(() => {
+					this.$refs.bt2 = this.$refs.bt
+				})
 				
 			},
+			async popupChange(e) {
+				this.isPopup = e['show']
+				await this.$nextTick()
+			},
+			async batchPrint(commandList) {
+				console.log(this.$refs.bt2)
+				let vm = this;
+				let binarys = [];
+				for (let command of commandList) {
+                    console.log('command: ',command);
+					switch (vm.printMode) {
+						case "tspl":
+							let tspl = await vm.$printer.tspl().clear();
+							tspl.raw(Raw.text(command))
+							console.log("print command锛歕n" + tspl.command().string())
+							binarys.push(tspl.command().binary());
+							break;
+						case "cpcl":
+							let cpcl = await vm.$printer.cpcl().clear();
+							cpcl.raw(Raw.text(command))
+							console.log("print command锛歕n" + cpcl.command().string())
+							binarys.push(cpcl.command().binary());
+							break;
+						case "esc":
+							let esc = await vm.$printer.esc().clear();
+							esc.raw(Raw.text(command))
+							console.log("print command锛歕n" + esc.command().string())
+							binarys.push(esc.command().binary());
+							break;
+						default:
+							return uni.showToast({
+								icon: 'none',
+								title: 'printMode绫诲瀷閿欒!'
+							})
+					}
+				}
+				let sendSuccess = false
+				for(let binary of binarys){
+                    
+                    try{
+                        sendSuccess = await this.$refs.bt2.sendMessage(binary);
+                        console.log("褰撳墠鍙戦�佹槸鍚︽垚鍔燂細 ", sendSuccess)
+                        
+                    }catch(e) {
+                        uni.showToast({
+                            icon: 'none',
+                            title: e
+                        })
+                        // 鏂紑钃濈墮杩炴帴
+                        this.$refs.bt2.closeBluetooth()
+                        // 鍋滄浼犺緭
+                        return
+                    }
+					
+				}
+                
+                if(sendSuccess === false) {
+                	return
+                }else {
+                    return uni.showToast({
+                        icon: 'none',
+                        title: '鎵撳嵃鎴愬姛'
+                    })
+                }
+			},
 			async execPrint() {
-				try{
+				// 妫�鏌ヨ摑鐗欒繛鎺�
+				let btStatus = bluetoothTool.getBluetoothStatus()
+				if (btStatus != true) {
+					this.showToast("钃濈墮杩炴帴寮傚父!")
+					return
+				}
+
+				// 妫�鏌ユ槸鍚﹁繛鎺ヨ澶�
+				let pairedDevices = bluetoothTool.getPairedDevices()
+				if (pairedDevices.length < 1) {
+					this.showToast("鏃犺澶囪繛鎺�!")
+					return
+				}
+				try {
 					if (typeof this.printInfo === 'function') {
 						// 浼犲叆鐨刾rintInfo鏄嚱鏁帮紝鐩存帴鎵ц
 						let msg = await this.printInfo()
-						
-						msg = this.uint8ArrayToSignedArray(msg)
-						console.log(msg)
-						this.sendMessage(msg)
-					} 
-					else if (typeof this.printInfo === 'string') {
+						this.$refs.bt2.sendMessage(msg)
+					} else if (typeof this.printInfo === 'string') {
 						// 浼犲叆鐨勫弬鏁版槸瀛楃涓诧紝鍒欐牴鎹墦鍗版ā寮忚皟鐢ㄤ笉鍚岀殑鎵撳嵃API
 						// 杩欓噷鐨勫瓧绗︿覆闇�瑕佸搴旀墦鍗版ā寮�
-						
-						let printStr = this.printInfo.replace(/\n/g, "\r\n")
-						let vm = this;
-						let binary = null;
-						switch (vm.printMode) {
-							case "tspl":
-								const tspl = await vm.$printer.tspl().clear();
-								tspl.raw(Raw.text(printStr))
-								console.log("print command锛�",tspl.command().string())
-								binary = tspl.command().binary();
-								await vm.sendMessage(Array.from(vm.uint8ArrayToSignedArray(binary)));
-								break;
-							case "cpcl":
-								const cpcl = await vm.$printer.cpcl().clear();
-								console.log(cpcl)
-								cpcl.raw(Raw.text(printStr))
-								console.log("print command锛歕n",cpcl.command().string())
-								binary = cpcl.command().binary();
-								await vm.sendMessage(Array.from(vm.uint8ArrayToSignedArray(binary)));
-								break;
-							case "esc":
-								const esc = await vm.$printer.esc().clear();
-								esc.raw(Raw.text(printStr))
-								console.log("print command锛歕n",esc.command().string())
-								binary = esc.command().binary();
-								await vm.sendMessage(Array.from(vm.uint8ArrayToSignedArray(binary)));
-								break;
-							default:
-								return uni.showToast({
-									icon: 'none',
-									title: 'printMode绫诲瀷閿欒!'
-								})
+						if (CommonUtils.isJson(this.printInfo) === true) {
+							// 濡傛灉闇�瑕佹壒閲忎紶杈擄紝闇�瑕佷紶JSON
+							let commandList = JSON.parse(this.printInfo)
+							for (let command of commandList) {
+								command.replace(/\n/g, "\r\n")
+							}
+							this.batchPrint(commandList)
+						} else {
+							let printStr = this.printInfo.replace(/\n/g, "\r\n")
+							let vm = this;
+							let binary = null;
+							switch (vm.printMode) {
+								case "tspl":
+									const tspl = await vm.$printer.tspl().clear();
+									tspl.raw(Raw.text(printStr))
+									console.log("print command锛歕n" + tspl.command().string())
+									binary = tspl.command().binary();
+									await this.$refs.bt2.sendMessage(binary);
+									break;
+								case "cpcl":
+									const cpcl = await vm.$printer.cpcl().clear();
+									cpcl.raw(Raw.text(printStr))
+									console.log("print command锛歕n" + cpcl.command().string())
+									binary = cpcl.command().binary();
+									await this.$refs.bt2.sendMessage(binary);
+									break;
+								case "esc":
+									const esc = await vm.$printer.esc().clear();
+									esc.raw(Raw.text(printStr))
+									console.log("print command锛歕n" + esc.command().string())
+									binary = esc.command().binary();
+									await this.$refs.bt2.sendMessage(binary);
+									break;
+								default:
+									return uni.showToast({
+										icon: 'none',
+										title: 'printMode绫诲瀷閿欒!'
+									})
+							}
 						}
-					} 
-					else {
+					} else {
 						uni.showToast({
 							icon: 'none',
 							title: 'printInfo绫诲瀷閿欒!'
 						})
 					}
-				}catch(e) {
+				} catch (e) {
 					console.error(e);
 					uni.showToast({
 						icon: "none",
 						title: e
 					})
 				}
-				
+
 			},
-			async sendMessage(cmd) {
-				console.log(cmd);
-				const result = bluetoothTool.sendByteData(cmd);
-				uni.showToast({
-					icon: 'none',
-					title: result ? '鍙戦�佹垚鍔燂紒' : '鍙戦�佸け璐�...'
-				})
-			},
-			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;
-			},
-		}
+		},
 	}
 </script>
 
-<style lang="scss">
-
+<style lang="scss" scoped>
+	* {
+		box-sizing: border-box;
+	}
+	.container[hidden] {
+		padding: 0 !important;
+		height: 0 !important;
+	}
 </style>
\ No newline at end of file

--
Gitblit v1.9.1