2023-11-25 16:30:38 +00:00
|
|
|
|
<template>
|
2024-10-21 14:15:29 +00:00
|
|
|
|
<view v-if="showlog">
|
|
|
|
|
|
<view v-for="item in logs">{{item}}</view>
|
|
|
|
|
|
</view>
|
2023-11-25 16:30:38 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-06-16 08:08:53 +00:00
|
|
|
|
import { getSessionSystemInfo } from "@/session"
|
2023-11-25 16:30:38 +00:00
|
|
|
|
export default {
|
|
|
|
|
|
props: {
|
2023-12-23 07:50:49 +00:00
|
|
|
|
value: {
|
|
|
|
|
|
default () {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
2024-10-21 14:15:29 +00:00
|
|
|
|
},
|
|
|
|
|
|
showlog: {
|
|
|
|
|
|
default () {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2023-12-23 07:50:49 +00:00
|
|
|
|
},
|
2023-11-25 16:30:38 +00:00
|
|
|
|
},
|
2024-10-12 08:48:47 +00:00
|
|
|
|
data() {
|
|
|
|
|
|
let { hongWai } = getSessionSystemInfo()
|
|
|
|
|
|
let { actionKey = 'com.android.receive_scan_action', codeKey = 'data', scanDownKey = 'KEYCODE_SCAN_L_DOWN' } = hongWai || {}
|
|
|
|
|
|
return {
|
|
|
|
|
|
customintent: { // 默认配置
|
|
|
|
|
|
// !!注意: 不同的设备配置项是不同的
|
|
|
|
|
|
scanDownKey,
|
|
|
|
|
|
actionKey,
|
|
|
|
|
|
codeKey,
|
|
|
|
|
|
},
|
2023-11-25 16:30:38 +00:00
|
|
|
|
receiver: '',
|
|
|
|
|
|
filter: '',
|
|
|
|
|
|
codeQueryTag: false,
|
2024-10-21 14:15:29 +00:00
|
|
|
|
main: '',
|
|
|
|
|
|
logs: ['扫描组件日志']
|
2023-11-25 16:30:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
2024-07-06 06:29:57 +00:00
|
|
|
|
this.initScan()
|
|
|
|
|
|
this.startScan();
|
2023-11-25 16:30:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
onHide() {
|
2023-12-23 07:50:49 +00:00
|
|
|
|
// this.stopScan();
|
2023-11-25 16:30:38 +00:00
|
|
|
|
},
|
2023-12-23 07:50:49 +00:00
|
|
|
|
unmounted() {
|
2023-11-25 16:30:38 +00:00
|
|
|
|
this.stopScan();
|
|
|
|
|
|
},
|
2024-10-21 14:15:29 +00:00
|
|
|
|
methods: {
|
|
|
|
|
|
logInfo(info){
|
|
|
|
|
|
console.log(info)
|
|
|
|
|
|
this.logs.push(info)
|
|
|
|
|
|
},
|
2023-11-25 16:30:38 +00:00
|
|
|
|
initScan() {
|
2024-10-21 14:15:29 +00:00
|
|
|
|
let that = this;
|
|
|
|
|
|
that.logInfo("执行initScan调用")
|
|
|
|
|
|
that.logInfo("actionKey==== " + that.customintent.actionKey)
|
|
|
|
|
|
that.logInfo("codeKey==== " + that.customintent.codeKey)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #ifdef APP
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo('initScan');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
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);
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("receive_pda_sn注册成功")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
that.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
|
|
|
|
|
onReceive: (context, intent) => {
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("BroadcastReceiver--onReceive-回调执行")
|
|
|
|
|
|
that.logInfo('onReceive');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
plus.android.importClass(intent);
|
|
|
|
|
|
//下面的getStringExtra内改为自己的广播标签--有误
|
|
|
|
|
|
let code = intent.getStringExtra(that.customintent.codeKey);
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("getStringExtra - code:" + code)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
that.queryCode(code);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("BroadcastReceiver绑定完成")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
startScan() {
|
|
|
|
|
|
const that = this
|
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
this.main.registerReceiver(this.receiver, this.filter);
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo('startScan');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
2024-10-21 14:15:29 +00:00
|
|
|
|
stopScan() {
|
2023-11-25 16:30:38 +00:00
|
|
|
|
const that = this
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo('stopScan');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
this.main.unregisterReceiver(this.receiver);
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
queryCode: function(code) {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
// #ifdef APP
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo('queryCode');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
if (that.codeQueryTag) return false;
|
|
|
|
|
|
that.codeQueryTag = true;
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
that.codeQueryTag = false;
|
|
|
|
|
|
}, 150);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
that.$emit('onChange', code)
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("uni.$emit触发wuli-appscan")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
triggerKeyScan() {
|
|
|
|
|
|
const that = this
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("执行triggerKeyScan调用")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
//获取Android意图类
|
|
|
|
|
|
let Intent = plus.android.importClass('android.content.Intent');
|
|
|
|
|
|
//实例化意图
|
|
|
|
|
|
let intent = new Intent();
|
|
|
|
|
|
//定义意图,模拟按下L键,L键实际上是打开激光的物理键映射,由厂商提供
|
|
|
|
|
|
const scanDownKey = "com.android.action.keyevent." + this.customintent.scanDownKey
|
|
|
|
|
|
intent.setAction(scanDownKey);
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("模拟按下L键: " + scanDownKey)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
//广播这个意图
|
|
|
|
|
|
that.main.sendBroadcast(intent);
|
2024-10-21 14:15:29 +00:00
|
|
|
|
that.logInfo("广播按下L键")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|