barcode_scan.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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" />
  6. <meta name="HandheldFriendly" content="true" />
  7. <meta name="MobileOptimized" content="320" />
  8. <title>Hello H5+</title>
  9. <script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
  10. <script type="text/javascript" src="../js/common.js"></script>
  11. <script src="../libs/choujiang/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
  12. <script src="http://121.42.151.57:7999/service/dyyj/demo.js/helper.js" type="text/javascript" charset="utf-8"></script>
  13. <script type="text/javascript">
  14. var DyyjDemo = new DyyjDemo('/service/dyyj/demo.js');
  15. var ws = null,
  16. wo = null;
  17. var scan = null,
  18. domready = false;
  19. // H5 plus事件处理
  20. function plusReady() {
  21. plus.nativeUI.closeWaiting();
  22. if (ws || !window.plus || !domready) {
  23. return;
  24. }
  25. // 获取窗口对象
  26. ws = plus.webview.currentWebview();
  27. wo = ws.opener();
  28. // 开始扫描
  29. ws.addEventListener('show', function() {
  30. scan = new plus.barcode.Barcode('bcid');
  31. scan.onmarked = onmarked;
  32. scan.start({
  33. conserve: true,
  34. filename: "_doc/barcode/"
  35. });
  36. });
  37. // 显示页面并关闭等待框
  38. ws.show("pop-in");
  39. // wo.evalJS("closeWaiting(s)");
  40. }
  41. if (window.plus) {
  42. plusReady();
  43. } else {
  44. mui.plusReady(function() {
  45. plusReady();
  46. })
  47. // document.addEventListener("plusready", plusReady, false);
  48. }
  49. // 监听DOMContentLoaded事件
  50. document.addEventListener("DOMContentLoaded", function() {
  51. domready = true;
  52. // plusReady();
  53. }, false);
  54. // 二维码扫描成功
  55. function onmarked(type, result, file) {
  56. switch (type) {
  57. case plus.barcode.QR:
  58. type = "QR";
  59. break;
  60. case plus.barcode.EAN13:
  61. type = "EAN13";
  62. break;
  63. case plus.barcode.EAN8:
  64. type = "EAN8";
  65. break;
  66. default:
  67. type = "其它";
  68. break;
  69. }
  70. result = result.replace(/\n/g, '');
  71. DyyjDemo.getInfoByBarcode(result, function(result) {
  72. if (result.rs) {
  73. var name = result.ms.item_name;
  74. var mess = '药物:' + name;
  75. plus.nativeUI.confirm(mess, function(e) {
  76. if (e.index == 0) {
  77. mui.openWindow({
  78. id: 'tixing',
  79. url: 'remind-drug.html',
  80. extras: {
  81. drug: name
  82. }
  83. });
  84. } else {
  85. var m = plus.webview.currentWebview();
  86. plus.webview.close(m);
  87. }
  88. (e.index == 0) ? "Yes!" : "No!"
  89. }, "确认", ["确定", "取消"]);
  90. } else {
  91. alert(result.ms);
  92. var m = plus.webview.currentWebview();
  93. plus.webview.close(m);
  94. }
  95. })
  96. // wo.evalJS("scaned('" + type + "','" + result + "','" + file + "');");
  97. // back();
  98. }
  99. // 从相册中选择二维码图片
  100. function scanPicture() {
  101. plus.gallery.pick(function(path) {
  102. plus.barcode.scan(path, onmarked, function(error) {
  103. plus.nativeUI.alert("无法识别此图片");
  104. });
  105. }, function(err) {
  106. plus.nativeUI.alert("Failed: " + err.message);
  107. });
  108. }
  109. </script>
  110. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
  111. <style type="text/css">
  112. #bcid {
  113. width: 100%;
  114. position: absolute;
  115. top: 0px;
  116. bottom: 44px;
  117. text-align: center;
  118. }
  119. .tip {
  120. color: #FFFFFF;
  121. font-weight: bold;
  122. text-shadow: 0px -1px #103E5C;
  123. }
  124. footer {
  125. width: 100%;
  126. height: 44px;
  127. position: absolute;
  128. bottom: 0px;
  129. line-height: 44px;
  130. text-align: center;
  131. color: #FFF;
  132. }
  133. .fbt {
  134. width: 50%;
  135. height: 100%;
  136. background-color: #e70012;
  137. float: left;
  138. }
  139. .fbt:active {
  140. -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
  141. box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5);
  142. }
  143. </style>
  144. </head>
  145. <body style="background-color: #000000;">
  146. <div id="bcid">
  147. <div style="height:40%"></div>
  148. <p class="tip">...载入中...</p>
  149. </div>
  150. <footer>
  151. <div class="fbt" onclick="back();">取  消</div>
  152. <div class="fbt" onclick="scanPicture();">从相册中选择</div>
  153. </footer>
  154. </body>
  155. </html>