优化request

This commit is contained in:
TOP糯米 2023-03-08 15:19:18 +08:00
parent 2a85c906dd
commit 01d511b620
1 changed files with 13 additions and 1 deletions

View File

@ -29,9 +29,13 @@ const request = async (args) => {
if (typeof rule.auth !== "undefined" && rule.auth === true && !$store.state.user.token) {
$store.commit("user/showLoginModal", true);
throw "需要登录";
return;
}
(rule.showLoading) && uni.showLoading({
title: "加载中"
});
const headers = {
"XX-Wxapp-AppId": prototype.$config.appId,
'XX-Token': $store.state.user.token,
@ -49,6 +53,14 @@ const request = async (args) => {
}
});
(rule.showLoading) && uni.hideLoading();
if (response.data.code == 10001) {
$store.dispatch("user/logout");
$store.commit("user/showLoginModal", true);
return;
}
return Promise.resolve(response.data);
};