feat(test_data): 搜索页面增加时分秒时间筛选

- HTML: 日期范围旁加 time input (step=1s),标签改为'时间范围'
- JS: 新增 getDatetime() 合并日期+时间,统一查/导出/图表/删除
- 后端: date 参数智能判断,纯日期自动补 23:59:59,带时间原样使用
This commit is contained in:
wangfq
2026-06-08 08:56:01 +08:00
parent bbfe085140
commit e538efafb5
3 changed files with 26 additions and 15 deletions

View File

@@ -168,10 +168,10 @@ def get_test_data(page: int = 1, per_page: int = 20,
params.append(f"%{serial}%")
if date_from:
where.append("t.create_time >= %s")
params.append(date_from)
params.append(date_from if len(date_from) > 10 else date_from)
if date_to:
where.append("t.create_time <= %s")
params.append(date_to + " 23:59:59")
params.append(date_to if len(date_to) > 10 else date_to + " 23:59:59")
if test_mode:
where.append("t.test_mode = %s")
params.append(int(test_mode))
@@ -223,10 +223,10 @@ def get_all_test_data_for_export(serial: str = "", date_from: str = "",
params.append(f"%{serial}%")
if date_from:
where.append("t.create_time >= %s")
params.append(date_from)
params.append(date_from if len(date_from) > 10 else date_from)
if date_to:
where.append("t.create_time <= %s")
params.append(date_to + " 23:59:59")
params.append(date_to if len(date_to) > 10 else date_to + " 23:59:59")
if test_mode:
where.append("t.test_mode = %s")
params.append(int(test_mode))
@@ -602,10 +602,10 @@ def delete_test_data(serial: str = "", date_from: str = "",
params.append(f"%{serial}%")
if date_from:
where.append("t.create_time >= %s")
params.append(date_from)
params.append(date_from if len(date_from) > 10 else date_from)
if date_to:
where.append("t.create_time <= %s")
params.append(date_to + " 23:59:59")
params.append(date_to if len(date_to) > 10 else date_to + " 23:59:59")
if data_source:
where.append("t.data_source = %s")
params.append(data_source)

View File

@@ -119,11 +119,20 @@ function switchView(view) {
// ─── 查询 ────────────────────────────────────────
/** 合并日期和时间输入框,返回 "YYYY-MM-DD" 或 "YYYY-MM-DD HH:MM:SS" 或 "" */
function getDatetime(dateId, timeId) {
const d = document.getElementById(dateId).value;
const t = document.getElementById(timeId).value;
if (!d) return "";
if (!t) return d;
return d + " " + t;
}
async function searchData(page = 1) {
currentPage = page;
const serial = document.getElementById("search-serial").value;
const dateFrom = document.getElementById("search-date-from").value;
const dateTo = document.getElementById("search-date-to").value;
const dateFrom = getDatetime("search-date-from", "search-time-from");
const dateTo = getDatetime("search-date-to", "search-time-to");
const v = VIEWS[currentView];
const perPage = parseInt(document.getElementById("per-page").value) || 20;
@@ -200,8 +209,8 @@ function renderPagination() {
function exportCSV() {
const serial = document.getElementById("search-serial").value;
const dateFrom = document.getElementById("search-date-from").value;
const dateTo = document.getElementById("search-date-to").value;
const dateFrom = getDatetime("search-date-from", "search-time-from");
const dateTo = getDatetime("search-date-to", "search-time-to");
const v = VIEWS[currentView];
const params = new URLSearchParams();
@@ -293,8 +302,8 @@ async function loadChart() {
if (!container || container.style.display === 'none') return;
const serial = document.getElementById('search-serial').value;
const dateFrom = document.getElementById('search-date-from').value;
const dateTo = document.getElementById('search-date-to').value;
const dateFrom = getDatetime('search-date-from', 'search-time-from');
const dateTo = getDatetime('search-date-to', 'search-time-to');
const v = VIEWS[currentView];
// 全部视图不适用,用 B2 或 B4
@@ -416,8 +425,8 @@ searchData(1);
function confirmDelete() {
const serial = document.getElementById('search-serial').value;
const dateFrom = document.getElementById('search-date-from').value;
const dateTo = document.getElementById('search-date-to').value;
const dateFrom = getDatetime('search-date-from', 'search-time-from');
const dateTo = getDatetime('search-date-to', 'search-time-to');
const v = VIEWS[currentView];
const ds = v.data_source || '';

View File

@@ -16,10 +16,12 @@
<input type="text" id="search-serial" placeholder="输入设备编码搜索...">
</label>
<label>
日期范围:
时间范围:
<input type="date" id="search-date-from">
<input type="time" id="search-time-from" step="1" style="width:110px;" title="起始时间(时:分:秒)">
<input type="date" id="search-date-to">
<input type="time" id="search-time-to" step="1" style="width:110px;" title="截止时间(时:分:秒)">
</label>
<button onclick="searchData(1)" class="btn-search">搜索</button>
<button onclick="exportCSV()" class="btn-export">导出 CSV</button>