修改时间范围组件,评查详情创建新的数据结构来适配新的返回格式

This commit is contained in:
2025-04-22 20:49:18 +08:00
parent cd2f060d87
commit 6261950356
14 changed files with 678 additions and 299 deletions
+28 -5
View File
@@ -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,
+12 -2
View File
@@ -251,7 +251,7 @@ export async function getReviewPoints(fileId: string) {
}
// 提取页码数组
let contentPage: Record<string, number[]> = {};
let contentPage: Record<string, object> = {};
// console.log('result-------', result.evaluated_results?.result);
// console.log('datacontent-------', data);
if (data && typeof data === 'object') {
@@ -296,7 +296,17 @@ export async function getReviewPoints(fileId: string) {
}
}
}
} catch (e) {
}
// // 4-22 更改数据结构:通过拿到的data数据(每一个key对应一个object),将object中的page提取出来
// try{
// const dataObj = data as Record<string, object>;
// for (const key in dataObj) {
// if (Object.prototype.hasOwnProperty.call(dataObj, key)) {
// contentPage[key] = dataObj[key];
// }
// }
// }
catch (e) {
console.error('解析评查点data失败:', e);
contentPage = {};
}
+44 -29
View File
@@ -1,18 +1,18 @@
import { postgrestGet, postgrestPut, type PostgrestParams } from '../postgrest-client';
import dayjs from 'dayjs';
// import dayjs from 'dayjs';
import { getDocumentTypes } from '../document-types/document-types';
import type { DocumentTypeUI } from '../document-types/document-types';
import weekday from 'dayjs/plugin/weekday';
import updateLocale from 'dayjs/plugin/updateLocale';
// import weekday from 'dayjs/plugin/weekday';
// import updateLocale from 'dayjs/plugin/updateLocale';
import { formatDate } from '../../utils';
// 配置 dayjs
dayjs.extend(weekday);
dayjs.extend(updateLocale);
// 设置一周的第一天为周一
dayjs.updateLocale('en', {
weekStart: 1
});
// // 配置 dayjs
// dayjs.extend(weekday);
// dayjs.extend(updateLocale);
// // 设置一周的第一天为周一
// dayjs.updateLocale('en', {
// weekStart: 1
// });
// 文档数据库表接口
export interface Document {
@@ -79,7 +79,9 @@ export interface ReviewFileUI {
export interface DocumentSearchParams {
fileType?: string; // 文件类型ID
reviewStatus?: string; // 评查状态
dateRange?: string; // 日期范围
// dateRange?: string; // 日期范围
dateFrom?: string; // 开始日期
dateTo?: string; // 结束日期
keyword?: string; // 搜索关键字
sortOrder?: string; // 排序方式
page?: number; // 当前页码
@@ -277,28 +279,41 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
}
// 处理日期范围筛选
if (searchParams.dateRange) {
const now = dayjs();
const today = now.startOf('day').format('YYYY-MM-DD HH:mm:ss');
switch (searchParams.dateRange) {
case 'today':
filter['created_at'] = `gte.${today}`;
break;
case 'week': {
const weekStart = now.startOf('week').format('YYYY-MM-DD HH:mm:ss');
filter['created_at'] = `gte.${weekStart}`;
break;
}
case 'month': {
const monthStart = now.startOf('month').format('YYYY-MM-DD HH:mm:ss');
filter['created_at'] = `gte.${monthStart}`;
break;
}
if(searchParams.dateFrom){
filter['created_at'] = `gte.${searchParams.dateFrom+ ' 00:00:00'}`;
}
if(searchParams.dateTo){
const dateToKey = searchParams.dateFrom ? 'and' : 'created_at';
if(dateToKey === 'and'){
delete filter['created_at'];
filter[dateToKey] = `(created_at.gte.${searchParams.dateFrom+' 00:00:00'},created_at.lte.${searchParams.dateTo+' 23:59:59'})`;
}else{
filter['created_at'] = `lte.${searchParams.dateTo+' 23:59:59'}`;
}
}
// if (searchParams.dateRange) {
// const now = dayjs();
// const today = now.startOf('day').format('YYYY-MM-DD HH:mm:ss');
// switch (searchParams.dateRange) {
// case 'today':
// filter['created_at'] = `gte.${today}`;
// break;
// case 'week': {
// const weekStart = now.startOf('week').format('YYYY-MM-DD HH:mm:ss');
// filter['created_at'] = `gte.${weekStart}`;
// break;
// }
// case 'month': {
// const monthStart = now.startOf('month').format('YYYY-MM-DD HH:mm:ss');
// filter['created_at'] = `gte.${monthStart}`;
// break;
// }
// }
// }
// console.log('filter-----',filter);
params.filter = filter;
console.log('params-----',params);
// 发送API请求获取文档列表
const response = await postgrestGet<Document[]>('documents', params);
+26 -3
View File
@@ -17,6 +17,29 @@ export interface PostgrestParams {
headers?: Record<string, string>;
}
/**
* 将编码后的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;
}
}
/**
* 打印 PostgREST 查询日志
* @param endpoint 端点
@@ -32,9 +55,9 @@ function logPostgrestQuery(endpoint: string, params?: QueryParams, method: strin
// 确保 endpoint 格式正确
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
console.log('\n📦 PostgREST 查询日志 ========================');
console.log('\n📦 PostgREST 查询日志 ======================start=============');
console.log(`📦 HTTP 方法: ${method}`);
console.log(`📦 API 端点: ${baseUrl}/${normalizedEndpoint}`);
console.log(`📦 API 端点: ${decodeUrlForDisplay(`${baseUrl}/${normalizedEndpoint}`)}`);
if (params && Object.keys(params).length > 0) {
console.log('📦 查询参数:');
@@ -47,7 +70,7 @@ function logPostgrestQuery(endpoint: string, params?: QueryParams, method: strin
});
}
console.log('=========================================\n');
console.log('PostgREST 查询日志=============================end============\n');
}
}