This commit is contained in:
arraykeys
2019-08-08 17:13:34 +08:00
parent e8e5966a8c
commit f0bf2d5fec
2885 changed files with 1195993 additions and 12 deletions
+230
View File
@@ -0,0 +1,230 @@
/**
* 公共类
* Copyright (c) 2016 [email protected]
*/
var Common = {
/**
* 是否在弹出层
*/
inPopup: false,
/**
* 分页
* @param element
* @param pagedata
*/
paginator: function(element, pagedata) {
if (window["context"] == undefined) {
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
window["context"] = location.origin+"/V6.0";
}
var url = window.location.pathname;
var host = window.location.origin;
$(element).pagination({
pageSize: pagedata[0].pageSize,
pageIndex : pagedata[0].pageIndex,
total: pagedata[0].total,
firstBtnText:'首页',
lastBtnText:'末页',
showFirstLastBtn:true,
showInfo: true,
showJump: true,
jumpBtnText:'跳转',
infoFormat: '{start} ~ {end}条,共{total}条',
noInfoText: '0 条数据',
});
$(element).on("pageClicked", function (event, data) {
getRequest(data.pageIndex);
}).on("jumpClicked", function (event, data) {
getRequest(data.pageIndex);
});
//get请求
function getRequest(index) {
var urlQuerys = pagedata[0].urlQuery;
var trueUrl = host + url + "?";
for (key in urlQuerys) {
trueUrl = trueUrl + "&"+key+"="+urlQuerys[key]+"&";
}
trueUrl = trueUrl + "page_index=" + index +"&page_size=" + pagedata[0].pageSize;
window.location.href = trueUrl;
}
},
/**
* 提示
* @param text
* @param url
* @param data
* @param inPopup
*/
confirm: function(text, url, data, inPopup) {
if(inPopup) {
Common.inPopup = true;
}
swal({
title: text,
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonColor: "#D8534F",
confirmButtonText: "是",
cancelButtonText: "否",
closeOnConfirm: false
},
function() {
Common.submit(url, data, 'reload');
});
},
/**
* ajax 提交
* @param url
* @param data
* @param location
* @param redirect
*/
submit : function(url, data, location, redirect) {
$.ajax({
type : 'post',
url : url,
data : {'arr':data},
dataType: "json",
success : function(response) {
if(response.code == 0) {
swal({
title: "操作失败",
text: response.message,
type: "error"
});
} else {
swal({
title: "操作成功",
text: response.message,
type: "success",
showConfirmButton: false,
timer: 2000
});
}
Common.redirect(response.redirect);
},
error : function(response) {
swal({
title: "操作失败",
text: response.message,
type: "error"
});
}
});
},
/**
* 跳转
* @param redirect
* @param inPopup
*/
redirect: function (redirect, inPopup) {
if(inPopup != undefined) {
Common.inPopup = inPopup;
}
//如果设置了跳转
if(redirect) {
setTimeout(function() {
if(Common.inPopup) {
parent.location.href = redirect;
} else {
location.href = redirect;
}
}, 2000);
//重新刷新
setTimeout(function() {
if(Common.inPopup) {
parent.location.reload();
} else {
location.reload();
}
}, 2000);
}
},
/**
* 成功弹出框
* @param text
* @return json
*/
successAlert: function (text) {
swal({
title: '操作成功',
text: text,
type: "success",
showConfirmButton: false,
timer: 2000
});
},
/**
* 失败弹出框
* @param text
* @return json
*/
errorAlert: function (text) {
swal({
title: '操作失败',
text: text,
type: "error",
showConfirmButton: true,
timer: 2000
});
},
/**
* 警告弹出框
* @param text
* @return json
*/
warningAlert: function (text) {
swal({
title: '警告',
text: text,
type: "warning",
showConfirmButton: true,
timer: 2000
});
},
/**
* 删除弹出框
*/
confirmAlert: function (text) {
var isConfirm = true;
swal({
title: "警告",
text: text,
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonColor: "#DD6B55",
confirmButtonText: "YES",
cancelButtonText: "NO",
closeOnConfirm: false,
},
function() {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}
};
+100
View File
@@ -0,0 +1,100 @@
/**
* 表单提交类
* Copyright (c) 2017 [email protected]
*/
var Form = {
inPopup : false,
/**
* ajax 提交表单
* @param element
* @param inPopup
* @returns {boolean}
*/
ajaxSubmit: function (element, inPopup) {
var submitButton = $("button[name='submit']");
if(inPopup) {
Form.inPopup = true;
}
function successAlert(messages, data) {
// var text = messages.join("\n");
var text = messages;
var timer = 2000;
swal({
'title' : '操作成功',
'text' : "<h4>"+text+"</h4>",
'html' : true,
'type' : 'success',
'showConfirmButton' : false,
'timer' : timer,
'location' : null
});
}
function successNotify(messages, data) {
// var text = messages.join("\n");
var title = '<strong>操作成功:</strong>';
var text = messages;
var timer = 2000;
submitButton.notify(title + text, {
position: "right",
className: 'success'
})
}
//错误弹出信息
function failedAlert(errors, data) {
var text = errors.join("\n");
var timer = 2000;
swal({
'title' : '操作失败',
'text' : "<h4>"+text+"</h4>",
'html' : true,
'type' : 'error',
'showConfirmButton' : true
// 'timer' : timer
});
}
function failedNotify(error, data) {
var title = "<strong>操作失败:</strong>";
submitButton.notify(title + error, {
position: "right",
className: 'error'
})
}
//弹出信息
function response(result) {
if(result.code == 0) {
failedNotify(result.message, result.data);
}
if(result.code == 1) {
successNotify(result.message, result.data);
}
//如果设置了跳转
if(result.redirect.url) {
setTimeout(function() {
if(Form.inPopup) {
parent.location.href = result.redirect.url;
} else {
location.href = result.redirect.url;
}
}, result.redirect.sleep);
}
}
var options = {
dataType: 'json',
success: response
};
$(element).ajaxSubmit(options);
return false;
}
};