blob: b9d81b92f960dca01570022b1f17d7519ea06d63 [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 }
qiaoweif044a742019-07-10 16:04:20 +080025 },
qiaowei04771b02019-08-07 09:23:56 +080026 loadQrcode: function() {
27 $.showLoading("加载中");
28 V1Qrcode(function(ok, ret) {
29 if (ok) {
30 console.log(ret)
31 if (ret.code == 200) {
32 $.hideLoading();
33 var qrcode = new QRCode(document.getElementById("qrcode"), {
34 text: ret.qrcode,
qiaowei5f8f92f2019-11-15 10:27:57 +080035 width: 200,
36 height: 200,
qiaowei04771b02019-08-07 09:23:56 +080037 colorDark: "#000000",
38 colorLight: "#ffffff",
39 correctLevel: QRCode.CorrectLevel.L
40 });
qiaowei08e90682019-12-02 16:13:33 +080041 if(!setted&&brightness){
42 brightness.setBrightness(1, function(ret){
43 console.log(ret);
44 setted = true;
45 brightness.setKeepScreenOn(true);
46 }, function(e){
47 console.log(e)
48 });
49 }
50 } else {
51 $.hideLoading();
52 $.alert("请求失败,请稍后再试", "错误");
53 }
54 } else {
55 $.hideLoading();
56 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
57 }
58 })
59 },
60 refresh:function(){
61 V1Qrcode(function(ok, ret) {
62 if (ok) {
63 if (ret.code == 200) {
64 $.hideLoading();
65 var qrcode = new QRCode(document.getElementById("qrcode"), {
66 text: ret.qrcode,
67 width: 200,
68 height: 200,
69 colorDark: "#000000",
70 colorLight: "#ffffff",
71 correctLevel: QRCode.CorrectLevel.L
72 });
qiaowei04771b02019-08-07 09:23:56 +080073 } else {
74 $.hideLoading();
75 $.alert("请求失败,请稍后再试", "错误");
76 }
77 } else {
78 $.hideLoading();
79 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
80 }
81 })
82 },
qiaowei08e90682019-12-02 16:13:33 +080083 backTo:function(){
84 if(brightness&&bvalue){
85 brightness.setBrightness(bvalue, function(ret){
86 brightness.setKeepScreenOn(false);
87 }, function(e){
88 console.log(e)
89 });
90 }
qiaowei8055aa72019-12-05 11:40:00 +080091 window.location.href='main.html';
qiaoweif044a742019-07-10 16:04:20 +080092 }
93};
94app.initialize();