基本功能都已完成
This commit is contained in:
@@ -2,8 +2,8 @@ import Request from './luch-request/index.js';
|
||||
// 基础的url
|
||||
|
||||
|
||||
// const baseUrl = 'https://xyb.hexieweb.cn/xyb100zz';
|
||||
const baseUrl = 'http://192.168.1.168:5004';
|
||||
const baseUrl = 'https://yingji.hexieapi.com/prod-api';
|
||||
// const baseUrl = 'http://192.168.1.168:5004';
|
||||
|
||||
const http = new Request({
|
||||
baseURL: baseUrl,
|
||||
@@ -31,13 +31,15 @@ const objectToQueryString = (obj) => {
|
||||
return keyValuePairs.join('&');
|
||||
};
|
||||
|
||||
// 提示
|
||||
// 提示(延迟显示,避免和 hideLoading 冲突)
|
||||
function showToast(title) {
|
||||
uni.showToast({
|
||||
title,
|
||||
icon: 'none',
|
||||
duration: 1000,
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// 请求
|
||||
@@ -84,7 +86,7 @@ const requestAPI = (config) => {
|
||||
// 检查业务状态码(如果后端有的话)
|
||||
if (res.data && res.data.code !== undefined) {
|
||||
// 支持 code === 200 或 code === 0 作为成功状态
|
||||
if (res.data.code === 200 || res.data.code === 0) {
|
||||
if (res.data.code === 200 || res.data.code === 0 || res.code === 0) {
|
||||
resolve(res.data);
|
||||
} else if (res.data.code === 401) {
|
||||
// token过期处理
|
||||
@@ -96,10 +98,14 @@ const requestAPI = (config) => {
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}, 1500);
|
||||
reject('401');
|
||||
reject({ code: 401, msg: '登录已过期' });
|
||||
} else {
|
||||
showToast(res.data.msg || '请求失败');
|
||||
reject(res.data.code);
|
||||
// 支持多种错误信息字段:msg、message、error
|
||||
const errorMsg = res.data.msg || res.data.message || res.data.error || res.msg || '请求失败';
|
||||
console.error('接口错误:', res.data); // 打印完整错误信息便于调试
|
||||
showToast(errorMsg);
|
||||
// reject 时传递完整错误信息,方便页面获取
|
||||
reject({ code: res.data.code, msg: errorMsg, data: res.data });
|
||||
}
|
||||
} else {
|
||||
// 没有业务状态码,直接返回数据
|
||||
|
||||
Reference in New Issue
Block a user