Comparing version 1.1.5 to 1.1.6
192
lib/index.js
@@ -19,2 +19,3 @@ 'use strict'; | ||
var messageList = []; | ||
var urlList = []; | ||
var pushMessage = function pushMessage() { | ||
@@ -51,2 +52,4 @@ messageList = messageList.filter(function (item, index) { | ||
v.$message.error(messageList[0].message); | ||
} else if (messageList[0].type === 4) { | ||
v.$message.error('请求过于频繁,请稍后再试'); | ||
} | ||
@@ -60,2 +63,3 @@ messageList.splice(0, 1); | ||
var isloaded = _ref$isloaded === undefined ? false : _ref$isloaded; | ||
var test = _ref.test; | ||
@@ -75,105 +79,117 @@ /** | ||
var instanceRequest = _axios2['default'].interceptors.request.use(function (config) { | ||
var requestData = ''; // 防串改 参数集合 | ||
try { | ||
if (config.headers['Content-Type'] === 'application/json;charset=UTF-8' || config.headers['content-type'] === 'application/json;charset=UTF-8') { | ||
var _extends3 = _extends({}, config); | ||
if (urlList.includes(config.url)) { | ||
messageList.push({ | ||
type: 4 | ||
}); | ||
pushMessage(); | ||
} else { | ||
urlList.push(config.url); | ||
var requestData = ''; // 防串改 参数集合 | ||
try { | ||
if (config.headers['Content-Type'] === 'application/json;charset=UTF-8' || config.headers['content-type'] === 'application/json;charset=UTF-8') { | ||
var _extends3 = _extends({}, config); | ||
var data = _extends3.data; | ||
var data = _extends3.data; | ||
if (config.method === 'get') { | ||
// get请求 | ||
if (config.params) { | ||
for (var i in config.params) { | ||
requestData += i + '=' + config.params[i] + '&'; | ||
if (config.method === 'get') { | ||
// get请求 | ||
if (config.params) { | ||
for (var i in config.params) { | ||
requestData += i + '=' + config.params[i] + '&'; | ||
} | ||
requestData = requestData.replace(/&$/, ''); | ||
} else { | ||
var num = config.url.indexOf('?'); | ||
requestData = num > -1 ? config.url.substr(num + 1) : null; | ||
} | ||
requestData = requestData.replace(/&$/, ''); | ||
} else { | ||
var num = config.url.indexOf('?'); | ||
requestData = num > -1 ? config.url.substr(num + 1) : null; | ||
} | ||
} else { | ||
if (typeof data === 'string') { | ||
data = JSON.parse(data); | ||
} | ||
if (typeof data === 'object') { | ||
var arr = Object.keys(data); | ||
if (arr.length > 0) { | ||
arr = arr.sort(function (string1, string2) { | ||
var arrList = []; | ||
var num = string1.length > string2.length ? string1.length : string2.length; | ||
for (var i = 0; i < num; i++) { | ||
var val1 = string1[i] || ''; | ||
var val2 = string2[i] || ''; | ||
if (val1 < val2) { | ||
arrList.push(false); | ||
} else if (val1 > val2) { | ||
arrList.push(true); | ||
if (typeof data === 'string') { | ||
data = JSON.parse(data); | ||
} | ||
if (typeof data === 'object') { | ||
var arr = Object.keys(data); | ||
if (arr.length > 0) { | ||
arr = arr.sort(function (string1, string2) { | ||
var arrList = []; | ||
var num = string1.length > string2.length ? string1.length : string2.length; | ||
for (var i = 0; i < num; i++) { | ||
var val1 = string1[i] || ''; | ||
var val2 = string2[i] || ''; | ||
if (val1 < val2) { | ||
arrList.push(false); | ||
} else if (val1 > val2) { | ||
arrList.push(true); | ||
} | ||
} | ||
return arrList[0] ? 1 : -1; | ||
}); | ||
} | ||
var newData = {}; | ||
for (var i in arr) { | ||
var _extends2; | ||
newData = _extends({}, newData, (_extends2 = {}, _extends2[arr[i]] = data[arr[i]], _extends2)); | ||
} | ||
data = newData; | ||
for (var i in data) { | ||
if (typeof data[i] === 'string') { | ||
data[i] = data[i].replace(/(^\s*)|(\s*$)/g, ''); | ||
} | ||
return arrList[0] ? 1 : -1; | ||
}); | ||
} | ||
} | ||
var newData = {}; | ||
for (var i in arr) { | ||
var _extends2; | ||
newData = _extends({}, newData, (_extends2 = {}, _extends2[arr[i]] = data[arr[i]], _extends2)); | ||
} | ||
data = newData; | ||
for (var i in data) { | ||
if (typeof data[i] === 'string') { | ||
data[i] = data[i].replace(/(^\s*)|(\s*$)/g, ''); | ||
requestData = JSON.stringify(data); | ||
config.data = data; | ||
} | ||
} else if (config.headers['Content-Type'].indexOf('multipart/form-data') > -1) { | ||
(function () { | ||
var obj = new Object(); | ||
/* form-data 格式 获取参数 */ | ||
config.data.forEach(function (value, key) { | ||
if (typeof value !== 'object') { | ||
obj[key] = typeof value === 'number' ? String(value) : value; | ||
} | ||
}); | ||
var arr = Object.keys(obj); | ||
if (arr.length > 0) { | ||
(function () { | ||
arr = arr.sort(function (string1, string2) { | ||
var arrList = []; | ||
var num = string1.length > string2.length ? string1.length : string2.length; | ||
for (var i = 0; i < num; i++) { | ||
var val1 = string1[i] || ''; | ||
var val2 = string2[i] || ''; | ||
if (val1 < val2) { | ||
arrList.push(false); | ||
} else if (val1 > val2) { | ||
arrList.push(true); | ||
} | ||
} | ||
return arrList[0] ? 1 : -1; | ||
}); | ||
var sortData = {}; | ||
arr.forEach(function (item) { | ||
sortData[item] = obj[item]; | ||
}); | ||
requestData = JSON.stringify(sortData); | ||
})(); | ||
} | ||
} | ||
requestData = JSON.stringify(data); | ||
config.data = data; | ||
})(); | ||
} | ||
} else if (config.headers['Content-Type'].indexOf('multipart/form-data') > -1) { | ||
(function () { | ||
var obj = new Object(); | ||
/* form-data 格式 获取参数 */ | ||
config.data.forEach(function (value, key) { | ||
if (typeof value !== 'object') { | ||
obj[key] = typeof value === 'number' ? String(value) : value; | ||
} | ||
}); | ||
var arr = Object.keys(obj); | ||
if (arr.length > 0) { | ||
(function () { | ||
arr = arr.sort(function (string1, string2) { | ||
var arrList = []; | ||
var num = string1.length > string2.length ? string1.length : string2.length; | ||
for (var i = 0; i < num; i++) { | ||
var val1 = string1[i] || ''; | ||
var val2 = string2[i] || ''; | ||
if (val1 < val2) { | ||
arrList.push(false); | ||
} else if (val1 > val2) { | ||
arrList.push(true); | ||
} | ||
} | ||
return arrList[0] ? 1 : -1; | ||
}); | ||
var sortData = {}; | ||
arr.forEach(function (item) { | ||
sortData[item] = obj[item]; | ||
}); | ||
requestData = JSON.stringify(sortData); | ||
})(); | ||
} | ||
})(); | ||
} catch (e) {} | ||
var timestamp = new Date().getTime() + Number(store.state.timestampDiff); | ||
var SIGN = store.state.TOKEN + '&' + (Boolean(requestData) && requestData !== '{}' ? timestamp + '&' + requestData : timestamp); | ||
console.log(SIGN); | ||
config.headers['sign'] = _jsMd52['default'](SIGN); | ||
config.headers['timestamp'] = timestamp; | ||
if (store.state.TOKEN) { | ||
config.headers['X-XSRF-TOKEN'] = store.state.TOKEN; | ||
} | ||
} catch (e) {} | ||
var timestamp = new Date().getTime() + Number(store.state.timestampDiff); | ||
var SIGN = store.state.TOKEN + '&' + (Boolean(requestData) && requestData !== '{}' ? timestamp + '&' + requestData : timestamp); | ||
config.headers['sign'] = _jsMd52['default'](SIGN); | ||
config.headers['timestamp'] = timestamp; | ||
if (store.state.TOKEN) { | ||
config.headers['X-XSRF-TOKEN'] = store.state.TOKEN; | ||
return config; | ||
} | ||
return config; | ||
}); | ||
// 过滤响应 | ||
var instanceResponse = _axios2['default'].interceptors.response.use(function (result) { | ||
urlList = urlList.filter(function (item) { | ||
return item !== result.config.url; | ||
}); | ||
// console.log(result) | ||
@@ -180,0 +196,0 @@ /* result 为服务器响应回来的数据 */ |
{ | ||
"name": "one-sport", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "use for one-sport company", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10349
252