common.js 1.76 KB
//设置当前页面导航栏背景色
function addTabs(id) {
    $('.layui-nav-item').removeClass('layui-this')
    $(id).addClass('layui-this')
}

//设置ajax调取服务接口

function SetServicesPath() {
    return "http://192.168.2.108"
}

//设置全局參數
var portal =
{
    'api_url': "http://192.168.2.108:8000",        //属性名用引号括起来,属性间由逗号隔开
    'name': 'myName',
    "rootPath": GetRootPath()
};

//截取日期
function CutDate(times) {
    var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-");
    var timestr = "" + timearr[0] + "/" + timearr[1] + "/" + timearr[2]
    //var timestr = "" + timearr[1].split("")[1] + "月" + timearr[2] + "日\t" + timearr[3] + ":" + timearr[4] + ""
    return timestr
}

function GetRootPath() {
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    return curWwwPath.substring(0, pos);
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
    var r = window.location.search.substr(1).match(reg);
    if (r!=null) return (r[2]); return null;
 }
//  存储cookie
function setCookie(resdata,duration){
  var date = new Date();
  date.setTime(date.getTime() + duration*24*3600*1000);
  document.cookie = "myCookie=" + JSON.stringify(resdata) 
        + "; expires=" +date.toGMTString() + "; path=/";
  // document.cookie = " myCookie =" + JSON.stringify(resdata) + ';expires=' + date.toGMTString();
};

//获取cookie
function getCookie(){
  var str = document.cookie;
  if(str == ''){
    return false
  }else{
    $('.PersonLogin').css('pointer-events', 'none')
    var arr = str.replace(/(\s)+/g,'').split('=');
    return  JSON.parse(arr[1]);
  }
};