锘縱ar whir = window.whir || {}; var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var week = day * 7; var month = day * 30; whir.ajax = { get: function (url, data, callback) { $.get(url, data, function (result) { callback(result); }); }, getXML: function (url, data, callback) { $.get(url, data, function (result) { callback(result); }); }, htmlEncode: function (text) { var value = text; try { value = value.replace(/ /g, " "); value = value.replace(/&/, "&"); value = value.replace(//g, ">"); value = value.replace(/'/g, "'"); value = value.replace(/"/g, """); } catch (e) { var span = $(''); span.html(value); value = span.html(); value = value.replace(/&/, "&"); value = value.replace(//g, ">"); value = value.replace(/'/g, "'"); value = value.replace(/"/g, """); } return value; }, post: function (url, params) { var defaultParms = { url: url, data: { }, dataType: 'json', type: 'POST', success: function (response) { } }; var settings = $.extend(defaultParms, params); settings.data['__RequestVerificationToken'] = $('[name="__RequestVerificationToken"]').val() || ''; whir.loading.show(); $.ajax(settings); }, fixJsonDate: function (jsonDate, format) {// 鍙戠幇瀹炰綋杞崲鐨勬棩鏈熶細澶氫簡8涓皬鏃讹紝浣跨敤璇ユ柟娉曚細淇杩?涓皬鏃 if (!jsonDate) { return ""; } jsonDate = jsonDate.replace("鏄熸湡涓€", "").replace("鏄熸湡浜?, "").replace("鏄熸湡涓?, "").replace("鏄熸湡鍥?, "").replace("鏄熸湡浜?, "").replace("鏄熸湡鍏?, "").replace("鏄熸湡鏃?, ""); var date = null; if (jsonDate.toLowerCase().lastIndexOf("/date(")>=0) { if (jsonDate) { var strDate = jsonDate.toLowerCase().replace("/date(", "").replace(")/", ""); try { date = new Date(parseInt(strDate) - (8 * 3600 * 1000)); } catch (ex) { } } } else { if (jsonDate.lastIndexOf("-") >= 0) jsonDate = jsonDate.replace(/-/g, "/"); //涓轰簡鍏煎鑻规灉娴忚鍣ㄥ彧鏀寔/ date = new Date(jsonDate); } if (!date) { return ""; } date = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate(), hour: date.getHours(), minutes: date.getMinutes(),seconds:date.getSeconds() }; switch (format) { case '-': return date.year + '-' + fixTime(date.month) + '-' + fixTime(date.day); case '.': return date.year + '.' + fixTime(date.month) + '.' + fixTime(date.day); case '..': return date.year + fixTime(date.month) + '.' + fixTime(date.day); case 'zh': return date.year + '骞? + fixTime(date.month) + '鏈? + fixTime(date.day) + '鏃?; default: return date.year + '-' + fixTime(date.month) + '-' + fixTime(date.day) + ' ' + fixTime(date.hour) + ':' + fixTime(date.minutes) + ':' + fixTime(date.seconds); } function fixTime(value) { return value.toString().length > 1 ? value : "0" + value; } }, subString: function (data, subLenth) { if (data != "" && data != null) { data = data.replace(/<[^>]+>/g, ""); if (data.length > subLenth) { return data.substring(0, subLenth) + "..."; } } return data; }, getTimer: function (stringTime) { var time1 = new Date().getTime();//褰撳墠鐨勬椂闂存埑 //console.log(time1); var time2 = Date.parse(new Date(stringTime));//鎸囧畾鏃堕棿鐨勬椂闂存埑 //console.log(time2); var time = time1 - time2; var result = null; if (time < 0) { //alert("璁剧疆鐨勬椂闂翠笉鑳芥棭浜庡綋鍓嶆椂闂达紒"); } else if (time / month >= 1) { result = parseInt(time / month) + "鏈堝墠"; } else if (time / week >= 1) { result = parseInt(time / week) + "鍛ㄥ墠"; } else if (time / day >= 1) { result = parseInt(time / day) + "澶╁墠"; } else if (time / hour >= 1) { result = parseInt(time / hour) + "灏忔椂鍓?; } else if (time / minute >= 1) { result = parseInt(time / minute) + "鍒嗛挓鍓?; } else { result = "鍒氬垰"; } return result; } };