
全局请求封装
export function http(path, params = {}, loading = true, method = "POST") {
console.log('%c请求拦截:', ' background:orange', params);
if (loading) {
uni.showLoading({
title: "加载中",
mask: true
});
};
return new Promise((resolve, reject) => {
uni.request({
header: {
Authorization: uni.getStorageSync("Authorization") || ""
},
url: import.meta.env.VITE_BASE_URL + path,
method,
data: params,
async success(res) {
uni.hideLoading();
resolve(res.data);
console.log('响应拦截:', path, params, res.data);
if (res.data?.code !== 0) {
uni.showToast({
icon: "error",
duration: 2000,
title: res.data.msg
});
}
},
fail(err) {
uni.hideLoading();
uni.reLaunch({
url: "/pages/status/service/error"
})
reject(err);
},
complete() {
}
});
});
};
局部业务接口封装

使用接口
