window.stepTotal = 0;

window.stepNum = 0;

window.updateRun = false;

$('#update-start').click(function(){

window.updateRun = true;

updateStart();

})

$('#update-stop').click(function(){

window.updateRun = false;

})

$('#update-init').click(function(){

$('#ds-check-task-sys-log').html('');

$('#update-table-box').find('.progress-info').html('');

window.stepNum = 0;

window.stepTotal = false;

setTotalProgress();

initTableProgress();

$.ajax({//获取升级信息 url:'?r=data-update/initialization',

type:'GET',

dataType:'JSON',

async:false,

success:function(data){

if (data.code==0) {

alert(data.text);

}

},

});

})

function updateStart(){

updateInit();

return false;

updateStep();

}

//清除备份function updateClear(){

//检查是否可以执行备份操作 $.ajax({

url:'?r=data-back/update-clear',

type:'POST',

dataType:'JSON',

async:false,

data:{xconfirm:1},

success:function(data){

alert(data.text);

},

error:function(){

}

})

}

function updateCheck(){

var result = {code:'1', text:'备份检查未执行'};

//检查是否可以执行备份操作 $.ajax({

url:'?r=data-back/update-check',

type:'POST',

dataType:'JSON',

async:false,

success:function(data){

result = data;

},

error:function(){

result = {code:'1', text:'备份检查失败'};

}

})

return result;

}

function updateInit(){

$.ajax({//获取升级信息 url:'?r=data-update/get-update-info',

type:'POST',

dataType:'JSON',

async:false,

success:function(data){

window.stepTotal = data.step_total;

window.stepNum = 0;

setTotalProgress();

},

error:function(xhr){

}

});

polling();

}

function polling(){

$.ajax({//获取轮询 url:"/?r=data-update/polling",

type:"GET",

async:true,

dataType:"json",

success:function (msg){

//console.log(msg); if (msg.code==0 || msg.code==2){

if (msg.code==2){

polling_step();

}

window.stepNum = msg.step;

setTotalProgress();

$('#ds-check-task-sys-log').append(msg.text+'
');

polling();

} else {

alert(msg.text);

}

}

});

}

function polling_step(){

$.ajax({//获取轮询 url:"/?r=data-update/polling_step",

type:"GET",

async:true,

dataType:"json",

success:function (msg){

console.log(msg);

if(msg.stop==1 && msg.code!='info') {

var info = {

total:msg.step,

page:msg.code,

pagetotal:msg.text

};

$('#update-table-box').find('.progress-info').html('共有'+info.total+'条记录,备份进度['+info.page+'/'+info.pagetotal+'页]');

setTableProgress(info);

polling_step();

}

if (msg.code=='info'){

var content = $('#ds-check-task-sys-log').text();

var str=new RegExp(msg.text);

if(!str.test(content)){

$('#ds-check-task-sys-log').append(msg.text+'
');

}

polling_step();

}

}

});

}

function setTotalProgress(){

var tableNum = window.tableIndex;

if(window.stepTotal > 0){

var percent = Math.ceil((stepNum/window.stepTotal)*100);

}else{

var percent = 100;

}

var progressBox = $('#update-total-box');

progressBox.find('.step-total').html(window.stepTotal);

progressBox.find('.step-num').html(window.stepNum);

progressBox.find('.progress-bar').attr('aria-valuenow', window.stepNum);

progressBox.find('.progress-bar').attr('aria-valuemax', window.stepTotal);

progressBox.find('.progress-bar').width(percent+'%');

progressBox.find('.progress-bar').html(percent+'%');

}

function updateStep(stepNum, page){

if(!window.updateRun){

return false;

}

if(typeof(page) == 'undefined'){

var page = 1;

$('#update-table-box').find('.progress-info').html('共有0条记录,备份进度[0/0页]');

initTableProgress();//初始化进度条 }

var data = {table:table, pagesize:window.updatePagesize, page:page};

$.ajax({//获取数据库信息 url:'?r=data-update/step'+stepNum,

type:'POST',

dataType:'JSON',

data:data,

success:function(data){

if(data.code == 0){

var info = data.info;

setTableProgress(info);

//备份下一张表格 setTimeout(function(){

window.tableIndex++;

setTotalProgress();

updateTable();

}, 1000)

}else{

//备份下一页表数据 updateStep(stepNum, page + 1);

}

},

error:function(xhr){

}

})

}

function initTableProgress(){

var progressBox = $('#update-table-box');

progressBox.find('.progress-bar').attr('aria-valuenow', 0);

progressBox.find('.progress-bar').attr('aria-valuemax', 0);

progressBox.find('.progress-bar').width('0%');

progressBox.find('.progress-bar').html('0%');

}

function setTableProgress(info){

var progressBox = $('#update-table-box');

progressBox.find('.total-num').html(info.total);

progressBox.find('.current-page-num').html(info.page);

progressBox.find('.pagetotal-num').html(info.pagetotal);

if(info.pagetotal > 0){

var percent = Math.ceil((info.page/info.pagetotal)*100);

}else{

var percent = 100;

info['page'] = 1;

info['pagetotal'] = 1;

}

progressBox.find('.progress-bar').attr('aria-valuenow', info.page);

progressBox.find('.progress-bar').attr('aria-valuemax', info.pagetotal);

progressBox.find('.progress-bar').width(percent+'%');

progressBox.find('.progress-bar').html(percent+'%');

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐