2023-11-25 16:30:38 +00:00
|
|
|
|
<template>
|
2023-12-23 07:50:49 +00:00
|
|
|
|
<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: {
|
|
|
|
|
|
customintent: {
|
|
|
|
|
|
default () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
// !!注意: 不同的设备配置项是不同的
|
|
|
|
|
|
scanDownKey: "KEYCODE_SCAN_L_DOWN",
|
|
|
|
|
|
actionKey: 'com.android.receive_scan_action',
|
|
|
|
|
|
codeKey: "data"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-12-23 07:50:49 +00:00
|
|
|
|
value: {
|
|
|
|
|
|
default () {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-11-25 16:30:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
receiver: '',
|
|
|
|
|
|
filter: '',
|
|
|
|
|
|
codeQueryTag: false,
|
|
|
|
|
|
main: '',
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
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();
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
initScan() {
|
|
|
|
|
|
let that = this;
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("执行initScan调用")
|
|
|
|
|
|
console.log("actionKey==== " + that.customintent.actionKey)
|
|
|
|
|
|
console.log("codeKey==== " + that.customintent.codeKey)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #ifdef APP
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log('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);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("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) => {
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("BroadcastReceiver--onReceive-回调执行")
|
|
|
|
|
|
console.log('onReceive');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
plus.android.importClass(intent);
|
|
|
|
|
|
//下面的getStringExtra内改为自己的广播标签--有误
|
|
|
|
|
|
let code = intent.getStringExtra(that.customintent.codeKey);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("getStringExtra - code:" + code)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
that.queryCode(code);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("BroadcastReceiver绑定完成")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
startScan() {
|
|
|
|
|
|
const that = this
|
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
this.main.registerReceiver(this.receiver, this.filter);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log('startScan');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
stopScan() {
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log('stopScan');
|
2023-11-25 16:30:38 +00:00
|
|
|
|
const that = this
|
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
this.main.unregisterReceiver(this.receiver);
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
queryCode: function(code) {
|
2024-08-05 14:51:32 +00:00
|
|
|
|
// let { hongWaiSwitch } = getSessionSystemInfo()
|
|
|
|
|
|
// // 红外开启,才可使用该功能
|
|
|
|
|
|
// if(!hongWaiSwitch) {
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
// }
|
2023-11-25 16:30:38 +00:00
|
|
|
|
let that = this;
|
|
|
|
|
|
// #ifdef APP
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log('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)
|
|
|
|
|
|
console.log("uni.$emit触发wuli-appscan")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
},
|
|
|
|
|
|
triggerKeyScan() {
|
|
|
|
|
|
const that = this
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("执行triggerKeyScan调用")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
debugger
|
|
|
|
|
|
// #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);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("模拟按下L键: " + scanDownKey)
|
2023-11-25 16:30:38 +00:00
|
|
|
|
//广播这个意图
|
|
|
|
|
|
that.main.sendBroadcast(intent);
|
2023-12-23 07:50:49 +00:00
|
|
|
|
console.log("广播按下L键")
|
2023-11-25 16:30:38 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|