Commit 80bb979a by limin

调整http拦截逻辑

1 parent 746f7f08
.DS_Store
node_modules
/dist
# local env files
......
This diff could not be displayed because it is too large.
{
"name": "glsx-common",
"version": "1.3.3",
"version": "1.3.7",
"description": "glsx common",
"main": "./dist/glsx-common.js",
"private": false,
......
......@@ -38,9 +38,10 @@ Http.prototype.create = function () {
let _configSign = this.customer.sign || {}
data = createSign(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)
}
if (config.method.toLocaleLowerCase() == 'get') {
const method = config.method.toLocaleLowerCase()
if (method == 'get') {
config.params = data
} else if (config.method.toLocaleLowerCase() == 'post') {
} else if (method == 'post') {
config.data = qs.stringify(data)
}
return config
......@@ -48,24 +49,27 @@ Http.prototype.create = function () {
error => Promise.reject(error)
)
this.service.interceptors.response.use(
response => {
const { response: result } = this.customer
const res = response.data
let code = res[result.code_key || 'returnCode']
let errId = res[result.errId || 'errId']
({ data: res, config: { returnAll } }) => {
const {
response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' },
alert
} = this.customer
let code = res[code_key]
// let errId = res[errId]
// 特殊的code处理,可以增加
switch (code + '') {
case '200':
case code_success_value + '':
// 请求成功,不弹提示框,成功code可以更改
break
default:
this.customer.alert && this.customer.alert(res.message || res.msg || '出错了,请联系管理员')
alert && alert(res.message || res.msg || '出错了,请联系管理员')
break
}
return response.config.returnAll ? res : res[result.data_key || 'data']
return returnAll ? res : res[data_key]
},
error => {
this.customer.alert && this.customer.alert(error.message || '出错了,请联系管理员')
const { alert } = this.customer
alert && alert(error.message || '出错了,请联系管理员')
// 返回接口返回的错误信息
return Promise.reject(error)
}
......
......@@ -153,6 +153,7 @@ export const Util = {
// 创建签名
createSign: function (params, secret, noSignAttr = [], way = 'sha1') {
delete params.sign
params.timestamp = new Date().getTime()
var strQs = qs.stringify(params, { arrayFormat: 'indices', encode: false, allowDots: true })
const objQs = strQs.split('&')
const collect = objQs.reduce((collect, item) => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!