uniapp扫码功能兼容h5

            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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值