mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-05-24 05:55:22 +08:00
added 完善POST提交的动态刷新支持
This commit is contained in:
parent
b0a07f87fe
commit
ca80b59829
@ -47,7 +47,7 @@ class Menu extends Base {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'href' => url('Menu/del'),
|
'href' => url('Menu/del'),
|
||||||
'class'=> 'btn-danger',
|
'class'=> 'btn-danger ajax-delete',
|
||||||
'info'=> '删除',
|
'info'=> '删除',
|
||||||
'icon' => 'fa fa-trash',
|
'icon' => 'fa fa-trash',
|
||||||
'confirm' => 1,
|
'confirm' => 1,
|
||||||
@ -66,7 +66,7 @@ class Menu extends Base {
|
|||||||
[
|
[
|
||||||
'info' => '删除',
|
'info' => '删除',
|
||||||
'href' => url('Menu/del'),
|
'href' => url('Menu/del'),
|
||||||
'class'=> 'btn-danger',
|
'class'=> 'btn-danger ajax-delete',
|
||||||
'param'=> [$this->primaryKey],
|
'param'=> [$this->primaryKey],
|
||||||
'icon' => 'fa fa-trash',
|
'icon' => 'fa fa-trash',
|
||||||
'confirm' => 1,
|
'confirm' => 1,
|
||||||
@ -239,7 +239,7 @@ class Menu extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function del(){
|
public function del(){
|
||||||
|
$this->error('失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<button type="submit" target-form="form-login" class="btn btn-primary ajax-post btn-block btn-flat">登 录</button>
|
<button type="submit" target-form="form-login" class="btn btn-primary ajax-post redirect btn-block btn-flat">登 录</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -28,27 +28,130 @@
|
|||||||
/**
|
/**
|
||||||
* 消息弹框
|
* 消息弹框
|
||||||
* @param msg
|
* @param msg
|
||||||
|
* @param wait 等待时间(毫秒)
|
||||||
*/
|
*/
|
||||||
$.alertMsg = function( msg ){
|
$.alertMsg = function( msg, wait = 2800 ){
|
||||||
var dialog = bootbox.dialog({
|
var dialog = bootbox.dialog({
|
||||||
message: '<p class="text-center">'+msg+'</p>',
|
message: '<p class="text-center">'+msg+'</p>',
|
||||||
closeButton: false
|
closeButton: false
|
||||||
});
|
});
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
dialog.modal('hide');
|
dialog.modal('hide');
|
||||||
}, 3000);
|
}, wait);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajax Post 表单提交
|
* 刷新数据,允许带参数刷新
|
||||||
|
* @param url
|
||||||
|
* @param urlData
|
||||||
|
*/
|
||||||
|
$.refresh = function ( url, urlData = '' ) {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: url,
|
||||||
|
data: urlData,
|
||||||
|
success: function(data){
|
||||||
|
if( data.code == 200 ){
|
||||||
|
if( data.data.tempType == 'table' ){
|
||||||
|
if( $.buildTable ){
|
||||||
|
$('#content').html($.buildTable(data.data));
|
||||||
|
$('#tableBox').hide().fadeIn(800);
|
||||||
|
}else{
|
||||||
|
$.getScript(JS_PATH + '/template/table.js', function (){
|
||||||
|
$('#content').html($.buildTable(data.data));
|
||||||
|
$('#tableBox').hide().fadeIn(800);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( data.data.tempType == 'add' ){
|
||||||
|
if( $.buildAddForm ){
|
||||||
|
$('#content').html($.buildAddForm(data.data));
|
||||||
|
$('#formBox').hide().fadeIn(800);
|
||||||
|
}else{
|
||||||
|
$.getScript(JS_PATH + '/template/form.js', function (){
|
||||||
|
$('#content').html($.buildAddForm(data.data));
|
||||||
|
$('#formBox').hide().fadeIn(800);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( data.data.tempType == 'edit' ){
|
||||||
|
if( $.buildEditForm ){
|
||||||
|
$('#content').html($.buildEditForm(data.data));
|
||||||
|
$('#formBox').hide().fadeIn(800);
|
||||||
|
}else{
|
||||||
|
$.getScript(JS_PATH + '/template/form.js', function (){
|
||||||
|
$('#content').html($.buildEditForm(data.data));
|
||||||
|
$('#formBox').hide().fadeIn(800);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$.alertMsg(data.msg);
|
||||||
|
setTimeout(function() {
|
||||||
|
if (data.url) {
|
||||||
|
location.href = data.url;
|
||||||
|
}
|
||||||
|
}, 1000*data.wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax Post 表单提交(增)
|
||||||
*/
|
*/
|
||||||
bodyDom.on('click', '.ajax-post', function() {
|
bodyDom.on('click', '.ajax-post', function() {
|
||||||
|
var message,query,form,target;
|
||||||
|
var target_form = $(this).attr('target-form');
|
||||||
|
var isRedirect = $(this).hasClass('redirect');
|
||||||
|
form = $('#' + target_form);
|
||||||
|
query = form.serialize();
|
||||||
|
target = form.attr('action');
|
||||||
|
$.post(target, query).success(function(data) {
|
||||||
|
var wait = 1000*data.wait;
|
||||||
|
if (data.code == 1) {
|
||||||
|
if (data.url) {
|
||||||
|
message = data.msg + ' 页面即将自动跳转...';
|
||||||
|
} else {
|
||||||
|
message = data.msg;
|
||||||
|
}
|
||||||
|
$.alertMsg(message);
|
||||||
|
if( isRedirect ){
|
||||||
|
setTimeout(function() {
|
||||||
|
if (data.url) {
|
||||||
|
location.href = data.url;
|
||||||
|
} else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
}, wait);
|
||||||
|
}else{
|
||||||
|
setTimeout(function() {
|
||||||
|
if (data.url) {
|
||||||
|
$.refresh(data.url);
|
||||||
|
}
|
||||||
|
}, wait);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$.alertMsg(data.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax Put 表单提交(改)
|
||||||
|
*/
|
||||||
|
bodyDom.on('click', '.ajax-put', function() {
|
||||||
var message,query,form,target;
|
var message,query,form,target;
|
||||||
var target_form = $(this).attr('target-form');
|
var target_form = $(this).attr('target-form');
|
||||||
form = $('#' + target_form);
|
form = $('#' + target_form);
|
||||||
query = form.serialize();
|
query = form.serialize();
|
||||||
target = form.attr('action');
|
target = form.attr('action');
|
||||||
$.post(target, query).success(function(data) {
|
$.ajax({
|
||||||
|
type: "PUT",
|
||||||
|
url: target,
|
||||||
|
data: query
|
||||||
|
}).done(function( data ) {
|
||||||
var wait = 1000*data.wait;
|
var wait = 1000*data.wait;
|
||||||
if (data.code == 1) {
|
if (data.code == 1) {
|
||||||
if (data.url) {
|
if (data.url) {
|
||||||
@ -76,60 +179,61 @@
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax Delete 请求(删) *
|
||||||
|
*/
|
||||||
|
bodyDom.on('click', '.ajax-delete', function() {
|
||||||
|
var url = $(this).attr('url'), urlData = '';
|
||||||
|
if( $(this).attr('data') ){
|
||||||
|
urlData = $(this).attr('data');
|
||||||
|
}
|
||||||
|
if( $(this).hasClass('confirm') ){
|
||||||
|
bootbox.confirm({
|
||||||
|
title: "温馨提醒:",
|
||||||
|
message: "您确定要这么做么?",
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
label: '<i class="fa fa-times"></i> 取消'
|
||||||
|
},
|
||||||
|
confirm: {
|
||||||
|
label: '<i class="fa fa-check"></i> 确定'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: function (result) {
|
||||||
|
if( result ){
|
||||||
|
$.ajax({
|
||||||
|
type: "DELETE",
|
||||||
|
url: url,
|
||||||
|
data: urlData
|
||||||
|
}).done(function( data ) {
|
||||||
|
var wait = 1000*data.wait;
|
||||||
|
if (data.code == 1) {
|
||||||
|
$.alertMsg(data.msg);
|
||||||
|
setTimeout(function() {
|
||||||
|
if (data.url) {
|
||||||
|
$.refresh(data.url);
|
||||||
|
}
|
||||||
|
}, wait);
|
||||||
|
} else {
|
||||||
|
$.alertMsg(data.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax 刷新页面 *
|
||||||
|
*/
|
||||||
bodyDom.on('click', '.refresh', function() {
|
bodyDom.on('click', '.refresh', function() {
|
||||||
var url = $(this).attr('url'), urlData = '';
|
var url = $(this).attr('url'), urlData = '';
|
||||||
if( $(this).attr('data') ){
|
if( $(this).attr('data') ){
|
||||||
urlData = $(this).attr('data');
|
urlData = $(this).attr('data');
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.refresh(url, urlData);
|
||||||
type: "GET",
|
|
||||||
url: url,
|
|
||||||
data: urlData,
|
|
||||||
success: function(data){
|
|
||||||
if( data.code == 200 ){
|
|
||||||
if( data.data.tempType == 'table' ){
|
|
||||||
if( $.buildTable ){
|
|
||||||
$('#content').html($.buildTable(data.data));
|
|
||||||
$('#tableBox').hide().fadeIn(800);
|
|
||||||
}else{
|
|
||||||
$.getScript(JS_PATH + '/template/table.js', function (){
|
|
||||||
$('#content').html($.buildTable(data.data));
|
|
||||||
$('#tableBox').hide().fadeIn(800);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( data.data.tempType == 'add' ){
|
|
||||||
// if( $.buildAddForm ){
|
|
||||||
// $('#content').html($.buildAddForm(data.data));
|
|
||||||
// $('#formBox').hide().fadeIn(800);
|
|
||||||
// }else{
|
|
||||||
$.getScript(JS_PATH + '/template/form.js', function (){
|
|
||||||
$('#content').html($.buildAddForm(data.data));
|
|
||||||
$('#formBox').hide().fadeIn(800);
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
if( data.data.tempType == 'edit' ){
|
|
||||||
if( $.buildEditForm ){
|
|
||||||
$('#content').html($.buildEditForm(data.data));
|
|
||||||
$('#formBox').hide().fadeIn(800);
|
|
||||||
}else{
|
|
||||||
$.getScript(JS_PATH + '/template/form.js', function (){
|
|
||||||
$('#content').html($.buildEditForm(data.data));
|
|
||||||
$('#formBox').hide().fadeIn(800);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$.alertMsg(data.msg);
|
|
||||||
setTimeout(function() {
|
|
||||||
if (data.url) {
|
|
||||||
location.href = data.url;
|
|
||||||
}
|
|
||||||
}, 1000*data.wait);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user