//var origin = window.location.origin == null ? window.location.protocol + "//" + window.location.host : window.location.origin;
//var thisDomain = " http://localhost:82/stage-api";
//var thisWebSocket ="ws://localhost:15674/ws";
//服务器路径
var thisDomain = "http://192.168.6.235:82/stage-api";
var thisVideo = "http://192.168.6.235:18080";//18080国标平台
var thisWebSocket = "ws://192.168.6.235:15674/ws";
var systemSettingUrl = "http://192.168.6.235:82";
// var thisDomain = window.location.origin.split(":")[0]+":"+window.location.origin.split(":")[1]+":82/stage-api";
// var thisVideo = window.location.origin.split(":")[0]+":"+window.location.origin.split(":")[1]+":18080";//18080国标平台
// var thisWebSocket = "ws:"+window.location.origin.split(":")[1]+":15674/ws";
// var systemSettingUrl = window.location.origin.split(":")[0]+":"+window.location.origin.split(":")[1]+":82";
// //内网穿透服务器路径
// var thisDomain = "http://82.haoqi100.top/stage-api";
// var thisVideo = "http://18080.haoqi100.top";
// var thisWebSocket = "ws://15674.haoqi100.top/ws";
// var systemSettingUrl = "http://82.haoqi100.top";
// var thisDomain = "http://192.168.1.235:82/stage-api";
// var thisVideo = "http://192.168.1.235:18080";
// var thisWebSocket = "ws://192.168.1.235:15674/ws";
// var systemSettingUrl = "http://192.168.1.235:82";
// //云服务器路径
// var thisDomain = "http://120.92.100.129:81/stage-api";
// var thisVideo = "http://120.92.100.129:18080";
// var thisWebSocket = "ws://120.92.100.129:15674/ws";
// var systemSettingUrl = "http://120.92.100.129:81";
//var mqttjson={ip: "192.168.1.235", port: "15675", user: "client", password: "123456"};//老的
//mqtt服务器地址----------暂停使用20210901
//var mqttjson={ip: "192.168.2.235", port: "61614", user: "gt", password: "Gt123456"};
//WebSocket服务器地址
var WebSocketjson={user: "gt", password: "Gt123456"};
//内网穿透
//var mqttjson={ip: "61614.haoqi100.top", port: "61614", user: "gt", password: "Gt123456"};
//本地路径
// var systemSettingUrl = "http://localhost:81/";
// var thisDomain = " http://120.92.100.129:81/stage-api";
// var thisWebSocket = "ws://120.92.100.129:15674/ws";
var SYS_TITLE = "岳阳渔政执法系统";
var SYS_BIGTITLE = "渔政执法大数据综合管理平台";
// var SYS_TITLE = "岳阳渔政执法系统";
// var SYS_BIGTITLE = "渔政执法大数据综合管理平台";
var COOKIE_NAME = "YYYYZ";
var webHome = origin + "/yyyzweb";
//var webHome = window.location.origin + "/yyyzweb";
var vActionRefresh = thisDomain + "/";
var VideoActionRefresh = thisVideo + "/";
var ThisToken = getCookie(COOKIE_NAME);
let isLogOut = false;
var p = getParent();
// 检查浏览器
function getDomain() {
return thisDomain;
}
function getWebHome() {
return webHome;
}
function getRandomDate() {
var date = new Date();
var winName = date.getMonth() + 1;
winName += date.getDate();
winName += date.getHours();
winName += date.getMinutes();
winName += date.getSeconds();
winName += date.getMilliseconds();
return winName;
}
function TTClear() {
delCookie(COOKIE_NAME);
ThisToken = null;
}
function setToken(_tokenId) {
ThisToken = _tokenId;
setCookie(COOKIE_NAME, ThisToken, 60 * 24);
}
function doRefreshPost(url, _json, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : vActionRefresh + url;
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken, "Content-Type": "application/json;charset=UTF-8"};
$
.ajax({
type: "POST",
headers: _headers,
url: _vActionRefresh,
contentType: "application/json",
data: JSON.stringify(_json),
cache: false,
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
alert("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
function doRefreshPut(url, _json, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : vActionRefresh + url;
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken, "Content-Type": "application/json;charset=UTF-8"};
$
.ajax({
type: "PUT",
headers: _headers,
url: _vActionRefresh,
contentType: "application/json",
data: JSON.stringify(_json),
cache: false,
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
//alert("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
function doRefreshDelete(url, _paras, callfun, _showLoading) {
var _vActionRefresh = vActionRefresh + url + _paras;
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken};
$
.ajax({
type: "DELETE",
headers: _headers,
url: _vActionRefresh,
contentType: "application/x-www-form-urlencoded",
data: "",
cache: true,
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
// alert("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
//异步
function doRefreshGet(url, _paras, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : vActionRefresh + url;
let _isJson = isJSON(_paras);
if (!_isJson) {
_vActionRefresh += _paras;
}
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken};
$
.ajax({
type: "GET",
headers: _headers,
url: _vActionRefresh,
contentType: "application/x-www-form-urlencoded",
data: _isJson ? JSON.stringify(_paras) : "",
cache: true,
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
console.log("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
//同步
function doRefreshGetasync(url, _paras, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : vActionRefresh + url;
let _isJson = isJSON(_paras);
if (!_isJson) {
_vActionRefresh += _paras;
}
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken};
$
.ajax({
type: "GET",
headers: _headers,
url: _vActionRefresh,
contentType: "application/x-www-form-urlencoded",
data: _isJson ? JSON.stringify(_paras) : "",
cache: false,
async: false,//同步
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
console.log("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
//同步视频回放专用
function doRefreshGetasyncvideo(url, _paras, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : vActionRefresh + url;
let _isJson = isJSON(_paras);
if (!_isJson) {
_vActionRefresh += _paras;
}
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Content-Type": "application/json;"};
$
.ajax({
type: "GET",
headers: _headers,
url: _vActionRefresh,
contentType: "application/x-www-form-urlencoded",
data: _isJson ? JSON.stringify(_paras) : "",
cache: false,
async: false,//同步
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
//$("body")
// .append(
// "
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
console.log("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}
function getUrlValue(id) {
var url = window.location.href;
var reg = new RegExp("(^|&)" + id + "=([^&]*)(&|$)");
var r = url.substr(url.indexOf("\?") + 1).match(reg);
if (r != null)
return unescape(r[2]);
return "";
}
Number.prototype.toFixed = function (d) {
var s = this + "";
if (!d)
d = 0;
if (s.indexOf(".") == -1)
s += ".";
s += new Array(d + 1).join("0");
if (new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {
var s = "0" + RegExp.$2, pm = RegExp.$1, a = RegExp.$3.length, b = true;
if (a == d + 2) {
a = s.match(/\d/g);
if (parseInt(a[a.length - 1]) > 4) {
for (var i = a.length - 2; i >= 0; i--) {
a[i] = parseInt(a[i]) + 1;
if (a[i] == 10) {
a[i] = 0;
b = i != 1;
} else {
break;
}
}
}
s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"),
"$1.$2");
}
if (b)
s = s.substr(1);
return (pm + s).replace(/\.$/, "");
}
return this + "";
};
String.prototype.startWith = function (str) {
var reg = new RegExp("^" + str);
return reg.test(this);
};
function getParent() {
var temp_p = window.parent;
if (temp_p != null) {
for (var i = 0; i < 10; i++) {
if (temp_p.parent == null) {
break;
} else {
temp_p = temp_p.parent;
}
}
}
return temp_p;
}
function checkForm(form) {
$("#" + form)
.find(
'input[data-validate],textarea[data-validate],select[data-validate]')
.trigger("blur");
$(this).find('input[placeholder],textarea[placeholder]').each(function () {
$hideplaceholder($("#" + form));
});
var numError = $("#" + form).find('.check-error').length;
if (numError) {
// 获取第一个error的焦点
$("#" + form)
.find('.check-error')
.first()
.find(
'input[data-validate],textarea[data-validate],select[data-validate]')
.first().focus().select();
return false;
} else {
return true;
}
};
function logout() {
if (!isLogOut) {
alert("用户失效,请重新登录");
isLogOut = true;
}
p.location.href = getWebHome() + "/login.html";
}
function setCookie(name, value, saveTime) {
try {
if (saveTime == null) {
saveTime = 60;
}
var exp = new Date(); // new Date("December 31, 9998");
exp.setTime(exp.getTime() + saveTime * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";expires="
+ exp.toGMTString() + ";path=/";
} catch (ex) {
}
}
function getCookie(name) {
try {
var search = name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) {
end = document.cookie.length;
}
return unescape(document.cookie.substring(offset, end));
} else {
return "";
}
}
} catch (ex) {
return "";
}
}
function delCookie(name) {
try {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null) {
document.cookie = name + "=" + cval + ";expires="
+ exp.toGMTString() + ";path=/";
}
} catch (ex) {
return null;
}
}
function doRefreshVideoPost(url, _json, callfun, _showLoading) {
var _vActionRefresh = url.startWith("http") ? url : VideoActionRefresh + url;
_showLoading = _showLoading == null ? true : _showLoading;
var imgID = "loading_" + getRandomDate();
var _headers = {"Authorization": ThisToken, "Content-Type": "application/json;charset=UTF-8"};
$
.ajax({
type: "POST",
headers: _headers,
url: _vActionRefresh,
contentType: "application/json",
data: JSON.stringify(_json),
cache: false,
datatype: "json",
beforeSend: function (XMLHttpRequest) {
if (_showLoading) {
$("body")
.append(
"
");
}
},
success: function (_data, status, xhr) {
if (_data.code == 401) {
//用户失效
logout();
}
if (_data.code == 403) {
//用户失效
showH5Alert("one", _data.msg, "error");
} else {
callfun(_data);
}
},
error: function (XMLHttpRequest, status, e) {
// alert("error:" + status + ";" + e);
},
complete: function (XMLHttpRequest, textStatus) {
$("#" + imgID).remove();
},
});
}