对比图完成

This commit is contained in:
cheney
2026-04-26 11:41:39 +08:00
parent 342042577d
commit becf0364ad
6 changed files with 216 additions and 34 deletions
+12 -15
View File
@@ -22,30 +22,27 @@ async function handler(req, res) {
const params = [];
const conditions = [];
if (startDate) {
conditions.push('date >= ?');
params.push(startDate);
}
if (endDate) {
conditions.push('date <= ?');
params.push(endDate);
if (startDate && endDate) {
conditions.push('date BETWEEN ? AND ?');
params.push(startDate, endDate);
}
if (conditions.length > 0) {
query += ' WHERE ' + conditions.join(' AND ');
}
query += ' ORDER BY date ASC';
if (limit) {
query += ' LIMIT ?';
params.push(parseInt(limit));
}
query += ' ORDER BY date DESC';
const result = await pool.query(query, params);
const data = result.map(row => {
// 限制返回数量,默认为30
const limitValue = limit ? parseInt(limit) : 30;
const limitedResult = result.slice(0, limitValue);
// 反转顺序,使日期从早到晚
const sortedResult = limitedResult.reverse();
const data = sortedResult.map(row => {
let dateStr;
if (row.date instanceof Date) {
dateStr = row.date.toISOString().split('T')[0];