|
|
@ -2,11 +2,16 @@ import { isFunction } from '../is.js' |
|
|
import env from '@/env/index.js' |
|
|
import env from '@/env/index.js' |
|
|
const urlEnv = env === 'production' ? '' : `-${env}` |
|
|
const urlEnv = env === 'production' ? '' : `-${env}` |
|
|
const uploadUrl = `https://api-ops-yyt${urlEnv}.qniao.cn/cloud-print-user-center/utils/uploadImage` |
|
|
const uploadUrl = `https://api-ops-yyt${urlEnv}.qniao.cn/cloud-print-user-center/utils/uploadImage` |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 定义的一个thenable对象 |
|
|
|
|
|
*/ |
|
|
|
|
|
class ErrorPromise { |
|
|
|
|
|
then() {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export default class Http { |
|
|
export default class Http { |
|
|
constructor( |
|
|
|
|
|
config = {}, |
|
|
|
|
|
{ reqInterceptor, resInterceptor, tranformConfig } = {} |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
constructor(config = {}, { reqInterceptor, resInterceptor, tranformConfig } = {}) { |
|
|
this.baseUrl = config.baseUrl |
|
|
this.baseUrl = config.baseUrl |
|
|
this.header = config.header || { |
|
|
this.header = config.header || { |
|
|
'content-type': 'application/json;charset=UTF-8' |
|
|
'content-type': 'application/json;charset=UTF-8' |
|
|
@ -56,7 +61,11 @@ export default class Http { |
|
|
method: conf.method, |
|
|
method: conf.method, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
let data = resInterceptor(res, opt) |
|
|
let data = resInterceptor(res, opt) |
|
|
// 服务器错误也会用then抛出,需要自己判断data==null
|
|
|
|
|
|
|
|
|
if (!data) { |
|
|
|
|
|
console.log('报错的请求参数:', conf) |
|
|
|
|
|
reject(res) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
resolve(data) |
|
|
resolve(data) |
|
|
}, |
|
|
}, |
|
|
fail: (err) => { |
|
|
fail: (err) => { |
|
|
@ -68,8 +77,8 @@ export default class Http { |
|
|
}) |
|
|
}) |
|
|
}).catch((err) => { |
|
|
}).catch((err) => { |
|
|
// 吃掉请求产生的异常
|
|
|
// 吃掉请求产生的异常
|
|
|
// 后期可以记录
|
|
|
|
|
|
console.error('native response error', err) |
|
|
console.error('native response error', err) |
|
|
|
|
|
return new ErrorPromise() |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
// config:{}
|
|
|
// config:{}
|
|
|
|