修改需要登录的逻辑

This commit is contained in:
赵毅 2025-12-25 14:20:07 +08:00
parent fd16796aa3
commit df2d5538f7

View File

@ -55,7 +55,6 @@ const getCurrentEnvironment = () => {
// 获取当前环境配置
const currentEnv = getCurrentEnvironment();
console.log("🚀 ~ currentEnv:", currentEnv)
const envConfig = environments[currentEnv] || environments.production;
export const RequsetUrl = envConfig.apiUrl; // 请求地址前缀
@ -147,7 +146,13 @@ export const NavgateTo = (path, options = {}) => {
* @returns {Promise} 返回一个Promise对象
*/
export const request = (url, method = "POST", data = {}, options = {}) => {
export const request = (
url,
method = "POST",
data = {},
options = {},
noLogin = true
) => {
const { silent = true, nested = false } = options;
let ctoken = null;
@ -180,8 +185,8 @@ export const request = (url, method = "POST", data = {}, options = {}) => {
success: (res) => {
// console.log('请求成功,接口返参', res);
if (
res.statusCode == 401 ||
(res.statusCode == 500 && res.data.msg == "效验令牌失败")
(res.statusCode == 401 && noLogin) ||
(res.statusCode == 500 && res.data.msg == "效验令牌失败" && noLogin)
) {
uni.removeStorageSync("ctoken");
uni.removeStorageSync("userId");
@ -223,10 +228,10 @@ export const request = (url, method = "POST", data = {}, options = {}) => {
} else {
console.log("走到这列");
uni.hideLoading();
uni.showToast({
title: res.data.msg || "请求失败",
icon: "none",
});
// uni.showToast({
// title: res.data.msg || "请求失败",
// icon: "none",
// });
reject({
code: res.statusCode,
@ -237,10 +242,10 @@ export const request = (url, method = "POST", data = {}, options = {}) => {
},
fail: (err) => {
uni.hideLoading();
uni.showToast({
title: res.data.msg || "请求失败",
icon: "none",
});
// uni.showToast({
// title: res.data.msg || "请求失败",
// icon: "none",
// });
reject({
code: -1,
message: "接口异常,请稍后重试",
@ -521,3 +526,4 @@ export const formatDate = (date) => {
const seconds = String(date.getSeconds()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};