弹框组件统一替换为layer;

v1.7
xueli.xue 8 years ago
parent aeb1df7ea3
commit 3357529dd0

@ -49,7 +49,6 @@
<script src="${request.contextPath}/static/plugins/layer/layer.js"></script>
<#-- common -->
<script src="${request.contextPath}/static/js/xxl.alert.1.js"></script>
<script src="${request.contextPath}/static/js/common.1.js"></script>
<script>var base_url = '${request.contextPath}';</script>

@ -2,17 +2,29 @@ $(function(){
// logout
$("#logoutBtn").click(function(){
ComConfirm.show("确认注销登录?", function(){
layer.confirm('?', {icon: 3, title:''}, function(index){
layer.close(index);
$.post(base_url + "/logout", function(data, status) {
if (data.code == "200") {
ComAlert.show(1, "注销成功", function(){
window.location.href = base_url + "/";
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
window.location.href = base_url + "/";
}
});
} else {
ComAlert.show(1, data.msg);
layer.open({
title: '',
content: (data.msg || "操作失败"),
icon: '2'
});
}
});
});
});
// slideToTop

@ -18,7 +18,11 @@ $(function () {
lineChartInit(data)
pieChartInit(data);
} else {
ComAlert.show(2, data.msg || '' );
layer.open({
title: '',
content: (data.msg || ''),
icon: '2'
});
}
}
});

@ -49,15 +49,22 @@ $(function() {
var glueRemark = $("#glueRemark").val();
if (!glueRemark) {
ComAlert.show(2, "请输入备注");
layer.open({
title: '',
content: '',
icon: '2'
});
return;
}
if (glueRemark.length <4 || glueRemark.length > 100) {
ComAlert.show(2, "备注长度应该在4至100之间");
layer.open({
title: '',
content: '4100',
icon: '2'
});
return;
}
$.ajax({
type : 'POST',
url : base_url + '/jobcode/save',
@ -69,12 +76,21 @@ $(function() {
dataType : "json",
success : function(data){
if (data.code == 200) {
ComAlert.show(1, '', function(){
//$(window).unbind('beforeunload');
window.location.reload();
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
//$(window).unbind('beforeunload');
window.location.reload();
}
});
} else {
ComAlert.show(2, data.msg);
layer.open({
title: '',
content: (data.msg || "保存失败"),
icon: '2'
});
}
}
});

@ -4,7 +4,9 @@ $(function() {
$('.remove').on('click', function(){
var id = $(this).attr('id');
ComConfirm.show("确认删除分组?", function(){
layer.confirm('?', {icon: 3, title:''}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : base_url + '/jobgroup/remove',
@ -12,18 +14,25 @@ $(function() {
dataType : "json",
success : function(data){
if (data.code == 200) {
ComAlert.show(1, '');
window.location.reload();
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
window.location.reload();
}
});
} else {
if (data.msg) {
ComAlert.show(2, data.msg);
} else {
ComAlert.show(2, '');
}
layer.open({
title: '',
content: (data.msg || "删除失败"),
icon: '2'
});
}
},
});
});
});
// jquery.validate 自定义校验 “英文字母开头,只含有英文字母、数字和下划线”
@ -86,17 +95,20 @@ $(function() {
$.post(base_url + "/jobgroup/save", $("#addModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
setTimeout(function () {
ComAlert.show(1, "新增成功", function(){
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
window.location.reload();
});
}, 315);
}
});
} else {
if (data.msg) {
ComAlert.show(2, data.msg);
} else {
ComAlert.show(2, "新增失败");
}
layer.open({
title: '',
content: (data.msg || "新增失败"),
icon: '2'
});
}
});
}
@ -186,17 +198,21 @@ $(function() {
$.post(base_url + "/jobgroup/update", $("#updateModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
setTimeout(function () {
ComAlert.show(1, "更新成功", function(){
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
window.location.reload();
});
}, 315);
}
});
} else {
if (data.msg) {
ComAlert.show(2, data.msg);
} else {
ComAlert.show(2, "更新失败");
}
layer.open({
title: '',
content: (data.msg || "更新失败"),
icon: '2'
});
}
});
}

@ -202,7 +202,9 @@ $(function() {
var id = $(this).parent('p').attr("id");
ComConfirm.show("确认" + typeName + "?", function(){
layer.confirm('' + typeName + '?', {icon: 3, title:''}, function(index){
layer.close(index);
$.ajax({
type : 'POST',
url : url,
@ -212,14 +214,24 @@ $(function() {
dataType : "json",
success : function(data){
if (data.code == 200) {
ComAlert.show(1, typeName + "成功", function(){
if (needFresh) {
//window.location.reload();
jobTable.fnDraw();
layer.open({
title: '',
content: typeName + "成功",
icon: '1',
end: function(layero, index){
if (needFresh) {
//window.location.reload();
jobTable.fnDraw();
}
}
});
} else {
ComAlert.show(1, typeName + "失败");
layer.open({
title: '',
content: (data.msg || typeName + "失败"),
icon: '2'
});
}
},
});
@ -278,18 +290,21 @@ $(function() {
$.post(base_url + "/jobinfo/add", $("#addModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#addModal').modal('hide');
setTimeout(function () {
ComAlert.show(1, "新增任务成功", function(){
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
jobTable.fnDraw();
//window.location.reload();
});
}, 315);
}
});
} else {
if (data.msg) {
ComAlert.show(2, data.msg);
} else {
ComAlert.show(2, "新增失败");
}
layer.open({
title: '',
content: (data.msg || "新增失败"),
icon: '2'
});
}
});
}
@ -394,18 +409,21 @@ $(function() {
$.post(base_url + "/jobinfo/reschedule", $("#updateModal .form").serialize(), function(data, status) {
if (data.code == "200") {
$('#updateModal').modal('hide');
setTimeout(function () {
ComAlert.show(1, "更新成功", function(){
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
//window.location.reload();
jobTable.fnDraw();
});
}, 315);
}
});
} else {
if (data.msg) {
ComAlert.show(2, data.msg);
} else {
ComAlert.show(2, "更新失败");
}
layer.open({
title: '',
content: (data.msg || "更新失败"),
icon: '2'
});
}
});
}

@ -48,11 +48,20 @@ $(function(){
submitHandler : function(form) {
$.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
if (data.code == "200") {
ComAlert.show(1, "登录成功", function(){
window.location.href = base_url;
});
layer.open({
title: '',
content: '',
icon: '1',
end: function(layero, index){
window.location.href = base_url;
}
});
} else {
ComAlert.show(2, data.msg);
layer.open({
title: '',
content: (data.msg || "登录失败"),
icon: '2'
});
}
});
}

@ -1,98 +0,0 @@
/**
* Created by xuxueli on 16/8/12.
*
* dependency, jquery + bootstrap
*/
// 通用提示
var ComAlert = {
html:function(){
var html =
'<div class="modal fade" id="ComAlert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header hidden"><h4 class="modal-title"><strong>:</strong></h4></div>' +
'<div class="modal-body"><div class="alert alert-success"></div></div>' +
'<div class="modal-footer">' +
'<div class="text-center" >' +
'<button type="button" class="btn btn-default ok" data-dismiss="modal" ></button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
return html;
},
show:function(type, msg, callback){
// dom init
if ($('#ComAlert').length == 0){
$('body').append(ComAlert.html());
}
// 弹框初始
if (type == 1) {
$('#ComAlert .alert').attr('class', 'alert alert-success');
} else {
$('#ComAlert .alert').attr('class', 'alert alert-warning');
}
$('#ComAlert .alert').html(msg);
$('#ComAlert').modal('show');
$('#ComAlert .ok').click(function(){
$('#ComAlert').modal('hide');
if(typeof callback == 'function') {
callback();
}
});
// $("#ComAlert").on('hide.bs.modal', function () { }); // 监听关闭
}
};
// 通用确认弹框
var ComConfirm = {
html:function(){
var html =
'<div class="modal fade" id="ComConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-body"><div class="alert alert-success"></div></div>' +
'<div class="modal-footer">' +
'<div class="text-center" >' +
'<button type="button" class="btn btn-primary ok" data-dismiss="modal" ></button>' +
'<button type="button" class="btn btn-default cancel" data-dismiss="modal" ></button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
return html;
},
show:function(msg, callback){
// dom init
if ($('#ComConfirm').length == 0){
$("body").append(ComConfirm.html());
}
// 弹框初始
$('#ComConfirm .alert').attr('class', 'alert alert-warning');
$('#ComConfirm .alert').html(msg);
$('#ComConfirm').modal('show');
$('#ComConfirm .ok').unbind("click"); // 解绑陈旧事件
$('#ComConfirm .ok').click(function(){
$('#ComConfirm').modal('hide');
if(typeof callback == 'function') {
setTimeout(function(){
callback();
return;
}, 315);
}
});
$('#ComConfirm .cancel').click(function(){
$('#ComConfirm').modal('hide');
return;
});
}
};
Loading…
Cancel
Save