1830 lines
75 KiB
Vue
1830 lines
75 KiB
Vue
<script setup lang="ts">
|
||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||
import { toast } from 'vue-sonner'
|
||
import { open as openDialog } from '@tauri-apps/plugin-dialog'
|
||
import { appDataDir } from '@tauri-apps/api/path'
|
||
import {
|
||
CircleAlert,
|
||
CloudUpload,
|
||
Download,
|
||
FolderOpen,
|
||
HardDriveDownload,
|
||
History,
|
||
Info,
|
||
Link2,
|
||
ListMusic,
|
||
Loader2,
|
||
Music2,
|
||
Play,
|
||
Plus,
|
||
RotateCw,
|
||
Search,
|
||
Square,
|
||
Trash2,
|
||
Upload,
|
||
X
|
||
} from '@lucide/vue'
|
||
import {
|
||
useMusicStore,
|
||
type MusicDownloadTask,
|
||
type MusicQuality,
|
||
type MusicSong
|
||
} from '@/stores/musicStore'
|
||
import { useMusicUploadStore } from '@/stores/musicUploadStore'
|
||
import { useProxyStore } from '@/stores/proxyStore'
|
||
import { useFeiniuStore } from '@/stores/feiniuStore'
|
||
import { useModuleTabs } from '@/lib/use-module-tabs'
|
||
import { createLogger } from '@/lib/logger'
|
||
import { commands } from '@/lib/bindings'
|
||
import { sourceName, PICKER_SOURCES } from './sources'
|
||
import SourcePicker from './SourcePicker.vue'
|
||
import MyMusicLibrary from './components/MyMusicLibrary.vue'
|
||
import ConnectionsSettings from './components/settings/ConnectionsSettings.vue'
|
||
import CacheSettings from './components/settings/CacheSettings.vue'
|
||
import { Button } from '@/components/ui/button'
|
||
import { Badge } from '@/components/ui/badge'
|
||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||
import {
|
||
Dialog,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle
|
||
} from '@/components/ui/dialog'
|
||
import { Switch } from '@/components/ui/switch'
|
||
import { Input } from '@/components/ui/input'
|
||
import { Label } from '@/components/ui/label'
|
||
import { Separator } from '@/components/ui/separator'
|
||
import { Progress } from '@/components/ui/progress'
|
||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||
import { Checkbox } from '@/components/ui/checkbox'
|
||
import { Tabs, TabsContent } from '@/components/ui/tabs'
|
||
import { Empty, EmptyDescription, EmptyMedia, EmptyTitle } from '@/components/ui/empty'
|
||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||
|
||
const store = useMusicStore()
|
||
const proxyStore = useProxyStore()
|
||
const feiniu = useFeiniuStore()
|
||
/** 下载 → 上传飞牛的记账中枢(刻意放在 store 里,避免随组件卸载而失效) */
|
||
const uploader = useMusicUploadStore()
|
||
const logger = createLogger('music')
|
||
|
||
// ===== 模块导航 =====
|
||
const activeTab = ref('mymusic')
|
||
useModuleTabs('music', activeTab, [
|
||
{ value: 'mymusic', label: '曲库' },
|
||
{ value: 'discover', label: '发现音乐' },
|
||
{ value: 'settings', label: '设置' }
|
||
], { alwaysVisible: true })
|
||
|
||
// ===== 发现音乐:下载目标 =====
|
||
const downloadTarget = ref<'local' | 'feiniu'>('local')
|
||
|
||
/** 上传「最近下载」的音频(手动兜底入口;按任务精确的自动上传见 musicUploadStore) */
|
||
async function uploadRecentToFeiniu() {
|
||
try {
|
||
const { total, ok } = await feiniu.uploadRecentToFeiniu(10)
|
||
if (total === 0) toast.info('未找到最近下载的音频文件')
|
||
else toast.success(`已上传 ${ok}/${total} 首到飞牛曲库`)
|
||
} catch (e) {
|
||
toast.error(String(e))
|
||
}
|
||
}
|
||
|
||
// ===== 生命周期 =====
|
||
const appDataPath = ref('')
|
||
onMounted(async () => {
|
||
loadHistory()
|
||
try {
|
||
await store.init()
|
||
} catch (e) {
|
||
logger.error(`音乐模块初始化失败:${e}`)
|
||
}
|
||
// musicdl 未安装时不拉起桥接(避免常驻空转的 Python 进程)
|
||
if (store.env?.musicdlInstalled) store.loadSources().catch(() => {})
|
||
// 历史任务视为已处理:应用启动时不重传上一轮已上传过的文件
|
||
uploader.armAfterInit()
|
||
appDataDir()
|
||
.then((p) => (appDataPath.value = p))
|
||
.catch(() => {})
|
||
})
|
||
|
||
// ===== 搜索 =====
|
||
const keyword = ref('')
|
||
const sourceOptions = computed<string[]>(() => {
|
||
const avail = new Set(store.availableSources)
|
||
const list = store.availableSources.length
|
||
? PICKER_SOURCES.filter((s) => avail.has(s))
|
||
: [...PICKER_SOURCES]
|
||
const selected = store.settings?.sources ?? []
|
||
const extra = selected.filter((s) => !list.includes(s))
|
||
return [...list, ...extra]
|
||
})
|
||
|
||
async function doSearch() {
|
||
if (store.searching) return
|
||
const kw = keyword.value.trim()
|
||
if (!kw) return
|
||
const sources = store.settings?.sources ?? []
|
||
if (sources.length === 0) {
|
||
toast.error('请至少选择一个搜索源')
|
||
return
|
||
}
|
||
selectedKeys.value = new Set()
|
||
historyOpen.value = false
|
||
sourceFilter.value = 'all'
|
||
try {
|
||
await store.search(kw, sources)
|
||
pushHistory(kw)
|
||
} catch {
|
||
// 错误详情由结果区空态展示
|
||
}
|
||
}
|
||
|
||
// ===== 搜索历史 =====
|
||
const HISTORY_KEY = 'thing.music.searchHistory'
|
||
const HISTORY_MAX = 10
|
||
const searchHistory = ref<string[]>([])
|
||
const historyOpen = ref(false)
|
||
const searchBoxRef = ref<HTMLElement | null>(null)
|
||
|
||
function loadHistory() {
|
||
try {
|
||
const arr = JSON.parse(localStorage.getItem(HISTORY_KEY) ?? '[]')
|
||
searchHistory.value = Array.isArray(arr) ? arr.filter((h) => typeof h === 'string') : []
|
||
} catch {
|
||
searchHistory.value = []
|
||
}
|
||
}
|
||
function pushHistory(kw: string) {
|
||
const next = [kw, ...searchHistory.value.filter((h) => h !== kw)].slice(0, HISTORY_MAX)
|
||
searchHistory.value = next
|
||
try {
|
||
localStorage.setItem(HISTORY_KEY, JSON.stringify(next))
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}
|
||
function clearHistory() {
|
||
searchHistory.value = []
|
||
try {
|
||
localStorage.removeItem(HISTORY_KEY)
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}
|
||
const filteredHistory = computed(() => {
|
||
const kw = keyword.value.trim().toLowerCase()
|
||
if (!kw) return searchHistory.value
|
||
return searchHistory.value.filter((h) => h.toLowerCase().includes(kw))
|
||
})
|
||
function pickHistory(h: string) {
|
||
keyword.value = h
|
||
historyOpen.value = false
|
||
doSearch()
|
||
}
|
||
/** 焦点仍在搜索框/历史浮层内时保持展开,键盘 Tab 才能选中历史项 */
|
||
function onHistoryFocusOut(e: FocusEvent) {
|
||
const next = e.relatedTarget as Node | null
|
||
if (next && searchBoxRef.value?.contains(next)) return
|
||
historyOpen.value = false
|
||
}
|
||
|
||
// ===== 歌单解析 =====
|
||
const playlistUrl = ref('')
|
||
const parsingPlaylist = ref(false)
|
||
const playlistLinkOpen = ref(false)
|
||
async function doParsePlaylist() {
|
||
if (parsingPlaylist.value) return
|
||
const url = playlistUrl.value.trim()
|
||
if (!url) return
|
||
const sources = store.settings?.sources ?? []
|
||
if (sources.length === 0) {
|
||
toast.error('请至少选择一个搜索源')
|
||
return
|
||
}
|
||
parsingPlaylist.value = true
|
||
selectedKeys.value = new Set()
|
||
sourceFilter.value = 'all'
|
||
try {
|
||
const n = await store.parsePlaylist(url, sources)
|
||
toast.success(`歌单解析完成,共 ${n} 首`)
|
||
playlistLinkOpen.value = false
|
||
playlistUrl.value = ''
|
||
} catch {
|
||
toast.error(`歌单解析失败:${store.parseError || '未知错误'}`)
|
||
} finally {
|
||
parsingPlaylist.value = false
|
||
}
|
||
}
|
||
|
||
// ===== 结果扁平化 / 筛选 / 增量渲染 =====
|
||
interface FlatSong {
|
||
song: MusicSong
|
||
source: string
|
||
index: number
|
||
key: string
|
||
}
|
||
const flatResults = computed<FlatSong[]>(() => {
|
||
const out: FlatSong[] = []
|
||
for (const [source, songs] of Object.entries(store.results)) {
|
||
songs.forEach((song, index) => out.push({ song, source, index, key: `${source}|${index}` }))
|
||
}
|
||
return out
|
||
})
|
||
|
||
const LOSSLESS_EXTS = new Set(['flac', 'wav', 'alac', 'ape', 'wv', 'tta', 'dsf', 'dff'])
|
||
const sourceFilter = ref('all')
|
||
const qualityFilter = ref<'all' | 'lossless' | 'mp3'>('all')
|
||
const availableResultSources = computed(() => Object.keys(store.results))
|
||
const filteredResults = computed<FlatSong[]>(() => {
|
||
const src = sourceFilter.value
|
||
const q = qualityFilter.value
|
||
return flatResults.value.filter((f) => {
|
||
if (src !== 'all' && f.source !== src) return false
|
||
if (q === 'all') return true
|
||
const lossless = isLossless(f.song)
|
||
return q === 'lossless' ? lossless : !lossless
|
||
})
|
||
})
|
||
|
||
/** 分组后的展示项(源分组头 + 歌曲行) */
|
||
interface DisplayItem {
|
||
type: 'header' | 'song'
|
||
source?: string
|
||
count?: number
|
||
keys?: string[]
|
||
allSelected?: boolean
|
||
song?: FlatSong
|
||
}
|
||
const displayItems = computed<DisplayItem[]>(() => {
|
||
const out: DisplayItem[] = []
|
||
const bySource = new Map<string, FlatSong[]>()
|
||
for (const f of filteredResults.value) {
|
||
const arr = bySource.get(f.source)
|
||
if (arr) arr.push(f)
|
||
else bySource.set(f.source, [f])
|
||
}
|
||
for (const [source, list] of bySource) {
|
||
const keys = list.map((f) => f.key)
|
||
out.push({
|
||
type: 'header',
|
||
source,
|
||
count: list.length,
|
||
keys,
|
||
allSelected: keys.every((k) => selectedKeys.value.has(k))
|
||
})
|
||
for (const f of list) out.push({ type: 'song', song: f })
|
||
}
|
||
return out
|
||
})
|
||
|
||
const PAGE_SIZE = 80
|
||
const visibleCount = ref(PAGE_SIZE)
|
||
watch(filteredResults, () => {
|
||
visibleCount.value = PAGE_SIZE
|
||
})
|
||
const visibleItems = computed(() => displayItems.value.slice(0, visibleCount.value))
|
||
const hasMore = computed(() => visibleCount.value < displayItems.value.length)
|
||
|
||
const loadMoreRef = ref<HTMLElement | null>(null)
|
||
let loadMoreObserver: IntersectionObserver | null = null
|
||
onMounted(() => {
|
||
loadMoreObserver = new IntersectionObserver(
|
||
(entries) => {
|
||
if (entries.some((e) => e.isIntersecting)) {
|
||
visibleCount.value += PAGE_SIZE
|
||
nextTick(() => {
|
||
const el = loadMoreRef.value
|
||
if (el && loadMoreObserver) {
|
||
loadMoreObserver.unobserve(el)
|
||
loadMoreObserver.observe(el)
|
||
}
|
||
})
|
||
}
|
||
},
|
||
{ rootMargin: '300px' }
|
||
)
|
||
watch(
|
||
loadMoreRef,
|
||
(el) => {
|
||
if (!loadMoreObserver) return
|
||
loadMoreObserver.disconnect()
|
||
if (el) loadMoreObserver.observe(el)
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
})
|
||
onBeforeUnmount(() => loadMoreObserver?.disconnect())
|
||
|
||
function toggleSelectGroup(item: DisplayItem) {
|
||
const keys = item.keys ?? []
|
||
const next = new Set(selectedKeys.value)
|
||
if (item.allSelected) keys.forEach((k) => next.delete(k))
|
||
else keys.forEach((k) => next.add(k))
|
||
selectedKeys.value = next
|
||
}
|
||
|
||
// ===== 音质展示(降噪为单枚中性徽标 + 弹层详情) =====
|
||
const TIER_ORDER = ['Hi-Res', '无损', 'FLAC', '320K', '192K', '128K', '96K', '标准']
|
||
function tierRank(label?: string | null) {
|
||
const i = TIER_ORDER.indexOf((label ?? '').trim())
|
||
return i === -1 ? 99 : i
|
||
}
|
||
/** 该曲可用的最高音质档位 */
|
||
function bestTier(song: MusicSong): MusicQuality | null {
|
||
const list = song.qualities
|
||
if (!list || list.length === 0) return null
|
||
return [...list].sort((a, b) => tierRank(a.label) - tierRank(b.label))[0]
|
||
}
|
||
function isLossless(song: MusicSong): boolean {
|
||
const ext = (song.ext ?? '').toLowerCase()
|
||
if (ext) return LOSSLESS_EXTS.has(ext)
|
||
if (song.qualities?.length) return song.qualities.some((q) => q.lossless === true)
|
||
return song.lossless === true
|
||
}
|
||
/** 列表里展示的一行音质摘要:优先档位 label,其次 ext / 无损标记 */
|
||
function qualitySummary(song: MusicSong): string {
|
||
const best = bestTier(song)
|
||
if (best?.label) return best.ext ? `${best.label} · ${best.ext.toUpperCase()}` : best.label
|
||
if (song.ext) return song.ext.toUpperCase()
|
||
if (isLossless(song)) return '无损'
|
||
return ''
|
||
}
|
||
const formatBitrate = (b?: number | null) => {
|
||
if (!b || b <= 0) return ''
|
||
return b >= 1000 ? `${(b / 1000).toFixed(1)} Mbps` : `${b} kbps`
|
||
}
|
||
const formatDuration = (sec?: number | null, fallback?: string | null) => {
|
||
if (sec && sec > 0) {
|
||
const m = Math.floor(sec / 60)
|
||
const s = Math.floor(sec % 60)
|
||
return `${m}:${String(s).padStart(2, '0')}`
|
||
}
|
||
return fallback || '--:--'
|
||
}
|
||
|
||
// ===== 在线试听(走全局播放内核,与播放器共用同一 audio,天然互斥) =====
|
||
const resolvingKeys = ref<Set<string>>(new Set())
|
||
const previewKey = computed(() => feiniu.preview?.guid ?? '')
|
||
|
||
async function togglePreview(song: MusicSong, source: string, index: number) {
|
||
const key = `${source}|${index}`
|
||
if (previewKey.value === key) {
|
||
feiniu.stopPreview()
|
||
return
|
||
}
|
||
let target = song
|
||
if (!target.downloadUrl) {
|
||
if (!target.rawSearch || resolvingKeys.value.has(key)) return
|
||
resolvingKeys.value.add(key)
|
||
try {
|
||
const fresh = await store.resolveSong(source, index)
|
||
if (!fresh?.downloadUrl) {
|
||
toast.error('解析失败:暂无可用播放源')
|
||
return
|
||
}
|
||
target = fresh
|
||
} catch (e) {
|
||
toast.error(`解析失败:${e}`)
|
||
return
|
||
} finally {
|
||
resolvingKeys.value.delete(key)
|
||
}
|
||
}
|
||
feiniu.playPreview({
|
||
source: 'preview',
|
||
guid: key,
|
||
title: target.songName || '未知歌名',
|
||
artistNames: target.singers || '',
|
||
album: target.album || undefined,
|
||
coverUrl: target.coverUrl || undefined,
|
||
ext: target.ext || undefined,
|
||
url: target.downloadUrl!
|
||
})
|
||
}
|
||
|
||
// ===== 下载 =====
|
||
const proxyUrl = computed(() => {
|
||
const port = proxyStore.settings?.mixedPort
|
||
return port ? `http://127.0.0.1:${port}` : ''
|
||
})
|
||
|
||
/** WebDAV 测试连接进行中 */
|
||
const webdavTesting = ref(false)
|
||
/** WebDAV 已配置时默认收起凭据表单(账号/密码隐藏),点「修改配置」展开 */
|
||
const webdavEditing = ref(false)
|
||
|
||
async function testWebdav() {
|
||
if (webdavTesting.value) return
|
||
webdavTesting.value = true
|
||
try {
|
||
const msg = await feiniu.testWebdav()
|
||
toast.success(msg)
|
||
} catch (e) {
|
||
toast.error(String(e))
|
||
} finally {
|
||
webdavTesting.value = false
|
||
}
|
||
}
|
||
|
||
// 「下载到飞牛」与「完成后自动上传」的记账、收尾全部在 musicUploadStore 中,
|
||
// 不再放在本组件:否则用户下载途中切走音乐模块(组件卸载)后就永远不会触发上传。
|
||
|
||
const selectedKeys = ref<Set<string>>(new Set())
|
||
const selectedSongs = computed<MusicSong[]>(() =>
|
||
filteredResults.value.filter((f) => selectedKeys.value.has(f.key)).map((f) => f.song)
|
||
)
|
||
function toggleSelect(key: string) {
|
||
const next = new Set(selectedKeys.value)
|
||
if (next.has(key)) next.delete(key)
|
||
else next.add(key)
|
||
selectedKeys.value = next
|
||
}
|
||
const allSelected = computed(
|
||
() => filteredResults.value.length > 0 && filteredResults.value.every((f) => selectedKeys.value.has(f.key))
|
||
)
|
||
function toggleSelectAll() {
|
||
selectedKeys.value = allSelected.value ? new Set() : new Set(filteredResults.value.map((f) => f.key))
|
||
}
|
||
|
||
function openDir(path?: string) {
|
||
const dir = path || store.settings?.savedir
|
||
if (!dir) return
|
||
commands.downloaderOpenDir(dir).catch((e) => toast.error(`打开目录失败:${e}`))
|
||
}
|
||
|
||
async function doDownload(songs: MusicSong[], quality = '', clearSelection = false) {
|
||
const s = store.settings
|
||
if (!s || songs.length === 0) return
|
||
// Rust 引擎的任务在「下载器」模块管理,无法回传飞牛曲库
|
||
if (downloadTarget.value === 'feiniu' && s.downloadEngine === 'rust') {
|
||
toast.error('Rust 引擎的下载任务在「下载器」模块中管理,无法自动回传飞牛曲库。请改用 musicdl 引擎,或把下载目标改为本地目录。')
|
||
return
|
||
}
|
||
try {
|
||
const { engine, skipped, taskId } = await store.startDownload(songs, {
|
||
savedir: s.savedir,
|
||
lyric: s.lyricDownload,
|
||
cover: s.coverDownload,
|
||
proxyUrl: s.useProxy ? proxyUrl.value : '',
|
||
engine: s.downloadEngine,
|
||
maxConcurrent: s.maxConcurrent,
|
||
quality
|
||
})
|
||
if (skipped > 0) toast.warning(`${skipped} 首歌曲无下载链接,已跳过`)
|
||
if (clearSelection) selectedKeys.value = new Set()
|
||
if (engine === 'rust') {
|
||
toast.success('已交给「下载器」模块下载,可在该模块查看进度')
|
||
return
|
||
}
|
||
if (taskId && downloadTarget.value === 'feiniu') uploader.markUploadOnDone(taskId)
|
||
// 起播后直接把任务面板弹出来(原先跳「下载任务」tab,现在合并进这个 popover)
|
||
tasksOpen.value = true
|
||
} catch (e) {
|
||
toast.error(`启动下载失败:${e}`)
|
||
}
|
||
}
|
||
|
||
// ===== 音质选择 =====
|
||
const qualityDialogOpen = ref(false)
|
||
const pendingQualitySongs = ref<MusicSong[]>([])
|
||
const chosenQuality = ref('')
|
||
const pendingClearSelection = ref(false)
|
||
function qualityOptionsFor(songs: MusicSong[]): string[] {
|
||
const set = new Set<string>()
|
||
for (const s of songs) for (const q of s.qualities ?? []) if (q.label) set.add(q.label)
|
||
return ['最高', ...[...set].sort((a, b) => tierRank(a) - tierRank(b))]
|
||
}
|
||
function requestDownloadFlow(songs: MusicSong[], clearSelection = false) {
|
||
if (songs.length === 0) return
|
||
const s = store.settings
|
||
const defQ = s?.defaultDownloadQuality ?? ''
|
||
if (s?.selectQualityOnDownload) {
|
||
pendingQualitySongs.value = songs
|
||
pendingClearSelection.value = clearSelection
|
||
chosenQuality.value = defQ && qualityOptionsFor(songs).includes(defQ) ? defQ : ''
|
||
qualityDialogOpen.value = true
|
||
} else {
|
||
void doDownload(songs, defQ, clearSelection)
|
||
}
|
||
}
|
||
function confirmQualityDialog() {
|
||
qualityDialogOpen.value = false
|
||
const songs = pendingQualitySongs.value
|
||
const clear = pendingClearSelection.value
|
||
pendingQualitySongs.value = []
|
||
pendingClearSelection.value = false
|
||
void doDownload(songs, chosenQuality.value, clear)
|
||
}
|
||
function downloadOne(song: MusicSong) {
|
||
requestDownloadFlow([song])
|
||
}
|
||
function downloadSelected() {
|
||
const songs = selectedSongs.value
|
||
if (songs.length === 0) return
|
||
requestDownloadFlow(songs, true)
|
||
}
|
||
|
||
// ===== 任务展示 =====
|
||
const taskStatusInfo = (
|
||
task: MusicDownloadTask
|
||
): { label: string; variant: 'default' | 'secondary' | 'destructive' | 'outline'; class?: string } => {
|
||
switch (task.status) {
|
||
case 'downloading':
|
||
return { label: '下载中', variant: 'default' }
|
||
case 'cancelling':
|
||
return { label: '取消中', variant: 'outline' }
|
||
case 'done':
|
||
return { label: '完成', variant: 'outline', class: 'bg-success-soft text-success-text border-success/30' }
|
||
case 'error':
|
||
return { label: '出错', variant: 'destructive' }
|
||
case 'cancelled':
|
||
return { label: '已取消', variant: 'outline' }
|
||
case 'interrupted':
|
||
return { label: '已中断', variant: 'outline' }
|
||
}
|
||
}
|
||
const formatBytes = (n?: number) => {
|
||
if (!n || n <= 0) return ''
|
||
if (n >= 1048576) return `${(n / 1048576).toFixed(1)} MB`
|
||
if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`
|
||
return `${n} B`
|
||
}
|
||
function taskHeadInfo(task: MusicDownloadTask): { name: string; sub: string } {
|
||
const st = task.songs[0]
|
||
if (!st) return { name: '', sub: '' }
|
||
const n = task.songs.length
|
||
return { name: st.songName, sub: (st.singers || '未知歌手') + (n > 1 ? ` 等 ${n} 首` : '') }
|
||
}
|
||
const taskAggDone = (task: MusicDownloadTask) => task.songs.reduce((a, s) => a + (s.downloaded || 0), 0)
|
||
const taskAggTotal = (task: MusicDownloadTask) => task.songs.reduce((a, s) => a + (s.total || 0), 0)
|
||
const taskQualityDisplay = (task: MusicDownloadTask) =>
|
||
task.songs.find((s) => s.quality)?.quality || task.quality || ''
|
||
|
||
// ===== 下载任务(发现音乐工具栏里的 popover)=====
|
||
const TASK_DONE_STATUSES = ['done', 'cancelled', 'error', 'interrupted']
|
||
/** 可重新下载的状态(完成态不给「重新下载」,避免与「上传到飞牛」并排造成误操作) */
|
||
const TASK_RETRYABLE_STATUSES = ['error', 'cancelled', 'interrupted']
|
||
const tasksOpen = ref(false)
|
||
/** 未结束的任务数:入口角标只提示「还在跑」的,避免完成的任务一直挂数字 */
|
||
const activeTaskCount = computed(
|
||
() => store.tasks.filter((t) => !TASK_DONE_STATUSES.includes(t.status)).length
|
||
)
|
||
const finishedTaskCount = computed(
|
||
() => store.tasks.filter((t) => TASK_DONE_STATUSES.includes(t.status)).length
|
||
)
|
||
const taskPercent = (task: MusicDownloadTask): number => {
|
||
const total = taskAggTotal(task)
|
||
return total > 0 ? Math.min(100, Math.round((taskAggDone(task) / total) * 100)) : 0
|
||
}
|
||
/** 多曲目任务显示「已完成 a/b 首」,单曲不必 */
|
||
const taskSongProgress = (task: MusicDownloadTask): string =>
|
||
task.songs.length > 1 ? `${task.songs.filter((s) => s.status === 'done').length}/${task.songs.length} 首` : ''
|
||
function clearFinishedTasks() {
|
||
for (const t of store.tasks.filter((x) => TASK_DONE_STATUSES.includes(x.status))) {
|
||
store.removeTask(t.taskId)
|
||
}
|
||
}
|
||
|
||
// ===== 设置 =====
|
||
const settingsSources = computed<string[]>({
|
||
get: () => store.settings?.sources ?? [],
|
||
set: (v) => {
|
||
if (store.settings) store.settings.sources = v
|
||
}
|
||
})
|
||
const savedirModel = computed<string>({
|
||
get: () => store.settings?.savedir ?? '',
|
||
set: (v) => {
|
||
if (store.settings) store.settings.savedir = v
|
||
}
|
||
})
|
||
/** QQ 音乐 Cookie(可选):真身存系统凭据管理器,这里只是双向绑定入口 */
|
||
const qqCookieModel = computed<string>({
|
||
get: () => store.qqCookie,
|
||
set: (v) => store.setQqCookie(v)
|
||
})
|
||
const lyricModel = computed<boolean>({
|
||
get: () => store.settings?.lyricDownload ?? false,
|
||
set: (v) => {
|
||
if (store.settings) store.settings.lyricDownload = v
|
||
}
|
||
})
|
||
const coverModel = computed<boolean>({
|
||
get: () => store.settings?.coverDownload ?? false,
|
||
set: (v) => {
|
||
if (store.settings) store.settings.coverDownload = v
|
||
}
|
||
})
|
||
const proxyModel = computed<boolean>({
|
||
get: () => store.settings?.useProxy ?? false,
|
||
set: (v) => {
|
||
if (store.settings) store.settings.useProxy = v
|
||
}
|
||
})
|
||
const concurrentModel = computed<number>({
|
||
get: () => store.settings?.maxConcurrent ?? 4,
|
||
set: (v) => {
|
||
if (store.settings) {
|
||
const n = Number(v)
|
||
store.settings.maxConcurrent = !n || n < 1 ? 1 : n > 16 ? 16 : n
|
||
}
|
||
}
|
||
})
|
||
const engineModel = computed<string>({
|
||
get: () => store.settings?.downloadEngine ?? 'musicdl',
|
||
set: (v) => {
|
||
if (store.settings) store.settings.downloadEngine = v
|
||
}
|
||
})
|
||
const selectQualityModel = computed<boolean>({
|
||
get: () => store.settings?.selectQualityOnDownload ?? false,
|
||
set: (v) => {
|
||
if (store.settings) store.settings.selectQualityOnDownload = v
|
||
}
|
||
})
|
||
const defaultQualityModel = computed<string>({
|
||
get: () => store.settings?.defaultDownloadQuality ?? '',
|
||
set: (v) => {
|
||
if (store.settings) store.settings.defaultDownloadQuality = v
|
||
}
|
||
})
|
||
|
||
let saveTimer: ReturnType<typeof setTimeout> | null = null
|
||
watch(
|
||
() => store.settings,
|
||
() => {
|
||
if (!store.settings) return
|
||
if (saveTimer) clearTimeout(saveTimer)
|
||
saveTimer = setTimeout(() => {
|
||
// 只是把 loadSettings 读回来的快照又观察到了:没有真实改动就不写盘
|
||
if (!store.settingsChanged()) return
|
||
store.saveSettings().catch((e) => toast.error(`保存设置失败:${e}`))
|
||
}, 400)
|
||
},
|
||
{ deep: true }
|
||
)
|
||
|
||
async function browseDir() {
|
||
const picked = await openDialog({ directory: true, title: '选择音乐保存目录' })
|
||
if (picked && store.settings) {
|
||
store.settings.savedir = String(picked)
|
||
await store.saveSettings()
|
||
}
|
||
}
|
||
|
||
// ===== 本地曲库目录(可多选;下载目录始终会被扫描)=====
|
||
const localDirs = computed<string[]>({
|
||
get: () => store.settings?.feiniuLocalDirs ?? [],
|
||
set: (v) => {
|
||
if (store.settings) store.settings.feiniuLocalDirs = v
|
||
}
|
||
})
|
||
|
||
/** 重新扫描本地曲库并提示结果(目录变更后自动调用) */
|
||
async function rescanLocal() {
|
||
try {
|
||
await feiniu.scanLocal()
|
||
toast.success(`已扫描本地曲库:共 ${feiniu.localTracks.length} 首`)
|
||
} catch (e) {
|
||
toast.error(`扫描本地曲库失败:${e}`)
|
||
}
|
||
}
|
||
|
||
/** 添加本地曲库目录(支持一次多选),保存后自动重新扫描 */
|
||
async function addLocalDirs() {
|
||
const picked = await openDialog({
|
||
directory: true,
|
||
multiple: true,
|
||
title: '选择本地曲库目录(可多选)'
|
||
})
|
||
if (!picked) return
|
||
const list = (Array.isArray(picked) ? picked : [picked]).map(String)
|
||
const merged = [...localDirs.value]
|
||
for (const d of list) {
|
||
if (!merged.includes(d)) merged.push(d)
|
||
}
|
||
if (merged.length === localDirs.value.length) return
|
||
localDirs.value = merged
|
||
// 扫描命令读的是后端设置:先落盘再扫描,否则新目录尚未生效
|
||
await store.saveSettings()
|
||
await rescanLocal()
|
||
}
|
||
|
||
/** 移除一个本地曲库目录并自动重新扫描 */
|
||
async function removeLocalDir(index: number) {
|
||
const next = [...localDirs.value]
|
||
next.splice(index, 1)
|
||
localDirs.value = next
|
||
await store.saveSettings()
|
||
await rescanLocal()
|
||
}
|
||
|
||
const runtimeDisplay = computed(() => {
|
||
const p = store.env?.runtimeDir
|
||
if (!p) return ''
|
||
if (appDataPath.value && p.toLowerCase().startsWith(appDataPath.value.toLowerCase())) {
|
||
return '%APPDATA%' + p.slice(appDataPath.value.length)
|
||
}
|
||
return p
|
||
})
|
||
|
||
const pinging = ref(false)
|
||
async function testBridge() {
|
||
pinging.value = true
|
||
try {
|
||
const r = await store.pingBridge()
|
||
toast.success(`桥接正常 · 协议 v${r.version} · Python ${r.python}`)
|
||
await store.refreshEnv()
|
||
} catch (e) {
|
||
toast.error(`桥接不可用:${e}`)
|
||
} finally {
|
||
pinging.value = false
|
||
}
|
||
}
|
||
|
||
async function doInstall() {
|
||
try {
|
||
await store.installRuntime()
|
||
await store.loadSources()
|
||
} catch (e) {
|
||
if (!/已取消/.test(String(e))) toast.error(`安装失败:${e}`)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新 / 重装 musicdl。
|
||
*
|
||
* 只对齐到**本应用锁定的版本**:`bridge.py` 的 monkey patch 与 musicdl 版本强耦合
|
||
* (第三方解析链方法名、各源搜索字段映射、音质常量前缀),升到 PyPI 最新版会静默
|
||
* 破坏解析链。后端更新成功后会重启桥接进程,因此有下载任务在跑时按钮是禁用的。
|
||
*/
|
||
async function updateMusicdl(force: boolean) {
|
||
try {
|
||
await store.updateMusicdl(force)
|
||
toast.success(
|
||
force ? 'musicdl 已重装' : `musicdl 已更新到 ${store.env?.musicdlExpected || '锁定版本'}`
|
||
)
|
||
} catch (e) {
|
||
if (!/已取消/.test(String(e))) toast.error(`${force ? '重装' : '更新'} musicdl 失败:${e}`)
|
||
}
|
||
}
|
||
|
||
/** 环境面板头部徽标:区分 检测中 / 需更新 / 就绪 / 未安装 */
|
||
const envBadgeVariant = computed<'default' | 'secondary' | 'outline'>(() => {
|
||
if (store.envLoading) return 'outline'
|
||
if (store.env?.musicdlOutdated) return 'outline'
|
||
return store.env?.musicdlInstalled ? 'default' : 'secondary'
|
||
})
|
||
const envBadgeText = computed(() => {
|
||
if (store.envLoading) return '检测中…'
|
||
if (!store.env?.musicdlInstalled) return '未安装'
|
||
return store.env?.musicdlOutdated ? '需更新' : '就绪'
|
||
})
|
||
const envBadgeClass = computed(() =>
|
||
!store.envLoading && store.env?.musicdlOutdated
|
||
? 'border-warning/40 text-warning-text'
|
||
: ''
|
||
)
|
||
|
||
const installPercent = computed(() => store.installProgress?.percent ?? 0)
|
||
const installMessage = computed(() => store.installProgress?.message ?? '')
|
||
const diagnosticsOpen = ref(false)
|
||
|
||
/** 发现音乐结果行网格(表头与行保持一致) */
|
||
const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 92px' }
|
||
</script>
|
||
|
||
<template>
|
||
<div class="min-h-full p-5 flex flex-col">
|
||
<Tabs v-model="activeTab" class="min-h-0 flex-1 flex flex-col">
|
||
<!-- ===== 曲库 ===== -->
|
||
<TabsContent value="mymusic" class="min-h-0 flex-1 tab-animate">
|
||
<MyMusicLibrary />
|
||
</TabsContent>
|
||
|
||
<!-- ===== 发现音乐 ===== -->
|
||
<TabsContent value="discover" class="min-h-0 flex-1 flex flex-col tab-animate">
|
||
<!-- 工具栏:搜索主操作留在首行 -->
|
||
<header class="flex shrink-0 items-center gap-2 border-b pb-3">
|
||
<div ref="searchBoxRef" class="relative min-w-0 flex-1 max-w-md" @focusin="historyOpen = true" @focusout="onHistoryFocusOut">
|
||
<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="keyword"
|
||
class="h-9 pl-8"
|
||
placeholder="搜索歌名 / 歌手 / 专辑"
|
||
@keydown.enter="doSearch"
|
||
/>
|
||
<div
|
||
v-if="historyOpen && filteredHistory.length > 0"
|
||
class="absolute left-0 top-full z-50 mt-1 w-full rounded-lg border bg-popover p-1 shadow-md"
|
||
>
|
||
<div class="flex items-center justify-between px-2 py-1">
|
||
<span class="flex items-center gap-1 text-[10px] text-muted-foreground">
|
||
<History class="size-3" /> 搜索历史
|
||
</span>
|
||
<button type="button" class="text-[10px] text-muted-foreground hover:text-foreground" @click="clearHistory">
|
||
清空
|
||
</button>
|
||
</div>
|
||
<button
|
||
v-for="h in filteredHistory"
|
||
:key="h"
|
||
type="button"
|
||
class="flex w-full items-center gap-2 truncate rounded-md px-2 py-1.5 text-left text-[13px] hover:bg-row-hover"
|
||
@click="pickHistory(h)"
|
||
>
|
||
<History class="size-3.5 shrink-0 text-muted-foreground" />
|
||
<span class="truncate">{{ h }}</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<SourcePicker v-model="settingsSources" :options="sourceOptions" />
|
||
|
||
<Popover v-model:open="playlistLinkOpen">
|
||
<PopoverTrigger as-child>
|
||
<Button variant="outline" size="sm" class="h-9">
|
||
<Link2 class="size-3.5" />
|
||
<span class="ml-1.5">歌单链接</span>
|
||
</Button>
|
||
</PopoverTrigger>
|
||
<PopoverContent class="w-96 p-3" align="start">
|
||
<p class="mb-2 text-[12px] text-muted-foreground">
|
||
粘贴网易云 / QQ 音乐等歌单链接,解析后可直接批量试听与下载。
|
||
</p>
|
||
<div class="flex items-center gap-2">
|
||
<Input
|
||
v-model="playlistUrl"
|
||
class="h-8"
|
||
placeholder="https://music.163.com/playlist?id=..."
|
||
@keydown.enter="doParsePlaylist"
|
||
/>
|
||
<Button size="sm" class="h-8 shrink-0" :disabled="parsingPlaylist" @click="doParsePlaylist">
|
||
<Loader2 v-if="parsingPlaylist" class="size-3.5 animate-spin" />
|
||
<span :class="parsingPlaylist ? 'ml-1.5' : ''">{{ parsingPlaylist ? '解析中' : '解析' }}</span>
|
||
</Button>
|
||
</div>
|
||
</PopoverContent>
|
||
</Popover>
|
||
|
||
<Button class="h-9" :disabled="store.searching" @click="doSearch">
|
||
<Loader2 v-if="store.searching" class="size-4 animate-spin" />
|
||
<Search v-else class="size-4" />
|
||
<span class="ml-1.5">{{ store.searching ? '搜索中' : '搜索' }}</span>
|
||
</Button>
|
||
|
||
<!-- 下载任务:点击弹出,简化为 list item -->
|
||
<Popover v-model:open="tasksOpen">
|
||
<PopoverTrigger as-child>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
class="h-9 shrink-0"
|
||
:title="`下载任务(${store.tasks.length})`"
|
||
>
|
||
<ListMusic class="size-3.5" />
|
||
<span class="ml-1.5">下载任务</span>
|
||
<span
|
||
v-if="activeTaskCount > 0"
|
||
class="ml-1.5 min-w-4 rounded-full bg-primary/15 px-1 text-center text-[10.5px] tabular-nums text-primary"
|
||
>
|
||
{{ activeTaskCount }}
|
||
</span>
|
||
</Button>
|
||
</PopoverTrigger>
|
||
<PopoverContent align="end" class="w-[440px] p-0">
|
||
<div class="flex items-center justify-between border-b px-3 py-2">
|
||
<span class="text-[12.5px] font-medium">下载任务</span>
|
||
<button
|
||
v-if="finishedTaskCount > 0"
|
||
type="button"
|
||
class="text-[11px] text-muted-foreground transition-colors hover:text-foreground"
|
||
@click="clearFinishedTasks"
|
||
>
|
||
清除已完成({{ finishedTaskCount }})
|
||
</button>
|
||
</div>
|
||
|
||
<ScrollArea v-if="store.tasks.length" class="max-h-[340px]">
|
||
<ul class="flex flex-col gap-0.5 p-1">
|
||
<li
|
||
v-for="task in store.tasks"
|
||
:key="task.taskId"
|
||
class="flex flex-col gap-1.5 rounded-md px-2 py-2 transition-colors hover:bg-row-hover"
|
||
>
|
||
<div class="flex min-w-0 items-center gap-2">
|
||
<Badge
|
||
:variant="taskStatusInfo(task).variant"
|
||
:class="['shrink-0 px-1.5 py-0 text-[10.5px]', taskStatusInfo(task).class]"
|
||
>
|
||
{{ taskStatusInfo(task).label }}
|
||
</Badge>
|
||
<span class="min-w-0 flex-1 truncate text-[12.5px]">
|
||
{{ taskHeadInfo(task).name }}
|
||
<span v-if="taskHeadInfo(task).sub" class="text-muted-foreground">
|
||
· {{ taskHeadInfo(task).sub }}
|
||
</span>
|
||
</span>
|
||
<span
|
||
v-if="taskQualityDisplay(task)"
|
||
class="shrink-0 rounded border border-border px-1 py-px text-[10px] text-muted-foreground"
|
||
>
|
||
{{ taskQualityDisplay(task) }}
|
||
</span>
|
||
<span class="flex shrink-0 items-center">
|
||
<Button
|
||
v-if="task.status === 'downloading' || task.status === 'cancelling'"
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6"
|
||
:disabled="task.status === 'cancelling'"
|
||
title="取消下载"
|
||
aria-label="取消下载"
|
||
@click="store.cancelDownload(task.taskId)"
|
||
>
|
||
<X class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
v-if="TASK_RETRYABLE_STATUSES.includes(task.status) && task.songsData?.length"
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6"
|
||
title="重新下载"
|
||
aria-label="重新下载"
|
||
@click="store.redownloadTask(task.taskId).catch((e) => toast.error(`重新下载失败:${e}`))"
|
||
>
|
||
<RotateCw class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
v-if="task.savedir"
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6"
|
||
title="打开下载目录"
|
||
aria-label="打开下载目录"
|
||
@click="openDir(task.savedir)"
|
||
>
|
||
<FolderOpen class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
v-if="task.status === 'done'"
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6"
|
||
:disabled="feiniu.uploading || !feiniu.webdavReady"
|
||
:title="
|
||
feiniu.webdavReady
|
||
? '上传该任务下载的文件到飞牛曲库'
|
||
: '需先在「设置 → 存储与上传」完成 WebDAV 配置'
|
||
"
|
||
aria-label="上传该任务到飞牛曲库"
|
||
@click="uploader.uploadTask(task.taskId)"
|
||
>
|
||
<Upload class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6 text-destructive"
|
||
title="删除任务"
|
||
aria-label="删除任务"
|
||
@click="store.removeTask(task.taskId)"
|
||
>
|
||
<Trash2 class="size-3.5" />
|
||
</Button>
|
||
</span>
|
||
</div>
|
||
|
||
<div class="flex items-center gap-2">
|
||
<Progress class="h-1 flex-1" :model-value="taskPercent(task)" />
|
||
<span class="shrink-0 text-[10.5px] tabular-nums text-muted-foreground">
|
||
{{ formatBytes(taskAggDone(task)) }}<template v-if="taskAggTotal(task)">
|
||
/ {{ formatBytes(taskAggTotal(task)) }}</template
|
||
>
|
||
</span>
|
||
<span v-if="taskSongProgress(task)" class="shrink-0 text-[10.5px] text-muted-foreground">
|
||
{{ taskSongProgress(task) }}
|
||
</span>
|
||
</div>
|
||
|
||
<p v-if="task.errorMessage" class="truncate text-[11px] text-destructive">
|
||
{{ task.errorMessage }}
|
||
</p>
|
||
</li>
|
||
</ul>
|
||
</ScrollArea>
|
||
<p v-else class="px-3 py-8 text-center text-[12px] text-muted-foreground">
|
||
暂无下载任务,搜索并选择歌曲下载后会显示在这里。
|
||
</p>
|
||
</PopoverContent>
|
||
</Popover>
|
||
</header>
|
||
|
||
<!-- 筛选条 -->
|
||
<div
|
||
v-if="flatResults.length > 0"
|
||
class="flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 border-b py-2 text-[12px] text-muted-foreground"
|
||
>
|
||
<label class="flex cursor-pointer items-center gap-1.5">
|
||
<Checkbox
|
||
:model-value="allSelected"
|
||
:aria-label="'全选当前结果'"
|
||
@update:model-value="toggleSelectAll"
|
||
/>
|
||
全选
|
||
</label>
|
||
<span>
|
||
共 {{ store.resultTotal }} 条<template v-if="sourceFilter !== 'all' || qualityFilter !== 'all'">
|
||
(筛选后 {{ filteredResults.length }} 条)</template
|
||
>
|
||
</span>
|
||
|
||
<div class="ml-auto flex items-center gap-2">
|
||
<Select v-model="sourceFilter">
|
||
<SelectTrigger class="h-7 w-28 text-[12px]"><SelectValue /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="all">全部来源</SelectItem>
|
||
<SelectItem v-for="s in availableResultSources" :key="s" :value="s">{{ sourceName(s) }}</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
|
||
<Select v-model="qualityFilter">
|
||
<SelectTrigger class="h-7 w-28 text-[12px]"><SelectValue /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="all">全部音质</SelectItem>
|
||
<SelectItem value="lossless">仅无损</SelectItem>
|
||
<SelectItem value="mp3">仅 MP3</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
|
||
<Select v-model="downloadTarget">
|
||
<SelectTrigger class="h-7 w-28 text-[12px]"><SelectValue /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="local">下载到本地</SelectItem>
|
||
<SelectItem value="feiniu">下载到飞牛</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
|
||
<!-- 多选后的主操作:与「搜索」按钮同款(默认主色、h-9) -->
|
||
<Button v-if="selectedSongs.length > 0" class="h-9" @click="downloadSelected">
|
||
<Download class="size-4" />
|
||
<span class="ml-1.5">下载所选 ({{ selectedSongs.length }})</span>
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 结果列表 -->
|
||
<div class="min-h-0 flex-1">
|
||
<div class="pb-4">
|
||
<div v-if="store.searching" class="space-y-1.5 pt-3">
|
||
<div v-for="i in 8" :key="i" class="h-11 animate-pulse rounded-md bg-muted/40" />
|
||
</div>
|
||
|
||
<Empty v-else-if="store.searchError">
|
||
<EmptyMedia><CircleAlert class="size-8 text-destructive" /></EmptyMedia>
|
||
<EmptyTitle>搜索失败</EmptyTitle>
|
||
<EmptyDescription>{{ store.searchError }}</EmptyDescription>
|
||
</Empty>
|
||
|
||
<Empty v-else-if="store.resultTotal === 0 && store.searched">
|
||
<EmptyMedia><Info class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>未找到相关歌曲</EmptyTitle>
|
||
<EmptyDescription>试试更换关键词,或在右上角增加搜索源。</EmptyDescription>
|
||
</Empty>
|
||
|
||
<Empty v-else-if="flatResults.length === 0">
|
||
<EmptyMedia><Music2 class="size-8 text-muted-foreground" /></EmptyMedia>
|
||
<EmptyTitle>搜索多个平台的音乐</EmptyTitle>
|
||
<EmptyDescription>
|
||
输入关键词后回车即可聚合搜索;也可以粘贴歌单链接批量导入。
|
||
</EmptyDescription>
|
||
</Empty>
|
||
|
||
<template v-else>
|
||
<template v-for="d in visibleItems" :key="d.type === 'header' ? `h:${d.source}` : d.song!.key">
|
||
<!-- 分组头:不设底色/不吸顶,避免在浅色背景上出现白色横条 -->
|
||
<div
|
||
v-if="d.type === 'header'"
|
||
class="flex items-center gap-2 border-b border-border/60 px-2 py-1.5"
|
||
>
|
||
<Checkbox
|
||
:model-value="d.allSelected"
|
||
class="size-3.5"
|
||
:aria-label="`全选 ${sourceName(d.source!)} 结果`"
|
||
@update:model-value="toggleSelectGroup(d)"
|
||
/>
|
||
<span class="text-[12px] font-medium">{{ sourceName(d.source!) }}</span>
|
||
<span class="text-[11.5px] text-muted-foreground">{{ d.count }} 首</span>
|
||
</div>
|
||
|
||
<!-- 歌曲行 -->
|
||
<div
|
||
v-else
|
||
class="group grid h-11 items-center gap-3 rounded-md px-2 transition-colors hover:bg-row-hover"
|
||
:style="RESULT_GRID"
|
||
>
|
||
<Checkbox
|
||
:model-value="selectedKeys.has(d.song!.key)"
|
||
class="size-3.5"
|
||
:aria-label="`选择 ${d.song!.song.songName}`"
|
||
@update:model-value="toggleSelect(d.song!.key)"
|
||
/>
|
||
|
||
<img
|
||
v-if="d.song!.song.coverUrl"
|
||
:src="d.song!.song.coverUrl"
|
||
class="size-9 rounded object-cover"
|
||
referrerpolicy="no-referrer"
|
||
loading="lazy"
|
||
alt=""
|
||
@error="($event.target as HTMLImageElement).style.display = 'none'"
|
||
/>
|
||
<div v-else class="flex size-9 items-center justify-center rounded bg-muted text-muted-foreground">
|
||
<Music2 class="size-4" />
|
||
</div>
|
||
|
||
<div class="min-w-0">
|
||
<div class="truncate text-[13px]">{{ d.song!.song.songName || '未知歌名' }}</div>
|
||
<div class="truncate text-[11.5px] text-muted-foreground">
|
||
{{ d.song!.song.singers || '未知歌手'
|
||
}}<template v-if="d.song!.song.album"> · {{ d.song!.song.album }}</template>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 音质:单枚中性徽标,点击查看全部档位 -->
|
||
<div class="min-w-0">
|
||
<Popover v-if="d.song!.song.qualities?.length">
|
||
<PopoverTrigger as-child>
|
||
<button
|
||
type="button"
|
||
class="inline-flex max-w-full items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10.5px] text-muted-foreground transition-colors hover:bg-accent"
|
||
>
|
||
<span class="truncate">{{ qualitySummary(d.song!.song) }}</span>
|
||
<span v-if="d.song!.song.qualities.length > 1" class="shrink-0">
|
||
+{{ d.song!.song.qualities.length - 1 }}
|
||
</span>
|
||
</button>
|
||
</PopoverTrigger>
|
||
<PopoverContent class="w-60 p-2" align="start">
|
||
<p class="px-1 pb-1.5 text-[11px] text-muted-foreground">可选音质档位</p>
|
||
<div class="flex flex-col gap-0.5">
|
||
<div
|
||
v-for="(q, qi) in d.song!.song.qualities"
|
||
:key="q.label ?? qi"
|
||
class="flex items-center justify-between gap-3 rounded px-1.5 py-1 text-[12px]"
|
||
>
|
||
<span>{{ q.label || '未知' }}<span v-if="q.ext" class="ml-1 uppercase text-muted-foreground">{{ q.ext }}</span></span>
|
||
<span class="shrink-0 text-[11px] tabular-nums text-muted-foreground">
|
||
{{ q.size || formatBitrate(q.bitrate) }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</PopoverContent>
|
||
</Popover>
|
||
<span v-else-if="qualitySummary(d.song!.song)" class="text-[11px] text-muted-foreground">
|
||
{{ qualitySummary(d.song!.song) }}
|
||
</span>
|
||
</div>
|
||
|
||
<span class="text-right text-[11.5px] tabular-nums text-muted-foreground">
|
||
{{ formatDuration(d.song!.song.durationS, d.song!.song.duration) }}
|
||
</span>
|
||
|
||
<!-- 操作:悬停显现,保持行内干净 -->
|
||
<div class="flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100">
|
||
<Button
|
||
size="icon"
|
||
variant="ghost"
|
||
class="size-7"
|
||
:disabled="(!d.song!.song.downloadUrl && !d.song!.song.rawSearch) || resolvingKeys.has(d.song!.key)"
|
||
:title="
|
||
resolvingKeys.has(d.song!.key)
|
||
? '解析中…'
|
||
: previewKey === d.song!.key
|
||
? '停止试听'
|
||
: d.song!.song.downloadUrl || d.song!.song.rawSearch
|
||
? '在线试听'
|
||
: '无可用播放源'
|
||
"
|
||
@click="togglePreview(d.song!.song, d.song!.source, d.song!.index)"
|
||
>
|
||
<Loader2 v-if="resolvingKeys.has(d.song!.key)" class="size-3.5 animate-spin" />
|
||
<Square v-else-if="previewKey === d.song!.key" class="size-3.5" />
|
||
<Play v-else class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
size="icon"
|
||
variant="ghost"
|
||
class="size-7"
|
||
:disabled="!d.song!.song.downloadUrl && !d.song!.song.rawSearch"
|
||
:title="d.song!.song.downloadUrl || d.song!.song.rawSearch ? '下载' : '无可用下载源'"
|
||
@click="downloadOne(d.song!.song)"
|
||
>
|
||
<Download class="size-3.5" />
|
||
</Button>
|
||
<!-- 下载 + 上传飞牛一条龙(本地不留文件) -->
|
||
<Button
|
||
size="icon"
|
||
variant="ghost"
|
||
class="size-7"
|
||
:disabled="(!d.song!.song.downloadUrl && !d.song!.song.rawSearch) || uploader.rowUploadingKeys.has(d.song!.key)"
|
||
:title="
|
||
uploader.rowUploadingKeys.has(d.song!.key)
|
||
? '正在上传到飞牛…'
|
||
: !d.song!.song.downloadUrl && !d.song!.song.rawSearch
|
||
? '无可用下载源'
|
||
: feiniu.webdavReady
|
||
? '下载并上传到飞牛曲库(不保留本地文件)'
|
||
: '下载到飞牛(需先在设置中完成 WebDAV 配置)'
|
||
"
|
||
@click="uploader.downloadToFeiniu(d.song!.song, d.song!.source, d.song!.index)"
|
||
>
|
||
<Loader2 v-if="uploader.rowUploadingKeys.has(d.song!.key)" class="size-3.5 animate-spin" />
|
||
<CloudUpload v-else class="size-3.5" />
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<div
|
||
v-if="hasMore"
|
||
ref="loadMoreRef"
|
||
class="flex items-center justify-center gap-1.5 py-3 text-[11.5px] text-muted-foreground"
|
||
>
|
||
<Loader2 class="size-3.5 animate-spin" />
|
||
加载更多({{ visibleItems.length }}/{{ displayItems.length }})
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
</TabsContent>
|
||
|
||
<!-- ===== 设置(与其他模块一致的 Card 卡片式布局) ===== -->
|
||
<TabsContent value="settings" class="min-h-0 flex-1 tab-animate">
|
||
<div>
|
||
<div class="flex flex-col gap-4 pb-4">
|
||
<!-- 连接 -->
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle class="flex items-center gap-2 text-base">
|
||
<Link2 class="size-4 text-primary" />
|
||
飞牛音乐连接
|
||
</CardTitle>
|
||
</CardHeader>
|
||
<CardContent class="flex flex-col gap-3">
|
||
<p class="text-xs text-muted-foreground">
|
||
曲库与播放来自飞牛 NAS,可配置局域网(含 frp 等内网转发)或 FnConnect 两种接入方式。
|
||
</p>
|
||
<ConnectionsSettings />
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<!-- 存储与上传 -->
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle class="flex items-center gap-2 text-base">
|
||
<HardDriveDownload class="size-4 text-primary" />
|
||
存储与上传
|
||
</CardTitle>
|
||
</CardHeader>
|
||
<CardContent class="flex flex-col gap-3">
|
||
<p class="text-xs text-muted-foreground">
|
||
本地下载目录用于保存搜索下载的歌曲;NAS 文件服务用于把本地曲目回传到飞牛曲库。
|
||
</p>
|
||
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">本地下载目录</Label>
|
||
<div class="flex items-center gap-2">
|
||
<Input v-model="savedirModel" class="flex-1" />
|
||
<Button variant="ghost" size="icon" title="打开目录" @click="openDir()">
|
||
<FolderOpen class="size-4" />
|
||
</Button>
|
||
<Button variant="outline" size="sm" @click="browseDir">选择…</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 本地曲库目录:可指定多个,添加/移除后自动重扫 -->
|
||
<div class="flex flex-col gap-1.5">
|
||
<div class="flex items-center justify-between gap-2">
|
||
<Label class="text-muted-foreground">本地曲库目录</Label>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
class="h-7"
|
||
:disabled="feiniu.localScanBusy"
|
||
@click="addLocalDirs"
|
||
>
|
||
<Loader2 v-if="feiniu.localScanBusy" class="size-3.5 animate-spin" />
|
||
<Plus v-else class="size-3.5" />
|
||
添加目录
|
||
</Button>
|
||
</div>
|
||
<div v-if="localDirs.length" class="flex flex-col gap-1.5">
|
||
<div
|
||
v-for="(d, i) in localDirs"
|
||
:key="d"
|
||
class="flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"
|
||
>
|
||
<span class="min-w-0 flex-1 truncate font-mono text-[11.5px]" :title="d">{{ d }}</span>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6"
|
||
title="在文件管理器中打开"
|
||
aria-label="在文件管理器中打开"
|
||
@click="openDir(d)"
|
||
>
|
||
<FolderOpen class="size-3.5" />
|
||
</Button>
|
||
<Button
|
||
variant="ghost"
|
||
size="icon"
|
||
class="size-6 text-destructive"
|
||
title="移除该目录"
|
||
aria-label="移除该目录"
|
||
@click="removeLocalDir(i)"
|
||
>
|
||
<Trash2 class="size-3.5" />
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<p v-else class="text-[11.5px] text-muted-foreground">未指定额外目录。</p>
|
||
<p class="text-[11px] text-muted-foreground">
|
||
<template v-if="feiniu.localScanBusy">正在扫描本地曲库…</template>
|
||
<template v-else>
|
||
可添加多个;上面的下载目录始终会被扫描。添加或移除后会立即重新扫描本地曲库。
|
||
</template>
|
||
</p>
|
||
</div>
|
||
|
||
<div class="flex items-center justify-between gap-4">
|
||
<!-- 只写实际用到的能力:NAS 侧删除(webdav_delete)目前没有 UI 入口,不要写成「删除」 -->
|
||
<span class="text-[13px]">WebDAV 传输(上传到飞牛曲库 / 下载到飞牛后清理本地副本)</span>
|
||
<Badge :variant="feiniu.webdavReady ? 'default' : 'secondary'">
|
||
{{ feiniu.webdavReady ? '已配置' : '未配置' }}
|
||
</Badge>
|
||
</div>
|
||
|
||
<!-- 已配置且未在编辑:隐藏账号/密码,只显示摘要 -->
|
||
<template v-if="feiniu.webdavReady && !webdavEditing">
|
||
<div class="flex flex-col gap-1.5 rounded-md border border-border/70 px-3 py-2 text-[12.5px]">
|
||
<div class="flex items-center justify-between gap-4">
|
||
<span class="shrink-0 text-muted-foreground">服务地址</span>
|
||
<span class="truncate font-mono text-[11.5px]">{{ feiniu.webdav.url }}</span>
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<span class="shrink-0 text-muted-foreground">曲库目标目录</span>
|
||
<span class="truncate font-mono text-[11.5px]">{{ feiniu.webdav.dir }}</span>
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<span class="shrink-0 text-muted-foreground">账号 / 密码</span>
|
||
<span class="text-[11.5px] text-muted-foreground">已保存(系统凭据管理器加密存储)</span>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<Button variant="outline" size="sm" @click="webdavEditing = true">修改配置</Button>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
:disabled="webdavTesting || !feiniu.webdav.url || !feiniu.webdav.dir"
|
||
@click="testWebdav"
|
||
>
|
||
<Loader2 v-if="webdavTesting" class="size-3.5 animate-spin" />
|
||
<span :class="webdavTesting ? 'ml-1.5' : ''">
|
||
{{ webdavTesting ? '测试中…' : '测试连接' }}
|
||
</span>
|
||
</Button>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 未配置或编辑中:完整表单(密码输入框本身即为掩码显示) -->
|
||
<template v-else>
|
||
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||
<div class="flex flex-col gap-1.5 md:col-span-2">
|
||
<Label class="text-muted-foreground">WebDAV 服务地址</Label>
|
||
<Input
|
||
:model-value="feiniu.webdav.url"
|
||
placeholder="http://192.168.110.100:5005"
|
||
@update:model-value="(v: unknown) => feiniu.patchWebdav({ url: String(v ?? '') })"
|
||
/>
|
||
</div>
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">账号</Label>
|
||
<Input
|
||
:model-value="feiniu.webdav.username"
|
||
placeholder="飞牛账号"
|
||
@update:model-value="(v: unknown) => feiniu.patchWebdav({ username: String(v ?? '') })"
|
||
/>
|
||
</div>
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">密码</Label>
|
||
<Input
|
||
:model-value="feiniu.webdav.password"
|
||
type="password"
|
||
placeholder="飞牛登录密码"
|
||
@update:model-value="(v: unknown) => feiniu.patchWebdav({ password: String(v ?? '') })"
|
||
/>
|
||
</div>
|
||
<div class="flex flex-col gap-1.5 md:col-span-2">
|
||
<Label class="text-muted-foreground">曲库目标目录(相对 WebDAV 根)</Label>
|
||
<Input
|
||
:model-value="feiniu.webdav.dir"
|
||
placeholder="例如:Music 或 我的文件/Music"
|
||
@update:model-value="(v: unknown) => feiniu.patchWebdav({ dir: String(v ?? '') })"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
:disabled="webdavTesting || !feiniu.webdav.url || !feiniu.webdav.dir"
|
||
@click="testWebdav"
|
||
>
|
||
<Loader2 v-if="webdavTesting" class="size-3.5 animate-spin" />
|
||
<span :class="webdavTesting ? 'ml-1.5' : ''">
|
||
{{ webdavTesting ? '测试中…' : '测试连接' }}
|
||
</span>
|
||
</Button>
|
||
<Button v-if="feiniu.webdavReady" variant="ghost" size="sm" @click="webdavEditing = false">
|
||
收起
|
||
</Button>
|
||
</div>
|
||
</template>
|
||
<details class="rounded-md border border-border/70 px-3 py-2">
|
||
<summary class="cursor-pointer text-[12px] font-medium text-muted-foreground">
|
||
飞牛 NAS 侧需要做什么?
|
||
</summary>
|
||
<ol class="mt-2 list-decimal space-y-1 pl-4 text-[11.5px] leading-relaxed text-muted-foreground">
|
||
<li>
|
||
登录飞牛后台 → <strong class="font-medium">系统设置 → 文件服务(文件共享协议)→ WebDAV</strong>,
|
||
开启 WebDAV 服务并记下端口(HTTP 默认 <code class="rounded bg-muted px-1">5005</code>、HTTPS 默认
|
||
<code class="rounded bg-muted px-1">5006</code>)。
|
||
</li>
|
||
<li>
|
||
在「可见文件夹范围」中勾选存放音乐的文件夹;<strong class="font-medium">团队文件夹</strong>需要在文件管理里编辑该文件夹,
|
||
勾选「允许通过文件共享协议(SMB、WebDAV、FTP)挂载到其他设备上」。
|
||
</li>
|
||
<li>确保上面的账号对该文件夹有<strong class="font-medium">读写</strong>权限。</li>
|
||
<li>目标目录请填 WebDAV 根下的相对路径(登录 WebDAV 后看到的目录结构,不一定是 NAS 内部路径)。</li>
|
||
</ol>
|
||
</details>
|
||
|
||
<div class="flex items-center justify-between gap-4">
|
||
<span class="text-[13px]">下载完成后自动上传到飞牛曲库</span>
|
||
<Switch
|
||
:model-value="feiniu.autoUpload"
|
||
@update:model-value="(v: boolean) => feiniu.setAutoUpload(!!v)"
|
||
/>
|
||
</div>
|
||
|
||
<div class="flex items-center gap-2">
|
||
<Button variant="outline" size="sm" :disabled="feiniu.uploading" @click="uploadRecentToFeiniu">
|
||
<Loader2 v-if="feiniu.uploading" class="size-4 animate-spin" />
|
||
<Upload v-else class="size-4" />
|
||
上传最近下载
|
||
</Button>
|
||
<span class="text-[11.5px] text-muted-foreground">上传最近 10 分钟内下载到本地目录的音频</span>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<!-- 播放 -->
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle class="flex items-center gap-2 text-base">
|
||
<Music2 class="size-4 text-primary" />
|
||
播放
|
||
</CardTitle>
|
||
</CardHeader>
|
||
<CardContent class="flex flex-col gap-3">
|
||
<p class="text-xs text-muted-foreground">
|
||
播放控制常驻在标题栏,切走音乐模块也能继续控制播放。
|
||
</p>
|
||
<CacheSettings />
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<!-- 搜索与下载 -->
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle class="flex items-center gap-2 text-base">
|
||
<Download class="size-4 text-primary" />
|
||
搜索与下载
|
||
</CardTitle>
|
||
</CardHeader>
|
||
<CardContent class="flex flex-col gap-4">
|
||
<p class="text-xs text-muted-foreground">
|
||
搜索与下载会在选中的平台聚合;默认网易云 / QQ 音乐 / 酷狗。
|
||
</p>
|
||
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">搜索源(可多选)</Label>
|
||
<SourcePicker v-model="settingsSources" :options="sourceOptions" />
|
||
</div>
|
||
|
||
<!-- QQ 音乐 Cookie(可选):解析需登录歌单 / VIP 音质 -->
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">QQ 音乐 Cookie(可选)</Label>
|
||
<Input
|
||
v-model="qqCookieModel"
|
||
type="password"
|
||
class="font-mono text-[12px]"
|
||
placeholder="粘贴 y.qq.com 的 Cookie(至少含 uin 与 qqmusic_key)"
|
||
autocomplete="off"
|
||
/>
|
||
<p class="text-[11px] text-muted-foreground">
|
||
用于解析需要登录的歌单(含自己的隐私歌单)与 VIP 音质。获取:浏览器登录
|
||
y.qq.com → F12 → Network → 任选请求 → 复制请求头 Cookie 全文粘贴;仅保存在本机
|
||
(系统凭据管理器加密存储,与 WebDAV 密码同级)。
|
||
注意:配置后 QQ 音乐会改走官方接口(跳过第三方解析源)。
|
||
</p>
|
||
</div>
|
||
|
||
<div class="grid grid-cols-2 gap-x-6 gap-y-3">
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">同步下载歌词</Label>
|
||
<Switch v-model="lyricModel" />
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">同步下载封面</Label>
|
||
<Switch v-model="coverModel" />
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">搜索 / 下载走代理</Label>
|
||
<Switch v-model="proxyModel" />
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">下载时弹窗选择音质</Label>
|
||
<Switch v-model="selectQualityModel" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="grid grid-cols-2 gap-x-6 gap-y-3">
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">默认下载音质</Label>
|
||
<Select v-model="defaultQualityModel">
|
||
<SelectTrigger><SelectValue placeholder="选择默认音质" /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="最高">最高</SelectItem>
|
||
<SelectItem value="Hi-Res">Hi-Res</SelectItem>
|
||
<SelectItem value="无损">无损</SelectItem>
|
||
<SelectItem value="320K">320K</SelectItem>
|
||
<SelectItem value="192K">192K</SelectItem>
|
||
<SelectItem value="128K">128K</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
</div>
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">最大并发下载数</Label>
|
||
<Input v-model="concurrentModel" type="number" min="1" max="16" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex flex-col gap-1.5">
|
||
<Label class="text-muted-foreground">下载引擎</Label>
|
||
<Select v-model="engineModel">
|
||
<SelectTrigger><SelectValue placeholder="选择下载引擎" /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="musicdl">musicdl(推荐:支持歌词 / 封面 / 解密)</SelectItem>
|
||
<SelectItem value="rust">Rust 引擎(任务在「下载器」模块)</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
<p class="text-[11.5px] text-muted-foreground">
|
||
musicdl 引擎的任务与进度在本模块内管理,并支持自动回传飞牛曲库;Rust 引擎把下载交给「下载器」模块,
|
||
该模式下「下载到飞牛」不可用。
|
||
</p>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<!-- 环境与诊断 -->
|
||
<Card>
|
||
<CardHeader>
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-2 text-left"
|
||
@click="diagnosticsOpen = !diagnosticsOpen"
|
||
>
|
||
<Info class="size-4 text-primary" />
|
||
<span class="text-base font-semibold leading-none">环境与诊断</span>
|
||
<Badge
|
||
:variant="envBadgeVariant"
|
||
:class="envBadgeClass"
|
||
class="ml-1"
|
||
>
|
||
{{ envBadgeText }}
|
||
</Badge>
|
||
<span class="ml-auto text-[11.5px] text-muted-foreground">
|
||
{{ store.envLoading ? '正在探测运行时…' : `Python ${store.env?.python ?? '—'}` }}
|
||
</span>
|
||
</button>
|
||
</CardHeader>
|
||
|
||
<CardContent v-if="diagnosticsOpen" class="flex flex-col gap-2">
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">Python 运行时</Label>
|
||
<div class="flex items-center gap-2">
|
||
<Badge
|
||
:variant="
|
||
store.envLoading
|
||
? 'outline'
|
||
: store.env?.pythonSource === 'none'
|
||
? 'destructive'
|
||
: 'secondary'
|
||
"
|
||
>
|
||
{{
|
||
store.envLoading
|
||
? '检测中…'
|
||
: store.env?.pythonSource === 'bundled'
|
||
? '便携版'
|
||
: store.env?.pythonSource === 'system'
|
||
? '系统'
|
||
: '未安装'
|
||
}}
|
||
</Badge>
|
||
<span class="text-[12.5px]">
|
||
{{ store.envLoading ? '探测中…' : store.env?.python ?? '—' }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">musicdl</Label>
|
||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||
<Badge
|
||
:variant="
|
||
store.envLoading
|
||
? 'outline'
|
||
: store.env?.musicdlOutdated
|
||
? 'outline'
|
||
: store.env?.musicdlInstalled
|
||
? 'default'
|
||
: 'secondary'
|
||
"
|
||
:class="
|
||
!store.envLoading && store.env?.musicdlOutdated
|
||
? 'border-warning/40 text-warning-text'
|
||
: ''
|
||
"
|
||
>
|
||
{{
|
||
store.envLoading
|
||
? '检测中…'
|
||
: store.env?.musicdlOutdated
|
||
? '版本不一致'
|
||
: store.env?.musicdlInstalled
|
||
? '已安装'
|
||
: '未安装'
|
||
}}
|
||
</Badge>
|
||
<span
|
||
class="text-[12.5px] tabular-nums"
|
||
:class="!store.envLoading && store.env?.musicdlOutdated ? 'text-warning-text' : ''"
|
||
>
|
||
<template v-if="store.envLoading">探测中…</template>
|
||
<template v-else-if="!store.env?.musicdlInstalled">—</template>
|
||
<template v-else-if="store.env?.musicdlOutdated">
|
||
{{ store.env?.musicdlVersion ?? '未知版本' }} → 需要 {{ store.env?.musicdlExpected }}
|
||
</template>
|
||
<template v-else>{{ store.env?.musicdlVersion ?? '—' }}</template>
|
||
</span>
|
||
<!-- 更新:只把 musicdl 对齐到本应用锁定的版本(升到 PyPI 最新会破坏 bridge 的版本耦合补丁) -->
|
||
<Button
|
||
v-if="!store.envLoading && store.env?.musicdlInstalled && store.env?.musicdlOutdated"
|
||
size="sm"
|
||
class="h-7"
|
||
:disabled="store.installing || activeTaskCount > 0"
|
||
:title="
|
||
activeTaskCount > 0
|
||
? '有下载任务进行中:更新会重启桥接进程并中断它们'
|
||
: `更新到 ${store.env?.musicdlExpected}`
|
||
"
|
||
@click="updateMusicdl(false)"
|
||
>
|
||
<RotateCw :class="store.installing ? 'size-3.5 animate-spin' : 'size-3.5'" />
|
||
<span class="ml-1">更新</span>
|
||
</Button>
|
||
<!-- 修复:强制重装。「能 import musicdl」证明不了子模块可用,这是那条灰区的出口 -->
|
||
<Button
|
||
v-if="!store.envLoading && store.env?.musicdlInstalled"
|
||
variant="outline"
|
||
size="sm"
|
||
class="h-7"
|
||
:disabled="store.installing || activeTaskCount > 0"
|
||
:title="
|
||
activeTaskCount > 0
|
||
? '有下载任务进行中:重装会重启桥接进程并中断它们'
|
||
: '强制重装 musicdl(搜索报错但探测显示已安装时使用)'
|
||
"
|
||
@click="updateMusicdl(true)"
|
||
>
|
||
修复
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">FFmpeg(可选)</Label>
|
||
<div class="flex items-center gap-2">
|
||
<Badge variant="outline">
|
||
{{ store.envLoading ? '检测中…' : store.env?.ffmpeg ? '可用' : '未安装' }}
|
||
</Badge>
|
||
<span class="text-[12px] text-muted-foreground">
|
||
{{ store.envLoading ? '探测中…' : store.env?.ffmpeg ?? '部分海外音源需要' }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-center justify-between gap-4">
|
||
<Label class="text-muted-foreground">桥接进程</Label>
|
||
<div class="flex items-center gap-2">
|
||
<Badge :variant="store.env?.bridgeRunning ? 'default' : 'outline'">
|
||
{{ store.env?.bridgeRunning ? '运行中' : '已停止' }}
|
||
</Badge>
|
||
<Button variant="outline" size="sm" class="h-7" :disabled="pinging" @click="testBridge">
|
||
<RotateCw :class="pinging ? 'size-3.5 animate-spin' : 'size-3.5'" />
|
||
<span class="ml-1">自检</span>
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<div class="flex items-start justify-between gap-4">
|
||
<Label class="shrink-0 text-muted-foreground">运行时目录</Label>
|
||
<span class="truncate font-mono text-[11.5px] text-muted-foreground" :title="store.env?.runtimeDir">
|
||
{{ runtimeDisplay || '—' }}
|
||
</span>
|
||
</div>
|
||
|
||
<template v-if="store.installing">
|
||
<Separator />
|
||
<div class="flex items-center justify-between">
|
||
<span class="text-[12.5px]">{{ installMessage }}</span>
|
||
<span class="text-[12.5px] font-medium">{{ installPercent }}%</span>
|
||
</div>
|
||
<Progress :model-value="installPercent" />
|
||
<p class="text-[11.5px] text-muted-foreground">
|
||
下载与安装依赖需要几分钟:进度条在下载阶段推进,依赖安装阶段按步骤跳转。
|
||
</p>
|
||
<Button variant="outline" size="sm" @click="store.cancelInstall()">取消</Button>
|
||
</template>
|
||
<template v-else>
|
||
<!-- 失败原因放在分支外:安装与更新共用同一块面板,更新失败也要看得见 -->
|
||
<p v-if="store.installError" class="break-all text-[11.5px] text-destructive">
|
||
{{ store.installError }}
|
||
</p>
|
||
<template v-if="!store.envLoading && !store.env?.musicdlInstalled">
|
||
<Separator />
|
||
<div class="flex items-center gap-2">
|
||
<Button size="sm" @click="doInstall">安装便携版(Python + musicdl)</Button>
|
||
<span class="text-[11.5px] text-muted-foreground">
|
||
自动下载约 11MB 便携 Python 并安装 musicdl
|
||
</span>
|
||
</div>
|
||
</template>
|
||
</template>
|
||
</CardContent>
|
||
</Card>
|
||
</div>
|
||
</div>
|
||
</TabsContent>
|
||
</Tabs>
|
||
|
||
<!-- 音质选择弹窗 -->
|
||
<Dialog v-model:open="qualityDialogOpen">
|
||
<DialogContent class="sm:max-w-sm">
|
||
<DialogHeader>
|
||
<DialogTitle>选择下载音质</DialogTitle>
|
||
<DialogDescription>
|
||
将下载
|
||
{{ pendingQualitySongs.length > 1 ? `${pendingQualitySongs.length} 首歌曲` : pendingQualitySongs[0]?.songName || '' }};
|
||
解析时取「≤ 所选」可用的最优音质,所选档位不可用时自动降档。
|
||
</DialogDescription>
|
||
</DialogHeader>
|
||
<div class="flex flex-col gap-1.5 py-1">
|
||
<button
|
||
v-for="opt in qualityOptionsFor(pendingQualitySongs)"
|
||
:key="opt"
|
||
type="button"
|
||
class="flex items-center justify-between rounded-md border px-3 py-2 text-[13px] transition-colors"
|
||
:class="
|
||
chosenQuality === opt
|
||
? 'border-primary bg-primary/10 text-foreground'
|
||
: 'border-border hover:bg-row-hover'
|
||
"
|
||
@click="chosenQuality = opt"
|
||
>
|
||
{{ opt }}
|
||
<span v-if="chosenQuality === opt" class="text-primary">✓</span>
|
||
</button>
|
||
</div>
|
||
<DialogFooter>
|
||
<Button variant="outline" @click="qualityDialogOpen = false">取消</Button>
|
||
<Button @click="confirmQualityDialog">开始下载</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</div>
|
||
</template>
|