剩余模块:生产退料
This commit is contained in:
2
uni_modules/qs-scanlistener/changelog.md
Normal file
2
uni_modules/qs-scanlistener/changelog.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## 1.0.0(2022-12-17)
|
||||
create
|
||||
@@ -0,0 +1,73 @@
|
||||
<template>
|
||||
<view></view>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
import scaninput from './scanInput.js'
|
||||
// #ifdef APP-PLUS
|
||||
scaninput.initScan()
|
||||
scaninput.startScan()
|
||||
// #endif
|
||||
export default {
|
||||
name:"scan-listener",
|
||||
created() {
|
||||
scaninput.install(this.scanHandle)
|
||||
uni.$on('scan_handle', this.scanHandle)
|
||||
},
|
||||
beforeDestroy() {
|
||||
scaninput.uninstall(this.scanHandle)
|
||||
},
|
||||
methods: {
|
||||
changeFun(str) {
|
||||
if (this.debounceTimer !== null) clearTimeout(this.debounceTimer)
|
||||
this.debounceTimer = setTimeout(() => {
|
||||
this.$emit('scan', this.inputVal)
|
||||
this.inputVal = ''
|
||||
}, 500)
|
||||
},
|
||||
onEvent(event) {
|
||||
console.log(event);
|
||||
if (event.key != 'Enter' && event.key != 'PrintScreen' && event.key != 'Shift' && event.key != 'Unidentified') { // 拼接输入的值,Enter与PrintScreen是物理按钮要排除
|
||||
this.inputVal = this.inputVal + event.key
|
||||
}
|
||||
if(this.inputVal) {
|
||||
this.changeFun(this.inputVal)
|
||||
}
|
||||
},
|
||||
scanHandle(code) {
|
||||
this.$emit('scan', code)
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
inputVal: '',
|
||||
debounceTimer:null
|
||||
};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script module="keyboard" lang="renderjs">
|
||||
export default {
|
||||
mounted () {
|
||||
const onKey = (event) => {
|
||||
const keys1 = ['type', 'timeStamp']
|
||||
const keys2 = ['altKey', 'code', 'ctrlKey', 'isComposing', 'key', 'location', 'metaKey', 'repeat', 'shiftKey']
|
||||
const keys3 = ['char', 'charCode', 'keyCode', 'keyIdentifier', 'keyLocation', 'which']
|
||||
const data = {}
|
||||
keys1.concat(keys2, keys3).forEach(key => {
|
||||
data[key] = event[key]
|
||||
})
|
||||
this.$ownerInstance.callMethod('onEvent', data)
|
||||
}
|
||||
const names = ['keyup'] //'keydown',
|
||||
names.forEach(name => {
|
||||
document.addEventListener(name, onKey, false)
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,55 @@
|
||||
let main, receiver, filter, _codeQueryTag = false, temp = [], init = false, start = false;
|
||||
export default {
|
||||
initScan() {
|
||||
if(init) return
|
||||
let _this = this;
|
||||
main = plus.android.runtimeMainActivity(); //获取activity
|
||||
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
|
||||
filter = new IntentFilter();
|
||||
//android.intent.ACTION_DECODE_DATA
|
||||
filter.addAction("com.uniappPda.ACTION"); // 换你的广播动作,你的pda设备里面看
|
||||
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
||||
onReceive: function(context, intent) {
|
||||
plus.android.importClass(intent);
|
||||
let code = intent.getStringExtra("com.uniapp.gatedge"); // 换你的广播标签,你的pda设备里面看
|
||||
_this.queryCode(code);
|
||||
|
||||
}
|
||||
});
|
||||
init = true
|
||||
},
|
||||
startScan() {
|
||||
if(!start) {
|
||||
start = true
|
||||
main.registerReceiver(receiver, filter);
|
||||
}
|
||||
},
|
||||
stopScan() {
|
||||
if(start) {
|
||||
start = false
|
||||
main.unregisterReceiver(receiver);
|
||||
}
|
||||
},
|
||||
install(fn) {
|
||||
if(typeof fn == 'function' && !~temp.indexOf(fn)) temp.push(fn)
|
||||
},
|
||||
uninstall(fn) {
|
||||
if(typeof fn == 'function') {
|
||||
const index = temp.find(i=>i == fn)
|
||||
if(~index) temp.splice(index, 1)
|
||||
}
|
||||
},
|
||||
queryCode: function(code) {
|
||||
//防重复
|
||||
// if (_codeQueryTag) return false;
|
||||
// _codeQueryTag = true;
|
||||
// setTimeout(function() {
|
||||
// _codeQueryTag = false;
|
||||
// }, 150);
|
||||
if(temp && temp.length) {
|
||||
temp[temp.length - 1](code)
|
||||
}
|
||||
uni.vibrateShort()
|
||||
uni.$emit("qs_scanlistener_handle", code);
|
||||
}
|
||||
}
|
||||
82
uni_modules/qs-scanlistener/package.json
Normal file
82
uni_modules/qs-scanlistener/package.json
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"id": "qs-scanlistener",
|
||||
"displayName": "qs-scanlistener PDA扫码",
|
||||
"version": "1.0.0",
|
||||
"description": "PDA扫码 兼容广播和键盘",
|
||||
"keywords": [
|
||||
"pda",
|
||||
"扫码"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "component-vue",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "y",
|
||||
"vue3": "y"
|
||||
},
|
||||
"App": {
|
||||
"app-vue": "y",
|
||||
"app-nvue": "n"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "n",
|
||||
"Android Browser": "n",
|
||||
"微信浏览器(Android)": "n",
|
||||
"QQ浏览器(Android)": "n"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "n",
|
||||
"IE": "n",
|
||||
"Edge": "n",
|
||||
"Firefox": "n",
|
||||
"Safari": "n"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "n",
|
||||
"阿里": "n",
|
||||
"百度": "n",
|
||||
"字节跳动": "n",
|
||||
"QQ": "n",
|
||||
"钉钉": "n",
|
||||
"快手": "n",
|
||||
"飞书": "n",
|
||||
"京东": "n"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "n",
|
||||
"联盟": "n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
uni_modules/qs-scanlistener/readme.md
Normal file
20
uni_modules/qs-scanlistener/readme.md
Normal file
@@ -0,0 +1,20 @@
|
||||
## qs-scanlistener PDA扫码
|
||||
## 支持广播和键盘
|
||||
---
|
||||
### 广播动作可在main.js设置uni._qs_scanlistener_action = 你的广播动作名称, 默认android.intent.ACTION_DECODE_DATA
|
||||
### 广播标签可在main.js设置uni._qs_scanlistener_label = 你的广播标签名称, 默认barcode_string
|
||||
---
|
||||
### 扫码结果也可以uni.$on('qs_scanlistener_handle', code=>{}) 中获取
|
||||
---
|
||||
Template
|
||||
```html
|
||||
<qs-scanlistener @scan="scan"></qs-scanlistener>
|
||||
```
|
||||
js
|
||||
```javascript
|
||||
methods: {
|
||||
scan(code) {
|
||||
console.log(code)
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user