var Login = {
// doMain: window.location.host.substring(window.location.host.indexOf(".")),
doMain: /^(\d+\.?)+$/.test(location.host) ? window.location.host : window.location.host.substring(window.location.host.indexOf(".")),
isIp: function isIp() {
//判断URL是否是IP地址,是IP地址返回IP地址,否则返回空字符串
var ip = "";
var host = location.host;
var reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
if (reg.test(host)) {
ip = host;
} else {
ip = "";
}
return ip;
},
isTip: "",
setTimeId: "",
setCookie: function setCookie(name, value) {
//登录的时候设置cookie的过期时间
var ip = Login.isIp();
var Days = 1,
//0.02
exp = new Date();
var time = exp.getTime() + Days * 24 * 60 * 60 * 1000;
exp.setTime(time);
// exp.setTime(exp.getTime() + 5 * 60 * 1000);
if (ip != "") {
Login.doMain = ip;
}
if (location.host == "bim-demo.wanda.cn" || name == "AuthUser_AuthToken1") {
exp.setTime(exp.getTime() + 365 * 24 * 60 * 60 * 1000);
}
document.cookie = name + "=" + value + ";expires=" + exp.toGMTString() + ";domain=" + Login.doMain + ";path=/";
},
getCookie: function getCookie(key, cookis) {
//获取cookie,然后判断是否自动登录
var cooks = cookis || document.cookie,
items = cooks.split("; "),
result,
len = items.length,
str,
pos;
for (var i = 0; i < len; i++) {
str = items[i];
pos = str.indexOf('=');
name = str.substring(0, pos);
if (name == key) {
result = str.substring(pos + 1);
break;
}
}
return result;
},
//删除cookie
delCookie: function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 31 * 24 * 60 * 60 * 1000);
var cval = this.getCookie(name);
if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";domain=" + Login.doMain + ";path=/";
},
//删除cookie
delCook: function delCook(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";domain=" + Login.doMain + ";path=/";
},
//cookie名称
cookieNames: function cookieNames(cookies) {
var items = cookies.split("; ");
var names = [],
len = items.length,
str,
pos;
for (var i = 0; i < len; i++) {
str = items[i];
pos = str.indexOf('=');
names.push(str.substring(0, pos));
}
return names;
},
}