- {{ cat.icon }} - {{ cat.name }} - {{ linksInCat(cat.id).length }} - - {{ collapsedCats.has(cat.id) ? '展开' : '收起' }} + {{ parent.icon }} + {{ parent.name }} + + {{ collapsedParents.has(parent.id) ? '展开' : '收起' }}
-
@@ -99,6 +128,7 @@ const search = ref('') const filteredLinks = ref([]) const searchTimer = ref>() const collapsedCats = ref>(new Set()) +const collapsedParents = ref>(new Set()) const showSuggestions = ref(false) const suggestions = ref([]) let suggestTimer: ReturnType @@ -109,9 +139,31 @@ function toggleCat(id: number) { collapsedCats.value = s } +function toggleParent(id: number) { + const s = new Set(collapsedParents.value) + if (s.has(id)) s.delete(id); else s.add(id) + collapsedParents.value = s +} + +// 构建分类树 +const categoryTree = computed(() => { + const cats = data.categories + const children = new Map() + const roots: any[] = [] + for (const c of cats) { + if (c.parent_id) { + if (!children.has(c.parent_id)) children.set(c.parent_id, []) + children.get(c.parent_id)!.push(c) + } else { + roots.push(c) + } + } + return roots.map(p => ({ ...p, children: children.get(p.id) || [] })) +}) + const filteredCategories = computed(() => { - return data.categories.filter((cat: any) => - linksInCat(cat.id).length > 0 + return categoryTree.value.filter((p: any) => + linksInCat(p.id).length > 0 || p.children.some((c: any) => linksInCat(c.id).length > 0) ) }) @@ -314,6 +366,40 @@ loadData() .collapse-btn:hover { background: rgba(99,102,241,0.1); } } +.sub-category { + margin-left: 20px; + margin-bottom: 20px; +} + +.sub-category-header { + display: flex; + align-items: center; + gap: 10px; + margin-bottom: 12px; + padding-bottom: 6px; + border-bottom: 1px solid #e5e7eb; + + .icon { font-size: 16px; } + .name { font-size: 15px; font-weight: 500; color: #555; } + .count { + font-size: 11px; + color: #888; + background: #f0f0f0; + padding: 1px 8px; + border-radius: 10px; + } + .collapse-btn { + margin-left: auto; + font-size: 12px; + color: #6366f1; + cursor: pointer; + padding: 2px 8px; + border-radius: 4px; + user-select: none; + } + .collapse-btn:hover { background: rgba(99,102,241,0.1); } +} + .links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); diff --git a/frontend/src/views/admin/Categories.vue b/frontend/src/views/admin/Categories.vue index 74df9af..24f7599 100644 --- a/frontend/src/views/admin/Categories.vue +++ b/frontend/src/views/admin/Categories.vue @@ -12,6 +12,11 @@ + + +