This commit is contained in:
2025-12-16 09:32:55 +08:00
parent 5420cb599a
commit c20f085384
36 changed files with 2720 additions and 751 deletions

View File

@@ -1,3 +1,4 @@
// api/request.js
import { BASE_URL } from './CommonValues.js';
import { loginSystem } from '@/api/login.js';
@@ -50,13 +51,50 @@ export async function SIMPLE(url, data, method) {
dataType: 'json',
data: data,
success: res => {
if(res.data.code == '200' || res.data.statusCode == '200') {
console.log(`API响应 ${url}:`, res);
// 更灵活的状态码判断
let isSuccess = false;
// 检查HTTP状态码
if (res.statusCode === 200) {
// 检查响应数据
if (res.data) {
// 如果data是数组直接认为是成功的
if (Array.isArray(res.data)) {
isSuccess = true;
}
// 如果有code字段且为200
else if (res.data.code === 200 || res.data.code === '200') {
isSuccess = true;
}
// 如果有statusCode字段且为200
else if (res.data.statusCode === 200 || res.data.statusCode === '200') {
isSuccess = true;
}
// 如果没有code字段但有data字段
else if (res.data.data !== undefined) {
isSuccess = true;
}
// 如果data是对象但不是错误结构
else if (typeof res.data === 'object' && !res.data.errMsg) {
isSuccess = true;
}
} else {
// 没有data字段但状态码是200
isSuccess = true;
}
}
if (isSuccess) {
resolve(res.data)
} else {
console.error('请求返回错误状态:', res.data);
reject(res)
}
},
fail: err => {
console.error('请求失败:', err);
reject(err)
}
})
@@ -75,13 +113,50 @@ export function SIMPLE_TOKEN(url, data, token, method) {
dataType: 'json',
data: data,
success: res => {
if(res.data.code == '200' || res.data.statusCode == '200') {
console.log(`API响应 ${url}:`, res);
// 更灵活的状态码判断
let isSuccess = false;
// 检查HTTP状态码
if (res.statusCode === 200) {
// 检查响应数据
if (res.data) {
// 如果data是数组直接认为是成功的
if (Array.isArray(res.data)) {
isSuccess = true;
}
// 如果有code字段且为200
else if (res.data.code === 200 || res.data.code === '200') {
isSuccess = true;
}
// 如果有statusCode字段且为200
else if (res.data.statusCode === 200 || res.data.statusCode === '200') {
isSuccess = true;
}
// 如果没有code字段但有data字段
else if (res.data.data !== undefined) {
isSuccess = true;
}
// 如果data是对象但不是错误结构
else if (typeof res.data === 'object' && !res.data.errMsg) {
isSuccess = true;
}
} else {
// 没有data字段但状态码是200
isSuccess = true;
}
}
if (isSuccess) {
resolve(res.data)
} else {
console.error('请求返回错误状态:', res.data);
reject(res)
}
},
fail: err => {
console.error('请求失败:', err);
reject(err)
}
})