checksaosao(){
//兼容h5的扫码页面
/*#ifdef H5*/
uni.$u.route(`/pages/my/saoma`)
return;
/*#endif*/
uni.scanCode({
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
let {
type,
uid,
} = JSON.parse(res.result);
console.log(type,uid);
if(type){
//扫码成功跳转输入金额页面
uni.$u.route(`/pages/my/amountEntered`, {
uid: uid,
type:type,
})
}else{
uni.$u.toast('未识别到二维码,请重新尝试!')
}
}
})
},
saoma.vue 页面 (这个页面用兼容h5扫码的)
<template>
<view class="scan size">
<u-navbar title="扫码" :autoBack="true" bgColor="black"></u-navbar>
<view class="sectionview"><view id="qr-reader" style="width:100%;height:100%;"></view></view>
<view class="footer">
<view style="margin-top: 60rpx;" class="btn" @click="getCameras">扫码</view> </view>
<u-toast ref="uToast" />
</view>
</template>
<script>
export default {
data() {
return {
codeUrl: '',
cameraId: '',
};
},
mounted() {
this.current = this.$route.query.current || 0;
this.init();
},
beforeDestroy() {
this.stop();
},
methods: {
//返回结果
getCode(res) {
let {
type,
uid,
} = JSON.parse(res);
console.log(type,uid);
if(type){
uni.$u.route(`/pages/my/amountEntered`, {
uid: uid,
type:type,
})
}else{
uni.$u.toast('未识别到二维码,请重新尝试!')
}
},
init() {
this.AddJs('https://blog.minhazav.dev/assets/research/html5qrcode/html5-qrcode.min.js');
//需要加载时间建议延时一点再获取设备列表
setTimeout(() => {
this.getCameras();
}, 1000);
},
stop() {
this.html5QrCode
.stop()
.then(ignore => {
// QR Code scanning is stopped.
console.log('QR Code scanning stopped.');
})
.catch(err => {
// Stop failed, handle it.
console.log('Unable to stop scanning.');
});
},
start() {
this.html5QrCode = new Html5Qrcode('qr-reader');
this.html5QrCode
.start(
this.cameraId, // retreived in the previous step.
{
fps: 10, // sets the framerate to 10 frame per second
qrbox: 250 // sets only 250 X 250 region of viewfinder to
// scannable, rest shaded.
},
qrCodeMessa