shish 4 лет назад
Родитель
Сommit
60b7d8a413

+ 0 - 71
hdPad/src/components/scan-code/scan-code.vue

@@ -1,71 +0,0 @@
-<template>  
-    <view class="content"></view>  
-</template>  
-<script>  
-var main,receiver,filter;    
-var _codeQueryTag = false;    
-export default {  
-    data() {  
-        return {  
-            scanCode:''  
-        }  
-    },  
-    created(){  
-        this.initScan()  
-        this.startScan();    
-    },    
-    onHide(){    
-        this.stopScan();    
-    },  
-    destroyed(){    
-        /*页面退出时一定要卸载监听,否则下次进来时会重复,造成扫一次出2个以上的结果*/    
-        this.stopScan();    
-    },  
-    methods: {  
-        initScan() {
-            let that = this;
-            main = plus.android.runtimeMainActivity(); //获取activity
-            var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
-              onReceive: that.pdaReceive
-            });
-            var IntentFilter = plus.android.importClass('android.content.IntentFilter');
-            var filter = new IntentFilter();
-            filter.addAction("nlscan.action.SCANNER_RESULT"); //监听扫描
-            main.registerReceiver(receiver, filter); //注册监听
-            console.log('!!!!!!!!!!!!!!!!!!!!!!!!PDA发起监听!!!!!!!!!!!!!!!!!!!!!!!!!')
-        },   
-		//接收pda扫码
-		pdaReceive(context, intent) {
-			//通过intent实例引入intent类,方便以后的'.'操作
-			plus.android.importClass(intent)
-			var productIdCode = intent.getStringExtra("SCAN_BARCODE1")
-			this.queryCode(productIdCode)
-		}, 
-        startScan(){    
-            main.registerReceiver(receiver,filter);  
-        },    
-        stopScan(){  
-            main.unregisterReceiver(receiver);    
-        },    
-        queryCode: function(code){  
-            //防重复
-            if(_codeQueryTag){
-                return false
-            }
-            _codeQueryTag = true;    
-            setTimeout(function(){    
-                _codeQueryTag = false;    
-            },150)
-            uni.$emit('scancodedate',{code:code})  
-        }  
-    }  
-}
-</script>
-<style>  
-    page {  
-        background-color: #efeff4;  
-    }  
-    .content {  
-        text-align: center;  
-    }  
-</style>

+ 14 - 0
hdPad/src/manifest.json

@@ -141,6 +141,20 @@
                     "pid" : "3514",
                     "parameters" : {}
                 }
+            },
+            "longyoung-KeyEventListen" : {
+                "__plugin_info__" : {
+                    "name" : "【longyoung】蓝牙usb外接键盘扫描枪监听获取输入内容【万能】 - [试用版,仅用于自定义调试基座]",
+                    "description" : "【万能监听】外接键盘扫描枪监听,有疑问,关注公众号「longyoung」后台发消息提问。",
+                    "platforms" : "Android",
+                    "url" : "https://ext.dcloud.net.cn/plugin?id=1744",
+                    "android_package_name" : "",
+                    "ios_bundle_id" : "",
+                    "isCloud" : true,
+                    "bought" : 0,
+                    "pid" : "1744",
+                    "parameters" : {}
+                }
             }
         }
     },

+ 3 - 40
hdPad/src/mixins/globalMixins.js

@@ -4,13 +4,9 @@ import { pageTo, isLogin } from '@/utils/util.js'
 import { getUser, wxMiniLogin } from '@/utils/auth'
 import { getDictionaries } from '@/api/mini'
 import { hasTokenAutoLogin } from '@/api/common'
-
-// #ifdef APP-PLUS
-const shangMiPrint = uni.requireNativePlugin('G5KJ-ShangMiPrint')
-const globalEvent = uni.requireNativePlugin('globalEvent')
-// #endif
-
+import scanMins from "@/mixins/scan";
 export default {
+  mixins: [scanMins],
 	data() {
 		return {
 			// 全局混入,插入链接参数
@@ -25,9 +21,7 @@ export default {
       //所有花材列表
       allProduct:[],
       //零售店对应的id
-      skCustomId:0,
-      //SUNMI 商米
-      globalDevice:''
+      skCustomId:0
 		}
 	},
 	computed: {
@@ -36,10 +30,6 @@ export default {
 	onLoad: function (option) {
 
     // #ifdef APP-PLUS
-    if(plus.device.vendor == 'SUNMI'){
-      this.globalDevice = 'SUNMI'
-    }
-
     //横屏锁定
     plus.screen.lockOrientation('landscape')
     // #endif
@@ -74,7 +64,6 @@ export default {
             let token = res.token || ''
             if (!this.$util.isEmpty(token)) {
               getUser(true)
-              this.setUserShopAll()
             }
             if (this.init) {
               this.init()
@@ -96,10 +85,6 @@ export default {
 					})
           store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
           this.skCustomId = subRes.data.skCustomId
-          // #ifdef APP-PLUS
-          this.listenScan()
-          // #endif
-          this.setUserShopAll()
           if (this.init) {
             this.init()
           }
@@ -116,27 +101,5 @@ export default {
     }
 	},
 	methods: {
-    ...mapActions(['setUserShopAll']),
-    // #ifdef APP-PLUS
-    //监听扫码
-    listenScan(){
-        let that = this
-        //商米收银台
-        if(globalDevice == 'SUNMI'){
-          //https://ext.dcloud.net.cn/plugin?id=3514
-          //初始化
-          shangMiPrint.init()
-          //扫码返回
-          globalEvent.addEventListener('scancode',function(e){
-            if(e.code == 'ok'){
-              let productIdCode = e.data
-              console.log(productIdCode)
-              that.$msg(productIdCode)
-            }
-          })
-          console.log('!!!!!!!!!!!!!!!!!!!!!!!!商米收银台发起监听!!!!!!!!!!!!!!!!!!!!!!!!')
-        }
-    }
-		// #endif
 	}
 }

+ 81 - 0
hdPad/src/mixins/scan.js

@@ -0,0 +1,81 @@
+// #ifdef APP-PLUS
+const shangMiPrint = uni.requireNativePlugin('G5KJ-ShangMiPrint')
+const globalEvent = uni.requireNativePlugin('globalEvent')
+var main =false
+var receiver = false
+var filter = false
+var _codeQueryTag = false;  
+export default {
+	data() {
+		return {
+		}
+	},
+    created(){
+
+        //this.listenScan()
+    },
+    onHide(){
+        this.stopScan()
+    }, 
+    destroyed(){
+        //页面退出时一定要卸载监听,否则下次进来时会重复,造成扫一次出2个以上的结果
+        this.stopScan()
+    },
+	methods: {
+        listenScan(){
+            //商米收银台
+            if(plus.device.vendor == 'SUNMI'){
+                //https://ext.dcloud.net.cn/plugin?id=3514
+                //初始化
+                shangMiPrint.init()
+                //扫码返回
+                globalEvent.addEventListener('scancode',function(e){
+                    if(e.code == 'ok'){
+                        let productIdCode = e.data
+                        uni.$emit('scancodedate',{code:productIdCode})
+                    }
+                })
+                console.log('商米监听扫码')
+            }else{
+                this.initScan()  
+                this.startScan()
+                console.log('其它设备监听扫码')
+            }
+        },
+        initScan() {
+            main = plus.android.runtimeMainActivity(); //获取activity
+            receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
+            onReceive: function(context, intent) {
+                //通过intent实例引入intent类,方便以后的'.'操作
+                plus.android.importClass(intent)
+                var productIdCode = intent.getStringExtra("SCAN_BARCODE1")
+                this.queryCode(productIdCode) 
+            }});
+            var IntentFilter = plus.android.importClass('android.content.IntentFilter');
+            filter = new IntentFilter();
+            filter.addAction("nlscan.action.SCANNER_RESULT");//监听扫描
+        },
+        startScan(){
+            if(main){
+                main.registerReceiver(receiver,filter)
+            }
+        },    
+        stopScan(){
+            if(main){
+                main.unregisterReceiver(receiver)
+            }
+        },
+        queryCode: function(code){  
+            //防重复
+            if(_codeQueryTag){
+                return false
+            }
+            _codeQueryTag = true;    
+            setTimeout(function(){    
+                _codeQueryTag = false;    
+            },150)
+            uni.$emit('scancodedate',{code:code})
+        }
+    }
+}
+// #endif

+ 5 - 3
hdPad/src/pages/home/cash.vue

@@ -74,10 +74,12 @@ export default {
 	onPullDownRefresh() {
 	},
 	onShow() {
-        var _this = this  
-        uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器  
+        var that = this
+		//每次进来先 移除全局自定义事件监听器
+        uni.$off('scancodedate') 
         uni.$on('scancodedate',function(data){  
-            console.log('你想要的code:', data.code)  
+            console.log('你想要的code:', data.code)
+			that.$msg(data.code)
         })
 	},
 	onunload(){