Browse Source

'修改request.js'

main
hflllll 1 month ago
parent
commit
5fe11de0ad
2 changed files with 24 additions and 12 deletions
  1. +18
    -6
      api/request.js
  2. +6
    -6
      config/index.js

+ 18
- 6
api/request.js View File

@ -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()
}
}
}) })
}) })
} }

+ 6
- 6
config/index.js View File

@ -12,7 +12,7 @@ const envParam = {
prod: 'production', prod: 'production',
} }
const env = envParam['prod']
const env = envParam['test']
// 全局配置 // 全局配置
const config = { const config = {
@ -46,11 +46,11 @@ const config = {
staticDomain: 'https://image.hhlm1688.com/' staticDomain: 'https://image.hhlm1688.com/'
}, },
production: { production: {
aliOSS_accessKey: 'LTAI5tRqoxbC9BKrWJduKDVT',
aliOSS_secretKey: 's5ANiOq4kYpzuMLQhqPMYL4IybMR7L',
aliOSS_bucketName: 'mulinyouni',
endpoint: 'oss-cn-beijing.aliyuncs.com',
staticDomain: 'https://image.mulinyouni.com/'
aliOSS_accessKey: 'LTAI5tQSs47izVy8DLVdwUU9',
aliOSS_secretKey: 'qHI7C3PaXYZySr84HTToviC71AYlFq',
aliOSS_bucketName: 'hanhaiimage',
endpoint: 'oss-cn-shenzhen.aliyuncs.com',
staticDomain: 'https://image.hhlm1688.com/'
}, },
}, },


Loading…
Cancel
Save