当前位置:   article > 正文

vue+Hbuilder 二维码扫码功能的实现_hbuilderx 二维码扫描源码

hbuilderx 二维码扫描源码

此代码须建立在Hbuilder上
代码如下: 只有真机运行才能起作用

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

  <title>XXXXX</title>


  <style type="text/css">
    *{ -webkit-user-select: none;}
    html,body{
      margin: 0px;
      padding: 0px;
      height: 100%;
    }
    #bcid {
      background:#0F0;
      height:480px;
      width:360px;
    }
  </style>

  <script type="text/javascript" >
      // 扩展API加载完毕后调用onPlusReady回调函数
      document.addEventListener( "plusready", onPlusReady, false );
      // 扩展API加载完毕,现在可以正常调用扩展API
      function onPlusReady() {
          var e = document.getElementById("scan");
          e.removeAttribute( "disabled" );
      }
      var scan = null;
      function onmarked( type, 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;
          }
          alert( text+result );
      }
      function startRecognize() {
          scan = new plus.barcode.Barcode('bcid');
          scan.onmarked = onmarked;
      }
      function startScan() {
          scan.start();
      }
      function cancelScan() {
          scan.cancel();
      }
      function setFlash() {
          scan.setFlash();
      }


      function startRecognize() {
          console.log("333333333333333");
          scan = new plus.barcode.Barcode('bcid');
          scan.onmarked = onmarked;
          this.startScan
      }
     function startScan () {
          scan.start();
      }
  </script>
</head>
<body>
<div>扫码功能</div>
<input type='button' onclick='startRecognize()' value='创建扫描控件' />
<input type='button' onclick='startScan()' value='开始扫描' />
<input type='button' onclick='cancelScan()' value='取消扫描' />
<input type='button' onclick='setFlash()' value='开启闪光灯' />
<div id= "bcid"></div>
<input type='text' id='text'/>
<!--<div id="app"></div>-->
<script src="../dist/build.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3mn83YpfI9VdPSZg1DfuK7lg0UqRljwt"></script>
</body>
</html>




  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号