|
@@ -1,82 +1,80 @@
|
|
<template>
|
|
<template>
|
|
- <view>
|
|
|
|
- <view class="content"></view>
|
|
|
|
- </view>
|
|
|
|
|
|
+ <view><view class="content"></view></view>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
- // #ifdef APP-PLUS
|
|
|
|
- var main, receiver, filter;
|
|
|
|
- var codeQueryTag = false;
|
|
|
|
- export default {
|
|
|
|
- data() {
|
|
|
|
- return {
|
|
|
|
- scanCode: ''
|
|
|
|
|
|
+// #ifdef APP-PLUS
|
|
|
|
+var main, receiver, filter;
|
|
|
|
+var codeQueryTag = false;
|
|
|
|
+export default {
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ scanCode: ''
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ created() {
|
|
|
|
+ this.initScan();
|
|
|
|
+ this.startScan();
|
|
|
|
+ },
|
|
|
|
+ onHide() {
|
|
|
|
+ this.stopScan();
|
|
|
|
+ },
|
|
|
|
+ destroyed() {
|
|
|
|
+ this.stopScan();
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ initScan() {
|
|
|
|
+ console.log('initScan');
|
|
|
|
+ let that = this;
|
|
|
|
+ main = plus.android.runtimeMainActivity(); //获取activity
|
|
|
|
+ //var context = plus.android.importClass('android.content.Context'); //上下文
|
|
|
|
+ var IntentFilter = plus.android.importClass('android.content.IntentFilter');
|
|
|
|
+ filter = new IntentFilter();
|
|
|
|
+ //下面的addAction内改为自己的广播动作
|
|
|
|
+ if (uni.getSystemInfoSync().deviceBrand == 'zebra technologies') {
|
|
|
|
+
|
|
|
|
+ filter.addAction('com.dwexample.ACTION');
|
|
|
|
+ } else {
|
|
|
|
+ filter.addAction('nlscan.action.SCANNER_RESULT');
|
|
}
|
|
}
|
|
|
|
+ let code;
|
|
|
|
+ receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
|
|
|
+ onReceive: (context, intent) => {
|
|
|
|
+ console.log('onReceive');
|
|
|
|
+ plus.android.importClass(intent);
|
|
|
|
+ //下面的getStringExtra内改为自己的广播标签--有误
|
|
|
|
+
|
|
|
|
+ if (uni.getSystemInfoSync().deviceBrand == 'zebra technologies') {
|
|
|
|
+ code = intent.getStringExtra('com.symbol.datawedge.data_string');
|
|
|
|
+ } else {
|
|
|
|
+ code = intent.getStringExtra('SCAN_BARCODE1');
|
|
|
|
+ }
|
|
|
|
+ that.queryCode(code);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
},
|
|
},
|
|
- created() {
|
|
|
|
- this.initScan()
|
|
|
|
- this.startScan();
|
|
|
|
- },
|
|
|
|
- onHide() {
|
|
|
|
- this.stopScan();
|
|
|
|
|
|
+ startScan() {
|
|
|
|
+ console.log('startScan');
|
|
|
|
+ main.registerReceiver(receiver, filter);
|
|
},
|
|
},
|
|
- destroyed() {
|
|
|
|
- this.stopScan();
|
|
|
|
|
|
+ stopScan() {
|
|
|
|
+ console.log('stopScan');
|
|
|
|
+ main.unregisterReceiver(receiver);
|
|
},
|
|
},
|
|
- methods: {
|
|
|
|
- initScan() {
|
|
|
|
-
|
|
|
|
- console.log('initScan');
|
|
|
|
- let that = this;
|
|
|
|
- main = plus.android.runtimeMainActivity(); //获取activity
|
|
|
|
- //var context = plus.android.importClass('android.content.Context'); //上下文
|
|
|
|
- var IntentFilter = plus.android.importClass('android.content.IntentFilter');
|
|
|
|
- filter = new IntentFilter();
|
|
|
|
- //下面的addAction内改为自己的广播动作
|
|
|
|
- filter.addAction("nlscan.action.SCANNER_RESULT");
|
|
|
|
- receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
|
|
|
- onReceive: (context, intent)=> {
|
|
|
|
- console.log('onReceive');
|
|
|
|
- plus.android.importClass(intent);
|
|
|
|
- //下面的getStringExtra内改为自己的广播标签--有误
|
|
|
|
- let code = intent.getStringExtra("SCAN_BARCODE1");
|
|
|
|
- that.queryCode(code);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
- 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('xwscan', {
|
|
|
|
- code: id
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ queryCode: function(code) {
|
|
|
|
+ console.log('queryCode');
|
|
|
|
+ if (codeQueryTag) return false;
|
|
|
|
+ codeQueryTag = true;
|
|
|
|
+ setTimeout(function() {
|
|
|
|
+ codeQueryTag = false;
|
|
|
|
+ }, 150);
|
|
|
|
+ var id = code;
|
|
|
|
+ uni.$emit('xwscan', {
|
|
|
|
+ code: id
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- }// #endif
|
|
|
|
|
|
+ }
|
|
|
|
+}; // #endif
|
|
</script>
|
|
</script>
|
|
|
|
|
|
-<style>
|
|
|
|
-
|
|
|
|
-</style>
|
|
|
|
-
|
|
|
|
|
|
+<style></style>
|