From aaa8efda7a2697cf36e7021a1c5d94f3a541b387 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 22 十月 2025 16:19:50 +0800
Subject: [PATCH] 物料下发/物料取消下发页面
---
components/scan/scan.vue | 218 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 146 insertions(+), 72 deletions(-)
diff --git a/components/scan/scan.vue b/components/scan/scan.vue
index c39741c..7940f65 100644
--- a/components/scan/scan.vue
+++ b/components/scan/scan.vue
@@ -1,93 +1,167 @@
<template>
<view>
<view class="content">
+ <!-- <text>鎵弿缁撴灉锛歿{ scanResult }}</text> -->
</view>
</view>
</template>
<script>
- var main, receiver, filter;
- var action, extraKey;
- var _codeQueryTag = false;
- export default {
- data() {
- return {
- scanCode: ''
- }
- },
- created: function(option) {
- uni.getSystemInfo({
- success: (res) => {
- var brand = res.brand.toUpperCase();
- var model = res.model.toUpperCase();
- if (brand.indexOf("ZEBRA")!=-1 && model.indexOf("TC2")!=-1) {
- action = "com.zebra.scan";
- extraKey = "com.motorolasolutions.emdk.datawedge.data_string";
- } else if (brand.indexOf("SEUIC")!=-1||brand.indexOf("AUTOID")!=-1) {
- action = "com.android.server.scannerservice.broadcast";
- extraKey = "scannerdata";
- }else{
- return;
- }
- console.log(action);
- console.log(extraKey);
- this.initScan()
- this.startScan();
+var main, receiver, filter;
+var action, extraKey;
+var _codeQueryTag = false;
+
+export default {
+ data() {
+ return {
+ scanCode: '',
+ scanResult: ''
+ }
+ },
+ created() {
+ uni.getSystemInfo({
+ success: (res) => {
+ var brand = res.brand.toUpperCase();
+ var model = res.model.toUpperCase();
+
+ console.log('璁惧鍝佺墝:', brand);
+ console.log('璁惧鍨嬪彿:', model);
+
+ // Zebra璁惧閰嶇疆
+ if (brand.indexOf("ZEBRA") != -1 && model.indexOf("TC2") != -1) {
+ action = "com.zebra.scan";
+ extraKey = "com.motorolasolutions.emdk.datawedge.data_string";
}
- })
+ // AUTOID9N璁惧閰嶇疆
+ else if (brand.indexOf("SEUIC") != -1 || brand.indexOf("AUTOID") != -1) {
+ // AUTOID9N涓撶敤閰嶇疆
+ if (model.indexOf("AUTOID9N") != -1) {
+ action = "com.android.server.scannerservice.broadcast";
+ extraKey = "scannerdata"; // 鎴� "BARCODE_STRING"锛屾牴鎹疄闄呮儏鍐佃皟鏁�
+ }
+ // 鍏朵粬SEUIC璁惧
+ else {
+ action = "com.android.server.scannerservice.broadcast";
+ extraKey = "scannerdata";
+ }
+ }
+ else {
+ console.log('鏈煡璁惧鍝佺墝锛屾棤娉曞垵濮嬪寲鎵爜');
+ return;
+ }
+ console.log('鎵爜骞挎挱閰嶇疆:', { action, extraKey });
+ this.initScan();
+ this.startScan();
+ },
+ fail: (err) => {
+ console.error('鑾峰彇绯荤粺淇℃伅澶辫触:', err);
+ }
+ });
+ },
+ onLoad() {
+ // 鐩戝惉鍏ㄥ眬鎵爜浜嬩欢
+ uni.$on('scan', (event) => {
+ this.scanResult = event.code;
+ console.log('鎵爜缁撴灉:', this.scanResult);
+ });
+ },
+ onUnload() {
+ this.stopScan();
+ uni.$off('scan'); // 绉婚櫎浜嬩欢鐩戝惉
+ },
+ methods: {
+ initScan() {
+ console.log('鍒濆鍖栨壂鐮佹帴鏀跺櫒');
-
- },
- onHide: function() {
- this.stopScan();
- },
- destroyed: function() {
- this.stopScan();
- },
- methods: {
- initScan() {
- console.log('initScan');
- let _this = this;
- main = plus.android.runtimeMainActivity(); //鑾峰彇activity
+ try {
+ main = plus.android.runtimeMainActivity(); // 鑾峰彇activity
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
filter = new IntentFilter();
- //涓嬮潰鐨刟ddAction鍐呮敼涓鸿嚜宸辩殑骞挎挱鍔ㄤ綔
filter.addAction(action);
+
+ console.log('娉ㄥ唽骞挎挱杩囨护鍣�:', action);
+
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
- onReceive: function(context, intent) {
- console.log('onReceive');
- plus.android.importClass(intent);
- //涓嬮潰鐨刧etStringExtra鍐呮敼涓鸿嚜宸辩殑骞挎挱鏍囩--鏈夎
- let code = intent.getStringExtra(extraKey);
- _this.queryCode(code);
- }
+ onReceive: function (context, intent) {
+ console.log('鎺ユ敹鍒版壂鐮佸箍鎾�');
+
+ try {
+ plus.android.importClass(intent);
+ let code = intent.getStringExtra(extraKey);
+
+ if (code) {
+ console.log('鎵爜鍐呭:', code);
+ this.queryCode(code);
+ } else {
+ console.warn('鎵爜鍐呭涓虹┖锛屽彲鑳紼xtraKey涓嶆纭�:', extraKey);
+
+ // 灏濊瘯澶囬�塃xtraKey
+ const altExtraKey = extraKey === "BARCODE_STRING" ? "scannerdata" : "BARCODE_STRING";
+ code = intent.getStringExtra(altExtraKey);
+
+ if (code) {
+ console.log('浣跨敤澶囬�塃xtraKey鑾峰彇鍒板唴瀹�:', altExtraKey);
+ this.queryCode(code);
+ }
+ }
+ } catch (e) {
+ console.error('澶勭悊鎵爜骞挎挱鏃跺嚭閿�:', e);
+ }
+ }.bind(this) // 纭繚this鎸囧悜缁勪欢瀹炰緥
});
- },
- startScan() {
- console.log('startScan');
- main.registerReceiver(receiver, filter);
- },
- stopScan() {
- console.log('stopScan');
- main.unregisterReceiver(receiver);
- },
- queryCode: function(code) {
- console.log('queryCode');
- if (_codeQueryTag) return false;
- _codeQueryTag = true;
- setTimeout(function() {
- _codeQueryTag = false;
- }, 150);
- var id = code
- uni.$emit('scan', {
- code: id
- })
+
+ console.log('鎵爜鎺ユ敹鍣ㄥ垵濮嬪寲鎴愬姛');
+ } catch (e) {
+ console.error('鍒濆鍖栨壂鐮佹帴鏀跺櫒澶辫触:', e);
}
+ },
+ startScan() {
+ console.log('寮�濮嬬洃鍚壂鐮佸箍鎾�');
+
+ try {
+ if (main && receiver && filter) {
+ main.registerReceiver(receiver, filter);
+ console.log('骞挎挱鎺ユ敹鍣ㄥ凡娉ㄥ唽');
+ } else {
+ console.error('鏃犳硶娉ㄥ唽骞挎挱鎺ユ敹鍣�: 缁勪欢鏈垵濮嬪寲');
+ }
+ } catch (e) {
+ console.error('娉ㄥ唽骞挎挱鎺ユ敹鍣ㄥけ璐�:', e);
+ }
+ },
+ stopScan() {
+ console.log('鍋滄鐩戝惉鎵爜骞挎挱');
+
+ try {
+ if (main && receiver) {
+ main.unregisterReceiver(receiver);
+ console.log('骞挎挱鎺ユ敹鍣ㄥ凡娉ㄩ攢');
+ }
+ } catch (e) {
+ console.error('娉ㄩ攢骞挎挱鎺ユ敹鍣ㄥけ璐�:', e);
+ }
+ },
+ queryCode(code) {
+ console.log('澶勭悊鎵爜缁撴灉:', code);
+
+ if (_codeQueryTag) {
+ console.log('蹇界暐閲嶅鎵爜');
+ return false;
+ }
+
+ _codeQueryTag = true;
+
+ // 闃叉姈澶勭悊
+ setTimeout(() => {
+ _codeQueryTag = false;
+ }, 150);
+
+ // 瑙﹀彂鍏ㄥ眬浜嬩欢
+ uni.$emit('scan', { code });
}
}
+}
</script>
-<style>
-
-</style>
+<style></style>
\ No newline at end of file
--
Gitblit v1.9.3