This commit is contained in:
aihe 2023-12-23 15:52:34 +08:00
parent 31841eeb2a
commit bea28f9942
2 changed files with 94 additions and 28 deletions

View File

@ -1,16 +1,11 @@
<template>
<view>
日志======
<view v-for="(v, index) in debugLog" class="">{{index + 1}}: {{v}}</view>
</view>
<view></view>
</template>
<script>
export default {
props: {
customintent: {
type: Object,
default () {
return {
// !!注意: 不同的设备配置项是不同的
@ -20,10 +15,14 @@
}
}
},
value: {
default () {
return ''
}
},
},
data() {
return {
debugLog: [],
receiver: '',
filter: '',
codeQueryTag: false,
@ -35,72 +34,70 @@
this.startScan();
},
onHide() {
this.stopScan();
// this.stopScan();
},
destroyed() {
unmounted() {
this.stopScan();
},
methods: {
initScan() {
let that = this;
that.debugLog.push("执行initScan调用")
that.debugLog.push("actionKey==== " + that.customintent.actionKey)
that.debugLog.push("codeKey==== " + that.customintent.codeKey)
console.log("执行initScan调用")
console.log("actionKey==== " + that.customintent.actionKey)
console.log("codeKey==== " + that.customintent.codeKey)
// #ifdef APP
that.debugLog.push('initScan');
console.log('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);
that.debugLog.push("receive_pda_sn注册成功")
console.log("receive_pda_sn注册成功")
that.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: (context, intent) => {
that.debugLog.push("BroadcastReceiver--onReceive-回调执行")
that.debugLog.push('onReceive');
console.log("BroadcastReceiver--onReceive-回调执行")
console.log('onReceive');
plus.android.importClass(intent);
//下面的getStringExtra内改为自己的广播标签--有误
let code = intent.getStringExtra(that.customintent.codeKey);
that.debugLog.push("getStringExtra - code:" + code)
console.log("getStringExtra - code:" + code)
that.queryCode(code);
}
});
that.debugLog.push("BroadcastReceiver绑定完成")
console.log("BroadcastReceiver绑定完成")
// #endif
},
startScan() {
const that = this
// #ifdef APP
this.main.registerReceiver(this.receiver, this.filter);
that.debugLog.push('startScan');
console.log('startScan');
// #endif
},
stopScan() {
console.log('stopScan');
const that = this
// #ifdef APP
this.main.unregisterReceiver(this.receiver);
that.debugLog.push('stopScan');
// #endif
},
queryCode: function(code) {
let that = this;
// #ifdef APP
that.debugLog.push('queryCode');
console.log('queryCode');
if (that.codeQueryTag) return false;
that.codeQueryTag = true;
setTimeout(function() {
that.codeQueryTag = false;
}, 150);
uni.$emit('wuli-appscan', {
code
})
that.debugLog.push("uni.$emit触发wuli-appscan")
that.$emit('onChange', code)
console.log("uni.$emit触发wuli-appscan")
// #endif
},
triggerKeyScan() {
const that = this
that.debugLog.push("执行triggerKeyScan调用")
console.log("执行triggerKeyScan调用")
debugger
// #ifdef APP
//获取Android意图类
@ -110,10 +107,10 @@
//定义意图,模拟按下L键,L键实际上是打开激光的物理键映射,由厂商提供
const scanDownKey = "com.android.action.keyevent." + this.customintent.scanDownKey
intent.setAction(scanDownKey);
that.debugLog.push("模拟按下L键: " + scanDownKey)
console.log("模拟按下L键: " + scanDownKey)
//广播这个意图
that.main.sendBroadcast(intent);
that.debugLog.push("广播按下L键")
console.log("广播按下L键")
// #endif
}
}

View File

@ -0,0 +1,69 @@
<template>
<u-input :placeholder="placeholder" :fontSize="fontSize" :modelValue="value"
:custom-style="`border-radius: 10rpx;padding: 8rpx 12rpx;${customStyle};`"
@change="handleChange"
>
<template v-slot:prefix>
<u-icon @click="handleScan" name="scan" :size="fontSize*1.5"></u-icon>
</template>
</u-input>
<tpx-physics-scan onChange="handleChange"></tpx-physics-scan>
</template>
<script>
import { scanCode } from "@/common/untool"
export default {
props: {
value: {
default () {
return ''
}
},
placeholder:{
default () {
return '请输入或扫码'
}
},
fontSize: {
default () {
return 26
}
},
customStyle:{
default () {
return ''
}
},
placeholderStyle:{
default () {
return ''
}
},
},
data() {
},
created() {
},
onHide() {
},
destroyed() {},
methods: {
async handleScan() {
const res = await scanCode()
this.handleChange(res)
},
handleChange(val){
this.$emit('change', val)
this.$emit('update:value', val)
}
}
}
</script>
<style scoped lang="scss">
</style>