From 527d1e703b44c173d02eb165c7d6e2345ab436b4 Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期六, 16 八月 2025 17:58:37 +0800
Subject: [PATCH] 加入缺少文件

---
 PadClient2/pages/index/test/PrintInit.vue |  205 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)

diff --git a/PadClient2/pages/index/test/PrintInit.vue b/PadClient2/pages/index/test/PrintInit.vue
new file mode 100644
index 0000000..2694aac
--- /dev/null
+++ b/PadClient2/pages/index/test/PrintInit.vue
@@ -0,0 +1,205 @@
+<template>
+	<view class="mui-content">	
+			<view class="mui-input-row">
+				<label>PDA鍦板潃:</label>
+				<input v-model="pdaMac" type="text" class="mui-input-clear" placeholder="璇疯緭鍏DA鐨凪AC鍦板潃" />
+			</view>
+			<view class="mui-input-row">
+				<label>鎵撳嵃鍦板潃:</label>
+				<input v-model="printMac" type="text" class="mui-input-clear" placeholder="璇疯緭鍏ユ墦鍗版満MAC鍦板潃" />
+			</view>
+		</form>
+		<view class="mui-table-view ulcss">
+			<view class="mui-table-view-cell acss" @tap="saveSettings" style="background-color: rgb(93, 204, 201);">
+				<text>淇濆瓨</text>
+			</view>
+		</view>
+		<view class="mui-table-view ulcss">
+			<view class="mui-table-view-cell acss" @tap="doPrint2" style="background-color: rgb(153, 204, 153);">
+				<text>鎵撳嵃娴嬭瘯</text>
+			</view>
+		</view>
+		<view class="mui-table-view ulcss">
+			<view class="mui-table-view-cell acss" @tap="getSettings" style="background-color: rgb(153, 204, 153);">
+				<text>鍒锋柊</text>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				pdaMac: '',
+				printMac:'',// '00:01:78:24:28:32',
+			};
+		},
+		created() {
+			this.getSettings();
+		},
+		methods: {
+			//璇诲彇pda mac鍦板潃
+			getSettings() {
+				var mac = "";
+				if (plus.os.name == "Android") {
+					//鑾峰彇鎵嬫満MAC鍦板潃
+					var Context = plus.android.importClass("android.content.Context");
+					var WifiManager = plus.android.importClass("android.net.wifi.WifiManager");
+					var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
+					var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo");
+					var wifiInfo = wifiManager.getConnectionInfo();
+					mac = wifiInfo.getMacAddress();
+					//濡傛灉mac涓衡��02:00:00:00:00:00鈥濓紝鍒欏彲鑳芥槸瀹夊崜6.0浠ヤ笂鐗堟湰锛屽垯浣跨敤鍙︿竴绉嶆柟娉曡幏鍙杕ac鍦板潃
+					if (mac == "02:00:00:00:00:00") {
+						var str = "";
+						try {
+							if (plus.os.name == "Android") {
+								var NetworkInterface = plus.android.importClass("java.net.NetworkInterface");
+								var networkInterface = NetworkInterface.getByName("wlan0");
+								var bytes = networkInterface.getHardwareAddress();
+								//灏哹yte[] 杞崲鎴� String
+								for (var i = 0; i < bytes.length; i++) {
+									var tmp = "";
+									var num = bytes[i];
+									if (num < 0) {
+										tmp = (255 + num + 1).toString(16);
+									} else {
+										tmp = num.toString(16);
+									}
+									if (tmp.length == 1) {
+										tmp = "0" + tmp;
+									}
+									str += (i == 0) ? (tmp) : (":" + tmp);
+								}
+							}
+						} catch (err) {
+							str = "02:00:00:00:00:00";
+						}
+						mac = str;
+					}
+					//濡傛灉mac浣跨敤鏂版柟娉曚緷鐒舵槸鈥�02:00:00:00:00:00鈥濆垯涓嶈繘琛屼繚瀛�
+					if (mac == "02:00:00:00:00:00") {
+						return;
+					}
+					uni.setStorageSync('pdaMac', mac);
+					console.log(mac);
+					this.pdaMac=mac;
+					this.printMac= uni.getStorageSync('printMac');
+				}
+			},
+			//淇濆瓨鍦板潃
+			saveSettings() {
+				if (!this.pdaMac) {
+					uni.showToast({
+						title: 'PDA鍦板潃涓嶈兘涓虹┖',
+						icon: 'none',
+					});
+					return;
+				}
+				if (!this.printMac) {
+					uni.showToast({
+						title: '鎵撳嵃鏈哄湴鍧�涓嶈兘涓虹┖',
+						icon: 'none',
+					});
+					return;
+				}
+				uni.setStorageSync('pdaMac', this.pdaMac);
+				uni.setStorageSync('printMac', this.printMac);
+				//鍏堜繚瀛樺湪缂撳瓨涓紝鑻ヨ淇濆瓨鑷虫暟鎹簱锛屽湪杩欓噷post
+			},
+			//鎵撳嵃娴嬭瘯
+			doPrint2() {
+				var mac_address =  uni.getStorageSync('printMac');
+				console.log('鎵撳嵃寮�濮�:'+mac_address)
+				var device = null,
+					BAdapter = null,
+					BluetoothAdapter = null,
+					uuid = null,
+					main = null,
+					bluetoothSocket = null;
+				if (!mac_address) {
+					this.$showMessage('璇烽�夋嫨钃濈墮鎵撳嵃鏈�');
+					return false;
+				}
+				main = plus.android.runtimeMainActivity();
+				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
+				let UUID = plus.android.importClass("java.util.UUID");
+				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
+				BAdapter = BluetoothAdapter.getDefaultAdapter();
+				device = BAdapter.getRemoteDevice(mac_address);
+				plus.android.importClass(device);
+				bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
+				plus.android.importClass(bluetoothSocket);
+				if (!bluetoothSocket.isConnected()) {
+					console.log('妫�娴嬪埌璁惧鏈繛鎺ワ紝灏濊瘯杩炴帴....');
+					bluetoothSocket.connect();
+				}
+				console.log('璁惧宸茶繛鎺�');
+				if (bluetoothSocket.isConnected()) {
+					var outputStream = bluetoothSocket.getOutputStream();
+					plus.android.importClass(outputStream);
+					let printStr =
+						"! 0 200 200 230 1\n" +
+						"PW 848\n" +
+						"TONE 0\n" +
+						"SPEED 0\n" +
+						"GAP-SENSE\n" +
+						"NO-PACE\n" +
+						"POSTFEED 0\n" +
+						"LEFT\n" +
+						"T 65 1 20 2 鐗╂枡缂栫爜锛歕n" +
+						"SETBOLD 2\n" +
+						"T 65 1 140 1 {0}\n" +
+						"SETBOLD 0\n" +
+						"T 65 1 300 1 {11}\n" +
+						"T 65 1 20 25 鐗╂枡瑙勬牸锛歿1}\n" +
+						"T 65 1 20 50 {2}\n" +
+						"T 65 0 20 75 渚涘簲鍟嗭細\n" +
+						"T 65 0 20 100 鏈夋晥鏈燂細\n" +
+						"T 65 0 20 125 妫�楠屽憳锛歕n" +
+						"T 65 0 20 150 鏍¢獙鏃ユ湡锛歕n" +
+						"T 55 0 120 80 {3}\n" +
+						"T 55 0 120 105 {4}\n" +
+						"T 55 0 120 130 {6}\n" +
+						"T 55 0 140 155 {5}\n" +
+						"SETBOLD 2\n" +
+						"SETBOLD 0\n" +
+						"SETMAG 0 0\n" +
+						"T 65 1 440 75 鏁伴噺锛歕n" +
+						"SETBOLD 2\n" +
+						"T 65 1 500 75 {9}\n" +
+						"SETBOLD 0\n" +
+						"B QR 600 2 M 2 U 4\n" +
+						"MA,{10}\n" +
+						"ENDQR\n" +
+						"B 128 1 0 50 320 100 {10}\n" +
+						"T 65 1 385 155 {10}\n" +
+						"FORM\n" +
+						"PRINT\n";
+					var bytes = plus.android.invoke(printStr, 'getBytes', 'gbk');
+					outputStream.write(bytes);
+					outputStream.flush();
+					device = null //杩欓噷鍏抽敭
+					bluetoothSocket.close(); //蹇呴』鍏抽棴钃濈墮杩炴帴鍚﹀垯鎰忓鏂紑鐨勮瘽鎵撳嵃閿欒
+					//this.$showMessage('OK');
+					console.log("鎵撳嵃鏈鸿繛鎺ョ姸鎬侊細111");
+					return true;
+				} else {
+					//this.$showMessage('NG');
+					console.log("鎵撳嵃鏈鸿繛鎺ョ姸鎬侊細222");
+					return false;
+				}
+			},
+		},
+	};
+</script>
+<style scoped>
+	.mui-content {
+		margin-top:80px;padding:10px;
+	}
+	.ulcss {
+		margin-top: 0.625rem;padding:2px;
+	}
+	
+</style>
\ No newline at end of file

--
Gitblit v1.9.3