blob: 016f2d7eb7c79663bdf860cb9a1d7825f69f1ac9 [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();
qiaowei0d9c0cd2020-06-24 16:27:18 +080015 },15000);
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);
qiaowei896e52a2020-06-28 18:01:58 +080029
30 window.plugins.preventscreenshot.disable(function(ret){}, function(ret){});
qiaoweif044a742019-07-10 16:04:20 +080031 },
qiaowei04771b02019-08-07 09:23:56 +080032 loadQrcode: function() {
33 $.showLoading("加载中");
34 V1Qrcode(function(ok, ret) {
35 if (ok) {
36 console.log(ret)
37 if (ret.code == 200) {
38 $.hideLoading();
39 var qrcode = new QRCode(document.getElementById("qrcode"), {
40 text: ret.qrcode,
qiaowei5f8f92f2019-11-15 10:27:57 +080041 width: 200,
42 height: 200,
qiaowei04771b02019-08-07 09:23:56 +080043 colorDark: "#000000",
44 colorLight: "#ffffff",
45 correctLevel: QRCode.CorrectLevel.L
46 });
qiaowei08e90682019-12-02 16:13:33 +080047 if(!setted&&brightness){
48 brightness.setBrightness(1, function(ret){
49 console.log(ret);
50 setted = true;
51 brightness.setKeepScreenOn(true);
52 }, function(e){
53 console.log(e)
54 });
55 }
56 } else {
57 $.hideLoading();
58 $.alert("请求失败,请稍后再试", "错误");
59 }
60 } else {
61 $.hideLoading();
62 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
63 }
64 })
65 },
66 refresh:function(){
67 V1Qrcode(function(ok, ret) {
68 if (ok) {
69 if (ret.code == 200) {
70 $.hideLoading();
qiaoweic5a87f72020-03-27 12:40:19 +080071 $("#qrcode").html('');
qiaowei08e90682019-12-02 16:13:33 +080072 var qrcode = new QRCode(document.getElementById("qrcode"), {
73 text: ret.qrcode,
74 width: 200,
75 height: 200,
76 colorDark: "#000000",
77 colorLight: "#ffffff",
78 correctLevel: QRCode.CorrectLevel.L
79 });
qiaowei04771b02019-08-07 09:23:56 +080080 } else {
81 $.hideLoading();
82 $.alert("请求失败,请稍后再试", "错误");
83 }
84 } else {
85 $.hideLoading();
86 $.alert("请求失败了:" + ret.status + "请稍后再试", "错误");
87 }
88 })
89 },
qiaowei08e90682019-12-02 16:13:33 +080090 backTo:function(){
91 if(brightness&&bvalue){
92 brightness.setBrightness(bvalue, function(ret){
93 brightness.setKeepScreenOn(false);
94 }, function(e){
95 console.log(e)
96 });
97 }
qiaowei8055aa72019-12-05 11:40:00 +080098 window.location.href='main.html';
qiaoweif044a742019-07-10 16:04:20 +080099 }
100};
101app.initialize();