fix: 移除重复的"全部"按钮,只更新样式

- HTML中已有"全部"按钮,不需要重复添加
- renderSubcategoryFilters只渲染子类别按钮
- 同时更新"全部"按钮的选中/未选中样式
- 选中时蓝色背景白色文字,未选中时白色背景灰色文字
This commit is contained in:
2026-04-29 22:51:16 +08:00
parent 2dd45854c1
commit 92fd52ce47

View File

@@ -542,15 +542,23 @@
else if (categoryId === 'cpus') currentFilter = cpuSubcategoryFilter; else if (categoryId === 'cpus') currentFilter = cpuSubcategoryFilter;
else if (categoryId === dynamicCategoryId) currentFilter = dynamicSubcategoryFilter; else if (categoryId === dynamicCategoryId) currentFilter = dynamicSubcategoryFilter;
container.innerHTML = ` // 只渲染子类别按钮,不渲染"全部"按钮HTML里已有
<button onclick="${filterFunction}('')" class="px-3 py-1 rounded text-sm ${currentFilter === '' ? 'bg-indigo-600 text-white' : 'bg-white border text-gray-600 hover:bg-gray-100'}"> container.innerHTML = cat.subcategories.map(sub => `
<i class="ri-apps-line mr-1"></i>全部
</button>
` + 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;
if (parent) {
const allBtn = parent.querySelector('button:first-of-type');
if (allBtn && currentFilter === '') {
allBtn.className = 'px-3 py-1 rounded text-sm bg-indigo-600 text-white';
} else if (allBtn) {
allBtn.className = 'px-3 py-1 rounded text-sm bg-white border text-gray-600 hover:bg-gray-100';
}
}
} }
const colorMap = { const colorMap = {