From 07925905f1a596e20e980de6d42db217abb753b0 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:06:11 +0800
Subject: [PATCH] plugin
---
App.vue | 196 +++++++++++++++++++++++++++++++++---------------
1 files changed, 134 insertions(+), 62 deletions(-)
diff --git a/App.vue b/App.vue
index 66024d6..7b95096 100644
--- a/App.vue
+++ b/App.vue
@@ -1,8 +1,12 @@
<script>
import {
showModal,
- showToast,
+ showInfo,
+ showError
} from "@/js/Page.js"
+ const rfidModule = uni.requireNativePlugin('RFIDModule');
+ // const honrfidModule = uni.requireNativePlugin('HonRFIDModule');
+ var main;
export default {
globalData: {
largeMode: false,
@@ -33,13 +37,28 @@
onLaunch: function() {
console.log('App Launch');
this.deviceInfo = uni.getSystemInfoSync();
- this.initscan();
+ this.init();
},
onUnload() {
+ if (this.deviceInfo) {
+ if (this.deviceInfo?.brand.includes('alps')) { // 姹夊痉闇嶅皵璁惧鐗瑰緛
+ // 姹夊痉闇嶅皵 PDA rfid鎵爜椤甸潰鍗歌浇鏃堕噴鏀捐祫婧�+ if (rfidModule) {
+ rfidModule.closeModule();
+ }
+ } else if (this.deviceInfo?.brand.includes('honeywell') || this.deviceInfo?.deviceBrand.includes(
+ 'honeywell')) {
+ // 闇嶅凹闊﹀皵 PDA rfid鎵爜椤甸潰鍗歌浇鏃堕噴鏀捐祫婧�+ if (rfidModule) {
+ rfidModule.closeModule();
+ }
+ } else {
+ main.unregisterReceiver(receiver); // 鍋滄鐩戝惉骞挎挱
+ }
+ } else {
+ main.unregisterReceiver(receiver); // 鍋滄鐩戝惉骞挎挱
+ }
- // // 姹夊痉闇嶅皵 PDA rfid鎵爜椤甸潰鍗歌浇鏃堕噴鏀捐祫婧�- // const rfidModule = uni.requireNativePlugin('HandheldRFID');
- // rfidModule.closeModule();
},
onShow: function() {
@@ -48,74 +67,127 @@
onHide: function() {
console.log('App Hide')
},
+ onError(err) {
+ console.error('[UniApp Error]', err)
+ // 鍙笂鎶ュ埌鏈嶅姟鍣�+ },
methods: {
- initscan() {
- let that = this;
- console.log("deviceInfo", this.deviceInfo)
- if (this.deviceInfo?.brand.includes('alps')) { // 姹夊痉闇嶅皵璁惧鐗瑰緛
-
- // const rfidModule = uni.requireNativePlugin('HandheldRFID');
- // console.log("rfidModule",rfidModule)
- // rfidModule.initModule((res) => {
- // console.log("rfid initModule", res)
- // })
- } else {
- var main = plus.android.runtimeMainActivity() //鑾峰彇activity
- var IntentFilter = plus.android.importClass('android.content.IntentFilter') //寮曞叆杩囨护鍣�- // Intent = plus.android.importClass('android.content.Intent'),
- var filter = new IntentFilter()
- var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
- onReceive: function(context, intent) { //瀹炵幇onReceiver鍥炶皟鍑芥暟
- //console.log('onReceive',intent);
- plus.android.importClass(intent);
- var decodesource = intent.getStringExtra("com.symbol.datawedge.source");
- var decodedata = intent.getStringExtra("com.symbol.datawedge.data_string");
- var data = intent.getStringExtra("data");
- var decodelabeltype = intent.getStringExtra("com.symbol.datawedge.label_type");
- var scanResult = {
- decodesource,
- decodedata: decodedata || data,
- decodelabeltype,
- };
- console.log('onReceive', scanResult);
- uni.$emit("scanresult", scanResult);
- }
- });
- filter.addAction("com.pda.formobox"); //鐩戝惉鎵爜骞挎挱
- filter.addAction('com.rfid.scan') //
- main.registerReceiver(receiver, filter); //娉ㄥ唽鐩戝惉
+ init() {
+ let that = this;
+ console.log(this.deviceInfo);
+ if (this.deviceInfo) {
+ if (this.deviceInfo.brand.includes('alps')) { // 姹夊痉闇嶅皵璁惧鐗瑰緛
+
+ rfidModule.initModule((res) => {
+ console.log("alps rfid initModule", res)
+ if (res.code < 0) {
+ showInfo(res.msg);
+ }
+
+ })
+ } else if (this.deviceInfo.brand.includes('honeywell') || this.deviceInfo.deviceBrand.includes(
+ 'honeywell')) { // 闇嶅凹闊﹀皵
+ console.log("honeywell rfid initModule")
+ rfidModule.initModule("honeywell",(res) => {
+ console.log("rfid initModule", res)
+ if (res.code < 0) {
+ showInfo(res.msg);
+ }
+
+ })
+
+ } else if (this.deviceInfo.brand.includes('mobiwire') || this.deviceInfo.deviceBrand.includes(
+ 'mobiwire')) { // 闇嶅凹闊﹀皵
+
+ this.initMobiwireScan()
+ } else {
+
+ console.log(this.initScan);
+ this.initScan()
+ }
+ } else {
+
+ this.initScan()
}
+
+ },
+ initMobiwireScan() {
+ main = plus.android.runtimeMainActivity(); // 鑾峰彇涓�activity
+ var IntentFilter = plus.android.importClass("android.content.IntentFilter");
+ var filter = new IntentFilter();
+ const action = "com.rfid.scan" //榛樿骞挎挱 com.honeywell.scan.broadcast
+ const stringExtra = "data"
+ filter.addAction(action); // 娣诲姞骞挎挱鍔ㄤ綔
+
+ receiver = plus.android.implements("io.dcloud.feature.internal.reflect.BroadcastReceiver", {
+ onReceive: function(context, intent) {
+ plus.android.importClass(intent);
+ let code = intent.getStringExtra(stringExtra); // 鑾峰彇骞挎挱涓殑瀛楃涓查澶栧弬鏁�+ uni.$emit("scanresult", code);
+ },
+ });
+ main.registerReceiver(receiver, filter); // 寮�鐩戝惉骞挎挱
+
+ },
+
+ initScan() {
+ main = plus.android.runtimeMainActivity() //鑾峰彇activity
+ var IntentFilter = plus.android.importClass('android.content.IntentFilter') //寮曞叆杩囨护鍣�+ // Intent = plus.android.importClass('android.content.Intent'),
+ var filter = new IntentFilter()
+ var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
+ onReceive: function(context, intent) { //瀹炵幇onReceiver鍥炶皟鍑芥暟
+ //console.log('onReceive',intent);
+ plus.android.importClass(intent);
+ // var decodesource = intent.getStringExtra("com.symbol.datawedge.source");
+ var decodedata = intent.getStringExtra("com.symbol.datawedge.data_string");
+ var data = intent.getStringExtra("data");
+ // var decodelabeltype = intent.getStringExtra("com.symbol.datawedge.label_type");
+ var scanResult = decodedata || data
+ console.log('onReceive', scanResult);
+ uni.$emit("scanresult", scanResult);
+ }
+ });
+
+ filter.addAction("com.pda.formobox"); //鐩戝惉鎵爜骞挎挱
+ filter.addAction('com.rfid.scan') //
+ main.registerReceiver(receiver, filter); //娉ㄥ唽鐩戝惉
},
onScan(callback) {
- console.log('onScan');
- if (this.deviceInfo?.brand.includes('alps')) { // 姹夊痉闇嶅皵璁惧鐗瑰緛
- // const rfidModule = uni.requireNativePlugin('HandheldRFID');
- // rfidModule.startScan((res) => {
- // if (res.code) {
- // console.log(res)
- // let data = res.data || ""
- // if (Array.isArray(data)) {
- // data = data.map((a) => a.epc).join(",")
- // }
- // var scanResult = {
- // decodesource: "epc",
- // decodedata: data,
- // decodelabeltype: "",
- // };
- // console.log(scanResult)
- // callback(scanResult);
- // } else {
- // console.log("rfid startScan", res)
- // }
- // })
+ if (this.deviceInfo) {
+ if (this.deviceInfo?.brand.includes('alps') ||(this.deviceInfo?.brand.includes('honeywell') || this.deviceInfo?.deviceBrand.includes(
+ 'honeywell'))) { // 姹夊痉闇嶅皵璁惧鐗瑰緛
+ if (!rfidModule)
+ return
+ rfidModule.startScan((ret) => {
+ console.log("startScan", ret)
+ let text = ""
+ if (ret.code < 0) {
+ showInfo(ret.msg);
+ } else {
+ const data = ret.data || []
+ if (Array.isArray(data)) {
+ if (data.length > 0)
+ text = data[0].epc
+ } else {
+ text = data.epc || ""
+ }
+ callback(text);
+ }
+ })
+ } else {
+ uni.$off("scanresult");
+ uni.$on("scanresult", (result) => {
+ callback(result);
+ });
+ }
} else {
uni.$off("scanresult");
uni.$on("scanresult", (result) => {
callback(result);
});
}
-
},
}
--
Gitblit v1.9.1