fix: 移除重复的"全部"按钮,只更新样式
- HTML中已有"全部"按钮,不需要重复添加 - renderSubcategoryFilters只渲染子类别按钮 - 同时更新"全部"按钮的选中/未选中样式 - 选中时蓝色背景白色文字,未选中时白色背景灰色文字
This commit is contained in:
@@ -542,15 +542,23 @@
|
||||
else if (categoryId === 'cpus') currentFilter = cpuSubcategoryFilter;
|
||||
else if (categoryId === dynamicCategoryId) currentFilter = dynamicSubcategoryFilter;
|
||||
|
||||
container.innerHTML = `
|
||||
<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'}">
|
||||
<i class="ri-apps-line mr-1"></i>全部
|
||||
</button>
|
||||
` + cat.subcategories.map(sub => `
|
||||
// 只渲染子类别按钮,不渲染"全部"按钮(HTML里已有)
|
||||
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'}">
|
||||
<i class="${sub.icon || 'ri-folder-line'} mr-1"></i>${sub.name}
|
||||
</button>
|
||||
`).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 = {
|
||||
|
||||
Reference in New Issue
Block a user