This commit is contained in:
cansnow
2025-12-17 09:13:15 +08:00
parent 2e793c3f77
commit 59d1ba9a7e
3 changed files with 40 additions and 37 deletions
+2
View File
@@ -52,6 +52,8 @@ const app = new Vue({
store, store,
...App, ...App,
}); });
app.REQUEST_TRACE = process.env.NODE_ENV == 'development';
app.REQUEST_TRACE = false;
// 引入请求封装 // 引入请求封装
import request from "./util/request/index"; import request from "./util/request/index";
+1 -1
View File
@@ -109,7 +109,7 @@ export default {
const _this = this; const _this = this;
// #ifdef APP // #ifdef APP
plus.runtime.getProperty(plus.runtime.appid, (inf) => { plus.runtime.getProperty(plus.runtime.appid, (inf) => {
console.log(inf); //console.log(inf);
_this.appversion = inf.version _this.appversion = inf.version
}); });
// if(options.isRedirect){ // if(options.isRedirect){
+37 -36
View File
@@ -4,41 +4,42 @@
*/ */
module.exports = (vm) => { module.exports = (vm) => {
uni.$u.http.interceptors.response.use((response) => { uni.$u.http.interceptors.response.use((response) => {
console.log("\n-" if(vm.REQUEST_TRACE){
+"\n=============================================================" console.log("\n-"
+"\nurl:"+response.config.fullPath +"\n============================================================="
+"\nparams:"+JSON.stringify(response.config.params) +"\nurl:"+response.config.fullPath
+"\ndata:"+JSON.stringify(response.config.data) +"\nparams:"+JSON.stringify(response.config.params)
+"\nheader:"+JSON.stringify(response.config.header) +"\ndata:"+JSON.stringify(response.config.data)
+"\nresponse:"+JSON.stringify(response.data) +"\nheader:"+JSON.stringify(response.config.header)
+"\n=============================================================\n"); +"\nresponse:"+JSON.stringify(response.data)
/* 对响应成功做点什么 可使用async await 做异步操作*/ +"\n=============================================================\n");
const data = response.data; }
// 自定义参数 /* 对响应成功做点什么 可使用async await 做异步操作*/
const custom = response.config?.custom; const data = response.data;
if (data.errCode !== 0 && data.code !== 0) { // 自定义参数
if(data?.msg){ const custom = response.config?.custom;
uni.$u.toast(data.msg) if (data.errCode !== 0 && data.code !== 0) {
} if(data?.msg){
// 服务端返回的状态码不等于200,则reject() uni.$u.toast(data.msg)
// 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
// if (custom.toast !== false) {
// uni.$u.toast(data.message)
// }
// 如果需要catch返回,则进行reject
// if (custom?.catch) {
console.error('http catch rejected', data)
return Promise.reject(data);
// } else {
// // 否则返回一个pending中的promise
// return new Promise(() => { })
// }
} }
return data.data || {}; // 服务端返回的状态码不等于200,则reject()
}, // 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
(response) => { // if (custom.toast !== false) {
/* 对响应错误做点什么 statusCode !== 200*/ // uni.$u.toast(data.message)
return Promise.reject(response); // }
}, // 如果需要catch返回,则进行reject
); // if (custom?.catch) {
console.error('http catch rejected', data)
return Promise.reject(data);
// } else {
// // 否则返回一个pending中的promise
// return new Promise(() => { })
// }
}
return data.data || {};
},
(response) => {
/* 对响应错误做点什么 statusCode !== 200*/
return Promise.reject(response);
});
}; };