feat: split config page into sub-tabs (MP / PLC)

This commit is contained in:
zlm committed 2026-06-10 08:56:43 +08:00
1 parent 6860e52579
commit 33d5442941
1 file changed
+44 -6
+44 -6
View File
@@ -59,18 +59,57 @@ qInput.addEventListener('keydown', e => { if (e.key === 'Enter') doQuery() })
/* ===== Config Page ===== */ /* ===== Config Page ===== */
let configLoaded = false let configLoaded = false
let plcTabLoaded = false
let activeSubTab: 'mp' | 'plc' = 'mp'
async function loadConfig() { async function loadConfig() {
configLoaded = true configLoaded = true
plcTabLoaded = false
activeSubTab = 'mp'
const el = document.getElementById('page-config')!
el.innerHTML = `
<div class="flex gap-1 mb-4 border-b border-gray-200 pb-0">
<button id="sub-tab-mp" class="sub-tab active px-4 py-2 text-sm font-medium border-b-2 border-indigo-600 text-indigo-700">检测点配置</button>
<button id="sub-tab-plc" class="sub-tab px-4 py-2 text-sm font-medium text-gray-500 border-b-2 border-transparent hover:text-gray-700">PLC配置</button>
</div>
<div id="mp-panel"></div>
<div id="plc-panel" class="hidden"></div>`
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()]) const [plcs, mps, stations] = await Promise.all([api.getPLCs(), api.getMPs(), api.getStations()])
renderMPTable(mps) renderMPTable(mps)
if (activeSubTab === 'plc') {
renderPLCTable(plcs, stations, mps) 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[]) { function renderMPTable(mps: MP[]) {
const el = document.getElementById('mp-list')! const el = document.getElementById('mp-panel')!
el.innerHTML = `<h3 class="text-lg font-semibold text-gray-800 mb-3">检测点</h3> el.innerHTML = `<div class="overflow-x-auto">
<div class="overflow-x-auto">
<table class="w-full text-sm"> <table class="w-full text-sm">
<thead><tr class="bg-gray-50 text-gray-500"> <thead><tr class="bg-gray-50 text-gray-500">
<th class="text-left p-2">名称</th><th class="text-left p-2">单位</th><th class="p-2"></th> <th class="text-left p-2">名称</th><th class="text-left p-2">单位</th><th class="p-2"></th>
@@ -114,9 +153,8 @@ function renderMPTable(mps: MP[]) {
} }
function renderPLCTable(plcs: PLC[], stations: Station[], mps: MP[]) { function renderPLCTable(plcs: PLC[], stations: Station[], mps: MP[]) {
const el = document.getElementById('plc-list')! const el = document.getElementById('plc-panel')!
el.innerHTML = `<h3 class="text-lg font-semibold text-gray-800 mb-3">PLC</h3> el.innerHTML = `<div class="overflow-x-auto">
<div class="overflow-x-auto">
<table class="w-full text-sm"> <table class="w-full text-sm">
<thead><tr class="bg-gray-50 text-gray-500"> <thead><tr class="bg-gray-50 text-gray-500">
<th class="text-left p-2">名称</th><th class="text-left p-2">IP</th><th class="text-left p-2">DB</th><th class="p-2"></th> <th class="text-left p-2">名称</th><th class="text-left p-2">IP</th><th class="text-left p-2">DB</th><th class="p-2"></th>