/* |-------------------------------------------------------------------------- | SkyCaiji (蓝天采集器) |-------------------------------------------------------------------------- | Copyright (c) 2018 https://www.skycaiji.com All rights reserved. |-------------------------------------------------------------------------- | 使用协议 https://www.skycaiji.com/licenses |-------------------------------------------------------------------------- */ 'use strict';function toolCheckFile(){$('#form_check').bind('submit',function(){var $_o=$(this);$_o.find('button[type="submit"]').attr('disabled',!0).html('正在校验...');ajaxOpen({type:'POST',dataType:'json',url:$(this).attr('action'),data:$(this).serialize(),success:function(data){if(data.code==1){toastr.success('程序文件全部完整!')}else{if(data.data.files){toastr.error('文件不完整!');var html='';for(var i in data.data.files){html+='
  • '+data.data.files[i]+'
  • '} $('#error_files').html(html).show()}else{toastr.error(data.msg)}}},complete:function(){$_o.find('button[type="submit"]').removeAttr('disabled').html('开始校验')}});return!1})} function toolCheckDb(){$('#form_check').bind('submit',function(){var $_o=$(this);window.check_error_tables=[];$('#error_box').hide();$('#error_box').children('[id^=error_]').hide();$('#repair_db').attr('disabled',!0).html('一键修复数据库');$_o.find('button[type="submit"]').attr('disabled',!0).html('正在校验...');window.check_db_success_msg='';ajaxOpen({type:'POST',dataType:'json',url:$(this).attr('action'),data:$(this).serialize(),success:function(data){if(data.code==1){window.check_db_success_msg='数据库全部一致!';$('#error_box').hide();$('#error_engines tbody').html('');$('#error_fields tbody').html('');$('#error_indexes tbody').html('')}else{var tbData=data.data;if(tbData.engines||tbData.fields||tbData.indexes){$('#error_box').show();if(isObject(tbData.engines)){var html='';for(var table in tbData.engines){html+=''+table+''+tbData.engines[table]+''} $('#error_engines').show();$('#error_engines tbody').html(html)} if(isObject(tbData.fields)){var html='';for(var table in tbData.fields){var fields=tbData.fields[table];for(var fi in fields){var field=fields[fi];html+=''+table+''+field.name+''+field.type+''+field['default']+''+field.primary+''+field.notnull+''+field.autoinc+''}} $('#error_fields').show();$('#error_fields tbody').html(html)}else{$('#error_fields').hide();$('#error_fields tbody').html('')} if(isObject(tbData.indexes)){var html='';var ix_types={'primary':'主键索引','index':'普通索引','unique':'唯一索引','fulltext':'全文索引'};for(var table in tbData.indexes){var indexes=tbData.indexes[table];for(var iname in indexes){var iindex=indexes[iname];html+=''+table+''+iname+''+iindex.field+''+iindex.type+' '+ix_types[iindex.type]+''}} $('#error_indexes').show();$('#error_indexes tbody').html(html)}else{$('#error_indexes').hide();$('#error_indexes tbody').html('')}}else{toastr.error(data.msg)}} ajaxOpen({type:'POST',dataType:'json',url:ulink('tool/checkTable'),success:function(data){checkDbCheckTable(data.data)},error(){$_o.find('button[type="submit"]').removeAttr('disabled').html('开始校验')}})},error:function(){$_o.find('button[type="submit"]').removeAttr('disabled').html('开始校验')}});return!1});$('#repair_db').bind('click',function(){var $_o=$(this);$('#error_box').children('[id^=error_]').hide();$_o.attr('disabled',!0).html('正在修复...');ajaxOpen({type:'POST',dataType:'json',url:ulink('tool/checkdb'),data:{repair:1},success:function(data){if(data.code==1){checkDbRepairTable()}else{$_o.html('操作失败');if(data.msg){$('#error_info').show().html(data.msg)}}},complete:function(){$_o.removeAttr('disabled')}});return!1})} function checkDbCheckTable(checkTables){if(!isObject(window.check_error_tables)){window.check_error_tables=[]} if(isObject(checkTables)&&checkTables.length>0){var checkTable=checkTables.shift();$('#form_check').find('button[type="submit"]').attr('disabled',!0).html('正在检测 '+checkTable+' 表...');ajaxOpen({type:'POST',dataType:'json',url:ulink('tool/checkTable?op=table&table='+checkTable),success:function(data){var table=data.data.table;if(table){if(table.error){window.check_error_tables.push(table.error)}} checkDbCheckTable(checkTables)},error:function(){checkDbCheckTable(checkTables)}})}else{if(window.check_error_tables.length>0){$('#error_box').show();$('#error_error_tables').html('需要修复的表:'+window.check_error_tables.join(', ')).show()}else{if(window.check_db_success_msg){prompt_success(window.check_db_success_msg)}} $('#repair_db').removeAttr('disabled').html('一键修复数据库');$('#form_check').find('button[type="submit"]').removeAttr('disabled').html('开始校验')}} function checkDbRepairTable(){if(isObject(window.check_error_tables)&&window.check_error_tables.length>0){var table=window.check_error_tables.shift();ajaxOpen({type:'POST',dataType:'json',url:ulink('tool/checkTable?op=repair&table='+table),success:function(data){$('#repair_db').attr('disabled',!0).html('正在修复 '+table+' 表...');checkDbRepairTable()}})}else{$('#repair_db').removeAttr('disabled').html('修复完成,请重新校验!')}}