vue扫码功能
直接写到组件里面,使用组件传值返回数据,返回功能还没做
<template>
<div class="scan">
<div id="bcid">
<div style="height:40%"></div>
<p class="tip">...载入中...</p>
</div>
<footer>
</footer>
</div>
</template>
<script type='text/ecmascript-6'>
let scan = null
export default {
data () {
return {
codeUrl: '',
}
},
mounted(){
this.startScan()
setTimeout(() => {
this.startScan1()
}, 500);
},
methods: {
back(){
scan.cancel();
scan.close();
this.scanShow=false
},
startScan1(){
if (!window.plus) return
scan.start()
console.log('开始扫描')
},
// 开始扫描
startScan() {
let that = this;
if (!window.plus) return;
//filter 扫描类型
var filter = [
plus.barcode.CODE128,
plus.barcode.EAN13,
plus.barcode.EAN8,
plus.barcode.QR,
];
scan = new plus.barcode.Barcode("bcid", filter);
scan.onmarked = onmarked;
function onmarked(type, result, file) {
switch (type) {
case plus.barcode.QR:
type = "QR";
break;
case plus.barcode.EAN13:
type = "EAN13";
break;
case plus.barcode.EAN8:
type = "EAN8";
break;
case plus.barcode.CODE128:
type = "EAN8";
break;
default:
type = "其它" + type;
break;
}
that.$emit('Numdata', result);
if (result) {
if (!window.plus) return;
scan.cancel();
scan.close();
}
};
}
}
}
</script>
<style lang="less">
.scan {
height: 100%;
#bcid {
width: 100%;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 3rem;
text-align: center;
color: #fff;
background: #ccc;
}
footer {
position: absolute;
left: 0;
bottom: 1rem;
height: 2rem;
line-height: 2rem;
z-index: 2;
}
}
</style>