barcode_scan.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"/>
  6. <meta name="HandheldFriendly" content="true"/>
  7. <meta name="MobileOptimized" content="320"/>
  8. <title>Hello H5+</title>
  9. <script type="text/javascript" src="../js/common.js"></script>
  10. <script type="text/javascript">
  11. var ws=null,wo=null;
  12. var scan=null;
  13. // H5 plus事件处理
  14. function plusReady(){
  15. // 获取窗口对象
  16. ws=plus.webview.currentWebview();
  17. wo=ws.opener();
  18. // 开始扫描
  19. ws.addEventListener('show', function(){
  20. scan=new plus.barcode.Barcode('bcid');
  21. scan.onmarked=onmarked;
  22. scan.start({conserve:true,filename:'_doc/barcode/'});
  23. createSubview();
  24. }, false);
  25. // 显示页面并关闭等待框
  26. ws.show('pop-in');
  27. }
  28. document.addEventListener('plusready', plusReady, false);
  29. // 二维码扫描成功
  30. function onmarked(type, result, file){
  31. switch(type){
  32. case plus.barcode.QR:
  33. type = 'QR';
  34. break;
  35. case plus.barcode.EAN13:
  36. type = 'EAN13';
  37. break;
  38. case plus.barcode.EAN8:
  39. type = 'EAN8';
  40. break;
  41. default:
  42. type = '其它'+type;
  43. break;
  44. }
  45. result = result.replace(/\r\n/g, '');
  46. wo.evalJS("scaned('"+ type +"','"+ result +"','"+ file +"');");
  47. back();
  48. }
  49. // 创建子窗口
  50. function createSubview(){
  51. //
  52. }
  53. // 从相册中选择二维码图片
  54. function scanPicture(){
  55. plus.gallery.pick(function(path){
  56. plus.barcode.scan(path,onmarked,function(error){
  57. plus.nativeUI.alert('无法识别此图片');
  58. });
  59. }, function(err){
  60. console.log('Failed: '+err.message);
  61. });
  62. }
  63. </script>
  64. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
  65. <style type="text/css">
  66. #bcid {
  67. width: 100%;
  68. position: absolute;
  69. top: 0px;
  70. bottom: 0px;
  71. text-align: center;
  72. }
  73. .tip {
  74. color: #FFFFFF;
  75. font-weight: bold;
  76. text-shadow: 0px -1px #103E5C;
  77. }
  78. </style>
  79. </head>
  80. <body style="background-color:#000000;">
  81. <div id="bcid">
  82. <div style="height:40%"></div>
  83. <p class="tip">...载入中...</p>
  84. </div>
  85. </body>
  86. </html>