fix(ui): 修复内存泄漏、搜索竞态、播客时长及颜色/指令边界问题

- MusicFullMobile: 卸载清理睡眠定时器 interval;getTextColors 补上调用括号
- loading 指令: 改为每元素独立实例、卸载真正销毁、class 用 classList,避免多个 v-loading 争用单例
- lyric/index: 歌词窗口 receive-lyric IPC 监听卸载时解绑
- SearchBar/SearchResult/list: 三处异步搜索加竞态守卫,丢弃过期返回避免旧结果覆盖新结果
- linearColor: 0 尺寸图片 NaN 兜底、渐变色标越界兜底
- utils/secondToMinute: 时长 >=1 小时进位为 h:mm:ss(修复播客时长显示 78:34)
This commit is contained in:
alger
2026-07-05 19:53:50 +08:00
parent 4734c4d566
commit c709daec38
8 changed files with 88 additions and 38 deletions
+10 -1
View File
@@ -115,6 +115,10 @@ const getAverageColor = (data: Uint8ClampedArray): number[] => {
b += data[i + 2];
count++;
}
// 0 尺寸图片(count 为 0)会得到 NaN,回退为中性灰避免生成 rgb(NaN,...)
if (count === 0) {
return [128, 128, 128];
}
return [Math.round(r / count), Math.round(g / count), Math.round(b / count)];
};
@@ -306,8 +310,13 @@ export const createGradientString = (
colors: { r: number; g: number; b: number }[],
percentages = [0, 50, 100]
) => {
const count = colors.length;
return `linear-gradient(to bottom, ${colors
.map((color, i) => `rgb(${color.r}, ${color.g}, ${color.b}) ${percentages[i]}%`)
.map((color, i) => {
// 当颜色数量与传入的 percentages 不一致时,按索引均匀分布,避免出现 undefined%
const percent = percentages[i] ?? (count > 1 ? Math.round((i / (count - 1)) * 100) : 0);
return `rgb(${color.r}, ${color.g}, ${color.b}) ${percent}%`;
})
.join(', ')})`;
};