// JavaScript Document var m_HostName = ""; var m_HttpPort = "80"; var m_Http = "http://"; var m_RtspPort = 554; var m_cyUserPwdValue = ""; var g_iSaveResTimer = 0; //保存结果清空timer的索引 var m_cyReInfo = ""; var iePlugVersion = "2.2.0.8027"; //插件版本 2.2.0.8027 var webVersion = "20.06.16.8065"; var first = 1; var nTimer = 0; m_Http = location.protocol + "//"; //获取当前地址栏协议 m_HostName = location.hostname; //获取当前地址栏主机名 if (location.port != "") { m_HttpPort = location.port; //获取当前地址样端口 } /************************************************* Function: SaveState Description: 保存后返回的状态 Input: xhr XMLHttpRequest 对象 Output: 无 return: 无 *************************************************/ function SaveState(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_if_succeed; } else { m_cyReInfo = str_if_fail; } $("#meg").html(m_cyReInfo); $("#meg").fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#meg").fadeOut(1000); $("#meg").html(""); }, 3000); } function SaveStateWifiMode(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_if_switchwifi_succeed; } else { m_cyReInfo = str_if_switchwifi_failed; } $("#meg").html(m_cyReInfo); $("#meg").fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#meg").fadeOut(1000); $("#meg").html(""); }, 3000); } function SaveStateTestEmail(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_if_testemail_succeed; } else { m_cyReInfo = str_if_testemail_fail; } $("#meg").html(m_cyReInfo); $("#meg").fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#meg").fadeOut(1000); $("#meg").html(""); }, 3000); } function SaveStateTestFtp(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_if_testftp_succeed; } else { m_cyReInfo = str_if_testftp_fail; } $("#meg").html(m_cyReInfo); $("#meg").fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#meg").fadeOut(1000); $("#meg").html(""); }, 3000); } function SaveStateDTF(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_if_succeed; } else { m_cyReInfo = str_if_fail; } $("#meg").html(m_cyReInfo); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#meg").html(""); }, 3000); } function SaveStateReboot(xhr) { var xmlDoc = xhr.responseXML; var state = $(xmlDoc).find('statusCode').eq(0).text(); if ("0" == state) { m_cyReInfo = str_rebooting; } else { m_cyReInfo = str_if_fail; } $("#meg").html(m_cyReInfo); $("#meg").fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } g_iSaveResTimer = setTimeout(function () { $("#meg").html(""); }, 3000); } /********************************** 功能: 对时 ***********************************/ // function setSyncDateTime() { // var now = new Date(); // var pcyear = now.getYear(); // if (pcyear < 1000) { // pcyear += 1900; // } // if ((pcyear < 1971) || (pcyear > 2036)) { // errorMsg(str_err_pctime, "meg"); // return false; // } // // var pcmonth = now.getMonth() + 1; // if (pcmonth < 10) pcmonth = "0" + pcmonth; // var pcday = now.getDate(); // if (pcday < 10) pcday = "0" + pcday; // var pchour = now.getHours(); // if (pchour < 10) pchour = "0" + pchour; // var pcminute = now.getMinutes(); // if (pcminute < 10) pcminute = "0" + pcminute; // var pcsecond = now.getSeconds(); // if (pcsecond < 10) pcsecond = "0" + pcsecond; // var setSyncPDT = pcyear + '.' + pcmonth + '.' + pcday + 'T' + pchour + '.' + pcminute + '.' + pcsecond; // setSyncPDT = setSyncPDT.replace(/[.]/g, ""); // var cyXml = "" + ""; // var cyURL = m_Http + m_HostName + ":" + m_HttpPort + "/System/Time"; // $.ajax({ // type: "PUT", // url: cyURL, // async: true, // processData: false, // data: cyXml, // beforeSend: function (xhr) { // xhr.setRequestHeader("If-Modified-Since", "0"); // }, // complete: function (xhr, textStatus) { // //SaveState(xhr); // } // }); // } /************************************************* Function: Logout Description: 注销用户 Input: 无 Output: 无 return: 无 *************************************************/ function Logout() { clearTimeout(gs_interval); $.cookie('userInfo', null); $.cookie('commandPort', null); $.cookie('strem', null); $.cookie('rtspPort', null); m_cyUserPwdValue = ""; window.location.href = "/"; } /************************************************* Function: Base64 Description: Base64加密解密 Input: 无 Output: 无 return: 无 *************************************************/ var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._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 + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { 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 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._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 = Base64._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; } } /************************************************* Function: errorMsg Description: 错误信息提示 *************************************************/ function errorMsg(msg, cyID) { $("#" + cyID).html(msg); $("#" + cyID).fadeIn(1000); if (0 != g_iSaveResTimer) { clearTimeout(g_iSaveResTimer); } //3秒后自动清除 g_iSaveResTimer = setTimeout(function () { $("#" + cyID).fadeOut(1000); $("#" + cyID).html(""); }, 3000); } /********************************** 功能: 计算字符串的长度 参数: szString: 输入的字符串 ***********************************/ function strlen(str) { var len = 0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); //单字节加1 if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) { len++; } else { len += 2; } } return len; } function checkStr(str) { var string = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/; if (string.test(str)) { return true } else { return false } } /************************************************* Function: CheckKeyDown Description: 输入时按下空格时,不允许输入 Input: iSetValue: 需要验证的值 Output: 无 return: 无 *************************************************/ function CheckKeyDown(event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode == 32) { if (navigator.appName == "Netscape" || navigator.appName == "Opera") { event.preventDefault(); } else { event.returnValue = false; //非ie浏览器event无returnValue属性 } return; } } /************************************************* Function: checkVal Description: 检测端口值 **************************************************/ function checkVal(tipsId) { if ($("#" + tipsId).val() > 65535) { $("#" + tipsId).val(65535); } if ($("#" + tipsId).val() < 1) { $("#" + tipsId).val(1); } } Date.prototype.format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } /** * 将日期格式化成指定格式的字符串 * @param date 要格式化的日期,不传时默认当前时间,也可以是一个时间戳 * @param fmt 目标字符串格式,支持的字符有:y,M,d,q,w,H,h,m,S,默认:yyyy-MM-dd HH:mm:ss * @returns 返回格式化后的日期字符串 */ var formatDatetostring = function (date, fmt) { date = date == undefined ? new Date() : date; date = typeof date == 'number' ? new Date(date) : date; fmt = fmt || 'yyyy-MM-dd HH:mm:ss'; var obj = { 'y': date.getFullYear(), // 年份,注意必须用getFullYear 'M': date.getMonth() + 1, // 月份,注意是从0-11 'd': date.getDate(), // 日期 'q': Math.floor((date.getMonth() + 3) / 3), // 季度 'w': date.getDay(), // 星期,注意是0-6 'H': date.getHours(), // 24小时制 'h': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, // 12小时制 'm': date.getMinutes(), // 分钟 's': date.getSeconds(), // 秒 'S': date.getMilliseconds() // 毫秒 }; var week = ['天', '一', '二', '三', '四', '五', '六']; for (var i in obj) { fmt = fmt.replace(new RegExp(i + '+', 'g'), function (m) { var val = obj[i] + ''; if (i == 'w') return (m.length > 2 ? '星期' : '周') + week[val]; for (var j = 0, len = val.length; j < m.length - len; j++) val = '0' + val; return m.length == 1 ? val : val.substring(val.length - m.length); }); } return fmt; } /** * 将字符串解析成日期 * @param str 输入的日期字符串,如'2014-09-13' * @param fmt 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S,不支持w和q * @returns 解析后的Date类型日期 */ var parseDate = function (str, fmt) { fmt = fmt || 'yyyy-MM-dd'; var obj = {y: 0, M: 1, d: 0, H: 0, h: 0, m: 0, s: 0, S: 0}; fmt.replace(/([^yMdHmsS]*?)(([yMdHmsS])\3*)([^yMdHmsS]*?)/g, function (m, $1, $2, $3, $4, idx, old) { str = str.replace(new RegExp($1 + '(\\d{' + $2.length + '})' + $4), function (_m, _$1) { obj[$3] = parseInt(_$1); return ''; }); return ''; }); obj.M--; // 月份是从0开始的,所以要减去1 var date = new Date(obj.y, obj.M, obj.d, obj.H, obj.m, obj.s); if (obj.S !== 0) date.setMilliseconds(obj.S); // 如果设置了毫秒 return date; } /** * 返回信息状态码提示 */ function statuscode(code) { if (-1 == code) { errorMsg(str_face_errone, "meg"); } if (-2 == code) { errorMsg(str_face_errteo, "meg"); } if (-3 == code) { errorMsg(str_face_errthree, "meg"); } if (-5 == code) { errorMsg(str_face_errthroth, "meg"); } if (-6 == code) { errorMsg(str_face_errfive, "meg"); } if (-7 == code) { errorMsg(str_face_errsix, "meg"); } if (-8 == code) { errorMsg(str_face_errseven, "meg"); } if (-9 == code) { errorMsg(str_face_erreight, "meg"); } if (-10 == code) { errorMsg(str_face_errnine, "meg"); } if (-11 == code) { errorMsg(str_face_errten, "meg"); } if (-12 == code) { errorMsg(str_face_prompt, "meg"); } if (-13 == code) { errorMsg(str_face_errshie, "meg"); } if (0x1001 == code) { errorMsg(str_face_errshisan, "meg"); } if (0x1002 == code) { errorMsg(str_face_errfourth, "meg"); } if (0x1003 == code) { errorMsg(str_face_errfifth, "meg"); } if (0x1004 == code) { errorMsg(str_face_errsixth, "meg"); } if (0x1005 == code) { errorMsg(str_face_errelevth, "meg"); } if (0x1006 == code) { errorMsg(str_face_creatfacefail, "meg"); } if (0x1007 == code) { errorMsg(str_face_eigenvalue, "meg"); } if (0x1008 == code) { errorMsg(str_face_inexistence, "meg"); } if (0x1009 == code) { errorMsg(str_face_facegroupexist, "meg"); } if (0x100A == code) { errorMsg(str_face_nameexist, "meg"); } if (0x100B == code) { errorMsg(str_face_pich, "meg"); } if (0x100C == code) { errorMsg(str_face_picmax, "meg"); } if (0x100D == code) { errorMsg(str_face_Supportwidth, "meg"); } if (0x100E == code) { errorMsg(str_face_checkfail, "meg"); } if (0x100F == code) { errorMsg(str_face_existing, "meg"); } if (0x1064 == code) { errorMsg(str_face_perex, "meg"); } if (0x1065 == code) { errorMsg(str_face_nameex, "meg"); } if (0x1066 == code) { errorMsg(str_face_faceguouptotal, "meg"); } if (0x1067 == code) { errorMsg(str_face_persontital, "meg"); } } /** * 错误码翻译 */ function statuscodetranslation(code) { if (-1 == code) { code = str_face_errone; return code; } if (-2 == code) { code = str_face_errteo; return code; } if (-3 == code) { code = str_face_errthree; return code; } if (-5 == code) { code = str_face_errthroth; return code; } if (-6 == code) { code = str_face_errfive; return code; } if (-7 == code) { code = str_face_errsix; return code; } if (-8 == code) { code = str_face_errseven; return code; } if (-9 == code) { code = str_face_erreight; return code; } if (-10 == code) { code = str_face_errnine; return code; } if (-11 == code) { code = str_face_errten; return code; } if (-12 == code) { code = str_face_prompt; return code; } if (-13 == code) { code = str_face_errshie; return code; } if (0x1001 == code) { code = str_face_errshisan; return code; } if (0x1002 == code) { code = str_face_errfourth; return code; } if (0x1003 == code) { code = str_face_errfifth; return code; } if (0x1004 == code) { code = str_face_errsixth; return code; } if (0x1005 == code) { code = str_face_errelevth; return code; } if (0x1006 == code) { code = str_face_creatfacefail; return code; } if (0x1007 == code) { code = str_face_eigenvalue; return code; } if (0x1008 == code) { code = str_face_inexistence; return code; } if (0x1009 == code) { code = str_face_facegroupexist; return code; } if (0x100A == code) { code = str_face_nameexist; return code; } if (0x100B == code) { code = str_face_pich; return code; } if (0x100C == code) { code = str_face_picmax; return code; } if (0x100D == code) { code = str_face_Supportwidth; return code; } if (0x100E == code) { code = str_face_checkfail; return code; } if (0x100F == code) { code = str_face_existing; return code; } if (0x1064 == code) { code = str_face_perex; return code; } if (0x1065 == code) { code = str_face_nameex; return code; } if (0x1066 == code) { code = str_face_faceguouptotal; return code; } if (0x1067 == code) { code = str_face_persontital; return code; } } function createXml(str) { if (document.all) {//IE浏览器 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.loadXML(str); return xmlDoc; } else {//非IE浏览器 return new DOMParser().parseFromString(str, "text/xml"); } } function converFileToBase64(path) //本地图片的base64的图片 { var ncx = document.getElementById("previewocx"); if (ncx == null) { alert("ActiveX plugin not attached"); } try { nRetbsae64 = ncx.ConverFileToBase64(path); console.log(nRetbsae64); } catch (e) { // alert(e.description); } } //将base64转换为Blob function dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), // bstr = Base64.decode(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], {type: mime}); } //将blob转换为file function blobToFile(theBlob, fileName) { theBlob.lastModifiedDate = new Date(); theBlob.name = fileName; return theBlob; } /** * 通用的打开下载对话框方法,没有测试过具体兼容性 * @param url 下载地址,也可以是一个blob对象,必选 * @param saveName 保存文件名,可选 */ function openDownloadDialog(url, saveName) { if (window.navigator.msSaveBlob) { try { window.navigator.msSaveBlob(url, saveName); } catch (e) { console.log(e); } }else{ if (typeof(url) == 'object' && (url) instanceof Blob) { url = window.URL.createObjectURL(url); // 创建blob地址 } var aLink = document.createElement('a'); aLink.href = url; aLink.download = saveName || '';// HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效 var event; if (window.MouseEvent) { event = new MouseEvent('click'); } else { event = document.createEvent('MouseEvents'); event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } aLink.dispatchEvent(event); } } function JudgeTextLength(str, charset) { var total = 0, charCode, i, len; charset = charset ? charset.toLowerCase() : ''; if (charset === 'utf-16' || charset === 'utf16') { for (i = 0, len = str.length; i < len; i++) { charCode = str.charCodeAt(i); if (charCode <= 0xffff) { total += 2; } else { total += 4; } } } else { for (i = 0, len = str.length; i < len; i++) { charCode = str.charCodeAt(i); if (charCode <= 0x007f) { total += 1; } else if (charCode <= 0x07ff) { total += 2; } else if (charCode <= 0xffff) { total += 3; } else { total += 4; } } } return total; } function valueReplace(v) { if (v.indexOf("\"") != -1) { v = v.toString().replace(new RegExp('(["\"])', 'g'), "\\\""); } else if (v.indexOf("\\") != -1) v = v.toString().replace(new RegExp("([\\\\])", 'g'), "\\\\"); return v; }