vue2.0 HBuilder打包添加扫一扫功能

项目中使用了keep-alive缓存, 扫描事件写在了activated里面了  这样每次进入页面都会开启扫描。

代码很简单,就直接贴上来了

<template>
    <div class="qr-code">
	    <div style="background: black;position: fixed;top: 50px;left: 0;right: 0;bottom: 0;">
        	<div id="bcid"></div>
	    </div>
    </div>
</template>

<script type='text/ecmascript-6'>
  let scan = null;

  export default {
    data() {
      return {
        codeUrl: '',
      }
    },
    created(){
    	
    },
    activated() {
    	this.startRecognize();
    },
    mounted(){
		
    },
    methods: {
      startRecognize() {
        let _this = this;
        if (!window.plus) return;
        //创建扫描控件
        scan = new plus.barcode.Barcode('bcid',
        [plus.barcode.QR, plus.barcode.EAN8, plus.barcode.EAN13],
        { frameColor: "#00FF00", scanbarColor: "#00FF00" });
      	//开始扫描
        scan.start();
        scan.onmarked = onmarked;
        function onmarked(type, result, file) {
        	let codes = result.split(":");
	        let key = codes[0];
	        let value = codes[1];
          switch (type) {
            case plus.barcode.QR:
              type = 'QR';
              break;
            case plus.barcode.EAN13:
              type = 'EAN13';
              break;
            case plus.barcode.EAN8:
              type = 'EAN8';
              break;
            default:
            _this.$layer.open({time:3,skin:'msg',content:'未能识别二维码'});
            scan.start();
            break;
          }
          result = result.replace(/\n/g, '');
          _this.codeUrl = result;
          if(_this.$route.params.type == 'homeIndex'){
          	_this.$router.push('/home')
          }else if(_this.$route.params.type == 'transferAccounts'){
          	_this.codeResult.$emit('result',result);
          	_this.$router.push('/transferAccounts')
          }
        }
      }
    },
    beforeDestroy() {
    	if(scan){
            //关闭扫描控件
	    	scan.close();
	    }
	  },
	  computed:{
	  	
	  }
  }
</script>

<style lang="css">
.qr-code{
    background-color: #FAF8F5;
}
#bcid {
  width: 100%;
      position: absolute;
      left: 0;
      right: 0;
      top: 50px;
      bottom:3rem;
      text-align: center;
      color: #fff;
      background: #000;
}
</style>

这个后面做了测试,不能开启扫描。一直没找的原因所在,想想会不会是keep-alive的原因,设置了keepAlive:false,再将activated里的方法放到created中。 结果就可以了。 

2019/02/11号 补充:

项目添加了很多新页面,从某一个页面跳转到扫描二维码页面不会开启扫描(其他页面都可以)并且返回上个页面后会自动横屏。最后加了一个setTimeout,可以了。具体原因不是很清楚

mounted(){
       setTimeout(() => {
		this.startRecognize();
    	},500)
    },

 

VueScan可以利用以下设备的高级硬件能力:尼康 LS-30/LS-2000,美能达 Dimage ScanDual,惠普PhotoSmart,尼康 LS-20/LS-1000,宝丽来 SprintScan 35/LE/ES/+,和佳能 CanoScan2700F底片扫描仪。利用 VueScan,你能够比平板扫描仪扫描照片更多地控制最终的图像。 VueScan 的特性包括:支持 200 种以上的底片类型,在剪取图像时制成关联单,复杂的白色平衡算法,用于检查物体表面暇疵的红外线底片扫描,成批扫描,自动剪取图像,等等。 VueScan是著名的第三方底片扫描仪驱动程序,支持市场可见绝大多数型号的底片扫描仪,可以更为灵活地控制扫描过程,更深入地发掘硬件潜力,获取色彩 完美的高质量扫描结果。VueScan支持200种以上的底片类型,在剪取图像时制成关联单,复杂的白色平衡算法,用于检查物体表面暇疵的红外线底片扫 描,成批扫描,自动剪取图像等等。 随着软件的走红,Vuescan不断升级,功能不断完善,应用界面也越来越美观实用,最后,很多扫描仪厂商干脆将它作为自己扫描仪的配套驱动程序。 随着数码相机的流行,RAW成为很多喜欢的文件格式,Vuescan也与时俱进,增加了RAW文件转换功能,凭借其优秀的图像算法,在RAW文件转换方 面,vuescan也独树一帜。如今,Vuescan已经发展成为一款多功能的图像处理软件,支持多达750款各类扫描仪和200多款能记录RAW文件的 数码相机,并支持Adobe的DNG数字底片格式! 功能: 支持1200种扫描仪 运行在Mac OS X,Windows和Linux 提高您的工作效率和质量的扫描 创建原始扫描文件 ICC配置文件和色彩空间 IT8色彩校正 注册信息: E-mail Address:wayne@dahaoren.com Serial Number:108824250 Customer Number:1560318833 或者(OR) E-mail Address:www@yyyww.com Serial Number:115973638 Customer Number:1608838852
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值