| | |
| | | let data = res.data |
| | | // 控制台显示数据信息 |
| | | uni.hideLoading() |
| | | // 登录过期 |
| | | if (data.code !== 200) { |
| | | setTimeout(() => { |
| | | uni.showToast({ |
| | | title: data.message, |
| | | icon: "none", |
| | | duration: 2000 |
| | | }) |
| | | // Spring Boot / Gateway 默认错误体(HTTP 500 时无 code 字段) |
| | | if (data && data.status && data.code == null) { |
| | | const errMsg = data.message || data.error || '服务异常,请稍后重试' |
| | | uni.showToast({ |
| | | title: errMsg, |
| | | icon: 'none', |
| | | duration: 2500 |
| | | }) |
| | | if (data.code === 500 || data.code === 5112) { |
| | | return resolve({ code: data.status, message: errMsg }) |
| | | } |
| | | // 业务失败 |
| | | if (data.code !== 200) { |
| | | const msg = data.message || '操作失败' |
| | | uni.showToast({ |
| | | title: msg, |
| | | icon: 'none', |
| | | duration: 2500 |
| | | }) |
| | | // 仅未登录(5112)跳转登录页,避免商户发码等业务错误误跳转 |
| | | if (data.code === 5112) { |
| | | const userType = uni.getStorageSync('userType') |
| | | uni.clearStorageSync() |
| | | return uni.navigateTo({ |
| | | url: '/pages/login' |
| | | }) |
| | | const loginUrl = userType === 1 ? '/pages/customer/login' : '/pages/login' |
| | | return uni.navigateTo({ url: loginUrl }) |
| | | } |
| | | return resolve(data) |
| | | } |