709 lines
29 KiB
Vue
709 lines
29 KiB
Vue
<script setup lang="ts">
|
||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||
import { toast } from 'vue-sonner'
|
||
import {
|
||
Cloud,
|
||
FolderOpen,
|
||
HardDrive,
|
||
ListMusic,
|
||
ListPlus,
|
||
Loader2,
|
||
Music2,
|
||
Pencil,
|
||
Play,
|
||
Plus,
|
||
RefreshCw,
|
||
Search,
|
||
Trash2
|
||
} from '@lucide/vue'
|
||
import { useFeiniuStore, type PlayableItem } from '@/stores/feiniuStore'
|
||
import TrackItem from './TrackItem.vue'
|
||
import PlaylistEditorDialog from './PlaylistEditorDialog.vue'
|
||
import { Button } from '@/components/ui/button'
|
||
import { Input } from '@/components/ui/input'
|
||
import { Empty, EmptyDescription, EmptyMedia, EmptyTitle } from '@/components/ui/empty'
|
||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||
import {
|
||
Dialog,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle
|
||
} from '@/components/ui/dialog'
|
||
|
||
const store = useFeiniuStore()
|
||
|
||
/** 曲库视图:飞牛 / 本地 / 歌单 */
|
||
type LibraryView = 'feiniu' | 'local' | 'playlists'
|
||
const view = ref<LibraryView>('feiniu')
|
||
|
||
const needsLogin = computed(() => !store.config.loggedIn && !store.activeConn)
|
||
|
||
const sourceNav = computed(() => [
|
||
{ value: 'feiniu' as const, label: '飞牛曲库', icon: Cloud, count: store.total || store.tracks.length },
|
||
{ value: 'local' as const, label: '本地曲库', icon: HardDrive, count: store.localTracks.length },
|
||
{ value: 'playlists' as const, label: '我的歌单', icon: ListMusic, count: store.playlists.length }
|
||
])
|
||
|
||
// ===== 曲库搜索:飞牛 track/list 接口**不支持**关键字过滤(实测忽略该参数),
|
||
// 因此搜索框只做**本地筛选**(歌名/歌手/专辑);输入时自动补齐剩余分页,
|
||
// 保证筛选覆盖全库而不是已加载的前几页。两个视图(飞牛/本地)共用同一个关键字。
|
||
let searchTimer: ReturnType<typeof setTimeout> | undefined
|
||
let searchSeq = 0
|
||
/** 全量补齐进行中:输入防抖与视图切换可能同时触发,用标志位避免并发重复翻页 */
|
||
let fillingAll = false
|
||
/** 本组件已完成挂载初始化:此前不触发补齐,避免与 ensureTracksFresh 的首页请求并发 */
|
||
let mountedReady = false
|
||
|
||
/**
|
||
* 补齐飞牛曲库的剩余分页。
|
||
* 飞牛 `track/list` 不支持关键字过滤,搜索框只做**本地筛选**,
|
||
* 因此必须先把剩余分页拉完,否则只能在「已加载的前几页」里找,
|
||
* 表现为「曲库里明明有这首歌却搜不到」。
|
||
*
|
||
* 必须避让任何在途的分页请求:补齐是「按页追加」,而首页刷新是
|
||
* `tracks = mapped`(整体替换);两者交错会把刚追加的页直接抹掉,造成曲目缺口。
|
||
*/
|
||
async function fillRemainingFeiniu() {
|
||
if (fillingAll || !store.hasMoreTracks) return
|
||
if (store.loading || store.refreshing || store.loadingMore) return
|
||
fillingAll = true
|
||
const seq = ++searchSeq
|
||
try {
|
||
await store.loadRemainingTracks()
|
||
} catch (e) {
|
||
if (seq === searchSeq) toast.error(String(e))
|
||
} finally {
|
||
fillingAll = false
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 搜索框输入:仅飞牛曲库需要补齐分页(本地曲库是已全量在内存的数组,输入即筛)。
|
||
* 两个视图共用同一个关键字,但按各自的数据来源决定是否发请求。
|
||
*/
|
||
function onSearchInput() {
|
||
clearTimeout(searchTimer)
|
||
searchTimer = setTimeout(() => {
|
||
if (view.value !== 'feiniu') return
|
||
void fillRemainingFeiniu()
|
||
}, 300)
|
||
}
|
||
|
||
const isFiltering = computed(() => !!filterKeyword.value)
|
||
|
||
/** 关键字规范化:全角空格→半角、压缩连续空白、转小写(中文不受影响) */
|
||
function normalizeKeyword(s: string) {
|
||
return s
|
||
.replace(/\u3000/g, ' ')
|
||
.trim()
|
||
.replace(/\s+/g, ' ')
|
||
.toLowerCase()
|
||
}
|
||
|
||
const filterKeyword = computed(() => normalizeKeyword(store.searchKeyword))
|
||
|
||
/**
|
||
* 保证飞牛曲库的筛选覆盖全库。
|
||
* 关键字在两个视图之间共享,所以「带着关键字从本地切回飞牛曲库」时
|
||
* 也必须补齐分页,否则只会在已加载的前几页里筛,结果数明显偏小。
|
||
* 挂载阶段由 onMounted 的串行链负责,此处只在挂载后响应视图 / 关键字变化。
|
||
*/
|
||
function ensureFeiniuFilterCoverage() {
|
||
if (!mountedReady) return
|
||
if (view.value !== 'feiniu' || !filterKeyword.value) return
|
||
void fillRemainingFeiniu()
|
||
}
|
||
watch([view, filterKeyword], ensureFeiniuFilterCoverage)
|
||
|
||
function matchesKeyword(t: PlayableItem, kw: string) {
|
||
// 曲库条目(PlayableItem)的字段是 title=歌名 / artistNames=歌手 / album=专辑。
|
||
// 千万不要用 musicdl 的 songName/singers——那是「发现音乐」的结构,用错字段
|
||
// 会导致 haystack 只剩专辑,表现为"歌名/歌手都搜不到"。
|
||
return `${t.title ?? ''} ${t.artistNames ?? ''} ${t.album ?? ''}`.toLowerCase().includes(kw)
|
||
}
|
||
|
||
const filteredTracks = computed(() => {
|
||
const kw = filterKeyword.value
|
||
if (!kw) return store.tracks
|
||
return store.tracks.filter((t) => matchesKeyword(t, kw))
|
||
})
|
||
|
||
const filteredLocalTracks = computed(() => {
|
||
const kw = filterKeyword.value
|
||
if (!kw) return store.localTracks
|
||
return store.localTracks.filter((t) => matchesKeyword(t, kw))
|
||
})
|
||
|
||
function refreshFeiniu() {
|
||
store.loadTracks(1).catch((e) => toast.error(String(e)))
|
||
}
|
||
function refreshLocal() {
|
||
store.scanLocal().catch((e) => toast.error(String(e)))
|
||
}
|
||
|
||
function playFeiniu() {
|
||
// 有筛选时只播放筛选结果
|
||
if (filteredTracks.value.length) store.playQueue(filteredTracks.value, 0)
|
||
}
|
||
function playLocal() {
|
||
if (filteredLocalTracks.value.length) store.playQueue(filteredLocalTracks.value, 0)
|
||
}
|
||
function playActivePlaylist() {
|
||
if (activePlaylist.value?.items.length) store.playQueue(activePlaylist.value.items, 0)
|
||
}
|
||
|
||
// ===== 列表增量渲染 + 滚动加载更多 =====
|
||
/**
|
||
* 一次挂载多少行。曲库没有虚拟滚动,补齐分页后行数可达 MAX_QUEUE_TRACKS(4000),
|
||
* 一次性挂载 4000 个 TrackItem(每个含封面 <img> 与下拉菜单)会明显卡顿,
|
||
* 因此改成「先渲染一屏,滚到底再追加」(与发现音乐页、播放队列同一策略)。
|
||
*/
|
||
const LIST_STEP = 200
|
||
const renderLimit = ref(LIST_STEP)
|
||
|
||
/** 当前视图正在展示的完整列表 */
|
||
const activeList = computed<PlayableItem[]>(() => {
|
||
if (view.value === 'feiniu') return filteredTracks.value
|
||
if (view.value === 'local') return filteredLocalTracks.value
|
||
return activePlaylist.value?.items ?? []
|
||
})
|
||
const visibleFeiniu = computed(() => filteredTracks.value.slice(0, renderLimit.value))
|
||
const visibleLocal = computed(() => filteredLocalTracks.value.slice(0, renderLimit.value))
|
||
const visiblePlaylistItems = computed(() => (activePlaylist.value?.items ?? []).slice(0, renderLimit.value))
|
||
/** 还有没渲染出来的行 */
|
||
const hasMoreRows = computed(() => renderLimit.value < activeList.value.length)
|
||
/** 实际渲染出来的行数(提示文案用) */
|
||
const shownRows = computed(() => Math.min(renderLimit.value, activeList.value.length))
|
||
/** 哨兵是否显示:要么还有行没渲染,要么飞牛曲库还有分页没拉 */
|
||
const showSentinel = computed(
|
||
() => hasMoreRows.value || (view.value === 'feiniu' && store.hasMoreTracks)
|
||
)
|
||
|
||
// 换视图 / 换关键字 / 换歌单时把渲染窗口收回一屏(监听放在 activePlaylistId 声明之后)
|
||
|
||
const loadMoreRef = ref<HTMLElement | null>(null)
|
||
let loadMoreObserver: IntersectionObserver | null = null
|
||
onMounted(() => {
|
||
loadMoreObserver = new IntersectionObserver(
|
||
(entries) => {
|
||
if (!entries.some((e) => e.isIntersecting)) return
|
||
// 先把已加载的数据渲染出来,都渲染完了再向 NAS 要下一页
|
||
if (renderLimit.value < activeList.value.length) {
|
||
renderLimit.value += LIST_STEP
|
||
// 哨兵节点没换位置、仍处于交叉状态时 IntersectionObserver 不会再触发,
|
||
// 需要重新 observe 一次才能连续追加
|
||
nextTick(() => {
|
||
const el = loadMoreRef.value
|
||
if (el && loadMoreObserver) {
|
||
loadMoreObserver.unobserve(el)
|
||
loadMoreObserver.observe(el)
|
||
}
|
||
})
|
||
return
|
||
}
|
||
if (view.value === 'feiniu' && store.hasMoreTracks) store.loadMoreTracks().catch(() => {})
|
||
},
|
||
{ rootMargin: '400px' }
|
||
)
|
||
watch(
|
||
loadMoreRef,
|
||
(el) => {
|
||
if (!loadMoreObserver) return
|
||
loadMoreObserver.disconnect()
|
||
if (el) loadMoreObserver.observe(el)
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
})
|
||
onBeforeUnmount(() => {
|
||
clearTimeout(searchTimer)
|
||
loadMoreObserver?.disconnect()
|
||
})
|
||
|
||
// ===== 歌单 =====
|
||
const activePlaylistId = ref('')
|
||
const activePlaylist = computed(() => store.playlists.find((p) => p.id === activePlaylistId.value) || null)
|
||
|
||
const createOpen = ref(false)
|
||
const newName = ref('')
|
||
const renameOpen = ref(false)
|
||
const renameValue = ref('')
|
||
/** 编辑歌单音乐(勾选加入 / 批量移出) */
|
||
const editorOpen = ref(false)
|
||
|
||
// 切换歌单时关闭编辑器,避免对着已切换的目标继续编辑
|
||
watch(activePlaylistId, () => (editorOpen.value = false))
|
||
|
||
// 换视图 / 换关键字 / 换歌单时把增量渲染窗口收回一屏,避免「切回来看到一屏旧内容」
|
||
watch([view, filterKeyword, activePlaylistId], () => {
|
||
renderLimit.value = LIST_STEP
|
||
})
|
||
|
||
// 切到歌单视图时自动选中第一个
|
||
watch(
|
||
[view, () => store.playlists.length],
|
||
() => {
|
||
if (view.value !== 'playlists') return
|
||
if (activePlaylistId.value && store.playlists.some((p) => p.id === activePlaylistId.value)) return
|
||
activePlaylistId.value = store.playlists[0]?.id ?? ''
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
function createPlaylist() {
|
||
const name = newName.value.trim()
|
||
if (!name) {
|
||
toast.error('请输入歌单名称')
|
||
return
|
||
}
|
||
activePlaylistId.value = store.createPlaylist(name)
|
||
newName.value = ''
|
||
createOpen.value = false
|
||
view.value = 'playlists'
|
||
}
|
||
|
||
function openRename() {
|
||
if (!activePlaylist.value) return
|
||
renameValue.value = activePlaylist.value.name
|
||
renameOpen.value = true
|
||
}
|
||
function confirmRename() {
|
||
const name = renameValue.value.trim()
|
||
if (!name || !activePlaylist.value) return
|
||
store.renamePlaylist(activePlaylist.value.id, name)
|
||
renameOpen.value = false
|
||
}
|
||
|
||
function removePlaylist() {
|
||
if (!activePlaylist.value) return
|
||
store.deletePlaylist(activePlaylist.value.id)
|
||
activePlaylistId.value = ''
|
||
}
|
||
|
||
// ===== 视图与筛选持久化:曲库页每次挂载都会重置本地状态,
|
||
// 而"搜索结果每次都要重新输"是用户明确反馈的问题 → 存 localStorage(跨重启) =====
|
||
const LIB_VIEW_KEY = 'thing.music.library.view'
|
||
const LIB_FILTER_KEY = 'thing.music.library.filter'
|
||
|
||
watch(
|
||
() => [view.value, store.searchKeyword] as const,
|
||
([v, kw]) => {
|
||
try {
|
||
localStorage.setItem(LIB_VIEW_KEY, v)
|
||
localStorage.setItem(LIB_FILTER_KEY, kw ?? '')
|
||
} catch {
|
||
/* 存储不可用时静默 */
|
||
}
|
||
}
|
||
)
|
||
|
||
onMounted(async () => {
|
||
try {
|
||
// 恢复上次的视图与筛选关键字
|
||
const savedView = localStorage.getItem(LIB_VIEW_KEY)
|
||
if (savedView === 'feiniu' || savedView === 'local' || savedView === 'playlists') {
|
||
view.value = savedView
|
||
}
|
||
store.searchKeyword = localStorage.getItem(LIB_FILTER_KEY) ?? ''
|
||
await store.init()
|
||
// 进入曲库页:命中新鲜窗口直接用内存缓存(不请求),过期才后台静默刷新,
|
||
// 避免每次切页都清空列表 + 重新拉取 + 重下封面
|
||
if (store.config.loggedIn) await store.ensureTracksFresh().catch(() => {})
|
||
// 恢复的是本地视图时自动扫描(标签有缓存,通常很快),否则恢复的筛选无内容可筛
|
||
if (view.value === 'local') void store.scanLocal().catch(() => {})
|
||
} finally {
|
||
// 挂载初始化结束才让「视图 / 关键字变化 → 补齐分页」的监听生效,
|
||
// 避免它与上面的首页请求并发(并发会因列表整体替换而丢页);
|
||
// 随后按同一串行顺序补一次,覆盖「启动时已带关键字」的情况
|
||
mountedReady = true
|
||
ensureFeiniuFilterCoverage()
|
||
}
|
||
})
|
||
|
||
/** 表格表头与 TrackItem 行保持同一条网格 */
|
||
const GRID = { gridTemplateColumns: '28px 36px minmax(0,1fr) 74px 28px' }
|
||
|
||
const listEmptyHint = computed(() => {
|
||
if (view.value === 'feiniu') {
|
||
return store.config.loggedIn ? '曲库为空,试试刷新或检查 NAS 曲库目录' : '请先在「设置 → 飞牛音乐连接」登录'
|
||
}
|
||
return '暂无本地音乐,点击「扫描本地曲库」,或到「设置 → 存储与上传」添加本地曲库目录'
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="flex h-full min-h-0">
|
||
<!-- ===== 左:来源导航 ===== -->
|
||
<aside class="flex w-[168px] shrink-0 flex-col border-r">
|
||
<ScrollArea class="min-h-0 flex-1">
|
||
<div class="flex flex-col p-2">
|
||
<p class="px-2 pb-1.5 pt-0.5 text-[11px] font-medium tracking-wide text-muted-foreground">曲库</p>
|
||
|
||
<!-- 来源:选中态与顶部 Tabs 一致(无容器底色,选中项为浮起胶囊) -->
|
||
<div class="flex flex-col gap-0.5">
|
||
<button
|
||
v-for="nav in sourceNav"
|
||
:key="nav.value"
|
||
type="button"
|
||
class="flex h-8 items-center gap-1.5 rounded-md px-2 text-[13px] transition-colors duration-150"
|
||
:class="
|
||
view === nav.value
|
||
? 'bg-background font-medium text-foreground shadow-sm ring-1 ring-border'
|
||
: 'text-muted-foreground hover:bg-accent/60 hover:text-foreground'
|
||
"
|
||
@click="view = nav.value"
|
||
>
|
||
<component :is="nav.icon" class="size-3.5 shrink-0" />
|
||
<span class="min-w-0 flex-1 truncate">{{ nav.label }}</span>
|
||
<!-- 数量始终渲染(无歌曲时显示 0),并固定宽度右对齐,保证数字列竖向对齐 -->
|
||
<span
|
||
class="min-w-[3ch] shrink-0 text-right text-[10.5px] tabular-nums"
|
||
:class="view === nav.value ? 'text-muted-foreground' : 'text-muted-foreground/70'"
|
||
>
|
||
{{ nav.count > 999 ? '999+' : nav.count }}
|
||
</span>
|
||
</button>
|
||
</div>
|
||
|
||
<!-- 歌单列表(选中「我的歌单」时展开) -->
|
||
<Transition name="pl-list">
|
||
<div v-if="view === 'playlists'" class="mt-1.5 ml-1.5 flex flex-col gap-0.5 border-l pl-1.5">
|
||
<button
|
||
v-for="p in store.playlists"
|
||
:key="p.id"
|
||
type="button"
|
||
class="flex h-7 items-center gap-1.5 rounded-md px-2 text-left text-[12.5px] transition-colors duration-150"
|
||
:class="
|
||
activePlaylistId === p.id
|
||
? 'bg-background font-medium text-foreground shadow-sm ring-1 ring-border'
|
||
: 'text-muted-foreground hover:bg-row-hover hover:text-foreground'
|
||
"
|
||
@click="activePlaylistId = p.id"
|
||
>
|
||
<span class="min-w-0 flex-1 truncate">{{ p.name }}</span>
|
||
<span class="min-w-[3ch] shrink-0 text-right text-[10.5px] tabular-nums">
|
||
{{ p.items.length > 999 ? '999+' : p.items.length }}
|
||
</span>
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="flex h-7 items-center gap-1.5 rounded-md px-2 text-[12.5px] text-muted-foreground transition-colors duration-150 hover:bg-row-hover hover:text-foreground"
|
||
@click="createOpen = true"
|
||
>
|
||
<Plus class="size-3.5 shrink-0" />
|
||
<span class="min-w-0 flex-1 truncate">新建歌单</span>
|
||
</button>
|
||
<p v-if="!store.playlists.length" class="px-2 py-1 text-[11.5px] text-muted-foreground">
|
||
还没有歌单
|
||
</p>
|
||
</div>
|
||
</Transition>
|
||
</div>
|
||
</ScrollArea>
|
||
</aside>
|
||
|
||
<!-- ===== 右:内容(key 随来源变化,复用全局 tab-animate 切换动画) ===== -->
|
||
<section :key="view" class="tab-animate flex min-w-0 flex-1 flex-col">
|
||
<!-- 未登录态:**只挡飞牛曲库**。本地曲库与「我的歌单」完全不依赖 NAS 登录,
|
||
此前把它们一起挡掉,等于让「只用发现音乐 + 本地曲库」的用户点进来只看得到登录提示 -->
|
||
<div
|
||
v-if="view === 'feiniu' && needsLogin"
|
||
class="flex min-h-0 flex-1 items-center justify-center px-6"
|
||
>
|
||
<Empty>
|
||
<EmptyMedia>
|
||
<Music2 class="size-8 text-muted-foreground" />
|
||
</EmptyMedia>
|
||
<EmptyTitle>飞牛曲库需要一个可用的音乐连接</EmptyTitle>
|
||
<EmptyDescription>
|
||
到「设置 → 飞牛音乐连接」添加并登录。本地曲库与「我的歌单」不依赖 NAS,可直接在左侧切换查看。
|
||
</EmptyDescription>
|
||
</Empty>
|
||
</div>
|
||
|
||
<template v-else>
|
||
<!-- 工具栏 -->
|
||
<header class="flex shrink-0 items-center gap-2 border-b px-4 py-2.5">
|
||
<template v-if="view === 'feiniu'">
|
||
<div class="relative w-full max-w-[280px]">
|
||
<Search class="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
|
||
<Input
|
||
v-model="store.searchKeyword"
|
||
class="h-8 pl-8"
|
||
placeholder="搜索歌名 / 歌手 / 专辑(本地筛选)"
|
||
@input="onSearchInput"
|
||
@keydown.enter="onSearchInput"
|
||
/>
|
||
</div>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
class="h-8"
|
||
:disabled="store.loading || store.refreshing"
|
||
@click="refreshFeiniu"
|
||
>
|
||
<RefreshCw :class="store.loading || store.refreshing ? 'size-3.5 animate-spin' : 'size-3.5'" />
|
||
刷新
|
||
</Button>
|
||
<span class="ml-1 shrink-0 whitespace-nowrap text-[11.5px] text-muted-foreground">
|
||
<template v-if="isFiltering">
|
||
匹配 {{ filteredTracks.length }} / 已加载 {{ store.tracks.length }} 首
|
||
</template>
|
||
<template v-else>
|
||
{{ store.tracks.length }}<template v-if="store.total > store.tracks.length"> / {{ store.total }}</template> 首
|
||
</template>
|
||
</span>
|
||
<Button size="sm" class="ml-auto h-8" :disabled="!filteredTracks.length" @click="playFeiniu">
|
||
<Play class="size-3.5" /> 播放全部
|
||
</Button>
|
||
</template>
|
||
|
||
<template v-else-if="view === 'local'">
|
||
<!-- 结构与飞牛曲库完全一致:搜索框 → 操作按钮 → 计数 → 播放全部;
|
||
提示语与筛选字段(歌名 / 歌手 / 专辑)也保持一致。
|
||
宽度收窄到与飞牛曲库同宽,把余量留给右侧的匹配数与「播放全部」 -->
|
||
<div class="relative w-full max-w-[280px]">
|
||
<Search class="pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" />
|
||
<Input
|
||
v-model="store.searchKeyword"
|
||
class="h-8 pl-8"
|
||
placeholder="搜索歌名 / 歌手 / 专辑(本地筛选)"
|
||
@input="onSearchInput"
|
||
@keydown.enter="onSearchInput"
|
||
/>
|
||
</div>
|
||
<Button variant="outline" size="sm" class="h-8" :disabled="store.localScanBusy" @click="refreshLocal">
|
||
<Loader2 v-if="store.localScanBusy" class="size-3.5 animate-spin" />
|
||
<FolderOpen v-else class="size-3.5" />
|
||
扫描本地曲库
|
||
</Button>
|
||
<span class="ml-1 shrink-0 whitespace-nowrap text-[11.5px] text-muted-foreground">
|
||
<template v-if="isFiltering">
|
||
匹配 {{ filteredLocalTracks.length }} / 已扫描 {{ store.localTracks.length }} 首
|
||
</template>
|
||
<template v-else>{{ store.localTracks.length }} 首</template>
|
||
</span>
|
||
<Button size="sm" class="ml-auto h-8" :disabled="!filteredLocalTracks.length" @click="playLocal">
|
||
<Play class="size-3.5" /> 播放全部
|
||
</Button>
|
||
</template>
|
||
|
||
<template v-else>
|
||
<template v-if="activePlaylist">
|
||
<div class="min-w-0">
|
||
<div class="truncate text-[13px] font-medium">{{ activePlaylist.name }}</div>
|
||
<div class="text-[11.5px] text-muted-foreground">{{ activePlaylist.items.length }} 首</div>
|
||
</div>
|
||
<div class="ml-auto flex items-center gap-1.5">
|
||
<Button variant="outline" size="sm" class="h-8" @click="editorOpen = true">
|
||
<ListPlus class="size-3.5" />
|
||
编辑音乐
|
||
</Button>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-8"
|
||
aria-label="重命名歌单"
|
||
@click="openRename"
|
||
>
|
||
<Pencil class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-8 text-destructive hover:text-destructive"
|
||
aria-label="删除歌单"
|
||
@click="removePlaylist"
|
||
>
|
||
<Trash2 class="size-3.5" />
|
||
</Button>
|
||
<Button size="sm" class="h-8" :disabled="!activePlaylist.items.length" @click="playActivePlaylist">
|
||
<Play class="size-3.5" /> 播放全部
|
||
</Button>
|
||
</div>
|
||
</template>
|
||
<span v-else class="text-[12.5px] text-muted-foreground">选择左侧歌单查看内容</span>
|
||
</template>
|
||
</header>
|
||
|
||
<!-- 列表 -->
|
||
<ScrollArea class="min-h-0 flex-1">
|
||
<div class="px-2 pb-4">
|
||
<!-- 表头 -->
|
||
<div
|
||
v-if="
|
||
(view === 'feiniu' && filteredTracks.length) ||
|
||
(view === 'local' && filteredLocalTracks.length) ||
|
||
(view === 'playlists' && activePlaylist?.items.length)
|
||
"
|
||
class="grid h-8 items-center gap-3 px-2 text-[11px] text-muted-foreground"
|
||
:style="GRID"
|
||
>
|
||
<span class="text-center">#</span>
|
||
<span />
|
||
<span>标题</span>
|
||
<span class="text-right">时长</span>
|
||
<span />
|
||
</div>
|
||
|
||
<!-- 飞牛曲库 -->
|
||
<template v-if="view === 'feiniu'">
|
||
<div v-if="store.loading" class="flex items-center justify-center gap-2 py-14 text-[12.5px] text-muted-foreground">
|
||
<Loader2 class="size-4 animate-spin" /> 加载曲库…
|
||
</div>
|
||
<Empty v-else-if="!store.tracks.length">
|
||
<EmptyMedia><Music2 class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>曲库为空</EmptyTitle>
|
||
<EmptyDescription>{{ listEmptyHint }}</EmptyDescription>
|
||
</Empty>
|
||
<Empty v-else-if="!filteredTracks.length">
|
||
<EmptyMedia><Search class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>没有匹配「{{ store.searchKeyword.trim() }}」的曲目</EmptyTitle>
|
||
<EmptyDescription>
|
||
已在{{ store.tracks.length }}首曲库中筛选(歌名 / 歌手 / 专辑)。
|
||
</EmptyDescription>
|
||
</Empty>
|
||
<template v-else>
|
||
<TrackItem
|
||
v-for="(t, i) in visibleFeiniu"
|
||
:key="t.guid || i"
|
||
:item="t"
|
||
:index="i"
|
||
:context="filteredTracks"
|
||
:active="store.current?.guid === t.guid"
|
||
/>
|
||
</template>
|
||
</template>
|
||
|
||
<!-- 本地曲库 -->
|
||
<template v-else-if="view === 'local'">
|
||
<Empty v-if="!store.localTracks.length && !store.localScanBusy">
|
||
<EmptyMedia><HardDrive class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>暂无本地音乐</EmptyTitle>
|
||
<EmptyDescription>{{ listEmptyHint }}</EmptyDescription>
|
||
</Empty>
|
||
<Empty v-else-if="store.localTracks.length && !filteredLocalTracks.length">
|
||
<EmptyMedia><Search class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>没有匹配「{{ store.searchKeyword.trim() }}」的本地曲目</EmptyTitle>
|
||
<EmptyDescription>已在扫描到的 {{ store.localTracks.length }} 首中筛选。</EmptyDescription>
|
||
</Empty>
|
||
<template v-else-if="filteredLocalTracks.length">
|
||
<TrackItem
|
||
v-for="(t, i) in visibleLocal"
|
||
:key="t.guid || i"
|
||
:item="t"
|
||
:index="i"
|
||
:context="filteredLocalTracks"
|
||
:active="store.current?.guid === t.guid"
|
||
/>
|
||
</template>
|
||
</template>
|
||
|
||
<!-- 歌单详情 -->
|
||
<template v-else>
|
||
<template v-if="activePlaylist">
|
||
<Empty v-if="!activePlaylist.items.length">
|
||
<EmptyMedia><ListMusic class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>歌单还是空的</EmptyTitle>
|
||
<EmptyDescription>
|
||
点击「编辑音乐」从全部音乐里勾选加入,或在曲库列表中通过「⋯」菜单单首添加。
|
||
</EmptyDescription>
|
||
<Button size="sm" class="mt-1" @click="editorOpen = true">
|
||
<ListPlus class="size-3.5" />
|
||
编辑音乐
|
||
</Button>
|
||
</Empty>
|
||
<TrackItem
|
||
v-for="(t, i) in visiblePlaylistItems"
|
||
:key="`${t.source}:${t.guid}:${i}`"
|
||
:item="t"
|
||
:index="i"
|
||
:context="activePlaylist.items"
|
||
:playlist-id="activePlaylist.id"
|
||
:playlist-index="i"
|
||
:active="store.current?.guid === t.guid"
|
||
show-source
|
||
/>
|
||
</template>
|
||
<Empty v-else>
|
||
<EmptyMedia><ListMusic class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>还没有歌单</EmptyTitle>
|
||
<EmptyDescription>点击左侧「新建歌单」开始整理你的收藏。</EmptyDescription>
|
||
</Empty>
|
||
</template>
|
||
|
||
<!-- 增量渲染 / 分页共用哨兵:滚到这里先追加一批行,行渲染完了再向 NAS 要下一页 -->
|
||
<div
|
||
v-if="showSentinel && activeList.length"
|
||
ref="loadMoreRef"
|
||
class="flex items-center justify-center gap-2 py-4 text-[12px] text-muted-foreground"
|
||
>
|
||
<Loader2 v-if="store.loadingMore" class="size-3.5 animate-spin" />
|
||
<template v-if="hasMoreRows">已显示 {{ shownRows }} / {{ activeList.length }} 首,继续滚动加载</template>
|
||
<template v-else>正在加载更多…</template>
|
||
</div>
|
||
</div>
|
||
</ScrollArea>
|
||
</template>
|
||
</section>
|
||
|
||
<!-- 新建歌单 -->
|
||
<Dialog v-model:open="createOpen">
|
||
<DialogContent class="sm:max-w-sm">
|
||
<DialogHeader>
|
||
<DialogTitle>新建歌单</DialogTitle>
|
||
<DialogDescription>歌单保存在本机,可混合飞牛 NAS 与本地曲目。</DialogDescription>
|
||
</DialogHeader>
|
||
<Input v-model="newName" placeholder="歌单名称" @keydown.enter="createPlaylist" />
|
||
<DialogFooter>
|
||
<Button variant="outline" @click="createOpen = false">取消</Button>
|
||
<Button @click="createPlaylist">创建</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
|
||
<!-- 重命名歌单 -->
|
||
<Dialog v-model:open="renameOpen">
|
||
<DialogContent class="sm:max-w-sm">
|
||
<DialogHeader>
|
||
<DialogTitle>重命名歌单</DialogTitle>
|
||
</DialogHeader>
|
||
<Input v-model="renameValue" placeholder="歌单名称" @keydown.enter="confirmRename" />
|
||
<DialogFooter>
|
||
<Button variant="outline" @click="renameOpen = false">取消</Button>
|
||
<Button @click="confirmRename">保存</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
|
||
<!-- 编辑歌单音乐:从全部音乐勾选加入 / 批量移出 -->
|
||
<PlaylistEditorDialog
|
||
v-if="activePlaylist"
|
||
v-model:open="editorOpen"
|
||
:playlist-id="activePlaylist.id"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
/* 歌单子树展开 / 收起 */
|
||
.pl-list-enter-active,
|
||
.pl-list-leave-active {
|
||
transition: opacity 0.18s ease, transform 0.18s ease;
|
||
}
|
||
.pl-list-enter-from,
|
||
.pl-list-leave-to {
|
||
opacity: 0;
|
||
transform: translateY(-6px);
|
||
}
|
||
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.pl-list-enter-active,
|
||
.pl-list-leave-active {
|
||
transition: none;
|
||
}
|
||
}
|
||
</style>
|