修改时间范围组件,评查详情创建新的数据结构来适配新的返回格式
This commit is contained in:
+28
-5
@@ -22,6 +22,29 @@ const API_BASE_URL = 'http://nas.7bm.co:3000';
|
||||
// 是否使用模拟数据(开发环境使用)
|
||||
const USE_MOCK_DATA = false; // 设置为true使用模拟数据,避免API连接问题
|
||||
|
||||
/**
|
||||
* 将编码后的URL解码为可读格式
|
||||
* @param url 编码后的URL
|
||||
* @returns 解码后的可读URL
|
||||
*/
|
||||
function decodeUrlForDisplay(url: string): string {
|
||||
try {
|
||||
// 首先解码整个URL
|
||||
const decodedUrl = decodeURIComponent(url);
|
||||
|
||||
// 如果URL中包含@符号作为前缀,则移除它
|
||||
if (decodedUrl.startsWith('@')) {
|
||||
return decodedUrl.substring(1);
|
||||
}
|
||||
|
||||
return decodedUrl;
|
||||
} catch (error) {
|
||||
// 如果解码失败,返回原始URL
|
||||
console.error('URL解码失败:', error);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整的 API URL
|
||||
*/
|
||||
@@ -64,7 +87,7 @@ const fetchWithTimeout = async (url: string, options: RequestInit, timeout = 500
|
||||
const id = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
try {
|
||||
console.log(`📦 API 端点: ${url}`);
|
||||
console.log(`📦 client.ts->请求URL: ${decodeUrlForDisplay(url)}`);
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
signal: controller.signal
|
||||
@@ -73,7 +96,7 @@ const fetchWithTimeout = async (url: string, options: RequestInit, timeout = 500
|
||||
return response;
|
||||
} catch (error) {
|
||||
clearTimeout(id);
|
||||
console.error(`📦 API请求失败: ${error}`);
|
||||
console.error(`📦 client.ts->请求请求失败: ${error}`);
|
||||
|
||||
// 检查是否是网络连接问题
|
||||
if (error instanceof TypeError && error.message.includes('fetch failed')) {
|
||||
@@ -171,11 +194,11 @@ export async function apiRequest<T>(
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`发送 ${options.method || 'GET'} 请求到: ${url}`);
|
||||
console.log(`client.ts->发送 ${options.method || 'GET'} 请求到: ${decodeUrlForDisplay(url)}`);
|
||||
if (options.body) {
|
||||
console.log(`请求体: ${options.body}`);
|
||||
console.log(`client.ts->请求体: \n${options.body}`);
|
||||
}
|
||||
|
||||
|
||||
// 发送请求,10秒超时
|
||||
const response = await fetchWithTimeout(url, {
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user