总结一下公共js的几个方法  有大神看到有问题的 直接提出 谢谢

ajax调用

GTsetAjax:function (type,url,data,okFn,beforeFn,completeFn){
let d
if(type=='get'){
d=data;
}else{
d=JSON.stringify(data)
}
$.ajax({
type:type,
url:base.path+url,
data:d,
contentType: 'application/json;charset=UTF-8',
beforeSend:function(xhr){
if(beforeFn || beforeFn != null){
beforeFn(xhr)
}else{
xhr.setRequestHeader("token", base.GTcookie.getCookie('token'));
xhr.setRequestHeader("appid", base.myId);
}
},
complete:function () {
if(completeFn || completeFn != null){
completeFn()
}
},
success:function(data){
if(okFn || okFn != null){
var a=data.state;
console.log(data)
if(data.state == '104' || data.state == '103'){
base.tip.tipsFn('您还没有登录哦');
return null
}else{
if(data.state == '200') {
okFn(data.data)
}else{
base.tip.tipsFn(data.message)
}
}
}
},
error:function(){
base.tip.tipsFn('服务器异常')
}
});
}

  地址栏参数截取

GTUrlParam: function GeTUrlParam() {
//优化 可以全部转小写 在进行取值
let arr = window.location.search.slice(1).split('&');
let obj = {};
for (let i = 0; i < arr.length; i++) {
let arr1 = arr[i].split('=');
obj[arr1[0]] = arr1[1];
}
return obj;
},

  时间

GTime: function timeFormat(needTime) {
function add0(m) {return m < 10 ? '0' + m : m;}
//needTime是整数,否则要parseInt转换
let time = new Date(needTime);
let y = time.getFullYear();
let m = time.getMonth()+1;
let d = time.getDate();
let h = time.getHours();
let mm = time.getMinutes();
let s = time.getSeconds();
return {
y:y,
m:add0(m),
d:add0(d),
h:add0(h),
mm:add0(mm),
s:add0(s)
};

  ]cookie的相关操作

GTcookie: {
//获取cookie
getCookie: function getCookie(objName) {
var arr = document.cookie.match(new RegExp("(^| )" + objName + "=([^;]*)(;|$)"));
if (arr != null) {
return unescape(arr[2]);
}
return null;
},
//添加cookie
/*
* setCookie 请求调用说明
* @param objName 名 require
* @param objValue 值 require
* @param objHours 时间(天)
* */
setCookie: function setCookie(objName, objValue, objHours) {
var str = objName + "=" + escape(objValue);
if (!objHours || objHours == null || objHours < 0) {
objHours = 999;
}
var date = new Date();
date.setTime(date.getTime() + objHours * 24 * 60 * 60 * 1000);
document.cookie = objName + "=" + escape(objValue) + ";expires=" + date.toGMTString();
},
//删除cookie
delCookie: function delCookie(objName) {
var date = new Date();
date.setTime(date.getTime() - 1);
var cval = base.cookie.getCookie(objName);
if (cval != null) {
document.cookie = objName + "=" + cval + ";expires=" + date.toGMTString();
return true;
} else {
return false;
}
},
//删除根目录cookie
delCookieByPath: function delCookieByPath(objName) {
var cval = base.cookie.getCookie(objName);
var objHours = -1;
if (cval != null) {
var str = objName + "=" + escape('');
var date = new Date();
date.setTime(date.getTime() + objHours * 24 * 60 * 60 * 1000);
document.cookie = str + ";path=/;expires=" + date.toGMTString();
return true;
} else {
return false;
}
}
},