mirror of
https://github.com/atdunbg/Nekosonic-Music.git
synced 2026-08-06 03:44:18 +08:00
- 详情页统一 DetailLayout 组件(常驻头部 + 独立滚动 + 紧凑态动画) - 歌曲/评论 tab 切换(懒加载 + 保活),专辑模糊搜索 - 皮肤系统 skins.ts(19 语义色 + 14 预设 + 自定义皮肤 + 壁纸) - 设置页皮肤模块(外观/主题色/皮肤编辑器/壁纸选择) - 可折叠侧边栏 + TopBar + 折叠态歌单浮层(高度不越 PlayerBar) - 首页扩展至 6 区块 + 通用卡片组件 + 虚拟歌曲列表 - audio.rs 拆为 8 模块,api.ts 拆为 api/ 目录,player store 拆为 4 store - 修复播放竞态、seek 暂停、评论提前加载、紧凑态卡死等
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref, watch } from 'vue';
|
|
import type { Song } from '../types/song';
|
|
|
|
const RECENT_KEY = 'recent_local';
|
|
const MAX_RECENT = 200;
|
|
|
|
function loadRecentLocal(): Song[] {
|
|
try {
|
|
const raw = localStorage.getItem(RECENT_KEY);
|
|
if (raw) return JSON.parse(raw);
|
|
} catch { /* 忽略 */ }
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 最近播放 store
|
|
*
|
|
* 管理最近播放过的歌曲列表,持久化到 localStorage。
|
|
*/
|
|
export const useRecentStore = defineStore('recent', () => {
|
|
/** 最近播放的歌曲列表(按时间倒序) */
|
|
const recentLocal = ref<Song[]>(loadRecentLocal());
|
|
|
|
let persistTimer: ReturnType<typeof setTimeout> | undefined;
|
|
|
|
/** 添加一首歌到最近播放列表(去重并放到最前) */
|
|
function addRecent(song: Song) {
|
|
recentLocal.value = recentLocal.value.filter(s => s.id !== song.id);
|
|
recentLocal.value.unshift(song);
|
|
if (recentLocal.value.length > MAX_RECENT) {
|
|
recentLocal.value = recentLocal.value.slice(0, MAX_RECENT);
|
|
}
|
|
}
|
|
|
|
watch(recentLocal, (val) => {
|
|
clearTimeout(persistTimer);
|
|
persistTimer = setTimeout(() => {
|
|
localStorage.setItem(RECENT_KEY, JSON.stringify(val));
|
|
}, 2000);
|
|
}, { deep: true });
|
|
|
|
return {
|
|
recentLocal,
|
|
addRecent,
|
|
};
|
|
});
|