From 080e00b6c67fd3aa1698468209bcbd48f1ccf2b4 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Wed, 29 Apr 2026 22:58:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=90=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E7=AD=9B=E9=80=89=E6=8C=89=E9=92=AE=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 用containerId判断currentFilter,而非categoryId - 用previousElementSibling找全部按钮,而非parent.querySelector - 确保点击子类别后样式正确切换 - 全部按钮和子类别按钮互斥选中状态 --- templates/admin.html | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/templates/admin.html b/templates/admin.html index d07eeb2..3c87311 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -535,27 +535,26 @@ return; } - // 获取当前筛选值 + // 获取当前筛选值 - 根据容器ID判断 let currentFilter = ''; - if (categoryId === 'ai-models') currentFilter = modelSubcategoryFilter; - else if (categoryId === 'gpus') currentFilter = gpuSubcategoryFilter; - else if (categoryId === 'cpus') currentFilter = cpuSubcategoryFilter; - else if (categoryId === dynamicCategoryId) currentFilter = dynamicSubcategoryFilter; + if (containerId === 'model-subcategory-filters') currentFilter = modelSubcategoryFilter; + else if (containerId === 'gpu-subcategory-filters') currentFilter = gpuSubcategoryFilter; + else if (containerId === 'cpu-subcategory-filters') currentFilter = cpuSubcategoryFilter; + else if (containerId === 'dynamic-subcategory-filters') currentFilter = dynamicSubcategoryFilter; - // 只渲染子类别按钮,不渲染"全部"按钮(HTML里已有) + // 渲染子类别按钮 container.innerHTML = cat.subcategories.map(sub => ` `).join(''); - // 更新"全部"按钮的样式 - const parent = container.parentElement; - if (parent) { - const allBtn = parent.querySelector('button:first-of-type'); - if (allBtn && currentFilter === '') { + // 更新"全部"按钮的样式 - 它是容器前面的那个按钮 + const allBtn = container.previousElementSibling; + if (allBtn && allBtn.tagName === 'BUTTON') { + if (currentFilter === '') { allBtn.className = 'px-3 py-1 rounded text-sm bg-indigo-600 text-white'; - } else if (allBtn) { + } else { allBtn.className = 'px-3 py-1 rounded text-sm bg-white border text-gray-600 hover:bg-gray-100'; } }