基於mui,h5+掃描功能

掃描》go~html

頁面一:點擊掃描,接收掃描的數據
頁面二:掃描
web



第一個頁面,邏輯不復雜,只是跳轉到第二個頁面,和接收數據
以及對掃描出來的數據進行判斷(每一個判斷方式都不同,暫不展現)bash

function scaned(t, r, f) { //接收數據
				console.log("end sm")
				console.log("ewm:: " + r)//接收到掃描的數據
				
				if(){//判斷二維碼格式
                                }
			}

			function closeWaiting() {
				console.log("closeWaiting");
			}複製代碼

第二個頁面htmldom

<div id="bcid">
			<div style="height:40%"></div>
			<p class="tip">...載入中...</p>
		</div>
		<footer>
			<div class="fbt" onclick="back()">取  消</div>
			<div class="fbt" onclick="scanPicture()">從相冊選擇二維碼</div>
		</footer>複製代碼

js  註釋都寫得很明白,很少解釋了ui

var ws = null,
				wo = null;
			var scan = null,
				domready = false;
			if (window.plus) {
				plusReady();
			} else {
				document.addEventListener('plusready', plusReady, false);
			}
			// 監聽DOMContentLoaded事件
			document.addEventListener('DOMContentLoaded', function() {
				domready = true;
				plusReady();
			}, false);
			// H5 plus事件處理
			function plusReady() {
				if (ws || !window.plus || !domready) {
					return;
				}
				// 獲取窗口對象
				ws = plus.webview.currentWebview();
				wo = ws.opener();
				// 開始掃描
				ws.addEventListener('show', function() {
					scan = new plus.barcode.Barcode('bcid');
					scan.onmarked = onmarked;
					scan.start({
						conserve: true,
						filename: '_doc/barcode/'
					});
				}, false);
				// 顯示頁面並關閉等待框
				ws.show('pop-in');
				wo.evalJS('closeWaiting()');
			}
			// 二維碼掃描成功
			function onmarked(type, result, file) {
				switch (type) {
					case plus.barcode.QR:
						type = 'QR';
						break;
					case plus.barcode.EAN13:
						type = 'EAN13';
						break;
					case plus.barcode.EAN8:
						type = 'EAN8';
						break;
					default:
						type = '其它' + type;
						break;
				}

				result = result.replace(/\n/g, '');
				wo.evalJS("scaned('" + type + "','" + result + "','" + file + "');");
				back();
			}
			// 從相冊中選擇二維碼圖片 
			function scanPicture() {
				plus.gallery.pick(function(path) {
					plus.barcode.scan(path, onmarked, function(error) {
						plus.nativeUI.alert('沒法識別此圖片');
					});
				}, function(err) {
					console.log('Failed: ' + err.message);
				});
			}
			function back(){
				//返回....
			}複製代碼
相關文章
相關標籤/搜索