From a73bd79eb54536138b30b86c27984a12fc44da36 Mon Sep 17 00:00:00 2001 From: cheng <545895878@qq.com> Date: Fri, 17 Jul 2026 07:16:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E7=A7=BB=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97=E5=B9=B6=E6=94=B9=E8=BF=9B=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了 API 请求的调试日志输出 - 优化了错误消息格式,添加了错误码前缀 - 为后端错误响应添加了 toast 提示 - 为网络请求失败添加了 toast 提示 --- common/api.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/api.js b/common/api.js index 9ce7701..40706c2 100644 --- a/common/api.js +++ b/common/api.js @@ -13,7 +13,6 @@ const API_HOST = 'https://dev.wash-painting.cn' // 参考 goodBooth 项目的 fetchsomething // ========================================== function httpRequest(url, params) { - console.log('[API] Request:', params.method, url, 'data:', JSON.stringify(params.data)) return new Promise((resolve, reject) => { // 自动注入 Authorization token const headers = Object.assign({}, params.headers || {}) @@ -40,11 +39,14 @@ function httpRequest(url, params) { uni.reLaunch({ url: '/pages/login/login' }) reject({ msg: '登录已过期,请重新登录' }) } else { - const errMsg = (res.data && res.data.msg) || (res.data && res.data.errmsg) || `请求失败(${code})` + const rawMsg = (res.data && res.data.msg) || (res.data && res.data.errmsg) || '请求失败' + const errMsg = `[${code}] ${rawMsg}` + uni.showToast({ title: errMsg, icon: 'none', duration: 2500 }) reject({ msg: errMsg, code }) } }, fail: (err) => { + uni.showToast({ title: err.errMsg || '网络请求失败', icon: 'none', duration: 2500 }) reject({ msg: err.errMsg || '网络请求失败' }) } })