1 line
6.6 KiB
JavaScript
1 line
6.6 KiB
JavaScript
(function($){var ckitem,ckcheret={},prootdom,appuldom,modaldom,modaltype=null,ckkey=0;var check=function(){var self=this;this.url=M.url.own_form+'a=doappcheck&lang='+M.lang;this.dlurl=M.url.own_form+'a=download&lang='+M.lang;this.icon=['icon fa-times-circle','icon fa-check-circle','icon fa-exclamation-circle','icon fa-clock-o','loader vertical-align-middle loader-circle'];$('#appmodal').on('show.bs.modal',function(event){modaltype=$(event.relatedTarget).data('type');self.modalshow()});$("#appmodal").on("hidden.bs.modal",function(){self.checkint(modaltype);modaltype=null});$(document).on('click','.apprepair',function(){$(this).attr('disabled','disabled').removeClass('apprepair').text('Loading...');$(this).parent().append('(状态:<i class="icon fa-times-circle"></i> 表示文件修复失败,可点击重新修复。)');modaldom.find("span.download_file").each(function(){self.filedl($(this))})});$(document).on('click','.download_file',function(){self.filedl($(this))});$(document).on('click','.appupdate',function(){self.appinstall($(this).parent(),{'data':'update|check'})});$(document).on('click','.appinstall',function(){self.appinstall($(this).parent(),{'data':'install|check'})});$(document).on('click','.weqrcode',function(){modaltype=$(this).data('type');self.modalshow()});$(document).on('click','.retry',function(){self.checkint($(this).data('type'))})};check.prototype={item:{server:{title:'服务通信',text:'服务通信检测中...',},system:{title:'系统环境',text:'网站系统环境检测中...',},accredit:{title:'应用授权',text:'应用授权检测中...',},appfile:{title:'应用安全',text:'应用文件安全检测...',},weqrcode:{title:'微信公众号',text:'检测微信公众号关注情况...',},update:{title:'版本信息',text:'检测应用版本更新...',},appcheck:{text:'<i class="loader vertical-align-middle loader-circle"></i> 核验检测结果...',}},domli:function(id,value,num){num++;var len=ckitem.length-1;return'<li class="list-group-item" id="'+id+'"><div class="media"><div class="media-body"><h4 class="media-heading hover">('+num+'/'+len+') '+value.title+'</h4><small>等待检测...</small></div><div class="media-right p-t-10 p-b-10 p-0"><i class="icon fa-clock-o"></i></div></div></li>'},dom:function(){var self=this;$.each(this.item,function(key,value){var num=$.inArray(key,ckitem);if(key!='appcheck'&&num!='-1')appuldom.append(self.domli(key,value,num))})},result:function(res){var self=this;appuldom.find('li .media-right i').eq(res.eqkey).removeClass().addClass(self.icon[res.key]);appuldom.find('li .media-body small').eq(res.eqkey).html(res.text)},modal:function(res){if(res.hasOwnProperty('title'))modaldom.find('.modal-title').text(res.title);if(res.hasOwnProperty('body'))modaldom.find('.modal-body').html(res.body);res.hasOwnProperty('foot')?modaldom.find('.modal-footer').html(res.foot).show():modaldom.find('.modal-footer').empty().hide()},resbody:function(text){prootdom.find('.panel-body').html(text)},check:function(){var self=this,type=ckitem[ckkey];if(type=='appcheck'){self.resbody(self.item[type].text);self.appcheck(type,self)}else{self.checkint(type)}},checkint:function(type){var self=this,eqkey=ckkey,ckout=true;if(ckcheret.hasOwnProperty(type)){eqkey=ckcheret[type].eqkey;if(ckcheret[type].key==2)ckout=false}self.result({eqkey:eqkey,key:4,text:self.item[type].text});$.getJSON(self.url,{type:type,eqkey:eqkey},function(json){self.result(json);ckcheret[type]=json;if(ckout&&(json.key==1||json.key==2)){ckkey++;self.check()}if(json.hasOwnProperty('modal')&&type=='appfile'){if(json.modal.suc==false){self.result(json.modal);self.aurepair(json)}}}).error(function(){self.result({eqkey:eqkey,key:0,text:'<font style="color:#E9595B">程序发生异常!</font><a href="javascript:;" class="retry" data-type="'+type+'">点击重试</a>'})})},aurepair:function(ret){var self=this,eqkey=ret.hasOwnProperty('eqkey')?ret.eqkey:ckkey;$.getJSON(self.dlurl,{data:ret.modal.data,eqkey:eqkey},function(json){self.result(json);if(json.key==1)self.check();if(json.key==4)self.aurepair(json)})},filedl:function(_this_){var self=this;_this_.html('<i class="loader vertical-align-middle loader-circle"></i>');$.getJSON(self.dlurl,{type:'download',data:_this_.data('download')},function(json){var key=json.key;if(key==1)_this_.removeClass('download_file');_this_.find('i').removeClass().addClass(self.icon[key]);self.dlfiledom()})},dlfiledom:function(){if(modaldom.find("span.download_file").length==0){var html='<button type="button" class="btn btn-success" data-dismiss="modal">关闭</button><i class="red-600">(文件全部修复)</i>';modaldom.find('.modal-footer').html(html)}},appinstall:function(_this_,ret){var self=this;$.getJSON(self.dlurl,{data:ret.data},function(json){_this_.html(json.text);if(json.key==1){if(ckitem[ckkey]=='appcheck'&&modaltype==null)window.location.replace(window.location.href+'&check=1');if(modaltype=='update')$("#appmodal").modal('hide')}else{self.appinstall(_this_,json.modal)}})},wechat_qrcode:function(endtime,sign){var self=this,url=M.url.own_form+'a=domodal&type=wechat&lang='+M.lang;if(modaltype!='weqrcode')return null;$.getJSON(url,{cache:false,endtime:endtime,sign:sign}).done(function(json){switch(json.key){case 0:modaldom.find('.modal-body').html('<div class="h-50 text-xs-center">'+json.text+'</div>');break;case 1:$("#appmodal").modal('hide');break;default:self.wechat_qrcode(json.endtime,json.sign);break}})},modalshow:function(){var self=this,modal=ckcheret[modaltype].modal;self.modal(modal);if(modal.hasOwnProperty('url'))self.modalajax(modal.url)},modalajax:function(url){var self=this;$.getJSON(url,function(json){self.modal(json);if(json.hasOwnProperty('callback'))self[json.callback]('')})},appcheck:function(type,_this_){var self=this,url=M.url.own_name+'c=index&a=doajax&lang='+M.lang;$.getJSON(url,{sign:type},function(json){if(type=='ajax'){if(json.key==1){var text='<li class="nav-item pull-xs-right"><span style="display: block; padding:.715rem 1.429rem;" class="cyan-600 font-weight-600">'+json.text+'</span></li>';_this_.find('.stat-list').append(text)}else{window.location.replace(url.replace('a=doajax','a=doindex&check=1'))}}if(type=='appcheck'&&json.key==1){self.resbody(json.text)}}).error(function(){if(type=='ajax')window.location.replace(url.replace('a=doajax','a=doindex&check=1'))})}};$.fn.appcheck=function(){prootdom=this;ckitem=this.data('ckitem').split('|');appuldom=this.find('ul');modaldom=this.find('div.modal');var appck=new check();appck.dom();appck.check()};$.fn.ajaxcheck=function(){var appck=new check();appck.appcheck('ajax',this)};$.ajaxSetup({cache:false});$('.appcheck').length?$('.appcheck').appcheck():$('.metadmin-main').ajaxcheck()})(jQuery); |