USER-20230908AJ\Administrator il y a 1 an
Parent
commit
0599a57917

+ 50 - 0
js_sdk/pysh-hwscan/js_sdk/pysh-hwscan.js

@@ -0,0 +1,50 @@
+class scanClass {
+	constructor(data) {
+		this.main = null;
+		this.receiver = null;
+		this.filter = null;
+	}
+	
+	startScan() {
+		/* #ifdef APP-PLUS */
+		this.main.registerReceiver(this.receiver, this.filter);
+		/* #endif */
+	}
+	
+	stopScan() {
+		/* #ifdef APP-PLUS */
+		this.main.unregisterReceiver(this.receiver);
+		/* #endif */
+	}
+	
+	initScan(fun) {
+		let _this = this;
+		/* #ifdef APP-PLUS */
+		_this.main = plus.android.runtimeMainActivity(); //获取activity
+	
+		_this.receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
+			onReceive: function(context, intent) {
+				console.info('content', '-----------------')
+	
+				//实现onReceiver回调函数
+				plus.android.importClass(intent);
+				var val = intent.getStringExtra("data"); //数据标识
+				console.info('val', val)
+	
+				fun(val)
+	
+			}
+		})
+	
+		var IntentFilter = plus.android.importClass('android.content.IntentFilter');
+	
+		_this.filter = new IntentFilter();
+		_this.filter.addAction("com.honeywell.scan.broadcast"); //广播名
+		_this.main.registerReceiver(_this.receiver, _this.filter); //注册广播
+	
+		/* #endif */
+	}
+}
+export {
+	scanClass
+}

+ 16 - 0
js_sdk/pysh-hwscan/package.json

@@ -0,0 +1,16 @@
+{
+    "id": "pysh-hwscan",
+    "name": "honeywell扫码获取广播内容",
+    "displayName": "honeywell扫码获取广播内容",
+    "version": "1.0.0",
+    "description": "honeywell扫码设备,使用广播方式接收扫码内容,既光标不在输入框也可以接收扫码内容。设置了软键盘弹起时不会顶起整个页面。",
+    "keywords": [
+        "honeywell扫码获取广播内容"
+    ],
+    "dcloudext": {
+        "category": [
+            "JS SDK",
+            "通用 SDK"
+        ]
+    }
+}

+ 24 - 0
package-lock.json

@@ -0,0 +1,24 @@
+{
+  "name": "zh-cashier-app",
+  "lockfileVersion": 2,
+  "requires": true,
+  "packages": {
+    "": {
+      "dependencies": {
+        "uniapp-keyboard-listener": "^1.0.4"
+      }
+    },
+    "node_modules/uniapp-keyboard-listener": {
+      "version": "1.0.4",
+      "resolved": "https://registry.npmmirror.com/uniapp-keyboard-listener/-/uniapp-keyboard-listener-1.0.4.tgz",
+      "integrity": "sha512-ehZXOTuM8xYqw5bxqK4hj3i5dh2yc6oLYFc0u1nzkYZzN3ipreT1k8Y2je8VXW69CGVtE6lB19JM60WR0j0dlQ=="
+    }
+  },
+  "dependencies": {
+    "uniapp-keyboard-listener": {
+      "version": "1.0.4",
+      "resolved": "https://registry.npmmirror.com/uniapp-keyboard-listener/-/uniapp-keyboard-listener-1.0.4.tgz",
+      "integrity": "sha512-ehZXOTuM8xYqw5bxqK4hj3i5dh2yc6oLYFc0u1nzkYZzN3ipreT1k8Y2je8VXW69CGVtE6lB19JM60WR0j0dlQ=="
+    }
+  }
+}

+ 5 - 0
package.json

@@ -0,0 +1,5 @@
+{
+  "dependencies": {
+    "uniapp-keyboard-listener": "^1.0.4"
+  }
+}

+ 37 - 5
pages/index/index.vue

@@ -15,20 +15,46 @@
   <view class="">
     {{aaa}}
   </view>
+
+  <keyboard-listener v-if="outscan" @keyup="monitorKeyboard"></keyboard-listener>
 </view>
 </template>
 
 <script>
+import keyboardListener from 'uniapp-keyboard-listener';
+
+
 export default {
+  components: {keyboardListener},
   data() {
     return {
       inputString: '',
       inputCache: '',
 	  text:'',
 	  aaa:'',
+      outscan:false,
+      keyArr:[],
+      nvalue:''
     };
   },
   methods: {
+    monitorKeyboard(e) {
+      console.log(e)
+      if (e.key.length == 1) {  // 字母和数字的长度都是1,所以只要字母和数字的按键,适配不同的设备
+        this.keyArr.push(e.key)
+      } else if (e.key == 'Enter') { // 监听到回车
+        let newArr = [];
+        this.nvalue = '';
+        // 条码中可能会有大写字母和未定义的按键,所以要过滤出来
+        newArr = this.keyArr.filter(item => item != 'Shift' && item != 'Enter' && item != 'Unidentified')
+        this.nvalue = newArr.join("")
+        console.log("回车", newArr, this.nvalue);
+        // if (this.nvalue) {
+        //   this.search(this.nvalue)
+        // }
+        this.keyArr = [];
+      }
+    },
     onConfirm(text) {
       // alert(JSON.stringify(text))
       console.log('拿到的text', text);
@@ -36,20 +62,26 @@ export default {
       this.text = text;
     },
     keypress(e) {
-		this.aaa = JSON.stringify(e);
-      // alert(JSON.stringify(e))
+      console.log(e)
+		  this.aaa = JSON.stringify(e);
       if (e.keyCode === 66 || e.key === 'Enter') {
         this.inputString = this.inputCache;
         this.onConfirm(this.inputString);
         this.inputCache = '';
       } else {
-        this.inputCache += e.key;
+        if (e.key !== 'Shift') {
+          this.inputCache += e.key;
+        }
       }
     }
   },
-  mounted() {
+  onLoad() {
+    this.outscan=true
+    // uni.onkeyup(res=>{
+    //   console.log(res)
+    // })
     // #ifdef APP-PLUS
-    plus.key.addEventListener("keyup", this.keypress);
+    // plus.key.addEventListener("keyup", this.keypress);
     // #endif
     // #ifdef H5
     document.addEventListener("keyup", this.keypress);