zq-scancode插件使用说明
1、引入包
// 扫码插件
var scanCodeModule = uni.requireNativePlugin("zq-scancode-module")
2、调用方法
scanCodeModule.startScan({
'name': '扫码',
'showTip': true,
'showLoading': true,
'tip': "自定义扫码",
'tipSize': 20,
'tipColor': "#FF0000"
},
(ret) => {
console.log("扫码内容:" + ret)
});
3、说明
startScan方法的参数:
第一个参数:json对象,根据实际情况传递,第二个参数会回传回来
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | String | 扫码 | 组件名称 |
| showTip | Boolean | true | 是否展示提示文字 |
| tip | String | 扫码中... | 提示文字 |
| tipSize | Number | 12 | 提示文字大小 |
| tipColor | String | #3B3B3C | 提示文字颜色 |
| showLoading | Boolean | true | 是否展示 loading |
第二个参数:扫码结果回调,返回json字符串,回调参数说明:
| 参数名 | 说明 |
|---|---|
| code | 状态码:200成功 |
| msg | 提示信息,比如:扫码成功 |
| data | 扫码结果 |
| extend | 第一个参数回传 |
4、完整示例代码
<template>
<div>
<button type="primary" @click="scanCode">开始扫码</button>
</div>
</template>
<script>
// 获取 module
var scanCodeModule = uni.requireNativePlugin("zq-scancode-module")
export default {
onLoad() {
plus.globalEvent.addEventListener('TestEvent', function(e) {
console.log("TestEvent收到:" + e.msg)
});
},
methods: {
// 扫码
scanCode() {
scanCodeModule.startScan({
'name': '扫码',
'showTip': true,
'showLoading': true,
'tip': "自定义扫码",
'tipSize': 20,
'tipColor': "#FF0000"
},
(ret) => {
console.log("扫码内容:" + ret)
});
}
}
}
</script>
5、补充说明
- 扫码枪的原理是外接输入法(类似:外接键盘),通过连接蓝牙或USB线连接设备就可以使用,不需要申请系统权限