This commit is contained in:
2025-04-14 17:44:30 +08:00
parent b3ed186231
commit b315fc0fea
2 changed files with 5 additions and 4 deletions
+5 -4
View File
@@ -186,20 +186,21 @@ export async function getDocuments(searchParams: DocumentSearchParams = {}): Pro
// 处理日期范围
if (searchParams.dateFrom) {
// 添加当天开始时间 00:00:00
filter['created_at'] = `gte.'${searchParams.dateFrom} 00:00:00'`;
filter['created_at'] = `gte.'${dayjs(`${searchParams.dateFrom} 00:00:00`).format()}'`;
}
if (searchParams.dateTo) {
// 如果有开始日期,使用and条件;否则直接设置结束日期
const dateToKey = searchParams.dateFrom ? 'and' : 'created_at';
const newDateFrom = dayjs(`${searchParams.dateFrom} 00:00:00`).format();
const newDateTo = dayjs(`${searchParams.dateTo} 23:59:59`).format();
// 添加当天结束时间 23:59:59
if (dateToKey === 'and') {
delete filter['created_at'];
// 使用OR操作符连接两个条件
filter[dateToKey] = `(created_at.gte.'${dayjs(searchParams.dateFrom).format()}',created_at.lte.'${dayjs(searchParams.dateTo).format()}')`;
filter[dateToKey] = `(created_at.gte.'${newDateFrom}',created_at.lte.'${newDateTo}')`;
} else {
filter['created_at'] = `lte.'${dayjs(searchParams.dateTo).format()}'`;
filter['created_at'] = `lte.'${newDateTo}'`;
}
}