blob: e75eba800d911ad44df0205e9e0e100ca14c4a89 [file] [log] [blame]
qiaoweif044a742019-07-10 16:04:20 +08001var app = {
2
3 // Application Constructor
4 initialize: function() {
5 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
6 },
7
8 onDeviceReady: function() {
9 console.log(2);
10 if (typeof(QRScanner) != 'undefined') {
11 //初始化检测,申请摄像头等权限
12 console.log(1);
13 QRScanner.destroy();
14 QRScanner.prepare(onDone); // show the prompt
15 } else {
16 $.alert('插件加载失败');
17 }
18 //showRet("http://ykt.supwisdom.com:9116/epay/wxpage/index")
19 function onDone(err, status) {
20 if (err) {
21 console.log(err);
22 $.alert('启动扫描出错:' + JSON.stringify(err), '提示');
23 }
24 if (status.authorized) {
25 //绑定扫描监听
26 // `QRScanner.cancelScan()` is called.
27 QRScanner.scan(displayContents);
28
29 function displayContents(err, text) {
30 if (err) {
31 // an error occurred, or the scan was canceled (error code `6`)
32 $.alert('扫描出错,请稍后再试:' + JSON.stringify(err), '提示');
33 } else {
34 // The scan completed, display the contents of the QR code:
35 //$.alert(text, '提示');
36 showRet(text);
37 QRScanner.destroy();
38 }
39 }
40 //开始扫描,需要将页面的背景设置成透明
41 QRScanner.show();
42 console.log("QRScanner.scan");
43 } else if (status.denied) {
44 // The video preview will remain black, and scanning is disabled. We can
45 // try to ask the user to change their mind, but we'll have to send them
46 // to their device settings with `QRScanner.openSettings()`.
47 $.alert('无法请求道相机权限,请在设置中开启', '提示');
48 } else {
49 // we didn't get permission, but we didn't get permanently denied. (On
50 // Android, a denial isn't permanent unless the user checks the "Don't
51 // ask again" box.) We can ask again at the next relevant opportunity.
52 $.alert('无法请求道相机权限,请在设置中开启', '提示');
53 }
54 }
55 this.receivedEvent()
56 },
57 receivedEvent: function() {
58 var light = false;
59 $('#lightBtn').click(function() {
60 if (light) {
61 QRScanner.enableLight();
62 } else {
63 QRScanner.disableLight();
64 }
65 light = !light;
66 });
67 },
68 goPage: function() {
69 QRScanner.destroy();
70 window.location = "main.html"
71 }
72};
73app.initialize();
74var inAppBrowserRef;
75function showRet(url) {
76 if(isEmpty(url)){
77 return;
78 }
79 var userid = window.localStorage.getItem("userid");
80 if(url.indexOf("?")>0){
81 url=url+'&uid='+userid;
82 }else{
83 url=url+'?uid='+userid;
84 }
85 inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
86 statusbar: {
87 color: '#03a9f4ff'
88 },
89 toolbar: {
90 height: 44,
91 color: '#03a9f4ff'
92 },
93 title: {
94 color: '#ffffffff',
95 showPageTitle: true
96 },
97 backButton: {
98 image: 'back.png',
99 imagePressed: 'back.png',
100 align: 'left',
101 event: 'backPressed'
102 },
103 closeButton: {
104 image: 'close.png',
105 imagePressed: 'close.png',
106 align: 'left',
107 event: 'closePressed'
108 },
109 backButtonCanClose: true
110 }).addEventListener('backPressed', function(e) {
111 //alert('back pressed');
112 }).addEventListener('closePressed', function(e) {
113 //alert('closePressed pressed');
114 inAppBrowserRef.close();
115 window.location = "main.html"
116 }).addEventListener(cordova.ThemeableBrowser.EVT_ERR, function(e) {
117 console.error(e.message);
118 }).addEventListener(cordova.ThemeableBrowser.EVT_WRN, function(e) {
119 console.log(e.message);
120 });
121 inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
122 inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);
123}
124function loadStartCallBack(params,callback) {
125 console.log("1",params.url);
126}
127function beforeloadCallBack(params,callback) {
128 console.log("2",params.url);
129}