common.js 1.92 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(name, resdata, duration) {
  var date = new Date();
  date.setTime(date.getTime() + duration * 12 * 3600 * 1000);
  document.cookie = name + "=" + JSON.stringify(resdata) + ";expires=" + date.toGMTString() + "; path=/";
};

//获取cookie
function getCookie() {
  var str = document.cookie;
  if (str == '') {
    return false
  } else {
    var arr = str.split(';')
    var arr1 = arr[0].replace(/(\s)+/g, '').split('=');
    return JSON.parse(arr1[1]);
  }
};
/*
  * 验证手机号码
  */
function validatorTel(content) {
  // 正则验证格式
  eval("var reg = /^1[34578]\\d{9}$/;");
  return RegExp(reg).test(content);
}

// 验证身份证 
function isCardNo(card) {
  var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  return pattern.test(card);
}