uniapp 自定义扫一扫页面


1. 展示效果: 

    

 

 

 

1.文件路径   

- project       
  + components   - static
    + css
    - font
       iconfont.css
       iconfont.eot
       iconfont.svg
       iconfont.ttf
       iconfont.woff
       iconfont.woff2
  
  - pages
    - scan
       scan.vue
  App.vue
  main.js
  manifest.json
  pages.json
  uni.scss

2.pages.json 配置

{
    "pages": [// #ifdef APP-PLUS || H5 || MP-ALIPAY
        {
            "path": "pages/scan/scan",
            "style": {
                "backgroundColor":"transparent",
                "navigationBarTitleText": "扫一扫",
                "transparentTitle": "auto"
            }
        }
        // #endif
    ],
    "globalStyle": {

    },
    "tabBar": {
    
    }

}

3.iconfont.css  icon 文件引入路径修改   “@/static/font/”    【引入自定义图标,在js drawRichText使用  \u + (iconfont.css 里对应图标的Unicode)】

@font-face {font-family: "c-icon";
  src: url('@/static/font/iconfont.eot?t=1597737803611'); /* IE9 */
  src: url('@/static/font/iconfont.eot?t=1597737803611#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAACEEAAsAAAAAPUAAACCzAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCIEgrkIM4XATYCJAOBCAtGAAQgBYRVB4QNGyQxRaSbnFYMZP9fEjgZg6vjz8oREfG2jMfSHmcMQVNnBWPl2ZAccmEFNodNVHDOSwnBRugrbyvFp0nxc8xQSh6+H/t23jfxtOCR2YiH5okS6cRKSxerDM/Prff/X/3FXxQlsNGjxkApdQktPeijWokUlRHiMHAWMHMWCBZWHIKRmCc2Hhh4mCineIn5v2kC++4PKxGKj8JieZ5Om+hO3YZ5AQSYpipo8fvRotTfslP7VPsYeNmCPVPvNH/XSdqZ3aSPFgLHk9i5At5dgUgrBY7sJJciP5J+V78LgkDBIMstBw6TMhhqgMDvnZale/dKOhUKk6/AoykVVS7LX+VURm803osBRXk8ATD/c/5rk8IHzh9hzzsZ3rEwgMbM+NxbvIG/pnl08wjT/ge3nL4PxGpnElCopg/bT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+hZuitnnC1XI+eZ53T6DW3WEOgfsZC/99zhKyCz8zMAIAD8AkAZvrhKURByQt7IhfwDdMjjuy7ixv7nupGbH0vdyGMxMNbEWZYVssQTwBm/rUXIa58Y7YiFg3PdLlNfNeGkN00rYZzsXQvroYuxMHIbYH/a/phJZbWhY37kVvBNcKfq84hbxEnfSW8O24YJnbGnk/huPpe60OsAVHfAyPIfN8F5CIixd/yorj/KXck4O778Fgqfe53EuW/u93P0w+EYFhc+Fw+GxQA/M0NHTF08P/hVsOLSu/arkvoXi3EnSDZYmaGLQNm4EUr5LTisKG1sIaQ+VNVJYQsAbcBBuCve1sA8AfcFhZ4mXbkIsAIBAi7APAwIAJTHgEEIGRxXnseDyjABRMkxRt4MnAE0oNTABsUAARAOBQAIAJLVzwEqKCbhwEGjvEIoIJBFue9zeMBDzzlCYAK5P/jB3/+29x4ez28YxjBrKZVRUvVRbsMVh/Tf8Av2fAuoPT+AfdIp7pzET/1f0IF+y3Td/5exCnHVNTHQO4ZcibVmB5hZQwi7eHGNYf3AEZLZW/wjmEEszKtykWjpepyZWD1+Yv/gF+yYe5SjP4D7heEbl+5M7p1ZD8JIBfLjNvcd/6eSMQpsjBTUT6mhiCjBCmNP9wjrIyCD6M9uEHrcm6lMV6lvCISaGTLve9feEYFMRmy5MhT+Mn5vQsSmlNJulpvtrv94ThfnC6vbty8dfvOXccf8rSU08nwO5oxuGx6+B59kEu7TNBPhhFo6Xij/ViaFtHCpvZGLC94/Sbn9Zm5MVa/LXPdhdh46GDqnG8jn1HVPSC7c3JOa992ehI2dWDu2178PADdIiz6GTKsMNWjHNNy2qJNQurz5tgM0cHCqNdx+ayetpjoaOrQmIJASRm0LbSD5iee2PB6xWgZNfZQUEXf0Yx4c2y3SUw8a73MTTjZ4QKwPC+rNlbiDpe28Bz16KI1EqkeBSo4xd/GUa99cdljG2vJrrkJW3mWAVJMXaNUxPb2AAAAAA==') format('woff2'),
  url('@/static/font/iconfont.woff?t=1597737803611') format('woff'),
  url('@/static/font/iconfont.ttf?t=1597737803611') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
  url('@/static/font/iconfont.svg?t=1597737803611#c-icon') format('svg'); /* iOS 4.1- */
}

.c-icon {
  font-family: "c-icon" !important;
  font-size: 32rpx;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

4. 在App.vue 引入iconfont.css

<script>
export default {
    onLaunch: function() {
        console.log('App Launch');
    },
    onShow: function() {
        console.log('App Show');
    },
    onHide: function() {
        console.log('App Hide');
    }
};
</script>

<style>

    @import "static/font/iconfont.css";

</style>

5.scan.vue 页面代码

<template>
    <view>
        <view class="c-scan-input-box" v-show="isEdit">
            <view ref="cScanInput" class="c-scan-input" :class="cScanInputH">
                <input class="uni-input" :focus="isEdit" v-model="value" placeholder="请输入需要添加的码" />
            </view>

            <view class="c-t-c">
                <button class="c-scan-btn c-scan-btn-gray" type="default" @click="switchScan">切换扫描</button>
                <button class="c-scan-btn c-scan-btn-orange" type="default" :disabled="!value ? true : false" @click="handleConfirm">确定</button>
            </view>
        </view>
    </view>
</template>

<script>

    
    export default {
        onLoad(opt) {
            // var data = opt ? JSON.parse(opt.scan) : {}; 
            // this.targetObj = data;
            // console.log('打开了',opt,data)
        },
        onUnload(){},
        data(){
            return {
                isEdit:false,
                targetObj:'',
                value:'',
                cScanInputH:'',
                barcode:{},
                flashLampObj:null,
                isFlash:false
                
            }
        },
            
        methods: {
                    
                    // 扫一扫
                    scan(){
                        var pages = getCurrentPages();
                        var page = pages[pages.length - 1];  
                        // #ifdef APP-PLUS  
                        var currentWebview = page.$getAppWebview(); //页面栈最顶层就是当前webview  
                        // #endif
                        
                        // 创建扫描码
                        var barcode = plus.barcode.create('barcode', [plus.barcode.CODE128, plus.barcode.QR], {
                            top:'0px',    
                            left:'0',    
                            width: '100%',    
                            height: '100%',    
                            position: 'static',
                            background:'#794fc4',
                            frameColor:'#794fc4',
                            scanbarColor:'#794fc4'
                        });    
                        

                        // 成功
                        barcode.onmarked = (type,result)=>{
                            // uni.showToast({
                            //     title: "("+type+")"+result ,
                            //     icon: "none"
                            // })
                            
                            this.returnValue(type,result)

                        };
                        
                        // 失败
                        barcode.onerror = (error)=>{
                            uni.showToast({
                                title: error ,
                                icon: "none"
                            })
                            
                            // barcode.start();
                        };
                        
                        this.barcode = barcode;
                        currentWebview.append(barcode);
                        barcode.start();
                    },
                    
                    // 扫一扫title
                    scanTitle(){
                            var view = new plus.nativeObj.View('scanTitle',{top:'20px',left:'40px',height:'36px',width:'100%'});
                            view.drawText('扫一扫', {left:'-40px'}, {size:'16px',color:'#ffffff',align:'center'});
                            view.show();
                    },
                    
                    // 手电筒
                    flashLamp(){
                        var that = this;
                        var view;
                        function _Create(flag){
                            var flashLamp = plus.nativeObj.View.getViewById('flashLamp');
                            if(flashLamp){flashLamp.close()}
                            view = new plus.nativeObj.View('flashLamp',{top:'60%',left:'40%',height:'60px',width:'80px'});
                            var color = flag ? '#794fc4' : '#ffffff';
                            view.drawRichText('<font color="'+ color +'" style="font-size:24px;">\ue65b</font><br/><font color="'+ color +'" style="font-size:10px;">轻触照亮</font>', {top:'0px',left:'0%',width:'100%', height:'wrap_content',color:'FF0000'},{size:'24px',family:'Times New Roman',fontSrc:'/static/font/iconfont.ttf',align:'center'});
                            view.show();
                            view.addEventListener("click", onClick, false);
                        }
                        
                        _Create();
                        
                        function onClick(){
                            that.isFlash = !that.isFlash;
                            that.barcode.setFlash(that.isFlash);
                            _Create(that.isFlash)
                        }
                    },
                    // 手动输入
                    manualInput(){
                        var that = this;
                        var view;
        
                        function _Create(flag){
                            view = new plus.nativeObj.View('manualInput',{bottom:'10%',left:'15%',height:'60px',width:'80px'});
                            var color = flag ? '#794fc4' : '#ffffff';
                            view.drawRichText('<font color="'+ color +'" style="font-size:28px;">\ue62d</font><br/><font color="'+ color +'" style="font-size:10px;">手动输入</font>', {top:'0px',left:'0%',width:'100%', height:'wrap_content',color:'FF0000'},{size:'24px',family:'Times New Roman',fontSrc:'/static/font/iconfont.ttf',align:'center'});
                            view.show();
                            view.addEventListener("click", onClick, false);
                        }
                        
                        _Create();
                        
                        function onClick(){
                            that.isEdit = true;
                            plus.nativeObj.View.getViewById('flashLamp').close();
                            plus.nativeObj.View.getViewById('manualInput').close();
                            plus.nativeObj.View.getViewById('localAlbum').close();
                            plus.barcode.getBarcodeById('barcode').close();
                            
                            setTimeout(()=>{
                                that.cScanInputH = 'c-scan-input-h';
                            },400)
                        }
                    },
                    // 本地相册
                    localAlbum(){
                        var that = this;
                        var view;
                        function _Create(flag){

                            view = new plus.nativeObj.View('localAlbum',{bottom:'10%',left:'60%',height:'60px',width:'80px'});
                            var color = flag ? '#794fc4' : '#ffffff';
                            view.drawRichText('<font color="'+ color +'" style="font-size:24px;">\ue7bf</font><br/><font color="'+ color +'" style="font-size:10px;">相册</font>', {top:'0px',left:'0%',width:'100%', height:'wrap_content',color:'FF0000'},{size:'24px',family:'Times New Roman',fontSrc:'/static/font/iconfont.ttf',align:'center'});
                            view.show();
                            
                            view.addEventListener("click", onClick, false);
                        }
                        
                        _Create();
                        
                        function onClick(){
                            plus.gallery.pick(function(path){
                                plus.barcode.scan( path, function(type,result) {
                                        // uni.showToast({
                                        //     title: "("+type+")"+result ,
                                        //     icon: "none"
                                        // })
                                        that.returnValue(type,result);
                                        console.log("Scan success:("+type+")"+result);
                                    }, function(e){
                                        uni.showToast({
                                            title: JSON.stringify(e) ,
                                            icon: "none"
                                        })
                                        console.log("Scan failed: "+JSON.stringify(e));
                                    } );

                            })
                    
                        }
                    },
                    closeView(){
                        var flashLamp = plus.nativeObj.View.getViewById('flashLamp');
                        var manualInput = plus.nativeObj.View.getViewById('manualInput');
                        var localAlbum = plus.nativeObj.View.getViewById('localAlbum');
                        var scanTitle = plus.nativeObj.View.getViewById('scanTitle');
                        
                        if(flashLamp) flashLamp.close();
                        if(manualInput) manualInput.close();
                        if(localAlbum) localAlbum.close();
                        if(scanTitle) scanTitle.close();

                    },
                    closeScan(){
                        var b = plus.barcode.getBarcodeById('barcode');
                        if(b){b.close();}
                    },
                    // 切换扫描
                    switchScan(){
                        this.isEdit = false;
                        this.scan();
                        this.flashLamp();
                        this.manualInput();
                        this.localAlbum();
                        this.cScanInputH = '';
                    },
                    // 确认事件
                    handleConfirm(){
                        
                        this.returnValue('edit',this.value);
                    },
                    // 返回值
                    returnValue(type,result){                        
                        var  pages = getCurrentPages();//当前页面栈
                        var prevPage = pages[pages.length - 2];//上一页面
                        var _url = prevPage.route.replace(/pages/g, "..")
                        var opt = {
                            type,result
                        }

                        // 返回返回结果
                        uni.$emit('scanUpdate',opt)
                        
                        uni.navigateBack({
                            delta: pages.length - 2
                        });                                    
                    }
                        
                },
                mounted(){
                    this.scan();
                    setTimeout(()=>{
                        this.flashLamp();
                        this.manualInput();
                        this.localAlbum();
                        this.scanTitle();
                    },500)
                },
                destroyed(){
                    this.closeView()
                }
            }
        </script>
        
    <style>
        .c-t-c{text-align: center;}
        .c-scan-input-box{position: absolute;left: 0;top: 0;height: 100%;width: 100%;background-color: #333333;}
        .c-scan-input{ height: 540rpx; width: 540rpx;background-color: #ffffff;margin: 384rpx auto 60rpx;margin-top: 384rpx; transition: height ease-out 0.35s; }
        .c-scan-text{display: block;color: #CCCCCC;padding: 16rpx 0 32rpx;}
        button.c-scan-btn{width: 218rpx;height: 80rpx;line-height: 80rpx;border-radius: 40rpx;margin: 50rpx;font-size: 28rpx;display: inline-block;}
        button.c-scan-btn-gray{background-color: #1F1F1F;color: #ffffff;}
        button.c-scan-btn-orange{background-color: #FF4000;color: #ffffff;}
        
        button.c-scan-btn[disabled]{background-color: #212121;color: #666666;}
        button.c-scan-btn-gray.button-hover[type=default] {color: #EEEEEE;background-color: #2F2F2F;}
        button.c-scan-btn-orange.button-hover[type=default] {color: #EEEEEE;background-color: #FF5C26;}
        .c-scan-input-h{height: 120rpx;transition: height ease-in 0.35s; line-height: 120rpx;}
        .c-scan-input-h .uni-input{height: 120rpx; line-height: 120rpx; caret-color: #794fc4; font-size: 36rpx;}

    </style>

6.调用方法

            handleScanPage(val){
                // var opt = {
                //     manualInput:true,
                //     localAlbum:true
                // }
                // var str = JSON.stringify(opt)
                
                // uni.navigateTo({
                //     url: `../scan/scan?scan=${str}`
                // });
                
                // 打开扫描页面
                uni.navigateTo({
                    url: '../scan/scan'
                });
                

                //  监听扫码成功返回值
                uni.$on('scanUpdate', (data)=>{
                    console.log('监听到事件来自 update ,携带参数 msg 为:',  data.type, data.result);
                     // data ? this[data.name] = data.value : null;
                     uni.showToast({
                         title: "("+data.type+")"+data.result ,
                         icon: "none"
                     })
                })
            }

7.相关参考资料
   uni-app中如何使用5+的原生界面控件https://ask.dcloud.net.cn/article/35036
   plus.barcode APIhttps://www.html5plus.org/doc/zh_cn/barcode.html
 html5plushttp://www.html5plus.org/doc/zh_cn/nativeobj.html#plus.nativeObj.View.addEventListener




 

posted @ 2020-08-21 15:02  一丝心情  阅读(5862)  评论(0编辑  收藏  举报