Files
Web_CRICS_Server_VS2010_Prod/WebSite/Scripts/tools.js
2025-12-11 09:17:16 +08:00

95 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//自定义tools类下各种方法
$.tools = {
//消息提示
alert: function (msg) {
$.messager.show({
title: lang.Prompt,
msg: msg,
showType: 'show'
});
},
//格式化日期
formatDate: function (val, row) {
if (val == null) return null;
return eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd");
},
//格式化日期时间
formatDateTime: function (val, row) {
if (val == null) return null;
return eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd hh:mm:ss");
},
//格式化日期(日期已到期或即将一个月后到期显示红色)
formatDateExpire: function (val, row) {
if (val == null) return null;
var now = new Date();
var nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()).format("yyyy-MM-dd");
var date = eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd");
if (nextMonth > date) {
date = "<font style='color:red'>" + date + "</font>";
}
else {
date = "<font style='color:black'>" + date + "</font>";
}
return date;
},
//noalert是否需要提示默认提示
ajaxRun: function (params, url, callback, scope, type, noalert) {
$.ajax({
type: type,
url: url,
data: params,
success: function (result) {
if (result.IsSuccess) {
if (noalert == true && callback != undefined) {
callback.call(scope, result);
return;
}
var msg = lang.OperationSuccessful;
if (result.Message != undefined && result.result != "") {
msg = result.Message;
}
$.tools.alert(msg);
if (callback != undefined) {
callback.call(scope, result);
}
}
else {
//$.tools.alert(result.Message);
$.messager.alert(lang.Prompt, result.Message, "warning");
}
},
error: function () {
//$.tools.alert(lang.OperationFailed);
$.messager.alert(lang.Prompt, lang.OperationFailed, "warning");
}
});
},
//ajax post方式
post: function (params, url, callback, scope, noalert) {
this.ajaxRun(params, url, callback, scope, "POST", noalert)
},
//删除ajax post
delPost: function (params, url, callback, scope) {
this.confrimPost(lang.AYSYWTDTSD, params, url, callback, scope);
},
//确认提示ajax post
confrimPost: function (msg, params, url, callback, scope) {
$.messager.confirm(lang.Prompt, msg, function (r) {
if (r) {
$.tools.post(params, url, callback, scope);
}
});
},
ajaxLoading: function (msg) {
$("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
$("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo("body").css({ display: "block", fontSize: "12px", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
},
ajaxLoadEnd: function () {
$(".datagrid-mask").remove();
$(".datagrid-mask-msg").remove();
},
//单格式上鼠标停留显示完整内容
formatCellTooltip: function (val) {
return "<span title='" + val + "'>" + val + "</span>";
}
}