feat: 增加收藏、下载种子数据功能
This commit is contained in:
@@ -49,6 +49,38 @@ const TAB_BAR_PATHS = new Set([
|
||||
// Page-level mutable state (shared across methods)
|
||||
let _categoryData: CategoryDataset | null = null;
|
||||
|
||||
// --- 以下仅为本地调试:拉取分类数据后查看各 worksheet 的 downloads / likes,非业务逻辑 ---
|
||||
|
||||
function debugLogWorksheetStatsAfterCategoryLoad(
|
||||
source:
|
||||
| { kind: 'cloud'; rows: Record<string, any>[] }
|
||||
| { kind: 'static'; data: CategoryDataset },
|
||||
) {
|
||||
let map: Record<string, { downloads: number; likes: number }> = {};
|
||||
if (source.kind === 'cloud') {
|
||||
for (const raw of source.rows) {
|
||||
const id = String(raw._id || '').trim();
|
||||
if (!id) continue;
|
||||
map[id] = {
|
||||
downloads: Number(raw.downloads) || 0,
|
||||
likes: Number(raw.likes) || 0,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
for (const group of source.data.categories) {
|
||||
for (const item of group.items) {
|
||||
map[item.id] = {
|
||||
downloads: Number(item.downloads) || 0,
|
||||
likes: Number(item.likes) || 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('worksheetStatsById', JSON.stringify(map, null, 2));
|
||||
}
|
||||
|
||||
// --- 调试块结束 ---
|
||||
|
||||
/** 将云端 worksheet 原始数据转换为 CategoryItem */
|
||||
function toDisplayItem(raw: Record<string, any>): CategoryItem {
|
||||
const difficulty = (Number(raw.difficulty) || 2) as 1 | 2 | 3 | 4;
|
||||
@@ -129,12 +161,16 @@ 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);
|
||||
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);
|
||||
return [...all]
|
||||
.sort((a, b) => (b.downloads || 0) - (a.downloads || 0))
|
||||
.slice(0, DYNAMIC_LIMIT);
|
||||
}
|
||||
|
||||
function getItemsByCategory(categoryId: string): CategoryItem[] {
|
||||
@@ -203,9 +239,15 @@ Page({
|
||||
const result = (res?.result as any) || {};
|
||||
if (!result.success) throw new Error(result.message || '查询失败');
|
||||
|
||||
_categoryData = buildCategoryDataFromCloud(result.data || []);
|
||||
const rows = result.data || [];
|
||||
_categoryData = buildCategoryDataFromCloud(rows);
|
||||
debugLogWorksheetStatsAfterCategoryLoad({ kind: 'cloud', rows });
|
||||
} catch {
|
||||
_categoryData = CATEGORY_DATA;
|
||||
debugLogWorksheetStatsAfterCategoryLoad({
|
||||
kind: 'static',
|
||||
data: CATEGORY_DATA,
|
||||
});
|
||||
}
|
||||
|
||||
const activeId =
|
||||
|
||||
Reference in New Issue
Block a user