Commit 9cca35c9 by 李伟康

```

fix(api): 增强网络异常处理逻辑并统一错误提示

- 在 http.js 和 signHttp.js 中增加网络类型判断,无网络时提示“网络异常”
- 修复 signHttp.js 中未正确处理网络状态的问题
- 在 init.js 的 error 回调中增加对 request fail 的判断并展示相应提示
- 修改 DailyReport.vue 中的错误字段名称 message 为 errorText 并调整相关引用
```
1 parent a6fd67d4
...@@ -37,10 +37,10 @@ class Request { ...@@ -37,10 +37,10 @@ class Request {
success (res) { success (res) {
if (res.networkType == "none") { if (res.networkType == "none") {
uni.hideLoading(); uni.hideLoading();
// uni.showToast({ uni.showToast({
// title: '网络异常', title: '网络异常',
// icon: "error", icon: "none",
// }); });
reject("网络异常"); reject("网络异常");
return; return;
} }
......
import { Request } from 'glsk-toolkit' import { Request } from 'glsk-toolkit'
module.exports = { module.exports = {
gscPost: (url, data, _config = {}) => { gscPost: (url, data, _config = {}) => {
if (!uni.$signHttp) uni.$signHttp = new Request(uni.signHttpConfig) return new Promise((resolve, reject) => {
return uni.$signHttp.post(url, data, _config) uni.getNetworkType({
success (res) {
if (['none'].includes(res.networkType)) {
uni.hideLoading();
uni.showToast({
title: '网络异常',
icon: "none",
});
reject({
msg: '网络异常'
});
return;
}
if (!uni.$signHttp) uni.$signHttp = new Request(uni.signHttpConfig)
resolve(uni.$signHttp.post(url, data, _config))
}
})
})
} }
} }
...@@ -68,6 +68,16 @@ uni.signHttpConfig = { ...@@ -68,6 +68,16 @@ uni.signHttpConfig = {
}, },
error: (error, config) => { error: (error, config) => {
console.log('error事件触发', error, config) console.log('error事件触发', error, config)
if(error && error.errMsg == 'request:fail') {
return uni.showToast({
title: '网络异常',
icon: 'none',
})
}
uni.showToast({
title: error.msg || '接口请求失败或没错误返回',
icon: 'none',
})
}, },
logout: config => { logout: config => {
console.log('logout事件触发', config) console.log('logout事件触发', config)
......
...@@ -312,11 +312,11 @@ export default { ...@@ -312,11 +312,11 @@ export default {
let { orderObj, currentDate } = this, let { orderObj, currentDate } = this,
apiName = 'addCarDailyReport' apiName = 'addCarDailyReport'
if (orderObj.orderQuantity == null || orderObj.orderQuantity == '') throw { if (orderObj.orderQuantity == null || orderObj.orderQuantity == '') throw {
message: '新车下订', errorText: '新车下订',
refId: 'orderQuantity' refId: 'orderQuantity'
} }
if (orderObj.deliveryQuantity == null || orderObj.deliveryQuantity == '') throw { if (orderObj.deliveryQuantity == null || orderObj.deliveryQuantity == '') throw {
message: '新车交付', errorText: '新车交付',
refId: 'deliveryQuantity' refId: 'deliveryQuantity'
} }
if (orderObj.id != null) apiName = 'editCarDailyReport' if (orderObj.id != null) apiName = 'editCarDailyReport'
...@@ -331,9 +331,9 @@ export default { ...@@ -331,9 +331,9 @@ export default {
} }
} catch (errorObj) { } catch (errorObj) {
uni.hideLoading() uni.hideLoading()
if (errorObj.message) { if (errorObj.errorText) {
uni.showToast({ uni.showToast({
title: `${errorObj.message}不能为空`, title: `${errorObj.errorText}不能为空`,
icon: 'none' icon: 'none'
}) })
this.to = errorObj.refId this.to = errorObj.refId
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!