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