l***@qq.com
l***@qq.com
  • 发布:2018-11-08 14:28
  • 更新:2018-11-08 14:28
  • 阅读:923

打包的 IOS应用 无法启动二维码扫描, 打包的Android应用 无法启动二维码扫描

分类:Native.js

打包的 IOS应用 无法启动二维码扫描, 打包的Android应用 无法启动二维码扫描

<template>
<div id = "qr" @click="startRecognize">
<x-icon type="chevron-left" @click="turnback" class="iconbutton backbutton" size="30"></x-icon>
<div id="bcid"></div>
<x-icon type="android-bulb" @click="lightStatus =! lightStatus" :class="[{'iconbutton': true}, {'lightButton': true}, {'lightButton-on': lightStatus}, {'lightButton-off': !lightStatus} ]" size="30" ></x-icon>
</div>
</template>

<script>
import { TransferDomDirective as TransferDom } from 'vux'
export default {
directives: {
TransferDom
},
name: 'QR',
watch: {
lightStatus (val) {
if (this.scanner) {
this.scanner.setFlash(val)
}
},
scanView (val) {
this.$emit('input', val)
if (!val) {
this.lightStatus = val
}
}
},
created () {
this.startRecognize()
},
data () {
return {
scanner: null,
lightStatus: false,
scanView: this.value
}
},
methods: {
turnback () {
if (this.scanner) {
this.scanner.close()
}
this.$router.back(-1)
},
exportResult (type, qrCode) {
this.$emit('qr-scan-result', type, qrCode)
this.turnback()
},
scanPicture () {
window.plus.gallery.pick(function (path) {
window.plus.barcode.scan(path, this.onmarked)
}, (err) => {
window.plus.nativeUI.alert('Failed: ' + err.message)
})
},
startRecognize () {
console.log('Start')
try {
const styles = {
frameColor: '#29E52C',
scanbarColor: '#29E52C',
background: '',
top: '0px',
position: 'absolute'
}
const qrfilter = [
window.plus.barcode.QR,
window.plus.barcode.EAN13,
window.plus.barcode.EAN8,
window.plus.barcode.CODE128
]
document.getElementById('bcid').removeAttribute('disabled')
this.scanner = new window.plus.barcode.Barcode('bcid', qrfilter, styles)
this.scanner.onmarked = this.onmarked
this.scanner.onerror = (error) => { console.log(error) }
this.scanner.start()
} catch (e) {
console.log('初始化错误:' + e)
}
},
onmarked (type, result) {
let qrType = ''
switch (type) {
case window.plus.barcode.QR:
qrType = 'QR: '
break
case window.plus.barcode.EAN13:
qrType = 'EAN13: '
break
case window.plus.barcode.EAN8:
qrType = 'EAN8: '
break
}
this.exportResult(qrType, result)
}
}
}
</script>

<style scoped>
.lightButton-on {
fill: #1AAD19;
}
.lightButton-off {
fill: #fff;
}
.lightButton{
position: absolute;
top: 2%;
right: 2%;
}
.iconbutton {
margin: 5%;
z-index: 3;
}
.backbutton {
position: absolute;
top: 2%;
fill: #fff;
}

bcid {

width: 100%;
height: 100%;
position: absolute;
top: 0;
background: #000000;
}
</style>

2018-11-08 14:28 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复