|
|
|
@ -1,50 +1,100 @@
|
|
|
|
|
/*一些基础的js方法,基础的业务js方法在lib.js里*/
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
|
xhrFields:{
|
|
|
|
|
withCredentials:true
|
|
|
|
|
},
|
|
|
|
|
crossDomain:true,
|
|
|
|
|
headers:{
|
|
|
|
|
"_sign":localStorage.getItem("_sign") // TP不用改动任何代码
|
|
|
|
|
},
|
|
|
|
|
beforeSend: function (XMLHttpRequest) {//ajax请求之前
|
|
|
|
|
if(this.url.indexOf(".json") >=0 && (this.url.indexOf("add") >=0 || this.url.indexOf("edit") >=0 || this.url.indexOf("set") >=0)){
|
|
|
|
|
layer.load(1);
|
|
|
|
|
var open = window.XMLHttpRequest.prototype.open,
|
|
|
|
|
send = window.XMLHttpRequest.prototype.send;
|
|
|
|
|
function openReplacement(method, url, async, user, password) {
|
|
|
|
|
return open.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCookie(key){
|
|
|
|
|
var va = null;
|
|
|
|
|
for (let str of document.cookie.split(";")) {
|
|
|
|
|
var kv = str.split("=");
|
|
|
|
|
if (kv[0] == key || Number(kv[0]+'') == Number(key+'') || kv[0] === key || (kv[0]+'') == (key+'') || (kv[0].indexOf(key)>=0 && key.indexOf('TOKEN') >= 0)) {
|
|
|
|
|
va = kv[1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//$("#loading_message").show();
|
|
|
|
|
},
|
|
|
|
|
complete: function (XMLHttpRequest, textStatus) {//responseText
|
|
|
|
|
if(this.url.indexOf(".json") >=0 && (this.url.indexOf("add") >=0 || this.url.indexOf("edit") >=0 || this.url.indexOf("set") >=0)){
|
|
|
|
|
layer.closeAll('loading');//关闭加载层
|
|
|
|
|
}
|
|
|
|
|
if (!$.isEmpty(XMLHttpRequest.responseJSON) && XMLHttpRequest.responseJSON.code == 401) {
|
|
|
|
|
layer.msg("网页已过期,请重新登陆!", {
|
|
|
|
|
offset: ['50%'],
|
|
|
|
|
icon: 2,
|
|
|
|
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
|
|
|
|
}, function () {
|
|
|
|
|
window.open(Common.ctxPath);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
return va;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取_role_tag
|
|
|
|
|
function getHeadTag(){
|
|
|
|
|
var reg = new RegExp("(^|&)_role_tag=([^&]*)(&|$)"),tokenInfo = ""; //构造一个含有目标参数的正则表达式对象
|
|
|
|
|
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
if (r == null) {
|
|
|
|
|
r = parent.window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
}
|
|
|
|
|
if (XMLHttpRequest.statusText == 'error' && !$.isEmpty(XMLHttpRequest.responseText)) {
|
|
|
|
|
var r = $.parseJSON(XMLHttpRequest.responseText);
|
|
|
|
|
if (r.code == 401) {
|
|
|
|
|
layer.msg("网页已过期,请重新登陆!", {
|
|
|
|
|
offset: ['50%'],
|
|
|
|
|
icon: 2,
|
|
|
|
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
|
|
|
|
}, function () {
|
|
|
|
|
window.open(Common.ctxPath);
|
|
|
|
|
});
|
|
|
|
|
if (r == null) {
|
|
|
|
|
r = parent.parent.window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
if (r != null) {
|
|
|
|
|
return unescape(r[2]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
//ajax请求失败
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendReplacement(data) { //添加请求头
|
|
|
|
|
var _role_tag = getHeadTag();
|
|
|
|
|
this.setRequestHeader("_role_tag", _role_tag);
|
|
|
|
|
var key = getCookie(_role_tag);
|
|
|
|
|
this.setRequestHeader("token", getCookie(key));
|
|
|
|
|
return send.apply(this, arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.XMLHttpRequest.prototype.open = openReplacement;
|
|
|
|
|
window.XMLHttpRequest.prototype.send = sendReplacement;
|
|
|
|
|
// $.ajaxSetup({
|
|
|
|
|
// complete: function (XMLHttpRequest) {//ajax请求之前
|
|
|
|
|
// console.log(1111111)
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
/*一些基础的js方法,基础的业务js方法在lib.js里*/
|
|
|
|
|
// $.ajaxSetup({
|
|
|
|
|
// xhrFields:{
|
|
|
|
|
// withCredentials:true
|
|
|
|
|
// },
|
|
|
|
|
// crossDomain:true,
|
|
|
|
|
// headers:{
|
|
|
|
|
// "_sign":localStorage.getItem($.getKeyInfo("_sign")) // TP不用改动任何代码
|
|
|
|
|
// },
|
|
|
|
|
// beforeSend: function (XMLHttpRequest) {//ajax请求之前
|
|
|
|
|
// if(this.url.indexOf(".json") >=0 && (this.url.indexOf("add") >=0 || this.url.indexOf("edit") >=0 || this.url.indexOf("set") >=0)){
|
|
|
|
|
// layer.load(1);
|
|
|
|
|
// }
|
|
|
|
|
// //$("#loading_message").show();
|
|
|
|
|
// },
|
|
|
|
|
// complete: function (XMLHttpRequest, textStatus) {//responseText
|
|
|
|
|
// if(this.url.indexOf(".json") >=0 && (this.url.indexOf("add") >=0 || this.url.indexOf("edit") >=0 || this.url.indexOf("set") >=0)){
|
|
|
|
|
// layer.closeAll('loading');//关闭加载层
|
|
|
|
|
// }
|
|
|
|
|
// if (!$.isEmpty(XMLHttpRequest.responseJSON) && XMLHttpRequest.responseJSON.code == 401) {
|
|
|
|
|
// layer.msg("网页已过期,请重新登陆!", {
|
|
|
|
|
// offset: ['50%'],
|
|
|
|
|
// icon: 2,
|
|
|
|
|
// time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
|
|
|
|
// }, function () {
|
|
|
|
|
// window.open(Common.ctxPath);
|
|
|
|
|
// });
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// if (XMLHttpRequest.statusText == 'error' && !$.isEmpty(XMLHttpRequest.responseText)) {
|
|
|
|
|
// var r = $.parseJSON(XMLHttpRequest.responseText);
|
|
|
|
|
// if (r.code == 401) {
|
|
|
|
|
// layer.msg("网页已过期,请重新登陆!", {
|
|
|
|
|
// offset: ['50%'],
|
|
|
|
|
// icon: 2,
|
|
|
|
|
// time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
|
|
|
|
// }, function () {
|
|
|
|
|
// window.open(Common.ctxPath);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// error: function () {
|
|
|
|
|
// //ajax请求失败
|
|
|
|
|
// },
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
if(typeof Object.assign != 'function') {
|
|
|
|
|
(function() {
|
|
|
|
@ -191,7 +241,7 @@ var Common = {
|
|
|
|
|
// });
|
|
|
|
|
var optionsData = Object.assign({}, {
|
|
|
|
|
type: 2,
|
|
|
|
|
content: Common.ctxPath + url,
|
|
|
|
|
content: Common.ctxPath + $.getUrlAddTag(url),
|
|
|
|
|
title: title || '',
|
|
|
|
|
maxmin: false
|
|
|
|
|
, cancel: function () {
|
|
|
|
@ -208,7 +258,7 @@ var Common = {
|
|
|
|
|
topOpenDlg: function (url, title) {
|
|
|
|
|
var index = top.layer.open({
|
|
|
|
|
type: 2,
|
|
|
|
|
content: Common.ctxPath + url,
|
|
|
|
|
content: Common.ctxPath + $.getUrlAddTag(url),
|
|
|
|
|
title: title,
|
|
|
|
|
area: ['100%', '100%'],
|
|
|
|
|
maxmin: false
|
|
|
|
@ -348,13 +398,15 @@ var Common = {
|
|
|
|
|
* cookie获取
|
|
|
|
|
*/
|
|
|
|
|
cookieGet: function(key) {
|
|
|
|
|
var va = null;
|
|
|
|
|
for (let str of document.cookie.split(";")) {
|
|
|
|
|
var kv = str.split("=");
|
|
|
|
|
if (kv[0] === key) {
|
|
|
|
|
return kv[1];
|
|
|
|
|
if (kv[0] == key || Number(kv[0]+'') == Number(key+'') || kv[0] === key || (kv[0]+'') == (key+'') || (kv[0].indexOf(key)>=0 && key.indexOf('TOKEN') >= 0)) {
|
|
|
|
|
va = kv[1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
return va;
|
|
|
|
|
},
|
|
|
|
|
post: function (url, paras, next) {
|
|
|
|
|
this.ajaxInit()
|
|
|
|
@ -652,10 +704,6 @@ var Common = {
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
},getUrlParam:function(name) {//获取url中的参数
|
|
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
|
|
|
|
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
if (r != null) return unescape(r[2]); return null; //返回参数值
|
|
|
|
|
},getLocalTime:function (nS) {//时间戳转换成时间格式
|
|
|
|
|
return new Date(parseInt(nS)).format('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
},getFormatDate:function (d) {
|
|
|
|
@ -696,6 +744,39 @@ var Common = {
|
|
|
|
|
let noWan = num % 10000;
|
|
|
|
|
if (noWan.toString().length < 4) noWan = "0" + noWan;
|
|
|
|
|
return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
|
|
|
|
|
}, getUrlParam: function (name) {//获取url中的参数
|
|
|
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
|
|
|
|
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
if (r != null) return unescape(r[2]);
|
|
|
|
|
return null; //返回参数值
|
|
|
|
|
}, getUrlAddTag: function (url) { //给地址添加标记
|
|
|
|
|
var reg = new RegExp("(^|&)_role_tag=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
|
|
|
|
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
if (r == null) {
|
|
|
|
|
r = parent.window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
}
|
|
|
|
|
if (r == null) {
|
|
|
|
|
r = parent.parent.window.location.search.substr(1).match(reg); //匹配目标参数
|
|
|
|
|
}
|
|
|
|
|
if (r != null) {
|
|
|
|
|
if (url.indexOf("?") >= 0) {
|
|
|
|
|
url += "&_role_tag=" + unescape(r[2]);
|
|
|
|
|
} else {
|
|
|
|
|
url += "?_role_tag=" + unescape(r[2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return url;
|
|
|
|
|
},
|
|
|
|
|
getKeyInfo:function (val){ //组装缓存的key值
|
|
|
|
|
const tag = getHeadTag(); //拿到头部指定参数
|
|
|
|
|
if($.isEmpty(tag)){
|
|
|
|
|
const tokenKye = getCookie(tag);; //根据唯一值拿存token的key
|
|
|
|
|
if(!$.isEmpty(tokenKye)){
|
|
|
|
|
return val + "_" + tokenKye; //传入的值 + 当前人的token的key
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|