msg
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 48s

This commit is contained in:
sexygoat
2026-04-29 17:48:54 +08:00
parent d679cad55f
commit cebe545440

View File

@@ -1,5 +1,13 @@
import { BASE_URL } from './env.js';
const showErrorToast = (message) => {
uni.showToast({
title: message || '请求失败,请稍后重试',
icon: 'none',
duration: 2000
});
};
const request = (options) => {
return new Promise((resolve, reject) => {
const token = uni.getStorageSync('token') || '';
@@ -14,35 +22,32 @@ const request = (options) => {
...options.header
},
success: (res) => {
const responseData = res.data || {};
const { code, msg, data } = responseData;
if (res.statusCode === 401) {
uni.removeStorageSync('token');
uni.removeStorageSync('identifier');
uni.showToast({
title: '登录已过期,请重新登录',
icon: 'none',
duration: 2000
});
showErrorToast(msg || '登录已过期,请重新登录');
setTimeout(() => {
uni.reLaunch({ url: '/pages/login/login' });
}, 2000);
reject(res.data);
reject(responseData);
return;
}
const { code, msg, data } = res.data;
if (code === 0 || code === 200) {
if (code === 0) {
resolve(data);
} else {
reject(res.data);
return;
}
if (options.showError !== false) {
showErrorToast(msg);
}
reject(responseData);
},
fail: (err) => {
uni.showToast({
title: '网络请求失败',
icon: 'none',
duration: 2000
});
showErrorToast('网络请求失败');
reject(err);
}
});