mirror of
https://github.com/atdunbg/Nekosonic-Music.git
synced 2026-06-22 00:58:51 +08:00
## 后端 - 替换 rodio 为 symphonia + ringbuf,重构 audio.rs 播放引擎 - 重构 api.rs,使用 api_call! 宏统一 API 调用模式 - 新增 media_controls.rs,使用 souvlaki 实现跨平台系统媒体控制 (Linux MPRIS / Windows SMTC / macOS Now Playing) - 版本号升至 v0.5.0 ## 前端 - 新增 - 新增 SongListItem 通用组件 - 新增 useOnlineStatus composable,检测网络状态 - 新增 usePageCache composable,页面数据缓存与失效 - 新增 getCoverUrl()、formatDate() 工具函数 - 新增 emitPlaybackState() 同步播放状态到系统媒体控制 - 新增 mpris-command 事件监听,响应系统媒体控制命令 - 新增 Toast 离线/恢复在线提示 - 各页面新增断网恢复后自动重试加载 - 新增路由守卫:已登录用户访问 /login 重定向至首页 - 新增音量持久化(settings store + localStorage) - 新增禁用右键菜单与用户选择限制(输入框除外) ## 前端 - 变更 - Song 接口从 player.ts 迁移至 song.ts 并导出 - AlbumDetail/ArtistDetail/PlaylistDetail/RecentPlays/LocalMusic 迁移至 SongListItem - PlayerBar 队列列表迁移至 SongListItem,封面使用 getCoverUrl() - downloadSong 参数类型从内联对象改为 Song,使用 getCoverUrl() - 默认主题从 green 改为 blue,ThemeName 及相关列表中 blue 移至首位 - 全局快捷键从 Alt+Control 改为 Control+Alt 顺序 - formatShortcut 新增 KeyP → P 显示 - keep-alive 从 max=3 固定 include 改为 max=5 动态列表,窗口隐藏时释放 - App.vue 封面使用 getCoverUrl() 替代手动 al/album 回退 - formatPlayCount 提取常量 - Login.vue text-warning 改为 text-yellow-400 ## 前端 - 删除 - 删除 Search.vue(与 Discover.vue 重复) - 删除 SongItemMenu.vue(被 SongListItem 替代) ## 修复 - 更新器跳过版本逻辑:仅静默检查时跳过已忽略版本,手动检查不再跳过 - 重复播放同一首歌时无法恢复播放 - settings.ts 重复的 ThemeName 定义 - PlayerBar.vue modeTexts 缺少类型注解 - Home.vue map 回调参数缺少类型 - Settings.vue v-for key 类型不匹配
121 lines
4.1 KiB
Vue
121 lines
4.1 KiB
Vue
<template>
|
|
<div class="min-h-screen flex items-center justify-center bg-base text-content">
|
|
<div class="bg-subtle backdrop-blur-md border border-line p-8 rounded-2xl w-full max-w-sm text-center">
|
|
<h1 class="text-xl font-bold mb-4">扫码登录</h1>
|
|
<p class="text-sm text-content-2 mb-6">请使用网易云音乐 App 扫描二维码</p>
|
|
|
|
<div v-if="qrimg" class="bg-white p-3 rounded-xl inline-block mb-4">
|
|
<img :src="qrimg" alt="二维码" class="w-48 h-48" />
|
|
</div>
|
|
<div v-else class="w-48 h-48 bg-subtle rounded-xl flex items-center justify-center mx-auto mb-4">
|
|
<span v-if="qrLoading" class="text-content-2">加载中...</span>
|
|
<span v-else-if="qrError" class="text-danger text-sm">{{ qrError }}</span>
|
|
</div>
|
|
|
|
<p class="text-sm" :class="statusColor">{{ statusText }}</p>
|
|
<button @click="refreshQr" class="mt-4 text-xs text-accent-text hover:underline">重新获取二维码</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
import { useRouter } from 'vue-router';
|
|
import { useUserStore } from '../stores/user';
|
|
import QRCode from 'qrcode';
|
|
|
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
|
const qrimg = ref('');
|
|
const qrLoading = ref(true);
|
|
const qrError = ref('');
|
|
const statusText = ref('等待扫码...');
|
|
const statusColor = ref('text-content-2');
|
|
let qrKey = '';
|
|
let pollTimer: ReturnType<typeof setInterval> | null = null;
|
|
|
|
onMounted(async () => {
|
|
if (userStore.isLoggedIn) {
|
|
router.push('/');
|
|
return;
|
|
}
|
|
await refreshQr();
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
if (pollTimer) clearInterval(pollTimer);
|
|
});
|
|
|
|
async function refreshQr() {
|
|
qrLoading.value = true;
|
|
qrError.value = '';
|
|
if (pollTimer) clearInterval(pollTimer);
|
|
try {
|
|
qrKey = await invoke('get_qr_key');
|
|
if (!qrKey) {
|
|
qrError.value = '未获取到登录密钥';
|
|
qrLoading.value = false;
|
|
return;
|
|
}
|
|
|
|
const qrUrl = `https://music.163.com/login?codekey=${qrKey}&type=1`;
|
|
|
|
const canvas = document.createElement('canvas');
|
|
await QRCode.toCanvas(canvas, qrUrl, { width: 200, margin: 1 });
|
|
qrimg.value = canvas.toDataURL('image/png');
|
|
qrLoading.value = false;
|
|
|
|
startPolling();
|
|
} catch (e: any) {
|
|
qrError.value = '获取二维码失败';
|
|
qrLoading.value = false;
|
|
}
|
|
}
|
|
|
|
function startPolling() {
|
|
pollTimer = setInterval(async () => {
|
|
try {
|
|
const jsonStr: string = await invoke('check_qr_status', { query: { key: qrKey } });
|
|
const data = JSON.parse(jsonStr);
|
|
const code = data.code;
|
|
if (code === 800) {
|
|
statusText.value = '二维码已过期,请刷新';
|
|
statusColor.value = 'text-danger';
|
|
clearInterval(pollTimer!);
|
|
} else if (code === 801) {
|
|
statusText.value = '等待扫码...';
|
|
statusColor.value = 'text-content-2';
|
|
} else if (code === 802) {
|
|
statusText.value = '请在手机上确认登录';
|
|
statusColor.value = 'text-yellow-400';
|
|
} else if (code === 803) {
|
|
clearInterval(pollTimer!);
|
|
statusText.value = '登录成功!';
|
|
statusColor.value = 'text-accent-text';
|
|
await fetchUserProfile();
|
|
setTimeout(() => router.push('/'), 500);
|
|
}
|
|
} catch (e) {
|
|
console.error('轮询失败', e);
|
|
}
|
|
}, 3000);
|
|
}
|
|
|
|
async function fetchUserProfile() {
|
|
try {
|
|
const profileJson: string = await invoke('get_login_status');
|
|
const profile = JSON.parse(profileJson);
|
|
if (profile.profile) {
|
|
userStore.setUser({
|
|
userId: profile.profile.userId,
|
|
nickname: profile.profile.nickname,
|
|
avatarUrl: profile.profile.avatarUrl,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.error('获取用户信息失败', e);
|
|
}
|
|
}
|
|
</script>
|