<template>
</template>
<script>
export default {
data() {
return {
barcode:null,//创建扫一扫对象
result:'',//扫描结果
setFlash:false,//是否开启闪光灯
}
},
onLoad() {
let _this = this;
_this.barcode = null;
if(!_this.barcode){
// 创建Barcode扫码控件,此方法创建扫码识别控件并不会显示在页面中,需要调用plus.webview.Webview窗口对象的append方法将其添加到Webview窗口中才能显示
let top ='44px';
// #ifdef APP-PLUS
top = uni.getSystemInfoSync().statusBarHeight + 44 +'px'
// #endif
_this.barcode = plus.barcode.create('barcode', [plus.barcode.QR], {
top:top ,
left:'0',
width: '100%',
height: '100%',
position: 'static'
});
plus.webview.currentWebview().append(_this.barcode);
_this.barcode.onmarked = onmarked;
}
_this.barcode.start();//开启扫一扫
//获取扫描结果
function onmarked(type, result) {
_this.result = result;
var text = '未知: ';
switch(type){
case plus.barcode.QR:
text = 'QR: ';
break;
case plus.barcode.EAN13:
text = 'EAN13: ';
break;
case plus.barcode.EAN8:
text = 'EAN8: ';
break;
}
_this.barcode.cancel();//结束对摄像头获取图片数据进行条码识别操作,同时关闭摄像头的视频捕获。 结束后可调用start方法重新开始识别。
_this.barcode.close();//释放控件占用系统资源,调用close方法后控件对象将不可使用。
alert(result)
}
},
methods: {
//页面跳转
goBack(name) {
if (name == 1) {
this.barcode.cancel();//结束对摄像头获取图片数据进行条码识别操作,同时关闭摄像头的视频捕获。 结束后可调用start方法重新开始识别。
this.barcode.close();//释放控件占用系统资源,调用close方法后控件对象将不可使用。
if(this.result){
uni.reLaunch({
url: '/pages/login/login?result='+this.result,
animationType: 'pop-in',
animationDuration: 300
})
}else{
uni.navigateBack({
delta: name,
animationType: 'pop-out',
animationDuration: 300
});
}
} else {
uni.navigateTo({
url: name,
animationType: 'pop-in',
animationDuration: 300
})
}
},
}
}
</script>
<template>
<button @click="goBack()">扫一扫开启</button>
</template>
<script>
export default {
data() {
return {
url: "https://test.h5yw.dlsf-tech.com" // 是否正在扫一扫
}
},
onLoad() {
},
methods:{
goBack:function(){
uni.navigateTo({
url:'/pages/index/scan'
})
}
}
}
</script>