锘?.liyou = $.liyou || { version: '1.0' }; var _adminPath = _adminPath || "admin"; var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; $.extend($.liyou, { ajax: function (url, action, params) { var data = []; var base64Data = $.liyou.Base64.encode(JSON.stringify(params.params)); data = { action: action, base64Data: base64Data }; var defaultParms = { type: 'POST', url: url, data: data }; var settings = $.extend(defaultParms, params); $.ajax(settings); }, Base64: { // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = this._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { if (input === undefined || input == "") return ""; var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = _keyStr.indexOf(input.charAt(i++)); enc2 = _keyStr.indexOf(input.charAt(i++)); enc3 = _keyStr.indexOf(input.charAt(i++)); enc4 = _keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 !== 64) { output = output + String.fromCharCode(chr2); } if (enc4 !== 64) { output = output + String.fromCharCode(chr3); } } output = this._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } }, getjsonDate: function (jsonDate, format) { if (!jsonDate) { return ""; } jsonDate = jsonDate.replace("鏄熸湡涓€", "").replace("鏄熸湡浜?, "").replace("鏄熸湡涓?, "").replace("鏄熸湡鍥?, "").replace("鏄熸湡浜?, "").replace("鏄熸湡鍏?, "").replace("鏄熸湡鏃?, "").replace("T", " "); var date = null; if (jsonDate.toLowerCase().lastIndexOf("/date(") >= 0) { if (jsonDate) { var strDate = jsonDate.toLowerCase().replace("/date(", "").replace(")/", ""); try { date = new Date(parseInt(strDate)); } catch (ex) { return ""; } } } 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 + format + getTime(date.month) + format + getTime(date.day) + ' ' + getTime(date.hour) + ':' + getTime(date.minutes); case ' 鈥 ': return date.year + format + getTime(date.month) + format + getTime(date.day); case '-': return date.year + '-' + getTime(date.month) + '-' + getTime(date.day); case 'cn': return date.year + '骞? + getTime(date.month) + '鏈? + getTime(date.day) + '鏃?; default: return date.year + '-' + getTime(date.month) + '-' + getTime(date.day) + ' ' + getTime(date.hour) + ':' + getTime(date.minutes) + ':' + getTime(date.seconds); } function getTime(value) { return value.toString().length > 1 ? value : "0" + value; } }, subString: function (data, subLenth, subStr) { if (data !== "" && data !== null && data !== undefined) { data = data.replace(/<[^>]+>/g, ""); if (data.length > subLenth) { return data.substring(0, subLenth) + (subStr || "..."); } } return data; }, 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; }, editor: function (el, height) { tinymce.init({ selector: el, language: "zh_CN", height: height | 500, min_height: 500, //鏈€灏忛珮搴 toolbar: true, //宸ュ叿鏍 menubar: true, //鑿滃崟鏍 branding: false, //鍙充笅瑙掓妧鏈敮鎸 inline: false, //寮€鍚唴鑱旀ā寮 elementpath: false, skin: 'oxide', toolbar_sticky: true, visualchars_default_state: true, //鏄剧ず涓嶅彲瑙佸瓧绗 image_caption: true, paste_data_images: true, relative_urls: false, toolbar_mode: 'wrap', fontsize_formats: '8px 9px 10px 11px 12px 14px 16px 18px 24px 36px 48px 56px 72px', font_formats: '鎬濇簮榛戜綋=Source Han Sans;寰蒋闆呴粦=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;鑻规灉鑻规柟=PingFang SC,Microsoft YaHei,sans-serif;瀹嬩綋=simsun,serif;浠垮畫浣掿FangSong,serif;榛戜綋=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua;浠垮畫="浠垮畫";妤蜂綋="妤蜂綋";', images_upload_url: _adminPath + '/API/AdminUpload?isEditor=1&uploadType=0', plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template advcode codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount imagetools textpattern help emoticons autosave bdmap indent2em autoresize formatpainter axupimgs axupfiles code', toolbar: 'code undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent indent2em| \ styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \ table image media charmap emoticons hr pagebreak insertdatetime print preview axupimgs axupfiles | fullscreen | bdmap indent2em lineheight formatpainter importword', //plugins: [ // "advlist autolink lists link image charmap print preview hr anchor pagebreak imagetools axupimgs axupfiles", // "searchreplace visualblocks visualchars code fullpage", // "insertdatetime media nonbreaking save table directionality", // "emoticons paste textpattern imagetools codesample " //], //toolbar1: // " undo redo |fontselect fontsizeselect forecolor backcolor bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent removeformat |emoticons link image media axupimgs axupfiles |code print preview", file_picker_callback: function (callback, value, meta) { //鏂囦欢鍒嗙被 var filetype = ''; //鍚庣鎺ユ敹涓婁紶鏂囦欢鐨勫湴鍧€ var upurl = ''; //涓轰笉鍚屾彃浠舵寚瀹氭枃浠剁被鍨嬪強鍚庣鍦板潃 switch (meta.filetype) { case 'image': filetype = '.jpg, .jpeg, .png, .gif'; upurl = _adminPath + '/API/AdminUpload?isEditor=1&uploadType=0'; break; case 'file': var filetype = '.pdf, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4'; upurl = _adminPath + '/API/AdminUpload?isEditor=1&uploadType=1'; break; case 'media': filetype = '.mp3, .mp4'; upurl = _adminPath + '/API/AdminUpload?isEditor=1&uploadType=2'; break; } //妯℃嫙鍑轰竴涓猧nput鐢ㄤ簬娣诲姞鏈湴鏂囦欢 var input = document.createElement('input'); input.setAttribute('type', 'file'); input.setAttribute('accept', filetype); input.click(); input.onchange = function () { var file = this.files[0]; var xhr, formData; console.log(file.name); xhr = new XMLHttpRequest(); xhr.withCredentials = false; xhr.open('POST', upurl); xhr.onload = function () { var json; if (xhr.status != 200) { layer.msg('HTTP Error: ' + xhr.status); return; } json = JSON.parse(xhr.responseText); if (!json || typeof json.location != 'string') { layer.msg('Invalid JSON: ' + xhr.responseText); return; } callback(json.location); }; formData = new FormData(); formData.append('file', file, file.name); xhr.send(formData); }; }, images_upload_handler: function (blobInfo, succFun, failFun) { var xhr, formData; var file = blobInfo.blob();//杞寲涓烘槗浜庣悊瑙g殑file瀵硅薄 xhr = new XMLHttpRequest(); xhr.withCredentials = false; xhr.open('POST', _adminPath + '/API/AdminUpload?isEditor=1&uploadType=0'); xhr.onload = function () { var json; if (xhr.status != 200) { failFun('HTTP Error: ' + xhr.status); return; } json = JSON.parse(xhr.responseText); if (!json || typeof json.location != 'string') { failFun('涓婁紶澶辫触: ' + json.msg); return; } succFun(json.location); }; formData = new FormData(); formData.append('file', file, file.name); xhr.send(formData); }, files_upload_handler: function (blobInfo, succFun, failFun) { var xhr, formData; var file = blobInfo.blob();//杞寲涓烘槗浜庣悊瑙g殑file瀵硅薄 xhr = new XMLHttpRequest(); xhr.withCredentials = false; xhr.open('POST', _adminPath + '/API/AdminUpload?isEditor=1&uploadType=1'); xhr.onload = function () { var json; if (xhr.status != 200) { failFun('HTTP Error: ' + xhr.status); return; } json = JSON.parse(xhr.responseText); if (!json || typeof json.location != 'string') { failFun('涓婁紶澶辫触: ' + json.msg); return; } succFun(json.location); }; formData = new FormData(); formData.append('file', file, file.name); xhr.send(formData); } }); }, randomNum: function (minNum, maxNum) { minNum = (minNum == undefined ? 0 : minNum); maxNum = (maxNum == undefined ? 2147483647 : maxNum); return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10); }, setImage: function (src) { var html = ''; var num = this.randomNum(); if (src == null || src == undefined) { src = "" } if (src.indexOf('*') > -1) { html += ''; var imgList = src.split('*'); for (var i = 0; i < imgList.length; i++) { html += ''; } html += ""; } else html = ''; return html; }, openImage: function (img) { layer.photos({ photos: "#"+img , anim: 5 //0-6鐨勯€夋嫨锛屾寚瀹氬脊鍑哄浘鐗囧姩鐢荤被鍨 }); }, setFile: function (src) { var html = ''; if (src.indexOf('*') > -1) { var imgList = src.split('*'); for (var i = 0; i < imgList.length; i++) { html += '涓嬭浇鏂囦欢' + i + 1 + '; '; } } else html = '涓嬭浇鏂囦欢 '; return html; }, setOption: function (option, options) { try { option = JSON.parse(option); } catch { var temp = []; temp.push(option); option = temp; } options = JSON.parse(options); if (option === null || option=="" || option.length == 0 || options.length == 0) return ""; try { option = option.map(function (p) { return options.filter(function (m) { return m.value == p })[0]; }); } catch { option = options.filter(function (m) { return m.value == option }); } var titles = option.map(function (m) { return m.title }).join(";"); var html = '' + titles + ""; return html; }, getArea: function (data, el, id) { var areaList = []; if (data == null || data == "") return ""; if (areaList.length == 0) { $.get("/Res/ChinaArea.json", function (res) { areaList = res; if (areaList.length == 0) { return ""; } else { var provinceId = data.split("|")[0] || 0; var province = areaList[86][provinceId]; var cityId = data.split("|")[1] || 0; var city = areaList[provinceId][cityId]; var areaId = data.split("|")[2] || 0; var area = areaList[cityId][areaId]; var html = (province || '') + (city || '') + (area || ''); $("#area-" + el + "-" + id).html(html); } }); } }, getDateDiff: function (dateStr) { var publishTime = Date.parse(dateStr.replace(/-/gi, "/")) / 1000, d_seconds, d_minutes, d_hours, d_days, timeNow = parseInt(new Date().getTime() / 1000), d, date = new Date(publishTime * 1000), Y = date.getFullYear(), M = date.getMonth() + 1, D = date.getDate(), H = date.getHours(), m = date.getMinutes(), s = date.getSeconds(); //灏忎簬10鐨勫湪鍓嶉潰琛? if (M < 10) { M = '0' + M; } if (D < 10) { D = '0' + D; } if (H < 10) { H = '0' + H; } if (m < 10) { m = '0' + m; } if (s < 10) { s = '0' + s; } d = timeNow - publishTime; d_days = parseInt(d / 86400); d_hours = parseInt(d / 3600); d_minutes = parseInt(d / 60); d_seconds = parseInt(d); if (d_days > 0 && d_days < 3) { return d_days + '澶╁墠'; } else if (d_days <= 0 && d_hours > 0) { return d_hours + '灏忔椂鍓?; } else if (d_hours <= 0 && d_minutes > 0) { return d_minutes + '鍒嗛挓鍓?; } else if (d_seconds < 60) { if (d_seconds <= 0) { return '鍒氬垰'; } else { return d_seconds + '绉掑墠'; } } else if (d_days >= 3) { return Y + '.' + M + '.' + D; } }, setCookie: function (name, value, day) { var exp = new Date(); exp.setTime(exp.getTime() + day * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); }, getCookie: function (name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; }, delCookie: function (name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); }, setStorage: function (name, value) { localStorage.setItem(name, value); }, getStorage: function (name) { return localStorage.getItem(name); }, delStorage: function (name) { localStorage.removeItem(name);銆€銆€ }, getWhereJson: function () { try { var page = JSON.parse(this.Base64.decode(this.getStorage(this.Base64.encode(window.location.search + "where")) || "")); if (page === undefined) return true; else return page; } catch { return true; } }, setWhereJson: function (pageStr) { this.setStorage(this.Base64.encode(window.location.search + "where"), this.Base64.encode(pageStr)); }, getPageOption: function () { try { var page = JSON.parse(this.Base64.decode(this.getStorage(this.Base64.encode(window.location.search)) || "")); if (page === undefined) return true; else return page; } catch { return true; } }, setPageOption: function (pageStr) { this.setStorage(this.Base64.encode(window.location.search), this.Base64.encode(pageStr)); }, });