1 Commits

Author SHA1 Message Date
080e00b6c6 fix: 修复子类别筛选按钮点击无效问题
- 用containerId判断currentFilter,而非categoryId
- 用previousElementSibling找全部按钮,而非parent.querySelector
- 确保点击子类别后样式正确切换
- 全部按钮和子类别按钮互斥选中状态
2026-04-29 22:58:44 +08:00

View File

@@ -535,27 +535,26 @@
return; return;
} }
// 获取当前筛选值 // 获取当前筛选值 - 根据容器ID判断
let currentFilter = ''; let currentFilter = '';
if (categoryId === 'ai-models') currentFilter = modelSubcategoryFilter; if (containerId === 'model-subcategory-filters') currentFilter = modelSubcategoryFilter;
else if (categoryId === 'gpus') currentFilter = gpuSubcategoryFilter; else if (containerId === 'gpu-subcategory-filters') currentFilter = gpuSubcategoryFilter;
else if (categoryId === 'cpus') currentFilter = cpuSubcategoryFilter; else if (containerId === 'cpu-subcategory-filters') currentFilter = cpuSubcategoryFilter;
else if (categoryId === dynamicCategoryId) currentFilter = dynamicSubcategoryFilter; else if (containerId === 'dynamic-subcategory-filters') currentFilter = dynamicSubcategoryFilter;
// 渲染子类别按钮,不渲染"全部"按钮HTML里已有 // 渲染子类别按钮
container.innerHTML = cat.subcategories.map(sub => ` container.innerHTML = cat.subcategories.map(sub => `
<button onclick="${filterFunction}('${sub.id}')" class="px-3 py-1 rounded text-sm ${currentFilter === sub.id ? 'bg-indigo-600 text-white' : 'bg-white border text-gray-600 hover:bg-gray-100'}"> <button onclick="${filterFunction}('${sub.id}')" class="px-3 py-1 rounded text-sm ${currentFilter === sub.id ? 'bg-indigo-600 text-white' : 'bg-white border text-gray-600 hover:bg-gray-100'}">
<i class="${sub.icon || 'ri-folder-line'} mr-1"></i>${sub.name} <i class="${sub.icon || 'ri-folder-line'} mr-1"></i>${sub.name}
</button> </button>
`).join(''); `).join('');
// 更新"全部"按钮的样式 // 更新"全部"按钮的样式 - 它是容器前面的那个按钮
const parent = container.parentElement; const allBtn = container.previousElementSibling;
if (parent) { if (allBtn && allBtn.tagName === 'BUTTON') {
const allBtn = parent.querySelector('button:first-of-type'); if (currentFilter === '') {
if (allBtn && currentFilter === '') {
allBtn.className = 'px-3 py-1 rounded text-sm bg-indigo-600 text-white'; 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'; allBtn.className = 'px-3 py-1 rounded text-sm bg-white border text-gray-600 hover:bg-gray-100';
} }
} }