From d00d199558fb4c397e05a6aed1996d9fbc1e3587 Mon Sep 17 00:00:00 2001 From: wangfq Date: Wed, 3 Jun 2026 17:02:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B5=8B=E8=AF=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=A1=B5=E6=8B=86=E4=B8=BA=E4=B8=89=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=EF=BC=88=E5=85=A8=E9=83=A8/B2/B4=EF=BC=89=EF=BC=8C=E6=8C=89dat?= =?UTF-8?q?a=5Fsource=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除混杂的24列大表,改为三个标签页切换 - 全部视图: 精简核心字段 - B2视图: 峰峰值、频率、距离、速度、故障、完成状态 - B4视图: 剩余次数、当前距离、速度、波动范围、进入/离开高度 - 后端增加data_source查询/导出参数支持 --- edc-web/app/models.py | 14 ++- edc-web/app/routes/test_data.py | 8 +- edc-web/app/static/js/test_data.js | 162 +++++++++++++++++++++------ edc-web/app/templates/test_data.html | 61 +++++----- 4 files changed, 168 insertions(+), 77 deletions(-) diff --git a/edc-web/app/models.py b/edc-web/app/models.py index 7ee80db..4ff7130 100644 --- a/edc-web/app/models.py +++ b/edc-web/app/models.py @@ -151,10 +151,12 @@ def get_latest_test_state(dnt_id: int) -> dict | None: def get_test_data(page: int = 1, per_page: int = 20, serial: str = "", date_from: str = "", - date_to: str = "", test_mode: str = "") -> tuple[list[dict], int]: + date_to: str = "", test_mode: str = "", + data_source: str = "") -> tuple[list[dict], int]: """分页查询测试数据(JOIN dnt_info),返回 (records, total) test_mode: ''=全部, '0'=灵敏度, '1'=波动 + data_source: ''=全部, 'B2', 'B4' """ conn = get_conn() try: @@ -173,6 +175,9 @@ def get_test_data(page: int = 1, per_page: int = 20, if test_mode: where.append("t.test_mode = %s") params.append(int(test_mode)) + if data_source: + where.append("t.data_source = %s") + params.append(data_source) where_clause = " AND ".join(where) if where else "1=1" @@ -201,10 +206,12 @@ def get_test_data(page: int = 1, per_page: int = 20, def get_all_test_data_for_export(serial: str = "", date_from: str = "", - date_to: str = "", test_mode: str = "") -> list[dict]: + date_to: str = "", test_mode: str = "", + data_source: str = "") -> list[dict]: """导出全部数据 test_mode: ''=全部, '0'=灵敏度, '1'=波动 + data_source: ''=全部, 'B2', 'B4' """ conn = get_conn() try: @@ -223,6 +230,9 @@ def get_all_test_data_for_export(serial: str = "", date_from: str = "", if test_mode: where.append("t.test_mode = %s") params.append(int(test_mode)) + if data_source: + where.append("t.data_source = %s") + params.append(data_source) where_clause = " AND ".join(where) if where else "1=1" cur.execute( diff --git a/edc-web/app/routes/test_data.py b/edc-web/app/routes/test_data.py index cdf1057..fbe2b27 100644 --- a/edc-web/app/routes/test_data.py +++ b/edc-web/app/routes/test_data.py @@ -24,8 +24,10 @@ def api_test_data(): date_from = request.args.get("date_from", "", type=str) date_to = request.args.get("date_to", "", type=str) test_mode = request.args.get("test_mode", "", type=str) + data_source = request.args.get("data_source", "", type=str) - records, total = get_test_data(page, per_page, serial, date_from, date_to, test_mode) + records, total = get_test_data(page, per_page, serial, date_from, date_to, + test_mode, data_source) return jsonify({ "records": records, "total": total, @@ -42,8 +44,10 @@ def api_export(): date_from = request.args.get("date_from", "", type=str) date_to = request.args.get("date_to", "", type=str) test_mode = request.args.get("test_mode", "", type=str) + data_source = request.args.get("data_source", "", type=str) - records = get_all_test_data_for_export(serial, date_from, date_to, test_mode) + records = get_all_test_data_for_export(serial, date_from, date_to, + test_mode, data_source) output = io.StringIO() writer = csv.writer(output) diff --git a/edc-web/app/static/js/test_data.js b/edc-web/app/static/js/test_data.js index 7ed758c..052368b 100644 --- a/edc-web/app/static/js/test_data.js +++ b/edc-web/app/static/js/test_data.js @@ -1,25 +1,112 @@ -// 测试信息页 +// 测试信息页 — 三视图 (全部 / B2 / B4) + +// ─── 视图定义 ─────────────────────────────────── + +const VIEWS = { + all: { + label: '全部数据', + data_source: '', // '' = 不过滤 + cols: [ + { key: 'id', title: 'ID' }, + { key: 'serial', title: '设备编码' }, + { key: 'dpg430_addr', title: '地址' }, + { key: 'model', title: '型号', render: r => r.sub_type === 1 ? 'PD132' : r.sub_type === 2 ? 'DLD110' : '-' }, + { key: 'str_type', title: '类型' }, + { key: 'data_source', title: '来源' }, + { key: 'test_mode', title: '测试模式', render: r => r.test_mode === 1 ? '波动' : '灵敏度' }, + { key: 'ppvalue', title: '峰峰值(V)', render: r => r.ppvalue?.toFixed(2) || '-' }, + { key: 'idle_freq', title: '开始频率' }, + { key: 'enter_dist', title: '进入距离' }, + { key: 'exit_dist', title: '离开距离' }, + { key: 'remain_count', title: '剩余次数' }, + { key: 'curr_dist', title: '当前距离' }, + { key: 'create_time', title: '时间' }, + ], + }, + b2: { + label: '灵敏度测试', + data_source: 'B2', + cols: [ + { key: 'id', title: 'ID' }, + { key: 'serial', title: '设备编码' }, + { key: 'dpg430_addr', title: '地址' }, + { key: 'model', title: '型号', render: r => r.sub_type === 1 ? 'PD132' : r.sub_type === 2 ? 'DLD110' : '-' }, + { key: 'str_type', title: '类型' }, + { key: 'test_mode', title: '测试模式', render: r => r.test_mode === 1 ? '波动' : '灵敏度' }, + { key: 'iffinish', title: '完成', render: r => r.iffinish === '1' ? '是' : '否' }, + { key: 'fault_info', title: '故障信息' }, + { key: 'relay_out', title: '继电器' }, + { key: 'ppvalue', title: '峰峰值(V)', render: r => r.ppvalue?.toFixed(2) || '-' }, + { key: 'idle_freq', title: '开始频率' }, + { key: 'enter_freq', title: '进入频率' }, + { key: 'exit_freq', title: '离开频率' }, + { key: 'enter_dist', title: '进入距离' }, + { key: 'exit_dist', title: '离开距离' }, + { key: 'enter_speed', title: '进入速度', render: r => toSpeed(r.enter_speed) }, + { key: 'exit_speed', title: '离开速度', render: r => toSpeed(r.exit_speed) }, + { key: 'create_time', title: '时间' }, + ], + }, + b4: { + label: '波动测试', + data_source: 'B4', + cols: [ + { key: 'id', title: 'ID' }, + { key: 'serial', title: '设备编码' }, + { key: 'dpg430_addr', title: '地址' }, + { key: 'remain_count', title: '剩余次数' }, + { key: 'work_freq', title: '工作频率(Hz)' }, + { key: 'curr_dist', title: '当前距离(mm)' }, + { key: 'speed', title: '速度(dm/s)' }, + { key: 'near_dist', title: '最近距离(mm)' }, + { key: 'far_dist', title: '最远距离(mm)' }, + { key: 'b4_enter_dist', title: '进入高度(mm)' }, + { key: 'b4_leave_dist', title: '离开高度(mm)' }, + { key: 'relay_out', title: '继电器' }, + { key: 'create_time', title: '时间' }, + ], + }, +}; + +// ─── 状态 ─────────────────────────────────────── + +let currentView = 'all'; +let currentPage = 1; +let totalPages = 1; function toSpeed(v) { if (v === null || v === undefined || v === '') return '-'; return (parseFloat(v) / 10).toFixed(1); } -let currentPage = 1; -let totalPages = 1; +// ─── 视图切换 ──────────────────────────────────── + +function switchView(view) { + currentView = view; + document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active')); + document.getElementById('tab-' + view).classList.add('active'); + // 重置分页 + currentPage = 1; + searchData(1); +} + +// ─── 查询 ──────────────────────────────────────── 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 testMode = document.getElementById("search-test-mode").value; + const v = VIEWS[currentView]; const params = new URLSearchParams({ page, per_page: 20 }); if (serial) params.set("serial", serial); if (dateFrom) params.set("date_from", dateFrom); if (dateTo) params.set("date_to", dateTo); - if (testMode) params.set("test_mode", testMode); + // 按 data_source 过滤(全部不过滤) + if (v.data_source) { + params.set("data_source", v.data_source); + } try { const resp = await fetch(`/api/test-data?${params}`); @@ -32,42 +119,39 @@ async function searchData(page = 1) { } } +// ─── 渲染表头 ──────────────────────────────────── + +function renderHead() { + const thead = document.querySelector("#test-data-table thead"); + const v = VIEWS[currentView]; + thead.innerHTML = '' + + v.cols.map(c => `${c.title}`).join('') + + ''; +} + +// ─── 渲染数据行 ────────────────────────────────── + function renderTable(records) { + renderHead(); const tbody = document.querySelector("#test-data-table tbody"); + const v = VIEWS[currentView]; + const nCols = v.cols.length; + if (!records.length) { - tbody.innerHTML = '暂无数据'; + tbody.innerHTML = `暂无数据`; return; } - tbody.innerHTML = records.map(r => ` - - ${r.id} - ${r.serial || '-'} - ${r.dpg430_addr} - ${r.sub_type === 1 ? 'PD132' : r.sub_type === 2 ? 'DLD110' : '-'} - ${r.str_type || '-'} - ${r.test_mode === 1 ? '波动测试' : '灵敏度测试'} - ${r.data_source || '-'} - ${r.iffinish === '1' ? '是' : '否'} - ${r.fault_info || '无'} - ${r.relay_out || '无'} - ${r.ppvalue?.toFixed(2) || '-'} - ${r.idle_freq || '-'} - ${r.enter_freq || '-'} - ${r.exit_freq || '-'} - ${r.enter_dist || '-'} - ${r.exit_dist || '-'} - ${toSpeed(r.enter_speed)} - ${toSpeed(r.exit_speed)} - ${r.remain_count || '-'} - ${r.curr_dist || '-'} - ${r.speed || '-'} - ${r.near_dist || '-'} - ${r.far_dist || '-'} - ${r.create_time || '-'} - - `).join(""); + tbody.innerHTML = records.map(r => + '' + v.cols.map(c => { + if (c.render) return `${c.render(r)}`; + const val = r[c.key]; + return `${val !== null && val !== undefined && val !== '' ? val : '-'}`; + }).join('') + '' + ).join(""); } +// ─── 分页 ──────────────────────────────────────── + function renderPagination() { const div = document.getElementById("pagination"); let html = ""; @@ -83,20 +167,24 @@ function renderPagination() { div.innerHTML = html; } +// ─── 导出 ──────────────────────────────────────── + 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 testMode = document.getElementById("search-test-mode").value; + const v = VIEWS[currentView]; const params = new URLSearchParams(); if (serial) params.set("serial", serial); if (dateFrom) params.set("date_from", dateFrom); if (dateTo) params.set("date_to", dateTo); - if (testMode) params.set("test_mode", testMode); + if (v.data_source) params.set("data_source", v.data_source); window.location.href = `/api/test-data/export?${params}`; } -// 初始加载 +// ─── 初始加载 ──────────────────────────────────── + +renderHead(); searchData(1); diff --git a/edc-web/app/templates/test_data.html b/edc-web/app/templates/test_data.html index 11433f7..44a9ca7 100644 --- a/edc-web/app/templates/test_data.html +++ b/edc-web/app/templates/test_data.html @@ -4,19 +4,17 @@ {% block content %}

测试信息

+
+ + + +
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
ID设备编码DG430地址设备型号类型测试模式数据来源是否完成故障信息继电器峰峰值(V)开始频率(Hz)进入频率(Hz)离开频率(Hz)进入距离(mm)离开距离(mm)进入速度(m/s)离开速度(m/s)剩余次数当前距离(mm)速度(dm/s)最近距离(mm)最远距离(mm)时间
@@ -63,5 +34,23 @@ {% endblock %} {% block scripts %} + {% endblock %}