音乐控制/解密

This commit is contained in:
LFeng committed 2026-09-28 00:21:12 +08:00
1 parent 9e6d73e191
commit ff1d5cd517
41 files changed
+10827 -4

No files matched your search

+25
View File
@@ -19,6 +19,7 @@ import {
Plus,
RotateCw,
Search,
Smartphone,
Square,
Trash2,
Upload,
@@ -39,8 +40,10 @@ import { commands } from '@/lib/bindings'
import { sourceName, PICKER_SOURCES } from './sources'
import SourcePicker from './SourcePicker.vue'
import MyMusicLibrary from './components/MyMusicLibrary.vue'
import DecryptPanel from './components/DecryptPanel.vue'
import ConnectionsSettings from './components/settings/ConnectionsSettings.vue'
import CacheSettings from './components/settings/CacheSettings.vue'
import RemoteSettings from './components/settings/RemoteSettings.vue'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
@@ -76,6 +79,7 @@ const activeTab = ref('mymusic')
useModuleTabs('music', activeTab, [
{ value: 'mymusic', label: '曲库' },
{ value: 'discover', label: '发现音乐' },
{ value: 'decrypt', label: '解密' },
{ value: 'settings', label: '设置' }
], { alwaysVisible: true })
@@ -1263,6 +1267,11 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
</div>
</TabsContent>
<!-- ===== 解密(本地加密音乐文件解密) ===== -->
<TabsContent value="decrypt" class="min-h-0 flex-1 flex flex-col tab-animate">
<DecryptPanel />
</TabsContent>
<!-- ===== 设置(与其他模块一致的 Card 卡片式布局) ===== -->
<TabsContent value="settings" class="min-h-0 flex-1 tab-animate">
<div>
@@ -1283,6 +1292,22 @@ const RESULT_GRID = { gridTemplateColumns: '24px 36px minmax(0,1fr) 108px 52px 9
</CardContent>
</Card>
<!-- 手机互联(MUSIC_REMOTE_PLAN:发现/配对/设备管理) -->
<Card>
<CardHeader>
<CardTitle class="flex items-center gap-2 text-base">
<Smartphone class="size-4 text-primary" />
手机互联
</CardTitle>
</CardHeader>
<CardContent class="flex flex-col gap-3">
<p class="text-xs text-muted-foreground">
手机上的 LFMusic 自动发现并连接本机,显示当前播放、远程控制(播放/暂停/切歌/进度)。
</p>
<RemoteSettings />
</CardContent>
</Card>
<!-- 存储与上传 -->
<Card>
<CardHeader>
@@ -0,0 +1,505 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { toast } from 'vue-sonner'
import { open as openDialog } from '@tauri-apps/plugin-dialog'
import { revealItemInDir } from '@tauri-apps/plugin-opener'
import {
CircleAlert,
CircleCheck,
CloudDownload,
FileAudio,
FolderOpen,
FolderSearch,
Image,
Loader2,
Play,
RotateCw,
Trash2,
TriangleAlert,
X
} from '@lucide/vue'
import { useDecryptStore, type DecryptRow, type DecryptTask } from '@/stores/decryptStore'
import { useMusicStore } from '@/stores/musicStore'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Progress } from '@/components/ui/progress'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Switch } from '@/components/ui/switch'
import { Label } from '@/components/ui/label'
import { StateBlock, StatusBadge, StatusDot } from '@/components/common'
const store = useDecryptStore()
const music = useMusicStore()
/**
* 支持的后缀,仅用于文件对话框的过滤器。
*
* **真正的平台判定在 Rust 侧按内容做**(`scan::route`:先看 ncm 头部魔数、
* 再看 QMC 尾部形态),所以文件夹扫描不依赖这张表——它只是让散选时
* 用户能一眼看到哪些格式可选。
*/
const NCM_EXT = ['ncm']
const QQ_EXT = [
'mgg',
'mgg0',
'mgg1',
'mggl',
'mflac',
'mflac0',
'mflach',
'mmp4',
'qmc0',
'qmc2',
'qmc3',
'qmcflac',
'qmcogg'
]
/** 输出目录:默认 `savedir/decrypted`,允许本次会话内改(不落盘,见计划 §8) */
const outDirOverride = ref('')
const defaultOutDir = computed(() => {
const base = music.settings?.savedir ?? ''
if (!base) return ''
return `${base.replace(/[\\/]+$/, '')}\\decrypted`
})
const outDir = computed(() => outDirOverride.value || defaultOutDir.value)
/** 就地解密:产物写在源文件同目录。文件夹批量默认开启(见 §4.4) */
const inPlace = ref(true)
/** 已选文件夹与扫描预览 */
const pickedFolder = ref('')
const scanning = ref(false)
const scanPreview = ref<{ total: number; ncm: number; qmc: number } | null>(null)
const latest = computed<DecryptTask | null>(() => store.tasks[0] ?? null)
const busy = computed(() => store.hasRunning)
onMounted(() => {
// 监听挂 store:本组件会随 Tabs 切换被卸载重建,事件不能绑在组件生命周期上
void store.ensureListener()
// QQ 在线能力探测:只读本机信息,代价很小,进页签就探一次
void store.probeQq()
})
/** 在线能力状态卡是否展开(折叠后不干扰日常使用) */
const qqStepsOpen = ref(false)
/** 默认只在未就绪时展开步骤,避免占地方 */
const showQqSteps = computed(() => qqStepsOpen.value || !store.qqStatus?.ready)
async function redetectQq() {
const s = await store.probeQq()
if (!s) {
toast.error('检测失败,请查看日志')
} else if (s.ready) {
toast.success('QQ 音乐在线解密已就绪')
} else {
toast.warning(s.message)
}
}
async function pickFolder() {
const picked = await openDialog({
directory: true,
title: '选择要批量解密的文件夹'
})
if (!picked) return
const dir = String(picked)
pickedFolder.value = dir
scanPreview.value = null
scanning.value = true
try {
const summary = await store.scanFolder(dir, dir)
scanPreview.value = summary
if (summary.total === 0) {
toast.warning('该文件夹里没有找到可解密的加密音乐文件')
}
} catch (e) {
toast.error(`扫描文件夹失败:${e}`)
} finally {
scanning.value = false
}
}
async function startFolder() {
if (!pickedFolder.value) return
await start({ folder: pickedFolder.value, root: pickedFolder.value })
}
async function pickFiles() {
const picked = await openDialog({
multiple: true,
title: '选择要解密的音乐文件',
filters: [
{ name: '加密音乐(网易云 / QQ音乐)', extensions: [...NCM_EXT, ...QQ_EXT] },
{ name: '网易云 .ncm', extensions: NCM_EXT },
{ name: 'QQ音乐 QMC 系列', extensions: QQ_EXT }
]
})
if (!picked) return
const files = (Array.isArray(picked) ? picked : [picked]).map(String)
await start({ files })
}
async function start(input: { files?: string[]; folder?: string; root?: string }) {
// 就地模式不需要输出目录;非就地模式必须有
if (!inPlace.value && !outDir.value) {
toast.error('请先在「设置」里配置本地下载目录,或在此指定输出目录')
return
}
try {
await store.run({
files: input.files,
folder: input.folder,
root: input.root,
outDir: outDir.value,
inPlace: inPlace.value
})
} catch (e) {
toast.error(`启动失败:${e}`)
}
}
async function pickOutDir() {
const picked = await openDialog({ directory: true, title: '选择解密输出目录' })
if (picked) outDirOverride.value = String(picked)
}
async function cancel() {
const t = latest.value
if (!t || t.status !== 'running') return
await store.cancel(t.taskId)
toast.info('已请求取消,当前文件完成后停止')
}
async function reveal(path?: string) {
if (!path) return
try {
await revealItemInDir(path)
} catch (e) {
toast.error(`打开所在目录失败:${e}`)
}
}
async function revealTaskDir(t: DecryptTask) {
const first = t.rows.find((r) => r.output)?.output
if (first) return reveal(first)
// 就地模式没有产物时退回源目录
if (t.folder) return reveal(t.folder)
toast.info('该任务还没有产出文件')
}
function rowStatusVariant(s: DecryptRow['status']): 'success' | 'danger' | 'warning' | 'neutral' | 'accent' {
if (s === 'ok') return 'success'
if (s === 'error') return 'danger'
if (s === 'unsupported') return 'warning'
if (s === 'running') return 'accent'
return 'neutral'
}
function rowStatusText(s: DecryptRow['status']): string {
return { pending: '待解密', running: '解密中', ok: '成功', error: '失败', unsupported: '不支持' }[s]
}
/** 平台徽标:优先按路径后缀;文件夹模式下路径可能只有文件名 */
function platformOf(row: DecryptRow): '网易云' | 'QQ音乐' | '—' {
const ext = row.path.split('.').pop()?.toLowerCase() ?? row.name.split('.').pop()?.toLowerCase() ?? ''
if (ext === 'ncm') return '网易云'
if (QQ_EXT.includes(ext)) return 'QQ音乐'
return '—'
}
/** 任务级进度百分比(按已完成文件数,不按字节——字节进度是单文件内的) */
function taskPercent(t: DecryptTask): number {
if (t.total === 0) return 0
return Math.round((t.done / t.total) * 100)
}
function fmtBytes(n: number): string {
if (!n) return '—'
const mb = n / 1024 / 1024
return mb >= 1 ? `${mb.toFixed(1)} MB` : `${Math.round(n / 1024)} KB`
}
const titleOf = (t: DecryptTask) => {
if (t.status === 'running') return `解密中 · ${t.done}/${t.total}`
if (t.status === 'cancelled') return `已取消 · 成功 ${t.ok} / 失败 ${t.failed}`
return `已完成 · 成功 ${t.ok} / 失败 ${t.failed}`
}
/** 文件夹模式下给任务行加相对目录前缀,便于区分同名文件 */
function displayName(row: DecryptRow): string {
if (!row.path) return row.name
return row.path
}
</script>
<template>
<div class="flex min-h-0 flex-1 flex-col gap-3">
<!-- 操作行 -->
<div class="flex flex-wrap items-center gap-2">
<Button size="sm" :disabled="busy" @click="pickFolder">
<FolderSearch class="size-3.5" />
<span class="ml-1.5">选择文件夹</span>
</Button>
<Button variant="outline" size="sm" :disabled="busy" @click="pickFiles">
<FileAudio class="size-3.5" />
<span class="ml-1.5">选择文件</span>
</Button>
<span class="flex items-center gap-1.5 rounded-md border px-2 py-1">
<Switch id="decrypt-inplace" v-model="inPlace" class="scale-90" />
<Label for="decrypt-inplace" class="cursor-pointer text-[11.5px]">就地解密</Label>
</span>
<Button v-if="busy" variant="outline" size="sm" @click="cancel">
<X class="size-3.5" />
<span class="ml-1.5">取消</span>
</Button>
<Button
v-if="store.tasks.some((t) => t.status !== 'running')"
variant="ghost"
size="sm"
@click="store.clearFinished()"
>
<Trash2 class="size-3.5" />
<span class="ml-1.5">清空记录</span>
</Button>
</div>
<!-- 输出目录(就地模式下置灰,因为它不参与写盘) -->
<div class="flex items-center gap-1.5">
<span class="shrink-0 text-[11.5px] text-muted-foreground">输出目录</span>
<Input
:model-value="inPlace ? '与源文件同目录(就地解密)' : outDir"
readonly
:disabled="inPlace"
class="h-8 min-w-0 flex-1 text-[11.5px]"
placeholder="未配置下载目录"
/>
<Button
variant="outline"
size="icon"
class="size-8 shrink-0"
:disabled="inPlace"
title="选择输出目录"
@click="pickOutDir"
>
<FolderOpen class="size-3.5" />
</Button>
</div>
<!-- QQ 音乐在线解密能力(新版 musicex 的前置条件) -->
<div class="rounded-lg border bg-card px-3 py-2">
<div class="flex flex-wrap items-center gap-2 text-[12px]">
<StatusDot
:state="store.qqStatus?.ready ? 'success' : store.qqStatus?.running ? 'warning' : 'neutral'"
:pulse="store.qqProbing"
/>
<span class="font-medium">QQ 音乐在线解密</span>
<span class="min-w-0 flex-1 truncate text-[11.5px] text-muted-foreground">
<template v-if="store.qqProbing">检测中…</template>
<template v-else-if="store.qqStatus">
{{ store.qqStatus.message }}
<template v-if="store.qqStatus.uin">(QQ {{ store.qqStatus.uin }})</template>
</template>
<template v-else>尚未检测</template>
</span>
<Button
variant="ghost"
size="sm"
class="shrink-0"
:disabled="store.qqProbing"
@click="redetectQq"
>
<RotateCw class="size-3.5" :class="store.qqProbing && 'animate-spin'" />
<span class="ml-1.5">重新检测</span>
</Button>
<Button
v-if="store.qqStatus && !store.qqStatus.ready"
variant="ghost"
size="sm"
class="shrink-0"
@click="qqStepsOpen = !qqStepsOpen"
>
{{ showQqSteps ? '收起步骤' : '怎么做?' }}
</Button>
</div>
<!-- 步骤说明 -->
<ol v-if="showQqSteps && store.qqStatus" class="mt-2 flex flex-col gap-1 border-t pt-2">
<li
v-for="(step, i) in store.qqStatus.steps"
:key="i"
class="text-[11.5px] leading-relaxed text-muted-foreground"
>
{{ step }}
</li>
</ol>
<p
v-if="showQqSteps && store.qqStatus && !store.qqStatus.ready"
class="mt-1.5 text-[11.5px] leading-relaxed text-muted-foreground"
>
说明:旧版下载的 <span class="text-foreground">.qmcflac / .mgg / .mflac</span>(尾部内嵌密钥)
以及所有 <span class="text-foreground">.ncm</span> 都<span class="text-foreground">不需要登录</span>,
现在就能离线解密。只有 QQ 客户端 19.57 以上的新版
<span class="text-foreground">musicex</span> 格式才需要上面这些步骤。
</p>
</div>
<!-- 文件夹扫描预览 -->
<div
v-if="pickedFolder"
class="flex flex-wrap items-center gap-2 rounded-lg border bg-card px-3 py-2 text-[12px]"
>
<FolderSearch class="size-3.5 shrink-0 text-muted-foreground" />
<span class="min-w-0 flex-1 truncate" :title="pickedFolder">{{ pickedFolder }}</span>
<template v-if="scanning">
<Loader2 class="size-3.5 animate-spin text-primary" />
<span class="text-[11.5px] text-muted-foreground">扫描中…</span>
</template>
<template v-else-if="scanPreview">
<span class="tabular-nums text-[11.5px] text-muted-foreground">
找到 {{ scanPreview.total }} 个 · 网易云 {{ scanPreview.ncm }} · QQ音乐 {{ scanPreview.qmc }}
</span>
<Button size="sm" :disabled="busy || scanPreview.total === 0" @click="startFolder">
<Play class="size-3.5" />
<span class="ml-1.5">开始解密</span>
</Button>
</template>
<template v-else>
<span class="flex items-center gap-1 text-[11.5px] text-warning-text">
<TriangleAlert class="size-3.5" />未扫描
</span>
</template>
</div>
<!-- 任务区 -->
<div class="flex min-h-0 flex-1 flex-col gap-3 overflow-hidden">
<StateBlock
v-if="store.tasks.length === 0"
variant="empty"
title="还没有解密任务"
description="选择文件夹可批量解密整个目录(递归、保留目录结构);也可散选文件。支持网易云 .ncm 与 QQ音乐 QMC 系列,全部在本机离线完成。"
>
<template #action>
<div class="flex items-center gap-2">
<Button size="sm" :disabled="busy" @click="pickFolder">
<FolderSearch class="size-3.5" />
<span class="ml-1.5">选择文件夹</span>
</Button>
<Button variant="outline" size="sm" :disabled="busy" @click="pickFiles">
<FileAudio class="size-3.5" />
<span class="ml-1.5">选择文件</span>
</Button>
</div>
</template>
</StateBlock>
<ScrollArea v-else class="min-h-0 flex-1">
<div class="flex flex-col gap-3 pr-2">
<div v-for="t in store.tasks" :key="t.taskId" class="rounded-lg border bg-card">
<!-- 任务头 -->
<div class="flex items-center gap-2 border-b px-3 py-2">
<Loader2 v-if="t.status === 'running'" class="size-3.5 shrink-0 animate-spin text-primary" />
<CircleCheck v-else-if="t.status === 'done'" class="size-3.5 shrink-0 text-success" />
<CircleAlert v-else class="size-3.5 shrink-0 text-warning" />
<span class="text-[12.5px] font-medium">{{ titleOf(t) }}</span>
<span class="min-w-0 truncate text-[11.5px] text-muted-foreground" :title="t.folder">
{{ t.folder ? t.folder : `共 ${t.total} 个文件` }}
</span>
<span class="ml-auto flex items-center gap-2">
<span class="text-[11.5px] text-muted-foreground tabular-nums">
<template v-if="t.status === 'running' && t.bytesTotal > 0">
{{ fmtBytes(t.bytesDone) }} / {{ fmtBytes(t.bytesTotal) }}
</template>
<template v-else>{{ t.done }}/{{ t.total }}</template>
</span>
<Button
variant="ghost"
size="icon"
class="size-7"
title="打开产物所在目录"
@click="revealTaskDir(t)"
>
<FolderOpen class="size-3.5" />
</Button>
<Button
v-if="t.status !== 'running'"
variant="ghost"
size="icon"
class="size-7"
title="移除记录"
@click="store.remove(t.taskId)"
>
<X class="size-3.5" />
</Button>
</span>
</div>
<!-- 进度条:结构恒定——任务结束后保留(满格),不整块消失 -->
<div class="px-3 pt-2">
<Progress :model-value="taskPercent(t)" class="h-1.5" />
</div>
<!-- 文件行 -->
<div class="divide-y">
<div
v-for="row in t.rows"
:key="row.index"
class="flex items-center gap-2 px-3 py-1.5 text-[12px]"
>
<span class="min-w-0 flex-1 truncate" :title="displayName(row)">{{ row.name }}</span>
<span class="shrink-0 text-[11.5px] text-muted-foreground">{{ platformOf(row) }}</span>
<StatusBadge :variant="rowStatusVariant(row.status)" size="sm">
{{ rowStatusText(row.status) }}
</StatusBadge>
<Button
v-if="row.output"
variant="ghost"
size="icon"
class="size-7 shrink-0"
title="打开产物所在目录"
@click="reveal(row.output)"
>
<FolderOpen class="size-3.5" />
</Button>
<span v-else class="size-7 shrink-0" />
<!-- 封面单独落盘:也给它一个入口,否则用户不知道它在哪 -->
<Button
v-if="row.cover"
variant="ghost"
size="icon"
class="size-7 shrink-0 text-muted-foreground"
title="打开封面所在目录"
@click="reveal(row.cover)"
>
<Image class="size-3.5" />
</Button>
<span v-else class="size-7 shrink-0" />
<!-- 成功时是备注(平台/密钥形态),失败时是原因 -->
<span
v-if="row.message"
class="max-w-[45%] shrink-0 truncate text-[11.5px]"
:class="row.status === 'ok' ? 'text-muted-foreground' : 'text-danger-text'"
:title="row.message"
>
{{ row.message }}
</span>
</div>
</div>
</div>
</div>
</ScrollArea>
</div>
<!-- 合规说明 -->
<p class="flex items-start gap-1.5 text-[11.5px] leading-relaxed text-muted-foreground">
<CloudDownload class="mt-0.5 size-3 shrink-0" />
仅处理你本人拥有合法访问权限的本地文件,请勿用于批量分发或规避付费授权。QQ音乐加密文件按内容识别(QMC1 固定密钥 / QMC2 尾部内嵌 ekey 可离线解密;新版 musicex 需登录 QQ 音乐联网取密钥,暂未支持)。
</p>
</div>
</template>
@@ -0,0 +1,249 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { toast } from 'vue-sonner'
import { Loader2, QrCode, Smartphone, Trash2 } from '@lucide/vue'
import { invoke } from '@tauri-apps/api/core'
import QRCode from 'qrcode'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
import { Switch } from '@/components/ui/switch'
/** 与 Rust `music::remote` 命令返回值对齐(camelCase;bindings 重生成前手写声明) */
interface RemoteConfig {
enabled: boolean
port: number
running: boolean
runningPort: number
deviceId: string
}
interface RemotePairingInfo {
code: string
qrPayload: string
secondsLeft: number
}
interface RemoteDeviceView {
id: string
name: string
lastConnectedMs: number
online: boolean
}
interface RemoteStatus {
running: boolean
port: number
online: RemoteDeviceView[]
pairing: RemotePairingInfo | null
}
const config = ref<RemoteConfig | null>(null)
const status = ref<RemoteStatus | null>(null)
const devices = ref<RemoteDeviceView[]>([])
const pairing = ref<RemotePairingInfo | null>(null)
const qrDataUrl = ref('')
const busy = ref(false)
const loading = ref(true)
let poll: number | null = null
async function refresh() {
try {
const [c, s, d] = await Promise.all([
invoke<RemoteConfig>('remote_get_config'),
invoke<RemoteStatus>('remote_status'),
invoke<RemoteDeviceView[]>('remote_list_devices'),
])
config.value = c
status.value = s
devices.value = d
const wasPairing = pairing.value !== null
pairing.value = s.pairing
if (s.pairing) {
if (!wasPairing || !qrDataUrl.value) await makeQr(s.pairing.qrPayload)
} else {
qrDataUrl.value = ''
}
} catch (e) {
console.error('remote status refresh failed', e)
} finally {
loading.value = false
}
}
async function makeQr(payload: string) {
try {
qrDataUrl.value = await QRCode.toDataURL(payload, { width: 176, margin: 1 })
} catch (e) {
console.error('QR 生成失败', e)
qrDataUrl.value = ''
}
}
const enabled = computed({
get: () => config.value?.enabled ?? false,
set: (v: boolean) => void toggle(v),
})
async function toggle(v: boolean) {
busy.value = true
try {
config.value = await invoke<RemoteConfig>('remote_set_enabled', { enabled: v })
toast.success(v ? '手机互联已开启,手机 App 可发现本机' : '手机互联已关闭')
if (!v) {
pairing.value = null
qrDataUrl.value = ''
}
await refresh()
} catch (e) {
toast.error(`开启失败:${String(e)}`)
await refresh()
} finally {
busy.value = false
}
}
async function startPairing() {
busy.value = true
try {
const info = await invoke<RemotePairingInfo>('remote_start_pairing')
pairing.value = info
await makeQr(info.qrPayload)
} catch (e) {
toast.error(String(e))
} finally {
busy.value = false
}
}
async function cancelPairing() {
try {
await invoke('remote_cancel_pairing')
} catch (e) {
console.error(e)
}
pairing.value = null
qrDataUrl.value = ''
}
async function revoke(d: RemoteDeviceView) {
if (!window.confirm(`确定吊销「${d.name}」?该设备下次连接需要重新配对。`)) return
try {
await invoke('remote_revoke_device', { id: d.id })
toast.success(`已吊销「${d.name}」`)
await refresh()
} catch (e) {
toast.error(String(e))
}
}
function fmtLast(ms: number): string {
if (!ms) return '从未连接'
return new Date(ms).toLocaleString()
}
onMounted(() => {
void refresh()
poll = window.setInterval(() => void refresh(), 5000)
})
onUnmounted(() => {
if (poll !== null) window.clearInterval(poll)
})
</script>
<template>
<div class="flex flex-col gap-3">
<div v-if="loading" class="flex items-center gap-2 text-xs text-muted-foreground">
<Loader2 class="size-3.5 animate-spin" />
读取手机互联状态…
</div>
<!-- 总开关 -->
<div class="flex items-start justify-between gap-4">
<div class="min-w-0">
<div class="flex items-center gap-2">
<Smartphone class="size-4 text-muted-foreground" />
<Label class="font-medium">手机互联</Label>
</div>
<p class="mt-1 text-[11.5px] text-muted-foreground">
开启后,局域网内的 LFMusic App 会自动发现本机并显示/控制当前播放(歌名、歌手、专辑、封面、进度)。
首次连接需要扫码配对;同一网络下 token 长期有效,可随时在此吊销。
</p>
</div>
<Switch v-model="enabled" class="mt-0.5 shrink-0" :disabled="busy" />
</div>
<!-- 运行状态 -->
<div
v-if="config?.running"
class="flex items-center justify-between rounded-lg border bg-card px-3 py-2 text-[12.5px]"
>
<div class="flex items-center gap-2">
<span class="inline-block size-2 rounded-full" :class="config.running ? 'bg-green-500' : 'bg-muted-foreground/40'" />
<span class="text-muted-foreground">服务运行中</span>
<span class="tabular-nums">ws://0.0.0.0:{{ config.runningPort }}</span>
<span class="text-muted-foreground/80">· 发现广播 :26123</span>
</div>
<span class="text-[11px] text-muted-foreground/80">
防火墙若弹窗,请勾选「专用网络」放行
</span>
</div>
<p v-else-if="config && !config.enabled" class="rounded-lg border border-dashed px-3 py-2 text-[11.5px] text-muted-foreground">
当前关闭。开启后手机端才能发现并连接本机。
</p>
<!-- 配对二维码 -->
<div v-if="pairing" class="flex items-center gap-4 rounded-lg border border-primary/40 bg-primary/5 px-3 py-3">
<img v-if="qrDataUrl" :src="qrDataUrl" class="size-44 rounded bg-white p-1" alt="配对二维码" />
<div class="flex min-w-0 flex-col gap-1.5">
<div class="flex items-center gap-2 text-xs text-muted-foreground">
<QrCode class="size-3.5" />
用手机 App 扫码,或手动输入配对码
</div>
<div class="text-3xl font-semibold tracking-[0.3em] tabular-nums">{{ pairing.code }}</div>
<div class="text-[11.5px] text-muted-foreground">
剩余 {{ Math.floor(pairing.secondsLeft / 60) }}:{{ String(pairing.secondsLeft % 60).padStart(2, '0') }}
· 一次性,成功后自动失效
</div>
<Button variant="outline" size="sm" class="mt-1 self-start" :disabled="busy" @click="cancelPairing">
取消配对
</Button>
</div>
</div>
<div v-else-if="config?.running">
<Button variant="outline" size="sm" :disabled="busy" @click="startPairing">
<QrCode class="mr-1.5 size-3.5" />
连接手机(生成配对码)
</Button>
</div>
<!-- 设备列表 -->
<div v-if="devices.length" class="flex flex-col gap-1.5">
<Label class="text-muted-foreground">已配对设备</Label>
<div
v-for="d in devices"
:key="d.id"
class="flex items-center justify-between gap-3 rounded-lg border bg-card px-3 py-2"
>
<div class="flex min-w-0 items-center gap-2.5">
<span
class="size-2 shrink-0 rounded-full"
:class="d.online ? 'bg-green-500' : 'bg-muted-foreground/30'"
:title="d.online ? '在线' : '离线'"
/>
<span class="truncate text-[13px]">{{ d.name }}</span>
<span class="shrink-0 text-[11px] text-muted-foreground">{{ fmtLast(d.lastConnectedMs) }}</span>
</div>
<Button
variant="ghost"
size="sm"
class="h-7 shrink-0 text-destructive hover:text-destructive"
@click="revoke(d)"
>
<Trash2 class="size-3.5" />
</Button>
</div>
</div>
<p class="text-[11px] text-muted-foreground/80">
协议与发现方式见 MUSIC_REMOTE_PLAN.md;手机端配对一次后,打开 App 即自动连接。
</p>
</div>
</template>
+6
View File
@@ -14,6 +14,12 @@ const searchItems: SearchIndexItem[] = [
keywords: ['发现音乐', '搜索', '下载', '聚合', '在线', '网易云', 'qq', '酷狗'],
tab: 'discover'
},
{
title: '音乐解密',
description: '解密本地加密音乐文件(网易云 .ncm;QQ音乐待支持)',
keywords: ['解密', 'decrypt', 'ncm', '网易云', '加密', 'mflac', 'mgg', 'qmc', '转换', '解锁'],
tab: 'decrypt'
},
{
title: '音乐设置',
description: '飞牛连接、播放缓存、下载目录与 Python 环境检查',