fix: 排行榜日期比较鲁棒性 + 下载计数请求取消

- ranking.ts: topByUpdate 改用时戳数字比较,兼容后端不一致的日期格式
  (如 2026-08-10 / 2026/08/10 / 带时分秒),无效日期兜底为 0 避免 NaN 乱序
- App.vue: fetchDownloadCount 的 fetch 加 rootAbortController.signal,
  组件卸载时可取消未完成请求,避免内存泄漏

(注: 这两个真实缺陷由 PR 审查在错误 diff 下点名,本提交独立于 Erotica PR)
This commit is contained in:
xiyidaiwa
2026-08-10 23:59:15 +08:00
parent 102ac72d89
commit 44fa822146
2 changed files with 9 additions and 1 deletions
+8 -1
View File
@@ -70,9 +70,16 @@ export function topByUpdate(
origin: AppOrigin,
topN: number = TOP_N,
): App[] {
// 按 update 字段倒序;后端日期格式可能不严格一致(如 2026-08-10 / 2026/08/10 /
// 带时分秒),用时间戳数字比较比 localeCompare 字符串比较更鲁棒。
// 无效日期 getTime() 为 NaN,统一按 0 处理,避免 NaN 参与比较导致乱序。
const toTime = (s: string | undefined): number => {
const t = new Date(s || "").getTime();
return Number.isFinite(t) ? t : 0;
};
return apps
.filter((a) => a.origin === origin && a.update)
.sort((a, b) => (b.update || "").localeCompare(a.update || ""))
.sort((a, b) => toTime(b.update) - toTime(a.update))
.slice(0, topN);
}