From 33d5442941e2278cafa3dd3b63f85be7c1c720f4 Mon Sep 17 00:00:00 2001 From: zlm Date: Wed, 10 Jun 2026 08:56:43 +0800 Subject: [PATCH] feat: split config page into sub-tabs (MP / PLC) --- project/web/src/main.ts | 52 +++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/project/web/src/main.ts b/project/web/src/main.ts index bfbc326..62a87d2 100644 --- a/project/web/src/main.ts +++ b/project/web/src/main.ts @@ -59,18 +59,57 @@ qInput.addEventListener('keydown', e => { if (e.key === 'Enter') doQuery() }) /* ===== Config Page ===== */ let configLoaded = false +let plcTabLoaded = false +let activeSubTab: 'mp' | 'plc' = 'mp' async function loadConfig() { configLoaded = true + plcTabLoaded = false + activeSubTab = 'mp' + const el = document.getElementById('page-config')! + el.innerHTML = ` +
+ + +
+
+ ` + + document.getElementById('sub-tab-mp')!.addEventListener('click', () => switchTab('mp')) + document.getElementById('sub-tab-plc')!.addEventListener('click', () => switchTab('plc')) + const [plcs, mps, stations] = await Promise.all([api.getPLCs(), api.getMPs(), api.getStations()]) renderMPTable(mps) - renderPLCTable(plcs, stations, mps) + if (activeSubTab === 'plc') { + renderPLCTable(plcs, stations, mps) + switchTab('plc') + } +} + +function switchTab(tab: 'mp' | 'plc') { + activeSubTab = tab + document.querySelectorAll('.sub-tab').forEach(b => { + b.classList.remove('border-indigo-600', 'text-indigo-700') + b.classList.add('border-transparent', 'text-gray-500') + }) + const btn = document.getElementById(`sub-tab-${tab}`)! + btn.classList.remove('border-transparent', 'text-gray-500') + btn.classList.add('border-indigo-600', 'text-indigo-700') + + document.getElementById('mp-panel')!.classList.toggle('hidden', tab !== 'mp') + document.getElementById('plc-panel')!.classList.toggle('hidden', tab !== 'plc') + + if (tab === 'plc' && !plcTabLoaded) { + plcTabLoaded = true + Promise.all([api.getPLCs(), api.getMPs(), api.getStations()]).then(([plcs, mps, stations]) => { + renderPLCTable(plcs, stations, mps) + }) + } } function renderMPTable(mps: MP[]) { - const el = document.getElementById('mp-list')! - el.innerHTML = `

检测点

-
+ const el = document.getElementById('mp-panel')! + el.innerHTML = `
@@ -114,9 +153,8 @@ function renderMPTable(mps: MP[]) { } function renderPLCTable(plcs: PLC[], stations: Station[], mps: MP[]) { - const el = document.getElementById('plc-list')! - el.innerHTML = `

PLC

-
+ const el = document.getElementById('plc-panel')! + el.innerHTML = `
名称单位
名称IPDB