修复数据库备份与恢复
This commit is contained in:
@@ -59,19 +59,22 @@ class Database extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$title = '数据还原';
|
$title = '数据还原';
|
||||||
|
$require = ['jsname' => 'database', 'actionname' => 'import'];
|
||||||
break;
|
break;
|
||||||
/* 数据备份 */
|
/* 数据备份 */
|
||||||
case 'export':
|
case 'export':
|
||||||
$list = \think\facade\Db::query('SHOW TABLE STATUS');
|
$list = \think\facade\Db::query('SHOW TABLE STATUS');
|
||||||
$list = array_map('array_change_key_case', $list);
|
$list = array_map('array_change_key_case', $list);
|
||||||
$title = '数据备份';
|
$title = '数据备份';
|
||||||
|
$require = ['jsname' => 'database', 'actionname' => 'export'];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return $this->error('参数错误!');
|
return $this->error('参数错误!');
|
||||||
}
|
}
|
||||||
//渲染模板
|
//渲染模板
|
||||||
$this->data = [
|
$this->data = [
|
||||||
'meta_title' => $type == 'import' ? "数据库恢复" : "数据库备份",
|
'meta_title' => $type == 'import' ? "数据库恢复" : "数据库备份",
|
||||||
|
'require' => $require,
|
||||||
'list' => $list
|
'list' => $list
|
||||||
];
|
];
|
||||||
return $this->fetch($type);
|
return $this->fetch($type);
|
||||||
|
|||||||
@@ -114,14 +114,14 @@ require(['jquery', 'bootstrap', 'message', 'adminlte'], function ($) {
|
|||||||
window.Config = Config;
|
window.Config = Config;
|
||||||
// 配置语言包的路径
|
// 配置语言包的路径
|
||||||
var paths = {}; // 避免目录冲突
|
var paths = {}; // 避免目录冲突
|
||||||
paths['backend/'] = 'backend/';
|
paths['backend'] = 'backend/';
|
||||||
require.config({paths: paths});
|
require.config({paths: paths});
|
||||||
$(function(){
|
$(function(){
|
||||||
require(['sent'], function(sent){
|
require(['sent'], function(sent){
|
||||||
require(['admin/js/backend'], function(backend){
|
require(['admin/js/backend'], function(backend){
|
||||||
//加载相应模块
|
//加载相应模块
|
||||||
if (Config.jsname) {
|
if (Config.jsname) {
|
||||||
require([Config.jsname], function (Controller) {
|
require(['admin/js/module/'+Config.jsname], function (Controller) {
|
||||||
if (Controller.hasOwnProperty(Config.actionname)) {
|
if (Controller.hasOwnProperty(Config.actionname)) {
|
||||||
Controller[Config.actionname]();
|
Controller[Config.actionname]();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
115
public/static/admin/js/module/database.js
Normal file
115
public/static/admin/js/module/database.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
define(['jquery', 'sent', 'form'], function($, sent, form){
|
||||||
|
var database = {
|
||||||
|
export: function(){
|
||||||
|
var $form = $("#export-form"), $export = $("#export"), tables
|
||||||
|
$optimize = $("#optimize"), $repair = $("#repair");
|
||||||
|
|
||||||
|
$optimize.add($repair).click(function(){
|
||||||
|
$.post(this.href, $form.serialize(), function(data){
|
||||||
|
if(data.code){
|
||||||
|
sent.msg(data.msg,'success');
|
||||||
|
} else {
|
||||||
|
sent.msg(data.msg,'error');
|
||||||
|
}
|
||||||
|
setTimeout(function(){
|
||||||
|
$('#top-alert').find('button').click();
|
||||||
|
$(this).removeClass('disabled').prop('disabled',false);
|
||||||
|
},1500);
|
||||||
|
}, "json");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$export.click(function(){
|
||||||
|
$export.parent().children().addClass("disabled");
|
||||||
|
$export.html("正在发送备份请求...");
|
||||||
|
$.post(
|
||||||
|
$form.attr("action"),
|
||||||
|
$form.serialize(),
|
||||||
|
function(data){
|
||||||
|
if(data.code){
|
||||||
|
tables = data.data.tables;
|
||||||
|
$export.html(data.msg + "开始备份,请不要关闭本页面!");
|
||||||
|
backup(data.data.tab);
|
||||||
|
window.onbeforeunload = function(){ return "正在备份数据库,请不要关闭!" }
|
||||||
|
} else {
|
||||||
|
sent.msg(data.msg,'error');
|
||||||
|
$export.parent().children().removeClass("disabled");
|
||||||
|
$export.html("立即备份");
|
||||||
|
setTimeout(function(){
|
||||||
|
$('#top-alert').find('button').click();
|
||||||
|
$(this).removeClass('disabled').prop('disabled',false);
|
||||||
|
},1500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
function backup(tab, status){
|
||||||
|
status && showmsg(tab.id, "开始备份...(0%)");
|
||||||
|
$.get($form.attr("action"), tab, function(data){
|
||||||
|
if(data.code){
|
||||||
|
var info = data.data;
|
||||||
|
showmsg(tab.id, data.msg);
|
||||||
|
|
||||||
|
if(!$.isPlainObject(info.tab)){
|
||||||
|
$export.parent().children().removeClass("disabled");
|
||||||
|
$export.html("备份完成,点击重新备份");
|
||||||
|
window.onbeforeunload = function(){ return null }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
backup(info.tab, tab.id != info.tab.id);
|
||||||
|
} else {
|
||||||
|
updateAlert(data.msg,'alert-error');
|
||||||
|
$export.parent().children().removeClass("disabled");
|
||||||
|
$export.html("立即备份");
|
||||||
|
setTimeout(function(){
|
||||||
|
$('#top-alert').find('button').click();
|
||||||
|
$(that).removeClass('disabled').prop('disabled',false);
|
||||||
|
},1500);
|
||||||
|
}
|
||||||
|
}, "json");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function showmsg(id, msg){
|
||||||
|
$form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
import: function(){
|
||||||
|
$(".db-import").click(function(){
|
||||||
|
var self = this, status = ".";
|
||||||
|
$.get(self.href, success, "json");
|
||||||
|
window.onbeforeunload = function(){ return "正在还原数据库,请不要关闭!" }
|
||||||
|
return false;
|
||||||
|
|
||||||
|
function success(data){
|
||||||
|
if(data.code){
|
||||||
|
if(data.data.gz){
|
||||||
|
data.msg += status;
|
||||||
|
if(status.length === 5){
|
||||||
|
status = ".";
|
||||||
|
} else {
|
||||||
|
status += ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(self).parent().prev().text(data.msg);
|
||||||
|
if(data.data.part){
|
||||||
|
$.get(self.href,
|
||||||
|
{"part" : data.data.part, "start" : data.data.start},
|
||||||
|
success,
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
window.onbeforeunload = function(){ return null; }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sent.msg(data.msg,'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return database;
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user