修改近3天为今天

This commit is contained in:
Von committed 2026-03-18 13:16:59 +08:00
1 parent 7700e49228
commit 6161ef039b
2 files changed
+52 -8

No files matched your search

+11 -8
View File
@@ -20,7 +20,7 @@
<div class="filter-group filter-group-presets">
<label>常用时间</label>
<div class="date-preset-group" role="group" aria-label="常用时间范围">
<button type="button" class="date-preset-btn" data-date-preset="last3" onclick="applyDatePreset('last3')">近3天</button>
<button type="button" class="date-preset-btn" data-date-preset="today" onclick="applyDatePreset('today')">今天</button>
<button type="button" class="date-preset-btn" data-date-preset="last7" onclick="applyDatePreset('last7')">近7天</button>
<button type="button" class="date-preset-btn" data-date-preset="all" onclick="applyDatePreset('all')">全部时间</button>
</div>
@@ -165,9 +165,12 @@
}
const end = new Date();
const start = new Date();
const offsetDays = preset === 'last7' ? 6 : 2;
start.setDate(end.getDate() - offsetDays);
const start = new Date(end);
if (preset === 'last7') {
start.setDate(end.getDate() - 6);
}
return {
startDate: toDateInput(start),
endDate: toDateInput(end)
@@ -179,9 +182,9 @@
return 'all';
}
const last3 = buildDatePresetRange('last3');
if (startDate === last3.startDate && endDate === last3.endDate) {
return 'last3';
const today = buildDatePresetRange('today');
if (startDate === today.startDate && endDate === today.endDate) {
return 'today';
}
const last7 = buildDatePresetRange('last7');
@@ -749,7 +752,7 @@
}
function setDefaultDateRange() {
const defaultRange = buildDatePresetRange('last3');
const defaultRange = buildDatePresetRange('today');
document.getElementById('startDate').value = defaultRange.startDate;
document.getElementById('endDate').value = defaultRange.endDate;
currentFilters = {
+41
View File
@@ -0,0 +1,41 @@
import unittest
from pathlib import Path
from flask import Flask, render_template
class DashboardDefaultDateRangeTests(unittest.TestCase):
def setUp(self) -> None:
presentation_root = Path(__file__).resolve().parents[1] / "src" / "presentation"
self.app = Flask(
__name__,
template_folder=str(presentation_root / "templates"),
static_folder=str(presentation_root / "static"),
static_url_path="/static",
)
def render_dashboard(self) -> str:
with self.app.app_context():
return render_template(
"index.html",
active_page="index",
current_username="",
auth_enabled=False,
)
def test_dashboard_shows_today_preset_button(self) -> None:
html = self.render_dashboard()
self.assertIn('data-date-preset="today"', html)
self.assertIn("今天</button>", html)
self.assertNotIn("近3天</button>", html)
def test_dashboard_defaults_date_range_to_today(self) -> None:
html = self.render_dashboard()
self.assertIn("const defaultRange = buildDatePresetRange('today');", html)
self.assertNotIn("const defaultRange = buildDatePresetRange('last3');", html)
if __name__ == "__main__":
unittest.main()