function getDTime(_key){
let date = _key;
const yyyy = date.getFullYear();
const MM = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
const dd = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
const HH = date.getHours() > 9 ? date.getHours() : '0' + date.getHours();
const mm = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
const ss = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
return [yyyy + '-' + MM + '-' + dd, " " + HH + ':' + mm + ':' + ss,yyyy + '-' + MM + '-' + dd+" " + HH + ':' + mm + ':' + ss];
}
function parseTime(time, pattern) {
if (!time) {
return null
}
const format = pattern || '{y}/{m}/{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
function dayChange(a, num) {
var timestamp = Date.parse(new Date(a.replace(/-/g, '\/')));
var newTimestamp = timestamp + num * 24 * 60 * 60 * 1000;
var date = new Date(newTimestamp);
if ((new Date() - new Date(date)) <= 0) {
showErr('不能再往下翻啦');
return;
} else {
return date;
}
}
function getTree(data,parentId){
var tree = [];
var temp;
for (var i = 0; i < data.length; i++) {
if (data[i].pid == parentId) {
var obj = data[i];
obj["show"] = (data[i].pid == 0?true:false);
obj["icon"] = (data[i].type == 0?'':(data[i].fence_type == 0?'icon-yuanxing':'icon-polygon'));
temp = getTree(data, data[i].id);
if (temp.length > 0) {
obj.children = [...temp];
}
tree.push(obj);
}
}
return tree;
}
function showErr(_msg) {
var boardDiv = `
`;
$(document.body).append(boardDiv);
setTimeout(() => {
$("#yzAlert").css("transform","translate(-50%, -100%)");
setTimeout(() => {
$("#yzAlert").remove();
}, 100);
}, 3000);
}
// var baseUrl = "http://121.37.6.200:8088";
var baseUrl = "https://hsws.enstation.com/hsws_war";
var vipUrl = "https://www.enstation.vip:9443";
var ys7Url = "https://open.ys7.com";
var helUrl = "https://caps.runde.pro/api";
var wireUrl = "https://www.jx-linkcreate.cn";
var staticUrl = "http://10.60.11.142:32000/Cctv";
// var staticUrl = "http://192.168.4.181:32000/Cctv";
// var staticUrl = "https://hsws.enstation.com/CctvO";
// 封装请求
function getAxios(opts,_data,_head){
$.Deferred(function(){});
return new Promise(function(resolve, reject) {
$.ajax({
url: opts.url,
type: opts.type,
traditional: true,
dataType: "json",
async: false,
headers: _head,
data: _data,
error: function(XMLHttpRequest, textStatus, errorThrown) {
},
success: function(res) {
if(res.code == "10002" || res.code == 401){
if(opts.url.indexOf("radarWarning") != -1){
resolve(res);
}else{
showErr("登录已过期,请重新登录....");
ajaxErr();
}
}else{
resolve(res);
}
},error:function(err){
if(opts.url.indexOf('micro-exhook') != -1&&(err.responseJSON.code == 10002||err.responseJSON.code == 10001)){
resolve(err);
}
}
})
})
}
function postAxios(opts,_data,_head){
$.Deferred(function(){});
return new Promise(function(resolve, reject) {
$.ajax({
url: opts.url,
type: opts.type,
traditional: true,
dataType: "json",
async: false,
headers: _head,
data: _data,
error: function(XMLHttpRequest, textStatus, errorThrown) {
},
success: function(res) {
if(res.code == "10002" || res.code == 401){
showErr("登录已过期,请重新登录....");
ajaxErr();
}else{
resolve(res);
}
}
})
})
}
function ajaxErr(){
setTimeout(() => {
delCookie("Admin-Token");
delCookie("ylToken");
delCookie("hemlTok");
delCookie("Admin-User");
delCookie("tzToken");
localStorage.removeItem("nowShip");
localStorage.removeItem("Histroy-List");
localStorage.removeItem("authorArr");
top.location.href = staticUrl + "/index.html";
},1000);
}
// 判断是PC端还是移动端
function IsPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
//写cookies
function setCookie(name,value){
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + 7*24*60*60*1000); //7天
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
}
//读取cookies
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
//删除cookies
function delCookie(name){
var exp = new Date();
exp.setTime(exp.getTime() - 10000);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString()+"; path=/";
}
function clearCookie(){
var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;)
document.cookie=keys[i]+'=0;expires=' + new Date( 0).toUTCString()
}
}
function checkLogin() {
if (getCookie("ylToken") != "null" && getCookie("ylToken") != null) {
// clearStor();
} else {
ajaxErr();
}
let _type = localStorage.getItem("ptType");
if (_type != null && _type != "null" && _type != undefined) {
var sheetObj = $("#linkSource")[0];
if (sheetObj != undefined) {
setStyle(sheetObj, ".heardYz", ["padding-top"], ["40px"]);
setStyle(sheetObj, ".appBox", ["padding-top"], ["80px"]);
setStyle(sheetObj, ".yzkjSider", ["top"], ["80px"]);
}
}
}
function setStyle(Obj, Text, _name, _val) {
var _Sheet = Obj.sheet;
var rules = _Sheet.cssRules;
var rule;
var selectorText;
for (i = 0; i < rules.length; i++) {
rule = rules[i];
selectorText = rule.selectorText;
if (selectorText == null || selectorText == "") {
continue;
} else if (selectorText === Text) {
for (var i = 0; i < _name.length; i++) {
rule.style.setProperty(_name[i], _val[i]);
}
return;
}
}
}
function clearStor(){
var href = origin = location.origin, pathname = location.pathname, search = location.search, hash = location.hash;
var searchs = search.replace(/_t_=[^&\?]*[&\?]*/g, '').replace(/(^[&\?]*)|([&\?]*$)/g, '');
if(localStorage.getItem('__clearcache__')) {
localStorage.removeItem('__clearcache__');
return history.replaceState({}, null, origin + pathname + (searchs ? '?' : '') + searchs + hash);
}
localStorage.setItem('__clearcache__', '1');
location.replace(origin + pathname + '?' + searchs + (searchs ? '&' : '') + '_t_=' + new Date().valueOf() + hash);
}
var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
var pi = 3.14159265358979324;
var a = 6378245.0;
var ee = 0.00669342162296594323;
function transformLon(x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
};
function transformLat(x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
function outOfChina(lat, lon) {
if (lon < 72.004 || lon > 137.8347){ return true; }
if (lat < 0.8293 || lat > 55.8271){ return true; }
return false;
}
function GpsToGd(wgLat, wgLon) {
var point = {};
// if(wgLat>90&&wgLon<60){
// let a = wgLat;
// wgLat = wgLon;
// wgLon = a;
// }
if (outOfChina(wgLat, wgLon)) {
point.lat = wgLat;
point.lon = wgLon;
return point;
}
var dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
var dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
var radLat = wgLat / 180.0 * pi;
var magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
point.lat = wgLat + dLat;
point.lon = wgLon + dLon;
return point;
};
function ShowLoading(_msg, _type) {
var boarddiv = "";
$(document.body).append(boarddiv);
if (_type == 1) {
setTimeout(() => {
$(".bulletBox").remove();
}, 2000);
}
}