blob: f3312810c54e75b0b16562f7f8ca6da7e2e36dcc [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 showRet(text);
qiaoweif044a742019-07-10 16:04:20 +080037 }
38 }
39 //开始扫描,需要将页面的背景设置成透明
40 QRScanner.show();
qiaoweif044a742019-07-10 16:04:20 +080041 } else if (status.denied) {
42 // The video preview will remain black, and scanning is disabled. We can
43 // try to ask the user to change their mind, but we'll have to send them
44 // to their device settings with `QRScanner.openSettings()`.
45 $.alert('无法请求道相机权限,请在设置中开启', '提示');
46 } else {
47 // we didn't get permission, but we didn't get permanently denied. (On
48 // Android, a denial isn't permanent unless the user checks the "Don't
49 // ask again" box.) We can ask again at the next relevant opportunity.
50 $.alert('无法请求道相机权限,请在设置中开启', '提示');
51 }
52 }
53 this.receivedEvent()
54 },
55 receivedEvent: function() {
56 var light = false;
57 $('#lightBtn').click(function() {
58 if (light) {
59 QRScanner.enableLight();
60 } else {
61 QRScanner.disableLight();
62 }
63 light = !light;
64 });
65 },
66 goPage: function() {
qiaoweie82a1f82019-09-26 17:45:32 +080067 //QRScanner.destroy();
qiaoweif044a742019-07-10 16:04:20 +080068 window.location = "main.html"
69 }
70};
71app.initialize();
qiaoweie82a1f82019-09-26 17:45:32 +080072function showRet1(url){
73 if(isEmpty(url)){
74 return;
75 }
76 var userid = window.localStorage.getItem("userid");
77 if (url.indexOf("yy.dlsmk.cn")>=0) {
qiaoweif044a742019-07-10 16:04:20 +080078 if(url.indexOf("?")>0){
qiaowei22e23f82019-09-26 11:15:57 +080079 url=url+'&userid='+userid;
qiaoweif044a742019-07-10 16:04:20 +080080 }else{
qiaowei22e23f82019-09-26 11:15:57 +080081 url=url+'?userid='+userid;
qiaoweif044a742019-07-10 16:04:20 +080082 }
qiaoweie82a1f82019-09-26 17:45:32 +080083 }
84 var ref = cordova.InAppBrowser.open(url, '_blank',"location=yes,beforeload=yes");
85 ref.addEventListener('loadstart', function(params){
86 if (params.url.indexOf("yy.dlsmk.cn")>=0) {
87 if (params.url.indexOf("userid")<0) {
88 if(params.url.indexOf("?")>0){
89 params.url=params.url+'&userid='+userid;
90 }else{
91 params.url=params.url+'?userid='+userid;
92 }
93 ref.hide();
94 var neRef = cordova.InAppBrowser.open(params.url, '_blank',"location=yes,beforeload=yes");
95 neRef.addEventListener('exit', function(e){
96 ref.close();
97 window.location = "main.html"
98 });
99 }
100 }
101 });
102}
103
104function showRet(url) {
105 if(isEmpty(url)){
106 return;
107 }
108 var userid = window.localStorage.getItem("userid");
109 if (url.indexOf("yy.dlsmk.cn")>=0) {
110 if(url.indexOf("?")>0){
111 url=url+'&userid='+userid;
112 }else{
113 url=url+'?userid='+userid;
114 }
115 }
qiaowei22e23f82019-09-26 11:15:57 +0800116 console.log(url)
qiaoweie82a1f82019-09-26 17:45:32 +0800117 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
qiaoweif044a742019-07-10 16:04:20 +0800118 statusbar: {
119 color: '#03a9f4ff'
120 },
121 toolbar: {
122 height: 44,
123 color: '#03a9f4ff'
124 },
125 title: {
126 color: '#ffffffff',
127 showPageTitle: true
128 },
129 backButton: {
130 image: 'back.png',
131 imagePressed: 'back.png',
132 align: 'left',
133 event: 'backPressed'
134 },
135 closeButton: {
136 image: 'close.png',
137 imagePressed: 'close.png',
138 align: 'left',
139 event: 'closePressed'
140 },
141 backButtonCanClose: true
qiaoweie82a1f82019-09-26 17:45:32 +0800142 }).addEventListener('loadstart', function(params){
143 if (params.url.indexOf("yy.dlsmk.cn")>=0) {
144 if (params.url.indexOf("userid")<0) {
145 if(params.url.indexOf("?")>0){
146 params.url=params.url+'&userid='+userid;
147 }else{
148 params.url=params.url+'?userid='+userid;
149 }
150 //ref.hide();
151 var neRef = cordova.ThemeableBrowser.open(params.url, '_blank');
152 neRef.addEventListener('closePressed', function(e){
153 neRef.close();
154 window.location = "main.html"
155 });
156 }
157 }
158 });
159 //inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
160 //inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);
qiaoweif044a742019-07-10 16:04:20 +0800161}
162function loadStartCallBack(params,callback) {
163 console.log("1",params.url);
164}
165function beforeloadCallBack(params,callback) {
166 console.log("2",params.url);
167}