blob: bb0a001302b50126e62d8952e23e8d35e2123cb3 [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:
qiaoweif044a742019-07-10 16:04:20 +080035 QRScanner.destroy();
qiaowei22e23f82019-09-26 11:15:57 +080036 $.alert(text, '提示');
37 showRet(text);
qiaoweif044a742019-07-10 16:04:20 +080038 }
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){
qiaowei22e23f82019-09-26 11:15:57 +080081 url=url+'&userid='+userid;
qiaoweif044a742019-07-10 16:04:20 +080082 }else{
qiaowei22e23f82019-09-26 11:15:57 +080083 url=url+'?userid='+userid;
qiaoweif044a742019-07-10 16:04:20 +080084 }
qiaowei22e23f82019-09-26 11:15:57 +080085 console.log(url)
qiaoweif044a742019-07-10 16:04:20 +080086 inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
87 statusbar: {
88 color: '#03a9f4ff'
89 },
90 toolbar: {
91 height: 44,
92 color: '#03a9f4ff'
93 },
94 title: {
95 color: '#ffffffff',
96 showPageTitle: true
97 },
98 backButton: {
99 image: 'back.png',
100 imagePressed: 'back.png',
101 align: 'left',
102 event: 'backPressed'
103 },
104 closeButton: {
105 image: 'close.png',
106 imagePressed: 'close.png',
107 align: 'left',
108 event: 'closePressed'
109 },
110 backButtonCanClose: true
111 }).addEventListener('backPressed', function(e) {
112 //alert('back pressed');
113 }).addEventListener('closePressed', function(e) {
114 //alert('closePressed pressed');
115 inAppBrowserRef.close();
116 window.location = "main.html"
117 }).addEventListener(cordova.ThemeableBrowser.EVT_ERR, function(e) {
118 console.error(e.message);
119 }).addEventListener(cordova.ThemeableBrowser.EVT_WRN, function(e) {
120 console.log(e.message);
121 });
122 inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
123 inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);
124}
125function loadStartCallBack(params,callback) {
126 console.log("1",params.url);
127}
128function beforeloadCallBack(params,callback) {
129 console.log("2",params.url);
130}