Comparing version 1.1.6 to 1.1.7
302
lib/index.js
@@ -1,63 +0,41 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _axios = require('axios'); | ||
var _axios2 = _interopRequireDefault(_axios); | ||
var _jsMd5 = require('js-md5'); | ||
var _jsMd52 = _interopRequireDefault(_jsMd5); | ||
import axios from 'axios'; | ||
import md5 from 'js-md5'; | ||
var _ = require('lodash'); | ||
var messageList = []; | ||
var urlList = []; | ||
var pushMessage = function pushMessage() { | ||
messageList = messageList.filter(function (item, index) { | ||
return index === 0 || index !== 0 && JSON.stringify(item) !== JSON.stringify(messageList[0]); | ||
let urlList = [] | ||
let pushMessage = function() { | ||
messageList = messageList.filter((item, index) => { | ||
return index === 0 || (index !== 0 && JSON.stringify(item) !== JSON.stringify(messageList[0])); | ||
}); | ||
showMessage(); | ||
}; | ||
var showMessage = _.debounce(function () { | ||
let showMessage = _.debounce(function() { | ||
if (messageList.length === 0) { | ||
return false; | ||
return false | ||
} | ||
if (messageList[0].type === 1) { | ||
v.$message.success(messageList[0].message); | ||
v.$message.success(messageList[0].message) | ||
} else if (messageList[0].type === 2) { | ||
(function () { | ||
var time = 0; | ||
messageList[0].message.forEach(function (item) { | ||
setTimeout(function () { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: item | ||
}); | ||
}, time); | ||
time = time + 500; | ||
}); | ||
/* v.$notify.error({ | ||
title: '提示', | ||
message: messageList[0].message | ||
}); */ | ||
})(); | ||
let time = 0 | ||
messageList[0].message.forEach(item => { | ||
setTimeout(() => { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: item | ||
}) | ||
}, time) | ||
time = time + 500 | ||
}) | ||
/* v.$notify.error({ | ||
title: '提示', | ||
message: messageList[0].message | ||
}); */ | ||
} else if (messageList[0].type === 3) { | ||
v.$message.error(messageList[0].message); | ||
} else if (messageList[0].type === 4) { | ||
v.$message.error('请求过于频繁,请稍后再试'); | ||
} | ||
v.$message.error(messageList[0].message); | ||
} else if (messageList[0].type === 4) { | ||
v.$message.error(`请求过于频繁,请稍后再试`); | ||
} | ||
messageList.splice(0, 1); | ||
}, 300); | ||
exports['default'] = function (_ref) { | ||
var store = _ref.store; | ||
var _ref$isloaded = _ref.isloaded; | ||
var isloaded = _ref$isloaded === undefined ? false : _ref$isloaded; | ||
var test = _ref.test; | ||
export default function({store, isloaded = false, test}) { | ||
/** | ||
@@ -70,123 +48,112 @@ * 1: 成功, | ||
// http请求设置 | ||
_axios2['default'].defaults.headers['Content-Type'] = 'application/json;charset=UTF-8'; | ||
if (isloaded) { | ||
return _axios2['default']; | ||
} | ||
axios.defaults.headers['Content-Type'] = 'application/json;charset=UTF-8' | ||
if (isloaded) {return axios} | ||
// 请求前配置 去首位空格 | ||
var instanceRequest = _axios2['default'].interceptors.request.use(function (config) { | ||
var instanceRequest = axios.interceptors.request.use(config => { | ||
if (urlList.includes(config.url)) { | ||
messageList.push({ | ||
type: 4 | ||
}); | ||
pushMessage(); | ||
}) | ||
pushMessage() | ||
} else { | ||
urlList.push(config.url); | ||
var requestData = ''; // 防串改 参数集合 | ||
urlList.push(config.url) | ||
let 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; | ||
let {data} = {...config} | ||
if (config.method === 'get') { | ||
// get请求 | ||
if (config.params) { | ||
for (var i in config.params) { | ||
requestData += i + '=' + config.params[i] + '&'; | ||
for (let i in config.params) { | ||
requestData += `${i}=${config.params[i]}&` | ||
} | ||
requestData = requestData.replace(/&$/, ''); | ||
requestData = requestData.replace(/&$/, '') | ||
} else { | ||
var num = config.url.indexOf('?'); | ||
requestData = num > -1 ? config.url.substr(num + 1) : null; | ||
let num = config.url.indexOf('?') | ||
requestData = num > -1 ? config.url.substr(num + 1) : null | ||
} | ||
} else { | ||
if (typeof data === 'string') { | ||
data = JSON.parse(data); | ||
data = JSON.parse(data) | ||
} | ||
if (typeof data === 'object') { | ||
var arr = Object.keys(data); | ||
let 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; | ||
arr = arr.sort(function(string1, string2) { | ||
let arrList = [] | ||
let num = string1.length > string2.length ? string1.length : string2.length | ||
for (var i = 0; i < num; i++) { | ||
var val1 = string1[i] || ''; | ||
var val2 = string2[i] || ''; | ||
var val1 = string1[i] || '' | ||
var val2 = string2[i] || '' | ||
if (val1 < val2) { | ||
arrList.push(false); | ||
arrList.push(false) | ||
} else if (val1 > val2) { | ||
arrList.push(true); | ||
arrList.push(true) | ||
} | ||
} | ||
return arrList[0] ? 1 : -1; | ||
}); | ||
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)); | ||
let newData = {} | ||
for (let i in arr) { | ||
newData = {...newData, ...{[arr[i]]: data[arr[i]]}} | ||
} | ||
data = newData; | ||
for (var i in data) { | ||
data = newData | ||
for (let i in data) { | ||
if (typeof data[i] === 'string') { | ||
data[i] = data[i].replace(/(^\s*)|(\s*$)/g, ''); | ||
data[i] = data[i].replace(/(^\s*)|(\s*$)/g, '') | ||
} | ||
} | ||
} | ||
requestData = JSON.stringify(data); | ||
config.data = data; | ||
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; | ||
const obj = new Object() | ||
/* form-data 格式 获取参数 */ | ||
config.data.forEach((value, key) => { | ||
if (typeof value !== 'object') { | ||
obj[key] = typeof value === 'number' ? String(value) : value | ||
} | ||
}) | ||
let arr = Object.keys(obj) | ||
if (arr.length > 0) { | ||
arr = arr.sort(function(string1, string2) { | ||
let arrList = [] | ||
let 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) | ||
} | ||
} | ||
}); | ||
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); | ||
})(); | ||
} | ||
})(); | ||
return arrList[0] ? 1 : -1 | ||
}) | ||
const sortData = {} | ||
arr.forEach(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; | ||
const timestamp = (config.data && config.data.timestamp) ? config.data.timestamp : new Date().getTime() + Number(store.state.timestampDiff) | ||
const SIGN = store.state.TOKEN + '&' + (Boolean(requestData) && requestData !== '{}' ? timestamp + '&' + requestData : timestamp) | ||
console.log(SIGN) | ||
config.headers['X-Sign'] = md5(SIGN) | ||
config.headers['X-Timestamp'] = timestamp | ||
if (store.state.TOKEN) { | ||
config.headers['X-XSRF-TOKEN'] = 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; | ||
}); | ||
var instanceResponse = axios.interceptors.response.use(result => { | ||
urlList = urlList.filter(item => { | ||
return item !== result.config.url | ||
}) | ||
// console.log(result) | ||
@@ -201,4 +168,4 @@ /* result 为服务器响应回来的数据 */ | ||
message: result.data.data | ||
}); | ||
pushMessage(); | ||
}) | ||
pushMessage() | ||
} else if (result.data.code === 200 && result.data.msg.trim() !== '') { | ||
@@ -208,35 +175,38 @@ messageList.push({ | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
}) | ||
pushMessage() | ||
// v.$message() | ||
} else if (result.data.code === 302) { | ||
// v.$message.error(result.data.msg) | ||
sessionStorage.clear(); | ||
store.commit('setName', ''); | ||
store.commit('setUserName', ''); | ||
store.commit('setUserId', ''); | ||
store.commit('setAuthority', []); | ||
v.$router.push('/'); | ||
messageList = []; | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
} else if (result.data.msg && result.data.msg.trim() !== '') { | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
// v.$message.error(result.data.msg) | ||
} | ||
return result; | ||
}, function (err) { | ||
// v.$message.error(result.data.msg) | ||
sessionStorage.clear() | ||
store.commit('setName', '') | ||
store.commit('setUserName', '') | ||
store.commit('setUserId', '') | ||
store.commit('setAuthority', []) | ||
v.$router.push('/') | ||
messageList = [] | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}) | ||
pushMessage() | ||
} else if (result.data.msg && result.data.msg.trim() !== '') { | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}) | ||
pushMessage() | ||
// v.$message.error(result.data.msg) | ||
} | ||
return result | ||
}, err => { | ||
/* 当响应出错的时候 */ | ||
return Promise.reject(err); | ||
}); | ||
return _axios2['default']; | ||
}; | ||
module.exports = exports['default']; | ||
if (err.config) { | ||
urlList = urlList.filter(item => { | ||
return item !== err.config.url | ||
}) | ||
} | ||
return Promise.reject(err) | ||
}) | ||
return axios | ||
} |
{ | ||
"name": "one-sport", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"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
9181
236