blob: 51b2aa1d39e1840cf640c873be3a6439f144ce8c [file] [log] [blame]
qiaowei08e90682019-12-02 16:13:33 +08001var brightness;
2var bvalue;
3var setted= false;
qiaoweif044a742019-07-10 16:04:20 +08004var app = {
5
6 // Application Constructor
7 initialize: function() {
8 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
9 },
qiaoweif044a742019-07-10 16:04:20 +080010 onDeviceReady: function() {
11 var uid = window.localStorage.getItem("token");
qiaowei08e90682019-12-02 16:13:33 +080012 app.loadQrcode();
qiaowei04771b02019-08-07 09:23:56 +080013 setInterval(function () {
14 window.location.reload();
15 },100000);
qiaowei08e90682019-12-02 16:13:33 +080016
17 brightness = cordova.plugins.brightness;
18 if(brightness){
19 brightness.getBrightness(function(val){
20 bvalue = val;
21 }, function(err){
22 console.log(err);
23 });
24 }
qiaoweic5a87f72020-03-27 12:40:19 +080025 document.addEventListener("backbutton", function(e){
26 e.preventDefault();
27 app.backTo();
28 }, false);
qiaoweif044a742019-07-10 16:04:20 +080029 },
qiaowei04771b02019-08-07 09:23:56 +080030 loadQrcode: function() {
31 $.showLoading("加载中");
32 V1Qrcode(function(ok, ret) {
33 if (ok) {
34 console.log(ret)
35 if (ret.code == 200) {
36 $.hideLoading();
37 var qrcode = new QRCode(document.getElementById("qrcode"), {
38 text: ret.qrcode,
qiaowei5f8f92f2019-11-15 10:27:57 +080039 width: 200,
40 height: 200,
qiaowei04771b02019-08-07 09:23:56 +080041 colorDark: "#000000",
42 colorLight: "#ffffff",
43 correctLevel: QRCode.CorrectLevel.L
44 });
qiaowei08e90682019-12-02 16:13:33 +080045 if(!setted&&brightness){
46 brightness.setBrightness(1, function(ret){
47 console.log(ret);
48 setted = true;
49 brightness.setKeepScreenOn(true);
50 }, function(e){
51 console.log(e)
52 });
53 }
54 } else {
55 $.hideLoading();
56 $.alert("请求失败,请稍后再试", "错误");
57 }
58 } else {
59 $.hideLoading();
60 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
61 }
62 })
63 },
64 refresh:function(){
65 V1Qrcode(function(ok, ret) {
66 if (ok) {
67 if (ret.code == 200) {
68 $.hideLoading();
qiaoweic5a87f72020-03-27 12:40:19 +080069 $("#qrcode").html('');
qiaowei08e90682019-12-02 16:13:33 +080070 var qrcode = new QRCode(document.getElementById("qrcode"), {
71 text: ret.qrcode,
72 width: 200,
73 height: 200,
74 colorDark: "#000000",
75 colorLight: "#ffffff",
76 correctLevel: QRCode.CorrectLevel.L
77 });
qiaowei04771b02019-08-07 09:23:56 +080078 } else {
79 $.hideLoading();
80 $.alert("请求失败,请稍后再试", "错误");
81 }
82 } else {
83 $.hideLoading();
84 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
85 }
86 })
87 },
qiaowei08e90682019-12-02 16:13:33 +080088 backTo:function(){
89 if(brightness&&bvalue){
90 brightness.setBrightness(bvalue, function(ret){
91 brightness.setKeepScreenOn(false);
92 }, function(e){
93 console.log(e)
94 });
95 }
qiaowei8055aa72019-12-05 11:40:00 +080096 window.location.href='main.html';
qiaoweif044a742019-07-10 16:04:20 +080097 }
98};
99app.initialize();