Comparing version 1.0.5 to 1.0.6
164
lib/index.js
'use strict'; | ||
exports.__esModule = true; | ||
var isArr = function isArr(someVar) { | ||
return Object.prototype.toString.call(someVar).slice(8, -1).toLowerCase() === 'array'; | ||
}; | ||
// var asb = 'adf'; | ||
exports['default'] = isArr; | ||
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); | ||
/* eslint-disable */ | ||
// http请求设置 | ||
_axios2['default'].defaults.headers['Content-Type'] = 'application/json;charset=UTF-8'; | ||
// 请求前配置 去首位空格 | ||
_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); | ||
var data = _extends3.data; | ||
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; | ||
} | ||
} 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); | ||
} | ||
} | ||
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); | ||
} | ||
} 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; | ||
config.headers['X-XSRF-TOKEN'] = store.state.TOKEN; | ||
return config; | ||
}); | ||
// 过滤响应 | ||
_axios2['default'].interceptors.response.use(function (result) { | ||
/* result 为服务器响应回来的数据 */ | ||
/* 方式一:直接返回处理后的 result */ | ||
if (result.data.code === 400) { | ||
(function () { | ||
/* 方式二:返回一个 Promise 对象 可以根据服务端返回的错误码进行判断 */ | ||
var time = 0; | ||
result.data.data.length > 0 && result.data.data.forEach(function (item) { | ||
setTimeout(function () { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: item | ||
}); | ||
}, time); | ||
time = time + 500; | ||
}); | ||
})(); | ||
} else if (result.data.code === 200 && result.data.msg.trim() !== '') { | ||
v.$message({ | ||
type: 'success', | ||
message: result.data.msg | ||
}); | ||
} 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('/'); | ||
} else if (result.data.msg && result.data.msg.trim() !== '') { | ||
v.$message.error(result.data.msg); | ||
} | ||
return result; | ||
}, function (err) { | ||
/* 当响应出错的时候 */ | ||
return Promise.reject(err); | ||
}); | ||
exports['default'] = _axios2['default']; | ||
module.exports = exports['default']; |
{ | ||
"name": "one-sport", | ||
"version": "1.0.5", | ||
"version": "1.0.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
7860
177