| | |
| | | // 是否需要设置 token |
| | | const isToken = (config.headers || {}).isToken === false |
| | | config.header = config.header || {} |
| | | if (getToken() && !isToken) { |
| | | config.header['Authorization'] = 'Bearer ' + getToken() |
| | | const token = getToken() |
| | | // 只有当token存在且不为空字符串时才添加到header |
| | | if (token && token.trim() !== '' && !isToken) { |
| | | config.header['Authorization'] = 'Bearer ' + token |
| | | } |
| | | // get请求映射params参数 |
| | | if (config.params) { |
| | |
| | | } |
| | | const code = res.data.code || 200 |
| | | const msg = errorCode[code] || res.data.msg || errorCode['default'] |
| | | |
| | | // 特殊处理:checkDuplicate 接口即使返回错误码也要进入 then 分支 |
| | | const isCheckDuplicateApi = config.url && config.url.includes('/task/checkDuplicate') |
| | | |
| | | if (code === 401) { |
| | | showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => { |
| | | if (res.confirm) { |
| | |
| | | }) |
| | | reject('无效的会话,或者会话已过期,请重新登录。') |
| | | } else if (code === 500) { |
| | | toast(msg) |
| | | // checkDuplicate 接口不显示 toast,让业务代码自己处理 |
| | | // if (!isCheckDuplicateApi) { |
| | | // toast(msg) |
| | | // } |
| | | // checkDuplicate 接口返回完整响应,不 reject |
| | | if (isCheckDuplicateApi) { |
| | | resolve(res.data) |
| | | return |
| | | } |
| | | reject('500') |
| | | } else if (code !== 200) { |
| | | toast(msg) |
| | | // checkDuplicate 接口不显示 toast,让业务代码自己处理 |
| | | // if (!isCheckDuplicateApi) { |
| | | // toast(msg) |
| | | // } |
| | | // checkDuplicate 接口返回完整响应,不 reject |
| | | if (isCheckDuplicateApi) { |
| | | resolve(res.data) |
| | | return |
| | | } |
| | | reject(code) |
| | | } |
| | | resolve(res.data) |
| | |
| | | } else if (message.includes('Request failed with status code')) { |
| | | message = '系统接口' + message.substr(message.length - 3) + '异常' |
| | | } |
| | | toast(message) |
| | | // toast(message) |
| | | reject(error) |
| | | }) |
| | | }) |