skycaiji/public/static/js/admin/index.js

16 lines
4.2 KiB
JavaScript

/*
|--------------------------------------------------------------------------
| SkyCaiji (蓝天采集器)
|--------------------------------------------------------------------------
| Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
|--------------------------------------------------------------------------
| 使用协议 https://www.skycaiji.com/licenses
|--------------------------------------------------------------------------
*/
'use strict';$(document).ready(function(){$('#op_clean').bind('click',function(){var obj=$(this);if(obj.attr('cleaning')==1){return!1}
confirmRight('确定清除缓存?',function(){obj.attr('cleaning',1).html('正在清理...');$.ajax({type:'get',dataType:'json',url:ulink('Setting/clean'),success:function(data){obj.attr('cleaning',0);if(data.code==1){obj.html('清理完成')}else{obj.html('清理失败')}}})});return!1});$('#upgrade_db').bind('click',function(){var obj=$(this);$.ajax({type:'get',dataType:'json',url:ulink('Install/upgrade/db'),success:function(data){if(data.code==1){obj.html(data.msg?data.msg:'升级成功')}else{obj.html(data.msg?data.msg:'升级失败')}}})});$('#a_collect_now').bind('click',function(){windowIframe('实时采集',ulink('Admin/Backstage/collect'))});$('#upgrade_check').html('正在检测更新...');$.ajax({type:'get',dataType:'json',async:!0,url:ulink('Upgrade/newVersion'),success:function(data){data=data.data;if(data){if(data.is_new_version){var html='<a href="javascript:;" id="op_upgrade">检测到新版本V'+data.new_version+'点击升级</a>';if(data.version_link){html+=' &nbsp;<a href="'+data.version_link[1]+'" target="_blank" style="color:red;">'+data.version_link[0]+'</a>'}
$('#upgrade_check').html(html)}else{$('#upgrade_check').html('暂无更新')}
if(data.is_new_admin_index){$('#refresh_admin_index').trigger('click')}}else{$('#upgrade_check').html('')}}});$('body').on('click','#op_upgrade',function(){var obj=$(this);if(obj.attr('upgrading')==1){return!1}
obj.html('正在检索更新文件...');$.ajax({type:'get',dataType:'json',url:ulink('Upgrade/newFiles'),success:function(data){obj.attr('upgrading',1);if(data.code==1){var fileList=new Array();if(data.data.files){for(var i in data.data.files){fileList.push(data.data.files[i])}}
if(fileList.length>0){obj.html('正在更新...');var upgradeClass=new UpgradeClass(fileList);upgradeClass.down_file(0)}else{obj.html('没有需要更新的文件')}}else{var upgradeClass=new UpgradeClass(null);upgradeClass.down_complete()}}});return!1});$('#refresh_admin_index').bind('click',function(){$('#skycaiji_admin_index').parents('.box').eq(0).find('.overlay').show();$.ajax({type:'get',dataType:'json',async:!0,url:ulink('Backstage/adminIndex?refresh=1'),success:function(data){var html=data.html?data.html:'';$('#skycaiji_admin_index').html(html);$('#skycaiji_admin_index').parents('.box').eq(0).find('.overlay').hide()}})})});function UpgradeClass(fileList){this.fileList=fileList;this.fileNum=fileList?fileList.length:0;this.downNum=0}
UpgradeClass.prototype={constructor:UpgradeClass,down_file:function(index){var $_o=this;var file=$_o.fileList[index];$.ajax({type:'get',dataType:'json',url:ulink('Upgrade/downFile'),data:{filename:file.file,filemd5:file.md5},success:function(data){if(data.code==1){$_o.downNum++;$('#op_upgrade').html('正在更新... '+$_o.downNum+'/'+$_o.fileNum)}else{$('#op_upgrade').html('更新失败');$('#upgrade_error').show();if(data.msg){$('#upgrade_error').append(data.msg+"\r\n")}else{$('#upgrade_error').append('更新失败:'+file.file+"\r\n")}}},error:function(){$('#op_upgrade').html('更新失败');$('#upgrade_error').show();$('#upgrade_error').append('获取失败:'+file.file+"\r\n")},complete:function(){if(index+1>=$_o.fileNum){if($_o.downNum>=$_o.fileNum){$_o.down_complete()}else{$('#op_upgrade').html('请刷新界面重新下载失败的文件!')}}else{$_o.down_file(index+1)}}})},down_complete:function(){$('#op_upgrade').html('正在校验更新文件...');$.ajax({type:'get',dataType:'json',url:ulink('Upgrade/downComplete'),success:function(data){if(data.code==1){$('#op_upgrade').html('更新成功')}else{$('#op_upgrade').html('更新失败');$('#upgrade_error').show();for(var fi in data.data){$('#upgrade_error').append('文件校验失败:'+data.data[fi]+"\r\n")}}}})}}