feat: 分类页骨架屏优化
This commit is contained in:
@@ -24,13 +24,18 @@ const DIFFICULTY_LABELS: Record<number, string> = {
|
||||
4: '挑战',
|
||||
};
|
||||
|
||||
const SIDEBAR_TABS: CategoryTab[] = CATEGORY_LIST_WITH_ALL.map(
|
||||
({ id, name, icon }) => ({
|
||||
id,
|
||||
name,
|
||||
icon,
|
||||
}),
|
||||
);
|
||||
const DYNAMIC_TABS: CategoryTab[] = [
|
||||
{ id: 'hot', name: '热门推荐', icon: '🔥' },
|
||||
{ id: 'top-downloads', name: '下载最多', icon: '📥' },
|
||||
];
|
||||
|
||||
const SIDEBAR_TABS: CategoryTab[] = [
|
||||
{ id: 'all', name: '全部', icon: '📋' },
|
||||
...DYNAMIC_TABS,
|
||||
...CATEGORY_LIST_WITH_ALL.filter((c) => c.id !== 'all').map(
|
||||
({ id, name, icon }) => ({ id, name, icon }),
|
||||
),
|
||||
];
|
||||
|
||||
const TAB_BAR_PATHS = new Set([
|
||||
'/pages/home/home',
|
||||
@@ -119,9 +124,23 @@ function buildAllItems(): CategoryItem[] {
|
||||
return sortWorksheets(items);
|
||||
}
|
||||
|
||||
const DYNAMIC_LIMIT = 12;
|
||||
|
||||
function buildHotItems(): CategoryItem[] {
|
||||
const all = buildAllItems();
|
||||
return [...all].sort((a, b) => (b.likes || 0) - (a.likes || 0)).slice(0, DYNAMIC_LIMIT);
|
||||
}
|
||||
|
||||
function buildTopDownloadsItems(): CategoryItem[] {
|
||||
const all = buildAllItems();
|
||||
return [...all].sort((a, b) => (b.downloads || 0) - (a.downloads || 0)).slice(0, DYNAMIC_LIMIT);
|
||||
}
|
||||
|
||||
function getItemsByCategory(categoryId: string): CategoryItem[] {
|
||||
if (!_categoryData) return [];
|
||||
if (categoryId === 'all') return buildAllItems();
|
||||
if (categoryId === 'hot') return buildHotItems();
|
||||
if (categoryId === 'top-downloads') return buildTopDownloadsItems();
|
||||
const group = _categoryData.categories.find((c) => c.id === categoryId);
|
||||
if (!group) return [];
|
||||
return group.items.map((item) => ({ ...item }));
|
||||
|
||||
Reference in New Issue
Block a user