/** 日期格式化 */Date.prototype.Format = function(format) { var o = { "M+" : this.getMonth() + 1, // month "d+" : this.getDate(), // day "H+" : this.getHou ...
/** 日期格式化 */
Date.prototype.Format = function(format) {
var o = {
"M+" : this.getMonth() + 1, // month
"d+" : this.getDate(), // day
"H+" : this.getHours(), // hour
"m+" : this.getMinutes(), // minute
"s+" : this.getSeconds(), // second
"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
"S" : this.getMilliseconds()
// millisecond
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
}
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;
};
/** 數字格式化 */
function numberFormat(s, n) {
n = n > 0 && n <= 20 ? n : 2;
var m = parseFloat(s + "") < 0 ? "-" : "";
s = parseFloat((Math.abs(s) + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return m + t.split("").reverse().join("") + "." + r;
}
/** 獲取當前周的起止日期 */
Date.prototype.getCurrentWeek = function(date) {
var today;
if (null == date || undefined == date || date == "") {
today = this;
} else {
today = date;
}
var week = today.getDay();
if (week == 0) {
week = 7
}
var startDate = new Date(today.valueOf() - (week - 1) * 24 * 60 * 60 * 1000);
var endDate = new Date(startDate.valueOf() + 6 * 24 * 60 * 60 * 1000);
var resultObj = new Object();
resultObj['startDate'] = startDate.Format("yyyy-MM-dd");
resultObj['endDate'] = endDate.Format("yyyy-MM-dd");
return resultObj;
};
/** 獲取當前月的起止日期 */
Date.prototype.getCurrentMonth = function(date) {
var today;
if (null == date || undefined == date || date == "") {
today = this;
} else {
today = date;
}
var year = today.getFullYear();
var month = today.getMonth();
var firstDay = new Date(year, month, 1);
if (month == 11) {
month = 0;
year++;
} else {
month++;
}
var nextDay = new Date(year, month, 1);
var resultObj = new Object();
resultObj['startDate'] = firstDay.Format("yyyy-MM-dd");
resultObj['endDate'] = new Date(nextDay.valueOf() - 24 * 60 * 60 * 1000)
.Format("yyyy-MM-dd");
return resultObj;
};
/**減一天標準格式(yyyy-MM-dd) */
function reduceOneDay(date) {
var dateTime = new Date(Date.parse(date.replace(/-/g, "/")));
var result = new Date(dateTime.getTime() - 24*60*60*1000);
return result.Format("yyyy-MM-dd");
}
/** 通過時間返回中文星期 */
function getChineseWeek(date) {
var d = new Date(date.replace(/-/g, "/"));
var week = d.getDay();
var str;
if (week == 0) {
str = "日";
} else if (week == 1) {
str = "一";
} else if (week == 2) {
str = "二";
} else if (week == 3) {
str = "三";
} else if (week == 4) {
str = "四";
} else if (week == 5) {
str = "五";
} else if (week == 6) {
str = "六";
}
return "星期" + str;
}
/**
* 將對象轉成get請求參數形式
* 如?param1=value1¶m2=value2
*/
function changeParamToStr(param) {
var result = "";
if (param) {
for ( var i in param) {
result += "&" + i + "=" + param[i];
}
}
if (result != "") {
result = "?" + result.substring(1);
}
return result;
}
/**處理等待遮罩層*/
function onLoading(selector, msg) {
var offset = $(selector).offset();
var dialog = $("<div class='diy-msk'></div>").dialog({
modal : true
});
$(dialog).parent().css("display", "none");
$(dialog).parent().next().css("display", "none");
$("<div class='datagrid-mask-msg'></div>").html(!msg ? "正在處理中,請稍候..." : msg)
.appendTo(selector).css({
display : "block",
left : ($(document.body).outerWidth(true) - 190) / 2,
top : offset.top + ($(selector).height() - 45) / 2
});
}
/**移除等待遮罩層*/
function removeLoad(selector) {
$(selector + " .panel window").remove();
$(selector + " .window-shadow").remove();
$(selector + " .window-mask").remove();
$(selector + " .datagrid-mask-msg").remove();
}
/**創建上傳視窗 公共方法,chunk 是否分割大文件,callBack 上傳成功之後的回調*/
function Uploader(root, param,callBack){
var addWin = $("<div style='overflow: hidden;'/>");
var upladoer = $("<iframe/>");
upladoer.attr({"src":root+"/plupload/uploader.jsp"+changeParamToStr(param),
width:"100%",height:"100%",frameborder:"0",scrolling:"no"});
addWin.window({
title:"上傳文件",
height:350,
width:550,
minimizable:false,
modal:true,
collapsible:false,
maximizable:false,
resizable:false,
content:upladoer,
onClose:function(){
var fw = GetFrameWindow(upladoer[0]);
var files = fw.files;
$(this).window("destroy");
callBack.call(this,files);
},
onOpen:function(){
var target = $(this);
setTimeout(function(){
var fw = GetFrameWindow(upladoer[0]);
fw.target = target;
},100);
}
});
}
/**根據iframe對象獲取iframe的window對象*/
function GetFrameWindow(frame){
return frame && typeof(frame)=="object" && frame.tagName == "IFRAME" && frame.contentWindow;
}
/**到年日期格式*/
function yearFormatter(date) {
return date.Format("yyyy");
}
/**到年解析日期*/
function yearParser(date) {
if(date != "") {
date += "-01-01";
return new Date(Date.parse(date.replace(/-/g, "/")));
} else {
return new Date();
}
}
/**到月日期格式*/
function monthFormatter(date) {
return date.Format("yyyy-MM");
}
/**到月解析日期*/
function monthParser(date) {
if(date != "") {
date += "-01";
return new Date(Date.parse(date.replace(/-/g, "/")));
} else {
return new Date();
}
}
/**處理datagrid合併*/
function sks_handleMerge(id, obj) {
for(var i in obj) {
var arr = obj[i];
if(null != arr && arr.length > 0) {
for(var j in arr) {
$(id).datagrid("mergeCells", {
index : arr[j].index,
type : "footer",
field : i,
rowspan : arr[j].rowspan,
colspan : 0
});
}
}
}
}