|
|
@ -16,6 +16,9 @@ export default function request ( { |
|
|
if (token) { |
|
|
if (token) { |
|
|
header['X-Access-Token'] = token |
|
|
header['X-Access-Token'] = token |
|
|
}else { |
|
|
}else { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: '请先登录', |
|
|
title: '请先登录', |
|
|
icon: 'none' |
|
|
icon: 'none' |
|
|
@ -40,6 +43,9 @@ export default function request ( { |
|
|
if (res.statusCode === 200 && res.data) { |
|
|
if (res.statusCode === 200 && res.data) { |
|
|
// 业务成功
|
|
|
// 业务成功
|
|
|
if (res.data.code === 200 ) { |
|
|
if (res.data.code === 200 ) { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
resolve(res.data) |
|
|
resolve(res.data) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -48,9 +54,13 @@ export default function request ( { |
|
|
const errorMsg = res.data.message || '请求失败' |
|
|
const errorMsg = res.data.message || '请求失败' |
|
|
|
|
|
|
|
|
if (showToast) { |
|
|
if (showToast) { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: errorMsg, |
|
|
title: errorMsg, |
|
|
icon: 'none' |
|
|
|
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 3000 |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
reject({ |
|
|
reject({ |
|
|
@ -82,6 +92,9 @@ export default function request ( { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (showToast) { |
|
|
if (showToast) { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: error.message, |
|
|
title: error.message, |
|
|
icon: 'none' |
|
|
icon: 'none' |
|
|
@ -93,6 +106,9 @@ export default function request ( { |
|
|
console.log(`Fail ${method} ${url}`, err); |
|
|
console.log(`Fail ${method} ${url}`, err); |
|
|
const errorMsg = err.errMsg || '请求失败' |
|
|
const errorMsg = err.errMsg || '请求失败' |
|
|
if (showToast) { |
|
|
if (showToast) { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
uni.showToast({ |
|
|
uni.showToast({ |
|
|
title: errorMsg, |
|
|
title: errorMsg, |
|
|
icon: 'none' |
|
|
icon: 'none' |
|
|
@ -105,11 +121,7 @@ export default function request ( { |
|
|
data: err |
|
|
data: err |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
complete: () => { |
|
|
|
|
|
if (showLoading) { |
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |