2014-06-12 21:36:05 +08:00
|
|
|
|
define(function (require, exports) {
|
|
|
|
|
|
|
|
|
|
exports.getError = function (data) {
|
|
|
|
|
/// <summary>获得指定返回数据中的错误信息</summary>
|
|
|
|
|
|
|
|
|
|
if (data.messages && data.messages instanceof Array) {
|
|
|
|
|
return { message: data.messages.join(";") };
|
|
|
|
|
}
|
|
|
|
|
if (data.data && data.data.isRelogin) {
|
|
|
|
|
return { message: "登录状态异常,请重新登录。", relogin: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { message: "未知错误信息" };
|
|
|
|
|
};
|
2014-06-20 20:55:14 +08:00
|
|
|
|
exports.formatDate = function (date, format) {
|
|
|
|
|
/// <summary>格式化指定日期</summary>
|
|
|
|
|
/// <param name="format" type="String">格式化字符串</param>
|
|
|
|
|
format = format || "yyyy-MM-dd";
|
|
|
|
|
var o = {
|
|
|
|
|
"M+": date.getMonth() + 1, //month
|
|
|
|
|
"d+": date.getDate(), //day
|
|
|
|
|
"h+": date.getHours(), //hour
|
|
|
|
|
"m+": date.getMinutes(), //minute
|
|
|
|
|
"s+": date.getSeconds(), //second
|
|
|
|
|
"q+": Math.floor((date.getMonth() + 3) / 3), //quarter
|
|
|
|
|
"S": date.getMilliseconds() //millisecond
|
|
|
|
|
};
|
2014-06-12 21:36:05 +08:00
|
|
|
|
|
2014-06-20 20:55:14 +08:00
|
|
|
|
if (/(y+)/i.test(format)) {
|
|
|
|
|
format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
|
|
|
}
|
2014-06-12 21:36:05 +08:00
|
|
|
|
|
2014-06-20 20:55:14 +08:00
|
|
|
|
for (var k in o) {
|
|
|
|
|
if (new RegExp("(" + k + ")").test(format)) {
|
|
|
|
|
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return format;
|
|
|
|
|
};
|
2014-06-12 21:36:05 +08:00
|
|
|
|
});
|