This commit is contained in:
aihe 2024-10-21 22:15:29 +08:00
parent 8c6174a115
commit b3bfcc9b5b

View File

@ -1,5 +1,7 @@
<template> <template>
<view></view> <view v-if="showlog">
<view v-for="item in logs">{{item}}</view>
</view>
</template> </template>
<script> <script>
@ -11,6 +13,11 @@
return '' return ''
} }
}, },
showlog: {
default () {
return false
}
},
}, },
data() { data() {
let { hongWai } = getSessionSystemInfo() let { hongWai } = getSessionSystemInfo()
@ -26,6 +33,7 @@
filter: '', filter: '',
codeQueryTag: false, codeQueryTag: false,
main: '', main: '',
logs: ['扫描组件日志']
} }
}, },
created() { created() {
@ -39,44 +47,48 @@
this.stopScan(); this.stopScan();
}, },
methods: { methods: {
logInfo(info){
console.log(info)
this.logs.push(info)
},
initScan() { initScan() {
let that = this; let that = this;
console.log("执行initScan调用") that.logInfo("执行initScan调用")
console.log("actionKey==== " + that.customintent.actionKey) that.logInfo("actionKey==== " + that.customintent.actionKey)
console.log("codeKey==== " + that.customintent.codeKey) that.logInfo("codeKey==== " + that.customintent.codeKey)
// #ifdef APP // #ifdef APP
console.log('initScan'); that.logInfo('initScan');
that.main = plus.android.runtimeMainActivity(); //获取activity that.main = plus.android.runtimeMainActivity(); //获取activity
//var context = plus.android.importClass('android.content.Context'); //上下文 //var context = plus.android.importClass('android.content.Context'); //上下文
var IntentFilter = plus.android.importClass('android.content.IntentFilter'); var IntentFilter = plus.android.importClass('android.content.IntentFilter');
that.filter = new IntentFilter(); that.filter = new IntentFilter();
//下面的addAction内改为自己的广播动作 //下面的addAction内改为自己的广播动作
that.filter.addAction(that.customintent.actionKey); that.filter.addAction(that.customintent.actionKey);
console.log("receive_pda_sn注册成功") that.logInfo("receive_pda_sn注册成功")
that.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', { that.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: (context, intent) => { onReceive: (context, intent) => {
console.log("BroadcastReceiver--onReceive-回调执行") that.logInfo("BroadcastReceiver--onReceive-回调执行")
console.log('onReceive'); that.logInfo('onReceive');
plus.android.importClass(intent); plus.android.importClass(intent);
//下面的getStringExtra内改为自己的广播标签--有误 //下面的getStringExtra内改为自己的广播标签--有误
let code = intent.getStringExtra(that.customintent.codeKey); let code = intent.getStringExtra(that.customintent.codeKey);
console.log("getStringExtra - code:" + code) that.logInfo("getStringExtra - code:" + code)
that.queryCode(code); that.queryCode(code);
} }
}); });
console.log("BroadcastReceiver绑定完成") that.logInfo("BroadcastReceiver绑定完成")
// #endif // #endif
}, },
startScan() { startScan() {
const that = this const that = this
// #ifdef APP // #ifdef APP
this.main.registerReceiver(this.receiver, this.filter); this.main.registerReceiver(this.receiver, this.filter);
console.log('startScan'); that.logInfo('startScan');
// #endif // #endif
}, },
stopScan() { stopScan() {
console.log('stopScan');
const that = this const that = this
that.logInfo('stopScan');
// #ifdef APP // #ifdef APP
this.main.unregisterReceiver(this.receiver); this.main.unregisterReceiver(this.receiver);
// #endif // #endif
@ -84,19 +96,19 @@
queryCode: function(code) { queryCode: function(code) {
let that = this; let that = this;
// #ifdef APP // #ifdef APP
console.log('queryCode'); that.logInfo('queryCode');
if (that.codeQueryTag) return false; if (that.codeQueryTag) return false;
that.codeQueryTag = true; that.codeQueryTag = true;
setTimeout(function() { setTimeout(function() {
that.codeQueryTag = false; that.codeQueryTag = false;
}, 150); }, 150);
that.$emit('onChange', code) that.$emit('onChange', code)
console.log("uni.$emit触发wuli-appscan") that.logInfo("uni.$emit触发wuli-appscan")
// #endif // #endif
}, },
triggerKeyScan() { triggerKeyScan() {
const that = this const that = this
console.log("执行triggerKeyScan调用") that.logInfo("执行triggerKeyScan调用")
// #ifdef APP // #ifdef APP
//获取Android意图类 //获取Android意图类
let Intent = plus.android.importClass('android.content.Intent'); let Intent = plus.android.importClass('android.content.Intent');
@ -105,10 +117,10 @@
//定义意图,模拟按下L键,L键实际上是打开激光的物理键映射,由厂商提供 //定义意图,模拟按下L键,L键实际上是打开激光的物理键映射,由厂商提供
const scanDownKey = "com.android.action.keyevent." + this.customintent.scanDownKey const scanDownKey = "com.android.action.keyevent." + this.customintent.scanDownKey
intent.setAction(scanDownKey); intent.setAction(scanDownKey);
console.log("模拟按下L键: " + scanDownKey) that.logInfo("模拟按下L键: " + scanDownKey)
//广播这个意图 //广播这个意图
that.main.sendBroadcast(intent); that.main.sendBroadcast(intent);
console.log("广播按下L键") that.logInfo("广播按下L键")
// #endif // #endif
} }
} }