3 Commits

Author SHA1 Message Date
c275461015 feat: v0.6.0 - 亮色主题、封面主色、发现页重做、漫游页重做、减少推荐、列表风格统一
新功能:
- 亮色主题:新增浅色外观模式,7种主题色各有对应亮色变体
- 封面主色背景:漫游抽屉自动提取封面主色,PlayerBar跟随继承
- 发现页重做:多类型搜索(歌曲/歌手/专辑)+搜索建议+搜索历史
- 漫游页重做:进入即播放,布局改为封面+歌名+播放/下一首/减少推荐
- 减少推荐:FM模式下可标记不推荐歌曲或歌手
- 列表风格统一:播放指示器跳动动画+hover播放图标+图标统一使用Lucide

修复:
- 专辑页艺术家过多时窗口缩小竖排,改为自动换行
- FM播放时退出登录后首页仍可点击下一首
- 本地音乐播放时缓冲进度条未重置
- 亮色主题下多处文字不可见
- 退出FM模式时状态未正确清理
- 暗色模式下关闭抽屉时PlayerBar闪烁亮色(改用opacity过渡)
- player.ts tickInterval双变量状态不同步,统一为clearTick/setTick

变更:
- 移除播放列表按钮数字角标
- 主页卡片标题固定白色不随主题变化
- 全项目空catch块格式统一
- 清理冗余注释和代码
2026-05-28 23:14:25 +08:00
6da544cffb v0.5.1: 修复缓存/FM/翻译/Linux等问题 2026-05-25 19:38:48 +08:00
65ed71503e feat: 架构重构与跨平台媒体控制集成
## 后端

- 替换 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 类型不匹配
2026-05-23 14:43:47 +08:00
44 changed files with 3852 additions and 1691 deletions

View File

@ -1,3 +1,70 @@
## v0.6.0
### ✨ 新功能
- **亮色主题**:新增浅色外观模式,支持深色/浅色切换7 种主题色各有对应亮色变体
- **封面主色背景**:全屏漫游抽屉背景自动提取封面图主色调,沉浸感更强;抽屉打开时底部播放栏也跟随封面主色,视觉融为一体
- **发现页重做**:支持多类型搜索(歌曲/歌手/专辑),输入时自动显示搜索建议,搜索历史和热门搜索
- **漫游增强**:全屏抽屉支持歌词/评论切换,播放栏新增减少推荐按钮
- **减少推荐**FM 模式下可标记"不推荐这首歌"或"不推荐这个歌手",后续不会再收到类似推荐
- **列表风格统一**:正在播放的歌曲序号位置显示跳动动画,鼠标悬停显示播放图标;红心/下载等图标统一使用图标库
### 🐛 修复
- 专辑页艺术家过多时窗口缩小会竖排显示,现在支持自动换行
- FM 播放时退出登录后首页仍可点击下一首
- 本地音乐播放时缓冲进度条未重置
- 亮色主题下多处文字看不见
- 退出 FM 模式时状态未正确清理
- 暗色模式下关闭抽屉时播放栏短暂闪烁亮色
### 🎨 变更
- 移除播放列表按钮上的数字角标
- 主页每日推荐和 FM 卡片标题固定为白色,不随主题变化
### 🧹 清理
- 内部代码优化和冗余清理
## v0.5.1
### 🐛 修复
- 修复页面缓存不刷新的问题:切换回已缓存的页面时数据永远不更新,现在超过 5 分钟会自动重新加载
- 修复本地音乐页面空列表时刷新按钮不显示的问题
- 修复修改下载路径后本地音乐列表不更新的问题,现在会自动刷新
- 修复私人 FM 播放约二三十首后循环重复的问题:新增听歌打卡上报,服务端推荐不再重复
- 修复歌词界面切换翻译开关时歌词未居中的问题
- 修复 Linux 下从外部控制暂停时进度条跳回 0 的问题MPRIS 现在正确报告播放进度位置
### ⚡ 优化
- 私人 FM 预取队列优化,队列剩余不足时自动后台拉取下一批
## v0.5.0
### ✨ 新功能
- **蓝牙耳机/键盘媒体键控制**:支持通过蓝牙耳机按钮、键盘媒体键、系统通知栏/锁屏面板控制播放、暂停、切歌Windows / Linux / macOS
- **网络状态检测**:断网和恢复时弹出提示,网络恢复后自动重新加载页面内容
- **音量记忆**:关闭应用后音量设置不丢失,下次打开自动恢复
- **歌词翻译**:支持显示歌词翻译,可在漫游页面切换开关
- **登录页优化**:已登录用户访问登录页会自动跳转回首页
### 🎨 变更
- 默认主题色改为天蓝色
- 全局快捷键显示顺序调整为 Ctrl + Alt之前是 Alt + Ctrl
- 快捷键显示优化:按键名更简洁,如 KeyP 显示为 P
- 页面缓存优化:更多页面切换时保留状态,窗口隐藏时自动释放
- 登录页等待确认时的文字颜色修正
### 🐛 修复
- 手动检查更新时,之前跳过的版本现在会正常弹出更新提示
- 点击正在播放的歌曲无法恢复播放的问题
- 部分内部类型定义问题导致的潜在隐患
### ⚡ 底层优化
- 音频播放引擎全面重构,播放更稳定
- 后端 API 调用模式统一,代码更易维护
- 歌曲数据模型统一,各页面显示更一致
## v0.4.1
添加音频输出外设选择
@ -72,4 +139,4 @@
## v0.1.0
Nekosonic 是一款基于 Tauri 2 + Rust 的跨平台桌面音乐播放器,音源主要来自网易云音乐,开箱即用。
Nekosonic 是一款基于 Tauri 2 + Rust 的跨平台桌面音乐播放器,音源主要来自网易云音乐,开箱即用。

View File

@ -14,6 +14,7 @@
- 📻 私人漫游 FM个性化推荐VIP 试听自动跳过)
- 🎵 本地音乐播放(支持 mp3 / flac / wav / ogg / aac / m4a / wma / opus
- 🔊 音频输出设备选择
- 🎧 系统媒体控制(蓝牙耳机/键盘媒体键/系统面板,支持 Linux / Windows / macOS
### 发现与浏览
@ -27,6 +28,7 @@
### 歌词与评论
- 🎤 实时滚动歌词(自动滚动 / 点击跳转 / 渐变透明度)
- 🎤 歌词翻译显示
- 🎤 全屏漫游模式(大封面 + 歌词 / 评论双标签页)
- 💬 歌曲评论查看(热门评论 + 无限滚动加载 + 点赞)
@ -47,10 +49,11 @@
- 📡 系统托盘(播放控制 / 显示窗口 / 退出)
- 🛡 单实例运行(防止重复启动)
- ⌨️ 自定义快捷键(应用内 + 系统全局)
- 🌚 Light / Dark Mode 主题切换
- 🎨 多主题切换(天蓝 / 翠绿 / 玫红 / 紫罗兰 / 橙色 / 青色 / 粉色)
- ⚙️ 关闭窗口行为设置(每次询问 / 最小化到托盘 / 直接退出)
- 🔄 自动更新(启动静默检测 + 自定义弹窗 + 忽略版本 + 下载进度)
- 📝 更新日志查看
- 📶 网络状态检测(断网/恢复 Toast 提示 + 自动重试加载)
## 📦️ 安装
@ -84,7 +87,8 @@ npm run tauri build
| 样式 | Tailwind CSS v4 + CSS 变量主题系统 |
| 状态管理 | Pinia |
| 路由 | Vue Router 4 |
| 音频播放 | rodio (Rust) |
| 音频解码 | symphonia + ringbuf (Rust) |
| 媒体控制 | souvlaki (Linux MPRIS / Windows SMTC / macOS Now Playing) |
| 网易云 API | ncm-api-rs |
| 构建工具 | Vite 6 |
@ -97,10 +101,11 @@ npm run tauri build
- [x] 专辑详情页
- [x] 自定义全局快捷键
- [x] 自动更新
- [x] 歌词翻译
- [x] 更多主题
- [x] 系统媒体控制(蓝牙耳机/键盘媒体键)
- [ ] MV 播放
- [ ] 音乐云盘
- [ ] 歌词翻译
- [ ] 更多主题
- [ ] 桌面歌词
欢迎提 Issue 和 Pull request。
@ -117,4 +122,5 @@ npm run tauri build
- [Tauri](https://tauri.app/) — 跨平台桌面应用框架
- [Vue.js](https://vuejs.org/) — 渐进式 JavaScript 框架
- [Tailwind CSS](https://tailwindcss.com/) — 实用优先的 CSS 框架
- [rodio](https://crates.io/crates/rodio) — Rust 音频播放
- [symphonia](https://crates.io/crates/symphonia) — Rust 音频解码
- [souvlaki](https://crates.io/crates/souvlaki) — 跨平台 OS 媒体控制库

35
package-lock.json generated
View File

@ -1,13 +1,14 @@
{
"name": "nekosonic",
"version": "0.3.0",
"version": "0.5.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "nekosonic",
"version": "0.3.0",
"version": "0.5.1",
"dependencies": {
"@iconify-json/lucide": "^1.2.110",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2.7.1",
"@tauri-apps/plugin-global-shortcut": "^2.3.1",
@ -22,6 +23,7 @@
"vue-router": "^4.6.4"
},
"devDependencies": {
"@iconify/utils": "^3.1.3",
"@tailwindcss/vite": "^4.2.4",
"@tauri-apps/cli": "^2",
"@types/node": "^25.6.0",
@ -538,23 +540,31 @@
"node": ">=18"
}
},
"node_modules/@iconify-json/lucide": {
"version": "1.2.110",
"resolved": "https://registry.npmmirror.com/@iconify-json/lucide/-/lucide-1.2.110.tgz",
"integrity": "sha512-rLeHqnZZBxZbprbVwf6uY7HB5GkGVgvT9VujhjvaUEqFDLKZON6zR8K1f8uD1brBwf5TJ0TIvvW8mz5u2XJU+w==",
"license": "ISC",
"dependencies": {
"@iconify/types": "*"
}
},
"node_modules/@iconify/types": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/@iconify/types/-/types-2.0.0.tgz",
"integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==",
"dev": true,
"license": "MIT"
},
"node_modules/@iconify/utils": {
"version": "3.1.1",
"resolved": "https://registry.npmmirror.com/@iconify/utils/-/utils-3.1.1.tgz",
"integrity": "sha512-MwzoDtw9rO1x+qfgLTV/IVXsHDBqeYZoMIQC8SfxfYSlaSUG+oWiAcoiB1yajAda6mqblm4/1/w2E8tRu7a7Tw==",
"version": "3.1.3",
"resolved": "https://registry.npmmirror.com/@iconify/utils/-/utils-3.1.3.tgz",
"integrity": "sha512-LPKOXPn/zV+zis1oOfGWogaXVpqUybF3ZS6SCZIsz8vg0ivVp9+fVqyYB7xq0aiST/VhUQYGO1qo6uoYSiEJqw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@antfu/install-pkg": "^1.1.0",
"@iconify/types": "^2.0.0",
"mlly": "^1.8.2"
"import-meta-resolve": "^4.2.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
@ -2584,6 +2594,17 @@
"node": ">= 4"
}
},
"node_modules/import-meta-resolve": {
"version": "4.2.0",
"resolved": "https://registry.npmmirror.com/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz",
"integrity": "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg==",
"dev": true,
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",

View File

@ -1,7 +1,7 @@
{
"name": "nekosonic",
"private": true,
"version": "0.3.0",
"version": "0.6.0",
"type": "module",
"scripts": {
"dev": "vite",
@ -10,6 +10,7 @@
"tauri": "tauri"
},
"dependencies": {
"@iconify-json/lucide": "^1.2.110",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2.7.1",
"@tauri-apps/plugin-global-shortcut": "^2.3.1",
@ -24,6 +25,7 @@
"vue-router": "^4.6.4"
},
"devDependencies": {
"@iconify/utils": "^3.1.3",
"@tailwindcss/vite": "^4.2.4",
"@tauri-apps/cli": "^2",
"@types/node": "^25.6.0",

839
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package]
name = "Nekosonic"
version = "0.4.1"
version = "0.6.0"
description = "A Simple music app"
authors = ["atdunbg"]
edition = "2021"
@ -23,7 +23,8 @@ tauri-plugin-opener = "2"
tauri-plugin-single-instance = "2"
tauri-plugin-global-shortcut = "2"
tauri-plugin-dialog = "2"
rodio = "0.20"
symphonia = { version = "0.5", features = ["mp3", "aac", "flac", "wav", "ogg", "vorbis", "isomp4", "mkv"] }
ringbuf = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
cpal = { version = "0.15" }
@ -38,3 +39,13 @@ tokio = { version = "1", features = ["rt", "sync"] }
tauri-plugin-process = "2.3.1"
tauri-plugin-updater = "2"
[target.'cfg(target_os = "linux")'.dependencies]
souvlaki = { version = "0.8", default-features = false, features = ["use_zbus"] }
[target.'cfg(target_os = "windows")'.dependencies]
souvlaki = "0.8"
raw-window-handle = "0.6"
[target.'cfg(target_os = "macos")'.dependencies]
souvlaki = "0.8"

View File

@ -2,7 +2,6 @@ use ncm_api_rs::{create_client, ApiClient, Query};
use serde::Deserialize;
use serde_json::json;
use tauri::{Manager, State, Emitter};
use tokio::sync::Mutex;
use std::sync::Mutex as StdMutex;
use std::sync::atomic::Ordering;
@ -14,12 +13,66 @@ use lofty::file::{AudioFile, TaggedFileExt};
use lofty::tag::Accessor;
use base64::Engine;
/// 统一的 API 调用宏,封装了「获取客户端 → 构建请求 → 发送 → 提取响应体」的完整流程。
///
/// 消除了每个 Tauri 命令中重复的 `client.lock().unwrap().clone()` + `build_query()` + `.map(|r| r.body.to_string())` 样板代码。
///
/// 提供三种调用方式:
///
/// 1. 无额外参数 — 仅使用 cookie 中的默认参数构建请求
/// ```
/// api_call!(state, get_playlist_detail)
/// // 等价于:
/// // let client = state.client.lock().unwrap().clone();
/// // let q = state.build_query();
/// // client.get_playlist_detail(&q).await.map(|r| r.body.to_string()).map_err(|e| e.to_string())
/// ```
///
/// 2. 附加参数 — 在默认参数基础上追加键值对
/// ```
/// api_call!(state, song_url_v1, params: [("id", id), ("level", "standard")])
/// // 等价于:
/// // let q = state.build_query().param("id", id).param("level", "standard");
/// // client.song_url_v1(&q).await...
/// ```
///
/// 3. 预构建查询 — 直接传入已构建好的 Query 对象,跳过 build_query()
/// ```
/// api_call!(state, playlist_track_all, query: my_query)
/// // 等价于:
/// // client.playlist_track_all(&my_query).await...
/// ```
macro_rules! api_call {
($state:expr, $method:ident) => {{
let client = $state.client.lock().unwrap().clone();
let q = $state.build_query();
client.$method(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
}};
($state:expr, $method:ident, params: [$(($key:expr, $val:expr)),* $(,)?]) => {{
let client = $state.client.lock().unwrap().clone();
let mut q = $state.build_query();
$(q = q.param($key, $val);)*
client.$method(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
}};
($state:expr, $method:ident, query: $q:expr) => {{
let client = $state.client.lock().unwrap().clone();
client.$method(&$q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
}};
}
pub struct ApiController {
client: Mutex<ApiClient>,
client: StdMutex<ApiClient>,
cookie: StdMutex<Option<String>>,
cookie_path: PathBuf,
}
/// 将 Cookie 字符串列表转换为 `key=value; key=value` 格式
fn cookies_to_key_values(cookies: &[String]) -> String {
cookies
.iter()
@ -31,6 +84,7 @@ fn cookies_to_key_values(cookies: &[String]) -> String {
impl ApiController {
/// 创建新的 API 控制器,从本地文件恢复已保存的 Cookie
pub fn new(app_data_dir: PathBuf) -> Self {
let _ = fs::create_dir_all(&app_data_dir);
let cookie_path = app_data_dir.join("netease_cookies.json");
@ -40,13 +94,14 @@ impl ApiController {
let client = create_client(None);
ApiController {
client: Mutex::new(client),
client: StdMutex::new(client),
cookie: StdMutex::new(saved_cookie),
cookie_path,
}
}
fn build_query(&self) -> Query {
/// 构建带当前 Cookie 的 API 查询对象
fn build_query(&self) -> Query {
let mut query = Query::new();
if let Ok(cookie_guard) = self.cookie.lock() {
if let Some(c) = cookie_guard.as_ref() {
@ -55,66 +110,88 @@ fn build_query(&self) -> Query {
}
query
}
/// 将 Cookie 字符串持久化到本地文件并同步到 API 客户端
fn save_cookie(&self, cookie_str: &str) {
let _ = fs::write(&self.cookie_path, cookie_str);
if let Ok(mut client) = self.client.lock() {
client.set_cookie(cookie_str.to_string());
}
}
}
/// 搜索查询参数
#[derive(Deserialize)]
pub struct SearchQuery { pub keyword: String }
/// 多类型搜索查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CloudSearchQuery {
pub keyword: String,
pub search_type: Option<i64>,
pub limit: Option<i64>,
pub offset: Option<i64>,
}
/// 搜索建议查询参数
#[derive(Deserialize)]
pub struct SearchSuggestQuery { pub keyword: String }
/// 手机号登录查询参数
#[derive(Deserialize)]
pub struct LoginQuery { pub phone: String, pub password: String }
/// 二维码登录密钥查询参数
#[derive(Deserialize)]
pub struct QrKeyQuery { pub key: String }
/// 搜索歌曲
#[tauri::command]
pub async fn search_songs(query: SearchQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query()
.param("keywords", &query.keyword)
.param("type", "1")
.param("limit", "30");
client.cloudsearch(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, cloudsearch, params: [("keywords", &query.keyword), ("type", "1"), ("limit", "30")])
}
/// 多类型搜索(歌曲/歌手/专辑)
#[tauri::command]
pub async fn cloudsearch(query: CloudSearchQuery, state: State<'_, ApiController>) -> Result<String, String> {
api_call!(state, cloudsearch, params: [
("keywords", &query.keyword),
("type", &query.search_type.unwrap_or(1).to_string()),
("limit", &query.limit.unwrap_or(30).to_string()),
("offset", &query.offset.unwrap_or(0).to_string())
])
}
/// 搜索建议
#[tauri::command]
pub async fn search_suggest(query: SearchSuggestQuery, state: State<'_, ApiController>) -> Result<String, String> {
api_call!(state, search_suggest, params: [("keywords", &query.keyword)])
}
/// 获取热搜词列表
#[tauri::command]
pub async fn get_hot_search(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query();
client.search_hot_detail(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, search_hot_detail)
}
/// 歌单全部曲目查询参数
#[derive(Deserialize)]
pub struct PlaylistTrackAllQuery { pub id: u64, pub limit: Option<i64>, pub offset: Option<i64> }
/// 获取歌单全部歌曲
#[tauri::command]
pub async fn playlist_track_all(query: PlaylistTrackAllQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query()
.param("id", &query.id.to_string())
.param("limit", &query.limit.unwrap_or(1000).to_string())
.param("offset", &query.offset.unwrap_or(0).to_string());
client.playlist_track_all(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, playlist_track_all, params: [("id", &query.id.to_string()), ("limit", &query.limit.unwrap_or(1000).to_string()), ("offset", &query.offset.unwrap_or(0).to_string())])
}
/// 歌曲播放地址查询参数
#[derive(Deserialize)]
pub struct SongUrlQuery { pub id: u64, pub level: Option<String>, pub fm_mode: Option<bool> }
/// 获取歌曲播放地址(返回完整 data 对象,包含 url、freeTrialInfo 等)
#[tauri::command]
pub async fn get_song_url(query: SongUrlQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let level = query.level.as_deref().unwrap_or("standard");
let resp = if query.fm_mode.unwrap_or(false) {
@ -162,27 +239,19 @@ pub async fn get_song_url(query: SongUrlQuery, state: State<'_, ApiController>)
/// 获取歌词
#[tauri::command]
pub async fn get_lyric(id: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("id", &id.to_string());
client.lyric(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, lyric, params: [("id", &id.to_string())])
}
/// 获取歌单详情
#[tauri::command]
pub async fn get_playlist_detail(id: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("id", &id.to_string());
client.playlist_detail(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, playlist_detail, params: [("id", &id.to_string())])
}
/// 手机号密码登录
#[tauri::command]
pub async fn login(query: LoginQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let q = Query::new()
.param("phone", &query.phone)
.param("password", &query.password);
@ -208,7 +277,7 @@ pub async fn logout(state: State<'_, ApiController>) -> Result<(), String> {
/// 获取二维码登录密钥
#[tauri::command]
pub async fn get_qr_key(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let q = state.build_query();
let resp = client.login_qr_key(&q).await.map_err(|e| e.to_string())?;
resp.body["unikey"]
@ -223,7 +292,7 @@ pub async fn create_qr(
query: QrKeyQuery,
state: State<'_, ApiController>,
) -> Result<String, String> {
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let q = state
.build_query()
.param("key", &query.key)
@ -239,7 +308,7 @@ pub async fn create_qr(
/// 检查二维码扫码状态
#[tauri::command]
pub async fn check_qr_status(query: QrKeyQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let q = state.build_query().param("key", &query.key);
let resp = client.login_qr_check(&q).await.map_err(|e| e.to_string())?;
if resp.body["code"].as_u64() == Some(803) && !resp.cookie.is_empty() {
@ -253,122 +322,131 @@ pub async fn check_qr_status(query: QrKeyQuery, state: State<'_, ApiController>)
/// 获取当前登录状态
#[tauri::command]
pub async fn get_login_status(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query();
client.user_account(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, user_account)
}
/// 获取用户歌单列表
#[tauri::command]
pub async fn user_playlist(uid: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("uid", &uid.to_string());
let resp = client.user_playlist(&q).await.map_err(|e| e.to_string())?;
Ok(resp.body.to_string())
api_call!(state, user_playlist, params: [("uid", &uid.to_string())])
}
/// 获取每日推荐歌曲
#[tauri::command]
pub async fn recommend_songs(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query();
let resp = client.recommend_songs(&q).await.map_err(|e| e.to_string())?;
Ok(resp.body.to_string())
api_call!(state, recommend_songs)
}
/// 获取推荐歌单
#[tauri::command]
pub async fn recommend_resource(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query();
let resp = client.recommend_resource(&q).await.map_err(|e| e.to_string())?;
Ok(resp.body.to_string())
api_call!(state, recommend_resource)
}
/// 私人漫游模式查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PersonalFmModeQuery {
pub mode: Option<String>,
pub sub_mode: Option<String>,
pub limit: Option<i64>,
}
/// 私人漫游(带模式)
#[tauri::command]
pub async fn personal_fm_mode(query: PersonalFmModeQuery, state: State<'_, ApiController>) -> Result<String, String> {
api_call!(state, personal_fm_mode, params: [
("mode", query.mode.as_deref().unwrap_or("DEFAULT")),
("submode", query.sub_mode.as_deref().unwrap_or("")),
("limit", &query.limit.unwrap_or(3).to_string())
])
}
/// FM 不喜欢查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FmTrashQuery {
pub id: u64,
pub time: Option<i64>,
}
/// FM 不喜欢(减少推荐)
#[tauri::command]
pub async fn fm_trash(query: FmTrashQuery, state: State<'_, ApiController>) -> Result<String, String> {
api_call!(state, fm_trash, params: [
("id", &query.id.to_string()),
("time", &query.time.unwrap_or(25).to_string())
])
}
/// 获取私人漫游歌曲
#[tauri::command]
pub async fn personal_fm(state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query();
let resp = client.personal_fm(&q).await.map_err(|e| e.to_string())?;
Ok(resp.body.to_string())
api_call!(state, personal_fm)
}
/// 听歌打卡查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScrobbleQuery {
pub id: u64,
pub sourceid: Option<String>,
pub time: u64,
}
/// 听歌打卡
#[tauri::command]
pub async fn scrobble(query: ScrobbleQuery, state: State<'_, ApiController>) -> Result<String, String> {
api_call!(state, scrobble, params: [("id", &query.id.to_string()), ("sourceid", query.sourceid.as_deref().unwrap_or("")), ("time", &query.time.to_string())])
}
/// 获取歌曲详情
#[tauri::command]
pub async fn get_song_detail(id: String, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("ids", &id);
let resp = client.song_detail(&q).await.map_err(|e| e.to_string())?;
Ok(resp.body.to_string())
api_call!(state, song_detail, params: [("ids", &id)])
}
/// 用户播放记录查询参数
#[derive(Deserialize)]
pub struct UserRecordQuery { pub uid: u64, pub r#type: String }
/// 喜欢/取消喜欢歌曲查询参数
#[derive(Deserialize)]
pub struct LikeSongQuery { pub id: u64, pub like: String }
/// 获取喜欢的歌曲ID列表
#[tauri::command]
pub async fn likelist(uid: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("uid", &uid.to_string());
client.likelist(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, likelist, params: [("uid", &uid.to_string())])
}
/// 获取用户播放记录
#[tauri::command]
pub async fn user_record(query: UserRecordQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query()
.param("uid", &query.uid.to_string())
.param("type", &query.r#type);
client.user_record(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, user_record, params: [("uid", &query.uid.to_string()), ("type", &query.r#type)])
}
/// 喜欢/取消喜欢歌曲
#[tauri::command]
pub async fn like_song(query: LikeSongQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query()
.param("id", &query.id.to_string())
.param("like", &query.like);
client.like(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, like, params: [("id", &query.id.to_string()), ("like", &query.like)])
}
/// 上报最近播放歌曲
#[tauri::command]
pub async fn record_recent_song(limit: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("limit", &limit.to_string());
client.record_recent_song(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, record_recent_song, params: [("limit", &limit.to_string())])
}
/// 歌单收藏/取消收藏查询参数
#[derive(Deserialize)]
pub struct PlaylistSubscribeQuery { pub id: u64, pub subscribe: Option<bool> }
/// 收藏/取消收藏歌单
#[tauri::command]
pub async fn playlist_subscribe(query: PlaylistSubscribeQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let t = if query.subscribe.unwrap_or(true) { "1" } else { "0" };
let q = state.build_query()
.param("id", &query.id.to_string())
.param("t", t);
client.playlist_subscribe(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, playlist_subscribe, params: [("id", &query.id.to_string()), ("t", t)])
}
/// 退出应用
@ -380,6 +458,7 @@ pub async fn exit_app(app_handle: tauri::AppHandle) {
}
}
/// 本地歌曲信息结构体
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LocalSongInfo {
@ -395,6 +474,7 @@ pub struct LocalSongInfo {
pub local: bool,
}
/// 下载歌曲查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DownloadSongQuery {
@ -408,6 +488,7 @@ pub struct DownloadSongQuery {
pub download_path: Option<String>,
}
/// 下载歌曲到本地,支持进度回调,并保存元数据文件
#[tauri::command]
pub async fn download_song(
app_handle: tauri::AppHandle,
@ -419,22 +500,18 @@ pub async fn download_song(
let q = state.build_query()
.param("id", &query.id.to_string())
.param("level", level);
let client = state.client.lock().await;
let client = state.client.lock().unwrap().clone();
let resp = client.song_url_v1(&q).await.map_err(|e| e.to_string())?;
let data = &resp.body["data"][0];
let url = data["url"].as_str().filter(|s| !s.is_empty());
let is_vip = data.get("freeTrialInfo").is_some_and(|v| !v.is_null());
if is_vip {
return Err("VIP歌曲无法下载".into());
}
if url.is_none() {
let free_trial = data.get("freeTrialInfo");
if free_trial.is_some() && !free_trial.unwrap().is_null() {
return Err("VIP歌曲无法下载".into());
}
return Err("暂无下载源,可能需要 VIP 权限".into());
}
let url = url.unwrap();
let free_trial = data.get("freeTrialInfo");
if free_trial.is_some() && !free_trial.unwrap().is_null() {
return Err("VIP歌曲无法下载".into());
}
let ext = if url.contains(".flac") { "flac" } else { "mp3" };
drop(client);
@ -505,6 +582,7 @@ pub async fn download_song(
Ok(filename)
}
/// 列出本地已下载的歌曲,优先使用元数据文件补充信息
#[tauri::command]
pub fn list_local_songs(app_handle: tauri::AppHandle, download_path: Option<String>) -> Result<Vec<LocalSongInfo>, String> {
let download_dir = resolve_download_dir(&app_handle, download_path.as_deref());
@ -600,6 +678,7 @@ pub fn list_local_songs(app_handle: tauri::AppHandle, download_path: Option<Stri
Ok(songs)
}
/// 读取音频文件的元数据(标题、艺术家、专辑、时长、封面)
fn read_audio_metadata(path: &PathBuf) -> (String, String, String, u64, Option<String>) {
match lofty::read_from_path(path) {
Ok(tagged_file) => {
@ -638,6 +717,7 @@ fn read_audio_metadata(path: &PathBuf) -> (String, String, String, u64, Option<S
}
}
/// 解析文件名,提取艺术家和歌曲名称(支持 "艺术家 - 歌名" 格式)
fn parse_filename(stem: &str) -> (String, String) {
if let Some(pos) = stem.find(" - ") {
let artist = &stem[..pos];
@ -652,6 +732,7 @@ fn parse_filename(stem: &str) -> (String, String) {
}
}
/// 删除本地歌曲查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteLocalSongQuery {
@ -660,6 +741,7 @@ pub struct DeleteLocalSongQuery {
pub download_path: Option<String>,
}
/// 删除本地已下载的歌曲文件及其元数据
#[tauri::command]
pub fn delete_local_song(
app_handle: tauri::AppHandle,
@ -678,6 +760,7 @@ pub fn delete_local_song(
Ok(())
}
/// 检查指定歌曲是否已下载到本地
#[tauri::command]
pub fn check_local_song(app_handle: tauri::AppHandle, id: u64, download_path: Option<String>) -> Result<bool, String> {
let download_dir = resolve_download_dir(&app_handle, download_path.as_deref());
@ -685,6 +768,7 @@ pub fn check_local_song(app_handle: tauri::AppHandle, id: u64, download_path: Op
Ok(meta_path.exists())
}
/// 解析下载目录,优先使用自定义路径,否则使用默认目录
fn resolve_download_dir(app_handle: &tauri::AppHandle, custom_path: Option<&str>) -> PathBuf {
if let Some(path) = custom_path {
if !path.is_empty() {
@ -694,6 +778,7 @@ fn resolve_download_dir(app_handle: &tauri::AppHandle, custom_path: Option<&str>
get_default_download_dir(app_handle)
}
/// 获取默认下载目录,优先使用应用数据目录下的 downloads 子目录
fn get_default_download_dir(app_handle: &tauri::AppHandle) -> PathBuf {
if let Ok(dir) = app_handle.path().app_data_dir() {
let download_dir = dir.join("downloads");
@ -708,11 +793,13 @@ fn get_default_download_dir(app_handle: &tauri::AppHandle) -> PathBuf {
music_dir.join("Nekosonic")
}
/// 获取默认下载路径字符串,供前端使用
#[tauri::command]
pub fn get_default_download_path(app_handle: tauri::AppHandle) -> String {
get_default_download_dir(&app_handle).to_string_lossy().to_string()
}
/// 清理文件名中的非法字符,将 `/ \ : * ? " < > |` 替换为下划线
fn sanitize_filename(name: &str) -> String {
name.chars()
.map(|c| {
@ -729,18 +816,15 @@ fn sanitize_filename(name: &str) -> String {
.to_string()
}
/// 获取歌手详情
#[tauri::command]
pub async fn artist_detail(id: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("id", &id.to_string());
client.artist_detail(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, artist_detail, params: [("id", &id.to_string())])
}
/// 获取歌手歌曲列表
#[tauri::command]
pub async fn artist_songs(query: ArtistSongsQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let mut q = state.build_query().param("id", &query.id.to_string());
if let Some(ref order) = query.order {
q = q.param("order", order);
@ -751,11 +835,10 @@ pub async fn artist_songs(query: ArtistSongsQuery, state: State<'_, ApiControlle
if let Some(offset) = query.offset {
q = q.param("offset", &offset.to_string());
}
client.artist_songs(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, artist_songs, query: q)
}
/// 歌手歌曲查询参数
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ArtistSongsQuery {
@ -765,9 +848,9 @@ pub struct ArtistSongsQuery {
pub offset: Option<u32>,
}
/// 获取歌手专辑列表
#[tauri::command]
pub async fn artist_album(id: u64, limit: Option<u32>, offset: Option<u32>, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let mut q = state.build_query().param("id", &id.to_string());
if let Some(limit) = limit {
q = q.param("limit", &limit.to_string());
@ -775,32 +858,24 @@ pub async fn artist_album(id: u64, limit: Option<u32>, offset: Option<u32>, stat
if let Some(offset) = offset {
q = q.param("offset", &offset.to_string());
}
client.artist_album(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, artist_album, query: q)
}
/// 获取歌手简介
#[tauri::command]
pub async fn artist_desc(id: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("id", &id.to_string());
client.artist_desc(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, artist_desc, params: [("id", &id.to_string())])
}
/// 获取专辑详情
#[tauri::command]
pub async fn album_detail(id: u64, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query().param("id", &id.to_string());
client.album(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, album, params: [("id", &id.to_string())])
}
/// 获取最新评论
#[tauri::command]
pub async fn comment_new(query: CommentNewQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let mut q = state.build_query()
.param("type", &query.r#type.to_string())
.param("id", &query.id.to_string());
@ -816,11 +891,10 @@ pub async fn comment_new(query: CommentNewQuery, state: State<'_, ApiController>
if let Some(cursor) = query.cursor {
q = q.param("cursor", &cursor.to_string());
}
client.comment_new(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, comment_new, query: q)
}
/// 最新评论查询参数
#[derive(Deserialize)]
pub struct CommentNewQuery {
pub r#type: u8,
@ -834,9 +908,9 @@ pub struct CommentNewQuery {
pub cursor: Option<u64>,
}
/// 获取热门评论
#[tauri::command]
pub async fn comment_hot(query: CommentHotQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let mut q = state.build_query()
.param("type", &query.r#type.to_string())
.param("id", &query.id.to_string());
@ -849,11 +923,10 @@ pub async fn comment_hot(query: CommentHotQuery, state: State<'_, ApiController>
if let Some(before) = query.before {
q = q.param("before", &before.to_string());
}
client.comment_hot(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, comment_hot, query: q)
}
/// 热门评论查询参数
#[derive(Deserialize)]
pub struct CommentHotQuery {
pub r#type: u8,
@ -863,9 +936,9 @@ pub struct CommentHotQuery {
pub before: Option<u64>,
}
/// 获取评论楼层(子评论)
#[tauri::command]
pub async fn comment_floor(query: CommentFloorQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let mut q = state.build_query()
.param("parentCommentId", &query.parent_comment_id.to_string())
.param("type", &query.r#type.to_string())
@ -876,11 +949,10 @@ pub async fn comment_floor(query: CommentFloorQuery, state: State<'_, ApiControl
if let Some(time) = query.time {
q = q.param("time", &time.to_string());
}
client.comment_floor(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, comment_floor, query: q)
}
/// 评论楼层查询参数
#[derive(Deserialize)]
pub struct CommentFloorQuery {
#[serde(rename = "parentCommentId")]
@ -891,19 +963,13 @@ pub struct CommentFloorQuery {
pub time: Option<u64>,
}
/// 点赞/取消点赞评论
#[tauri::command]
pub async fn comment_like(query: CommentLikeQuery, state: State<'_, ApiController>) -> Result<String, String> {
let client = state.client.lock().await;
let q = state.build_query()
.param("t", &query.t.to_string())
.param("type", &query.r#type.to_string())
.param("id", &query.id.to_string())
.param("cid", &query.cid.to_string());
client.comment_like(&q).await
.map(|r| r.body.to_string())
.map_err(|e| e.to_string())
api_call!(state, comment_like, params: [("t", &query.t.to_string()), ("type", &query.r#type.to_string()), ("id", &query.id.to_string()), ("cid", &query.cid.to_string())])
}
/// 评论点赞查询参数
#[derive(Deserialize)]
pub struct CommentLikeQuery {
pub t: u8,

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
mod api;
mod audio;
mod media_controls;
use api::ApiController;
use audio::AppAudio;
@ -25,6 +26,27 @@ pub fn run() {
let app_audio = AppAudio(std::sync::Mutex::new(audio_controller));
app.manage(app_audio);
#[cfg(target_os = "windows")]
{
use raw_window_handle::HasWindowHandle;
use raw_window_handle::RawWindowHandle;
let hwnd = if let Some(win) = app.get_webview_window("main") {
win.window_handle().ok().and_then(|h| {
if let RawWindowHandle::Win32(h) = h.as_raw() {
Some(h.hwnd.get() as *mut std::ffi::c_void)
} else {
None
}
})
} else {
None
};
media_controls::start_media_controls(app.handle().clone(), hwnd);
}
#[cfg(not(target_os = "windows"))]
media_controls::start_media_controls(app.handle().clone(), None);
let show = MenuItemBuilder::with_id("show", "显示窗口").build(app)?;
let _sep1 = PredefinedMenuItem::separator(app)?;
let prev = MenuItemBuilder::with_id("prev", "上一首").build(app)?;
@ -115,6 +137,8 @@ pub fn run() {
api::logout,
api::search_songs,
api::cloudsearch,
api::search_suggest,
api::get_song_url,
api::get_hot_search,
api::get_playlist_detail,
@ -123,6 +147,9 @@ pub fn run() {
api::recommend_resource,
api::recommend_songs,
api::personal_fm,
api::personal_fm_mode,
api::fm_trash,
api::scrobble,
api::get_song_detail,
api::get_qr_key,
api::create_qr,
@ -144,6 +171,7 @@ pub fn run() {
audio::get_output_devices,
audio::set_output_device,
audio::seek_audio,
audio::get_audio_position,
audio::set_volume,
api::download_song,

View File

@ -0,0 +1,127 @@
use std::sync::{Arc, Mutex};
use tauri::{AppHandle, Emitter, Listener};
use souvlaki::{
MediaControlEvent, MediaControls, MediaMetadata, MediaPlayback,
MediaPosition, PlatformConfig, SeekDirection,
};
struct MediaState {
controls: MediaControls,
}
pub fn start_media_controls(app_handle: AppHandle, hwnd: Option<*mut std::ffi::c_void>) {
let config = PlatformConfig {
dbus_name: "nekosonic",
display_name: "Nekosonic",
hwnd,
};
let mut controls = match MediaControls::new(config) {
Ok(c) => c,
Err(e) => {
eprintln!("Failed to create media controls: {e}");
return;
}
};
let ah = app_handle.clone();
if let Err(e) = controls.attach(move |event: MediaControlEvent| {
let cmd = match &event {
MediaControlEvent::Play => "Play",
MediaControlEvent::Pause => "Pause",
MediaControlEvent::Toggle => "PlayPause",
MediaControlEvent::Next => "Next",
MediaControlEvent::Previous => "Previous",
MediaControlEvent::Stop => "Stop",
MediaControlEvent::Raise => "Raise",
MediaControlEvent::Quit => "Quit",
MediaControlEvent::SetVolume(v) => {
let _ = ah.emit("mpris-command", format!("SetVolume:{v}"));
return;
}
MediaControlEvent::Seek(dir) => {
let offset_us = match dir {
SeekDirection::Forward => 5_000_000i64,
SeekDirection::Backward => -5_000_000i64,
};
let _ = ah.emit("mpris-command", format!("Seek:{offset_us}"));
return;
}
MediaControlEvent::SeekBy(dir, duration) => {
let offset_us: i64 = match dir {
SeekDirection::Forward => duration.as_micros() as i64,
SeekDirection::Backward => -(duration.as_micros() as i64),
};
let _ = ah.emit("mpris-command", format!("Seek:{offset_us}"));
return;
}
MediaControlEvent::SetPosition(pos) => {
let pos_us = pos.0.as_micros() as i64;
let _ = ah.emit("mpris-command", format!("SetPosition:{pos_us}"));
return;
}
MediaControlEvent::OpenUri(_) => return,
};
let _ = ah.emit("mpris-command", cmd);
}) {
eprintln!("Failed to attach media control handler: {e}");
return;
}
let state = Arc::new(Mutex::new(MediaState { controls }));
let state_for_listener = state.clone();
app_handle.listen("playback-state", move |event| {
if let Ok(data) = serde_json::from_str::<serde_json::Value>(event.payload()) {
let mut s = match state_for_listener.lock() {
Ok(s) => s,
Err(_) => return,
};
if let Some(status) = data.get("status").and_then(|v| v.as_str()) {
let position_us = data.get("positionUs").and_then(|v| v.as_i64()).unwrap_or(0);
let progress = if position_us > 0 {
Some(MediaPosition(std::time::Duration::from_micros(position_us as u64)))
} else {
None
};
let playback = match status {
"playing" => MediaPlayback::Playing { progress },
"paused" => MediaPlayback::Paused { progress },
_ => MediaPlayback::Stopped,
};
let _ = s.controls.set_playback(playback);
}
let title = data.get("title").and_then(|v| v.as_str()).unwrap_or("");
let album = data.get("album").and_then(|v| v.as_str()).unwrap_or("");
let artists = data
.get("artists")
.and_then(|v| v.as_array())
.map(|arr| {
arr.iter()
.filter_map(|a| a.as_str().map(|s| s.to_owned()))
.collect::<Vec<_>>()
})
.unwrap_or_default();
let artist_str = artists.join(", ");
let cover_url = data.get("coverUrl").and_then(|v| v.as_str()).unwrap_or("");
let duration_us = data.get("durationUs").and_then(|v| v.as_i64()).unwrap_or(0);
let metadata = MediaMetadata {
title: if title.is_empty() { None } else { Some(title) },
album: if album.is_empty() { None } else { Some(album) },
artist: if artist_str.is_empty() { None } else { Some(&artist_str) },
cover_url: if cover_url.is_empty() { None } else { Some(cover_url) },
duration: if duration_us > 0 {
Some(std::time::Duration::from_micros(duration_us as u64))
} else {
None
},
};
let _ = s.controls.set_metadata(metadata);
}
});
std::mem::forget(state);
}

View File

@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Nekosonic",
"version": "0.4.1",
"version": "0.6.0",
"identifier": "com.atdunbg.Nekosonic",
"build": {
"beforeDevCommand": "npm run dev",

View File

@ -16,23 +16,24 @@
<nav class="w-56 flex-shrink-0 flex flex-col bg-surface/80 backdrop-blur">
<div class="flex-1 p-4 overflow-y-auto min-h-0">
<div class="flex flex-col min-h-full">
<div class="relative mb-4">
<svg class="absolute left-3 top-1/2 -translate-y-1/2 text-content-3" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/></svg>
<input v-model="searchQuery" @keydown.enter="doSearch" type="text" placeholder="搜索音乐..."
class="w-full rounded-lg bg-subtle pl-9 pr-3 py-2 text-sm text-content placeholder-content-3 outline-none focus:bg-muted transition" />
</div>
<div class="space-y-0.5">
<router-link to="/"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12l9-9 9 9"/><path d="M5 10v10a1 1 0 001 1h3v-6h6v6h3a1 1 0 001-1V10"/></svg>
<IconHome class="w-[18px] h-[18px]" />
推荐
</router-link>
<router-link to="/discover"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<IconSearch class="w-[18px] h-[18px]" />
发现
</router-link>
<button
@click="openRoamFromSidebar"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle w-full text-left"
>
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.9 19.1C1 15.2 1 8.8 4.9 4.9"/><path d="M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.4"/><path d="M16.2 7.8c2.3 2.3 2.3 6.1 0 8.4"/><path d="M19.1 4.9C23 8.8 23 15.1 19.1 19"/></svg>
<IconRadio class="w-[18px] h-[18px]" />
漫游
</button>
</div>
@ -43,51 +44,54 @@
<router-link to="/favorites"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<IconHeart class="w-[18px] h-[18px]" />
我喜欢的音乐
</router-link>
<router-link to="/recent"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>
<IconClock class="w-[18px] h-[18px]" />
最近播放
</router-link>
<router-link to="/local-music"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
<IconMusic class="w-[18px] h-[18px]" />
本地音乐
</router-link>
</div>
</div>
<div class="mt-4 mb-1 pt-2" v-if="userStore.isLoggedIn">
<div class="flex items-center justify-between px-3 mb-1 cursor-pointer"
<div class="flex items-center justify-between px-3 mb-1 cursor-pointer group"
@click="showCreatedPlaylists = !showCreatedPlaylists">
<p class="text-xs text-content-3">我的歌单</p>
<span class="text-xs text-content-3 transition-transform"
:class="{ 'rotate-90': showCreatedPlaylists }"></span>
<IconChevronRight class="w-3 h-3 text-content-3 transition-transform" :class="{ 'rotate-90': showCreatedPlaylists }" />
</div>
<div v-show="showCreatedPlaylists" class="space-y-0.5">
<div v-for="pl in createdPlaylists" :key="pl.id" @click="goPlaylist(pl.id)"
class="px-3 py-1.5 rounded-lg text-sm cursor-pointer truncate transition-all duration-200"
:class="isPlaylistActive(pl.id) ? 'text-content bg-muted' : 'text-content-2 hover:text-content hover:bg-subtle'">
{{ pl.name }}
class="flex items-center gap-2.5 px-2 py-1.5 rounded-lg cursor-pointer transition-all duration-200"
:class="isPlaylistActive(pl.id) ? 'bg-muted' : 'hover:bg-subtle'">
<img :src="pl.coverImgUrl + '?param=80y80'" class="w-8 h-8 rounded object-cover flex-shrink-0" />
<span class="text-sm truncate"
:class="isPlaylistActive(pl.id) ? 'text-content font-medium' : 'text-content-2'">{{ pl.name }}</span>
</div>
</div>
</div>
<div class="mt-4 mb-1 pt-2" v-if="userStore.isLoggedIn">
<div class="flex items-center justify-between px-3 mb-1 cursor-pointer"
<div class="flex items-center justify-between px-3 mb-1 cursor-pointer group"
@click="showSubPlaylists = !showSubPlaylists">
<p class="text-xs text-content-3">收藏的歌单</p>
<span class="text-xs text-content-3 transition-transform" :class="{ 'rotate-90': showSubPlaylists }"></span>
<IconChevronRight class="w-3 h-3 text-content-3 transition-transform" :class="{ 'rotate-90': showSubPlaylists }" />
</div>
<div v-show="showSubPlaylists" class="space-y-0.5">
<div v-for="pl in subPlaylists" :key="pl.id" @click="goPlaylist(pl.id)"
class="px-3 py-1.5 rounded-lg text-sm cursor-pointer truncate transition-all duration-200"
:class="isPlaylistActive(pl.id) ? 'text-content bg-muted' : 'text-content-2 hover:text-content hover:bg-subtle'">
{{ pl.name }}
class="flex items-center gap-2.5 px-2 py-1.5 rounded-lg cursor-pointer transition-all duration-200"
:class="isPlaylistActive(pl.id) ? 'bg-muted' : 'hover:bg-subtle'">
<img :src="pl.coverImgUrl + '?param=80y80'" class="w-8 h-8 rounded object-cover flex-shrink-0" />
<span class="text-sm truncate"
:class="isPlaylistActive(pl.id) ? 'text-content font-medium' : 'text-content-2'">{{ pl.name }}</span>
</div>
</div>
</div>
@ -97,7 +101,7 @@
<router-link to="/settings"
class="flex items-center gap-3 px-3 py-2 rounded-lg transition-all duration-200 text-content-2 hover:text-content hover:bg-subtle"
active-class="!text-content !bg-muted">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
<IconSettings class="w-[18px] h-[18px]" />
设置
</router-link>
</div>
@ -105,7 +109,7 @@
<p class="text-xs text-content-3 mb-2">强烈建议登录以提升体验</p>
<router-link to="/login"
class="flex items-center justify-center gap-2 w-full px-4 py-2 rounded-lg bg-accent hover:bg-accent-hover transition text-sm font-medium text-white">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
<IconLogIn class="w-4 h-4" />
立即登录
</router-link>
</div>
@ -113,7 +117,7 @@
<img :src="userStore.user?.avatarUrl" class="w-8 h-8 rounded-full ring-2 ring-accent/50" />
<div class="min-w-0">
<p class="text-sm font-medium truncate">{{ userStore.user?.nickname }}</p>
<button @click="userStore.logout()"
<button @click="userStore.logout(); player.stop()"
class="text-xs text-content-3 hover:text-danger transition">退出登录</button>
</div>
</div>
@ -124,7 +128,7 @@
<main class="flex-1 overflow-y-auto pb-24">
<router-view v-slot="{ Component }">
<keep-alive :max="3" include="HomeView,DiscoverView">
<keep-alive :max="5" :include="keepAliveInclude">
<component :is="Component" />
</keep-alive>
</router-view>
@ -134,11 +138,14 @@
<Transition name="drawer">
<div
v-if="windowVisible && player.showRoamDrawer"
class="fixed inset-0 z-50 flex flex-col backdrop-blur-xl bg-black/80"
class="fixed inset-0 z-50 flex flex-col backdrop-blur-xl"
:class="!player.dominantColor && 'bg-surface/95'"
:style="player.dominantColor ? { backgroundColor: player.dominantColor } : {}"
>
<div class="h-10 flex items-center justify-between px-4 flex-shrink-0" data-tauri-drag-region>
<button @click="player.closeRoamDrawer()" class="text-content-2 hover:text-content transition">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
<div v-if="player.dominantColor" class="absolute inset-0 bg-black/60 pointer-events-none"></div>
<div class="h-10 flex items-center justify-between px-4 flex-shrink-0 relative z-10" data-tauri-drag-region>
<button @click="player.closeRoamDrawer()" :class="player.dominantColor ? 'text-white/60 hover:text-white' : 'text-content-2 hover:text-content'" class="transition">
<IconChevronDown class="w-5 h-5" />
</button>
<div class="flex items-center gap-1.5">
<button @click="minimizeWindow" class="w-3 h-3 rounded-full bg-yellow-500 hover:bg-yellow-400 transition" title="最小化"></button>
@ -146,7 +153,7 @@
<button @click="closeWindow" class="w-3 h-3 rounded-full bg-red-500 hover:bg-red-400 transition" title="关闭"></button>
</div>
</div>
<div class="flex-1 min-h-0 flex px-8 pb-8 gap-0">
<div class="flex-1 min-h-0 flex px-8 pb-8 gap-0 relative z-10">
<div class="w-2/5 flex flex-col items-center justify-center flex-shrink-0">
<img
v-if="roamCoverUrl && !roamCoverError"
@ -156,18 +163,19 @@
/>
<div
v-else
class="w-72 h-72 rounded-3xl bg-white/10 flex items-center justify-center shadow-2xl mb-4"
class="w-72 h-72 rounded-3xl flex items-center justify-center shadow-2xl mb-4"
:class="player.dominantColor ? 'bg-white/10' : 'bg-muted'"
>
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="text-white/30"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
<IconMusic class="w-16 h-16" :class="player.dominantColor ? 'text-white/30' : 'text-content-4'" />
</div>
<h1 class="text-2xl font-bold text-white text-center">{{ roamSong?.name }}</h1>
<p class="text-content-2 mt-2 text-center">
<h1 class="text-2xl font-bold text-center" :class="player.dominantColor ? 'text-white' : 'text-content'">{{ roamSong?.name }}</h1>
<p class="mt-2 text-center" :class="player.dominantColor ? 'text-white/70' : 'text-content-2'">
<template v-for="(a, i) in roamSong?.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span v-if="i > 0" :class="player.dominantColor ? 'text-white/40' : 'text-content-3'">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click="a.id && navigateFromDrawer({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="roamSong?.al?.name">
<span class="text-content-3 mx-1">·</span>
<span :class="player.dominantColor ? 'text-white/40' : 'text-content-3'" class="mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click="roamSong!.al.id && navigateFromDrawer({ name: 'album', params: { id: roamSong!.al.id } })">{{ roamSong.al.name }}</span>
</template>
</p>
@ -176,18 +184,24 @@
<div class="flex items-center gap-1 mb-3 px-4">
<button @click="roamTab = 'lyric'"
class="px-3 py-1 rounded-full text-sm transition"
:class="roamTab === 'lyric' ? 'bg-white/15 text-white font-medium' : 'text-white/50 hover:text-white/80'">
:class="player.dominantColor
? (roamTab === 'lyric' ? 'bg-white/15 text-white font-medium' : 'text-white/50 hover:text-white/80')
: (roamTab === 'lyric' ? 'bg-muted text-content font-medium' : 'text-content-3 hover:text-content')">
歌词
</button>
<button @click="roamTab = 'comment'"
class="px-3 py-1 rounded-full text-sm transition"
:class="roamTab === 'comment' ? 'bg-white/15 text-white font-medium' : 'text-white/50 hover:text-white/80'">
:class="player.dominantColor
? (roamTab === 'comment' ? 'bg-white/15 text-white font-medium' : 'text-white/50 hover:text-white/80')
: (roamTab === 'comment' ? 'bg-muted text-content font-medium' : 'text-content-3 hover:text-content')">
评论
</button>
<button v-if="hasTranslation" @click="toggleTranslation"
class="ml-auto px-2.5 py-1 rounded-full text-xs transition flex items-center gap-1"
:class="showTranslation ? 'bg-white/15 text-white font-medium' : 'text-white/40 hover:text-white/70'">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 8l6 6"/><path d="M4 14l6-6 2-3"/><path d="M2 5h12"/><path d="M7 2h1"/><path d="M22 22l-5-10-5 10"/><path d="M14 18h6"/></svg>
:class="player.dominantColor
? (showTranslation ? 'bg-white/15 text-white font-medium' : 'text-white/40 hover:text-white/70')
: (showTranslation ? 'bg-muted text-content font-medium' : 'text-content-4 hover:text-content-2')">
<IconLanguages class="w-3 h-3" />
</button>
</div>
@ -207,7 +221,7 @@
<span v-if="showTranslation && line.translation" class="block text-sm opacity-60 mt-1">{{ line.translation }}</span>
</p>
</div>
<div v-else class="text-content-3 text-center mt-8">暂无歌词</div>
<div v-else :class="player.dominantColor ? 'text-white/40' : 'text-content-3'" class="text-center mt-8">暂无歌词</div>
</div>
<div v-show="roamTab === 'comment'" class="flex-1 min-h-0 overflow-y-auto px-4 pb-4">
<CommentSection v-if="roamSong" :type="0" :id="player.commentSongId || roamSong.id" :key="player.commentSongId || roamSong.id" />
@ -238,7 +252,7 @@
<button @click="handleCloseAction('minimize')"
class="w-full flex items-center gap-3 px-4 py-3 rounded-xl bg-subtle hover:bg-muted transition text-left">
<div class="w-9 h-9 rounded-lg bg-accent-dim flex items-center justify-center flex-shrink-0">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><path d="M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"/></svg>
<IconMaximize2 class="w-[18px] h-[18px] text-accent-text" />
</div>
<div>
<p class="text-sm font-medium text-content">最小化到托盘</p>
@ -248,7 +262,7 @@
<button @click="handleCloseAction('exit')"
class="w-full flex items-center gap-3 px-4 py-3 rounded-xl bg-subtle hover:bg-muted transition text-left">
<div class="w-9 h-9 rounded-lg bg-danger-dim flex items-center justify-center flex-shrink-0">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-danger"><path d="M18 6L6 18M6 6l12 12"/></svg>
<IconX class="w-[18px] h-[18px] text-danger" />
</div>
<div>
<p class="text-sm font-medium text-content">退出程序</p>
@ -281,11 +295,27 @@ import ToastContainer from './components/ToastContainer.vue';
import CommentSection from './components/CommentSection.vue';
import UpdateDialog from './components/UpdateDialog.vue';
import { usePlayerStore } from './stores/player';
import { getCoverUrl, extractDominantColor } from './utils/song';
import { useOnlineStatus } from './composables/useOnlineStatus';
import { showToast } from './composables/useToast';
import { useLyric } from './composables/UserLyric';
import { useUpdater } from './composables/useUpdater';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { listen } from '@tauri-apps/api/event';
import { register, unregister } from '@tauri-apps/plugin-global-shortcut';
import IconHome from '~icons/lucide/home';
import IconSearch from '~icons/lucide/search';
import IconRadio from '~icons/lucide/radio';
import IconHeart from '~icons/lucide/heart';
import IconSettings from '~icons/lucide/settings';
import IconLogIn from '~icons/lucide/log-in';
import IconChevronDown from '~icons/lucide/chevron-down';
import IconChevronRight from '~icons/lucide/chevron-right';
import IconMaximize2 from '~icons/lucide/maximize-2';
import IconX from '~icons/lucide/x';
import IconClock from '~icons/lucide/clock';
import IconMusic from '~icons/lucide/music';
import IconLanguages from '~icons/lucide/languages';
const router = useRouter();
const route = useRoute();
@ -293,25 +323,26 @@ const userStore = useUserStore();
const player = usePlayerStore();
const settings = useSettingsStore();
const updater = useUpdater();
const { isOnline } = useOnlineStatus();
watch(isOnline, (val, old) => {
if (val && !old) showToast('网络已恢复', 'success');
else if (!val && old) showToast('网络已断开,部分功能不可用', 'error');
});
const createdPlaylists = ref<any[]>([]);
const subPlaylists = ref<any[]>([]);
const showCreatedPlaylists = ref(true);
const showSubPlaylists = ref(true);
const searchQuery = ref('');
const showCloseModal = ref(false);
const closeDontAskAgain = ref(false);
const windowVisible = ref(true);
const keepAliveInclude = ref<string[]>(['HomeView', 'DiscoverView', 'FavoriteSongsView', 'DailySongsView', 'LocalMusicView']);
watch(() => settings.theme, (val) => {
watch(() => settings.dataTheme, (val) => {
document.documentElement.setAttribute('data-theme', val);
}, { immediate: true });
function doSearch() {
const q = searchQuery.value.trim();
if (q) router.push({ path: '/discover', query: { q } });
}
const { lyrics, currentLyricIdx, hasTranslation, showTranslation, toggleTranslation } = useLyric();
const lyricScrollContainer = ref<HTMLElement | null>(null);
const roamLyricHovering = ref(false);
@ -321,9 +352,17 @@ const roamCoverError = ref(false);
const roamTab = ref<'lyric' | 'comment'>('lyric');
const roamCoverUrl = computed(() => {
if (!roamSong.value) return '';
return roamSong.value.al?.picUrl || roamSong.value.album?.picUrl || '';
return getCoverUrl(roamSong.value) || '';
});
watch(roamCoverUrl, async (url) => {
roamCoverError.value = false;
if (url) {
const color = await extractDominantColor(url);
player.dominantColor = color;
} else {
player.dominantColor = '';
}
});
watch(roamCoverUrl, () => { roamCoverError.value = false; });
let roamResizeObserver: ResizeObserver | null = null;
function updateRoamLyricPad() {
@ -365,6 +404,12 @@ watch(currentLyricIdx, () => {
}
});
watch(showTranslation, () => {
if (player.showRoamDrawer && !roamLyricHovering.value) {
nextTick(() => scrollToRoamActiveLyric());
}
});
function scrollToRoamActiveLyric() {
if (!lyricScrollContainer.value || roamLyricHovering.value) return;
const active = lyricScrollContainer.value.querySelector('.roam-lyric-active') as HTMLElement | null;
@ -375,12 +420,13 @@ function scrollToRoamActiveLyric() {
function getRoamLyricClass(idx: number): string {
const diff = Math.abs(idx - currentLyricIdx.value);
const hasColor = !!player.dominantColor;
if (idx === currentLyricIdx.value) {
return 'roam-lyric-active text-accent-text font-semibold text-xl';
}
if (diff === 1) return 'text-content/70 text-lg';
if (diff === 2) return 'text-content-2/50 text-[1rem]';
return 'text-content-3/35 text-[1rem]';
if (diff === 1) return hasColor ? 'text-white/70 text-lg' : 'text-content/70 text-lg';
if (diff === 2) return hasColor ? 'text-white/50 text-[1rem]' : 'text-content-2/50 text-[1rem]';
return hasColor ? 'text-white/35 text-[1rem]' : 'text-content-3/35 text-[1rem]';
}
function seekToRoamLyric(time: number) {
@ -395,6 +441,10 @@ function navigateFromDrawer(routeLocation: { name: string; params: any }) {
}
async function openRoamFromSidebar() {
if (!userStore.isLoggedIn) {
router.push('/login');
return;
}
if (player.isFmMode) {
player.openRoamDrawer();
} else {
@ -409,7 +459,7 @@ async function loadPlaylists() {
const data = JSON.parse(jsonStr);
createdPlaylists.value = (data.playlist || []).filter((p: any) => !p.subscribed).slice(1);
subPlaylists.value = (data.playlist || []).filter((p: any) => p.subscribed);
} catch (e) { /* 忽略 */ }
} catch { /* 忽略 */ }
}
function goPlaylist(id: number) {
@ -428,11 +478,13 @@ watch(() => userStore.isLoggedIn, (val) => {
});
onMounted(async () => {
document.addEventListener('contextmenu', (e) => e.preventDefault());
if (userStore.isLoggedIn) {
loadPlaylists();
player.loadLikedIds();
}
try { await invoke('stop_audio'); } catch {}
try { await invoke('stop_audio'); } catch { /* 忽略 */ }
try {
const jsonStr: string = await invoke('get_login_status');
const data = JSON.parse(jsonStr);
@ -444,7 +496,7 @@ onMounted(async () => {
avatarUrl: profile.avatarUrl,
});
}
} catch {}
} catch { /* 忽略 */ }
updater.checkForUpdate(true);
@ -452,8 +504,7 @@ onMounted(async () => {
if(settings.outputDevice) {
try {
await invoke('set_output_device', { device: settings.outputDevice });
}
catch{}
} catch { /* 忽略 */ }
}
});
@ -497,9 +548,11 @@ onMounted(() => {
});
const unlisten4 = listen('window-hidden', () => {
windowVisible.value = false;
keepAliveInclude.value = [];
});
const unlisten5 = listen('window-shown', () => {
windowVisible.value = true;
keepAliveInclude.value = ['HomeView', 'DiscoverView', 'FavoriteSongsView', 'DailySongsView', 'LocalMusicView'];
});
onBeforeUnmount(() => {
@ -522,12 +575,12 @@ async function registerGlobalShortcuts() {
for (const [id, action] of Object.entries(globalActions)) {
const key = settings.shortcuts[id]?.key;
if (!key) continue;
try { await unregister(key); } catch {}
try { await unregister(key); } catch { /* 忽略 */ }
try {
await register(key, (event) => {
if (event.state === 'Pressed') action();
});
} catch {}
} catch { /* 忽略 */ }
}
}

View File

@ -3,7 +3,7 @@
<div v-if="loading" class="py-8 text-center text-content-2 text-sm">加载中...</div>
<div v-else-if="comments.length === 0" class="py-8 text-center">
<svg class="mx-auto mb-2 text-content-3" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
<IconMessageSquare class="mx-auto mb-2 text-content-3 w-10 h-10" />
<p class="text-content-3 text-sm">暂无评论</p>
</div>
@ -26,7 +26,7 @@
@click="likeComment(comment.commentId)"
class="flex items-center gap-1 text-content-3 hover:text-danger transition text-xs"
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<IconHeart style="font-size: 14px" />
<span>{{ comment.likedCount }}</span>
</button>
</div>
@ -41,6 +41,8 @@
<script setup lang="ts">
import { ref, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { invoke } from '@tauri-apps/api/core'
import IconMessageSquare from '~icons/lucide/message-square'
import IconHeart from '~icons/lucide/heart'
const props = defineProps<{
type: number

View File

@ -6,7 +6,7 @@
:class="{ 'border-accent shadow-[0_0_0_2px_var(--c-accent-dim)]': isOpen }"
>
<span class="truncate">{{ currentLabel }}</span>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="transition-transform flex-shrink-0 ml-2" :class="{ 'rotate-180': isOpen }"><polyline points="6 9 12 15 18 9"/></svg>
<IconChevronDown style="font-size: 12px" class="transition-transform flex-shrink-0 ml-2" :class="{ 'rotate-180': isOpen }" />
</button>
<Transition name="dropdown">
<div v-if="isOpen" class="absolute right-0 top-full mt-1 bg-surface border border-line rounded-lg shadow-xl z-50 py-1 min-w-full max-w-[360px] overflow-hidden">
@ -18,7 +18,7 @@
:class="modelValue === key ? 'bg-accent-dim text-accent-text' : 'text-content-2 hover:bg-subtle hover:text-content'"
>
<span class="truncate">{{ label }}</span>
<svg v-if="modelValue === key" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
<IconCheck v-if="modelValue === key" style="font-size: 14px" />
</button>
</div>
</Transition>
@ -27,6 +27,8 @@
<script setup lang="ts">
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
import IconChevronDown from '~icons/lucide/chevron-down';
import IconCheck from '~icons/lucide/check';
const props = defineProps<{
modelValue: string;

View File

@ -1,75 +1,83 @@
<template>
<div
class="fixed bottom-0 left-0 right-0 bg-surface/95 backdrop-blur border-t border-line z-50 select-none">
class="fixed bottom-0 left-0 right-0 bg-surface/95 backdrop-blur border-t border-line z-50 select-none"
>
<div v-if="player.dominantColor"
class="absolute inset-0 pointer-events-none transition-opacity duration-300"
:class="drawerActive ? 'opacity-100' : 'opacity-0'"
:style="{ backgroundColor: player.dominantColor }"
>
<div class="absolute inset-0 bg-black/60"></div>
</div>
<div ref="progressBar" class="w-full h-1.5 bg-muted rounded-full relative group cursor-pointer overflow-visible"
<div ref="progressBar" class="w-full h-1.5 rounded-full relative group cursor-pointer overflow-visible"
:class="drawerActive ? 'bg-white/10' : 'bg-muted'"
@mousedown.prevent="startSeek">
<div class="absolute left-0 top-0 h-full bg-emphasis rounded-full" :style="{ width: cacheProgress + '%' }"></div>
<div class="absolute left-0 top-0 h-full rounded-full" :class="drawerActive ? 'bg-white/20' : 'bg-emphasis'" :style="{ width: cacheProgress + '%' }"></div>
<div class="absolute left-0 top-0 h-full bg-accent rounded-full"
:style="{ width: displayProgress + '%' }"></div>
<div
class="absolute top-1/2 -translate-y-1/2 w-3.5 h-3.5 rounded-full bg-white shadow-lg opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"
class="absolute top-1/2 -translate-y-1/2 w-3.5 h-3.5 rounded-full bg-white shadow-lg border border-line opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"
:style="{ left: `calc(${displayProgress}% - 7px)` }"></div>
</div>
<div class="flex items-center px-6 h-16">
<div class="flex items-center px-6 h-16 relative z-10">
<div class="flex items-center gap-3 w-56 min-w-0">
<div v-if="player.currentSong?.al?.picUrl" class="w-10 h-10 rounded-md overflow-hidden flex-shrink-0 cursor-pointer hover:scale-105 transition-transform" @click="player.toggleRoamDrawer()" title="全屏展示">
<img :src="player.currentSong.al.picUrl" class="w-full h-full object-cover" />
<div v-if="getCoverUrl(player.currentSong)" class="w-10 h-10 rounded-md overflow-hidden flex-shrink-0 cursor-pointer hover:scale-105 transition-transform" @click="player.toggleRoamDrawer()" title="全屏展示">
<img :src="getCoverUrl(player.currentSong)" class="w-full h-full object-cover" />
</div>
<div v-else class="w-10 h-10 rounded-md flex-shrink-0 bg-muted flex items-center justify-center cursor-pointer hover:scale-105 transition-transform" @click="player.toggleRoamDrawer()" title="全屏展示">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-content-3"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
<div v-else class="w-10 h-10 rounded-md flex-shrink-0 flex items-center justify-center cursor-pointer hover:scale-105 transition-transform" @click="player.toggleRoamDrawer()" title="全屏展示"
:class="drawerActive ? 'bg-white/10' : 'bg-muted'">
<IconMusic class="w-[18px] h-[18px]" :class="drawerActive ? 'text-white/50' : 'text-content-3'" />
</div>
<div class="min-w-0 flex-1">
<p class="text-sm font-medium truncate">{{ player.currentSong?.name }}</p>
<p class="text-xs text-content-2 truncate">
<p class="text-sm font-medium truncate" :class="drawerActive ? 'text-white' : ''">{{ player.currentSong?.name }}</p>
<p class="text-xs truncate" :class="drawerActive ? 'text-white/70' : 'text-content-2'">
<template v-for="(a, i) in player.currentSong?.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span v-if="i > 0" :class="drawerActive ? 'text-white/40' : 'text-content-3'">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="player.currentSong?.al?.name">
<span class="text-content-3 mx-1">·</span>
<span :class="drawerActive ? 'text-white/40' : 'text-content-3'" class="mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="player.currentSong!.al.id && router.push({ name: 'album', params: { id: player.currentSong!.al.id } })">{{ player.currentSong.al.name }}</span>
</template>
</p>
</div>
<button @click="player.currentSong && player.toggleLike(player.currentSong.id)" class="flex-shrink-0 transition" :class="player.currentSong && player.isLiked(player.currentSong.id) ? 'text-danger' : 'text-content-3 hover:text-danger'">
<svg v-if="player.currentSong && player.isLiked(player.currentSong.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<button @click="player.currentSong && player.toggleLike(player.currentSong.id)" class="flex-shrink-0 transition" :class="player.currentSong && player.isLiked(player.currentSong.id) ? 'text-danger' : (drawerActive ? 'text-white/50 hover:text-danger' : 'text-content-3 hover:text-danger')">
<IconHeart v-if="player.currentSong && player.isLiked(player.currentSong.id)" class="w-4 h-4 text-danger [&>path]:fill-current [&>path]:stroke-0" />
<IconHeart v-else class="w-4 h-4" />
</button>
<button v-if="player.currentSong" @click="player.openRoamDrawer('comment')" class="flex-shrink-0 text-content-3 hover:text-accent-text transition" title="评论">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
<button v-if="player.currentSong" @click="player.openRoamDrawer('comment')" class="flex-shrink-0 transition" :class="drawerActive ? 'text-white/50 hover:text-white' : 'text-content-3 hover:text-accent-text'" title="评论">
<IconMessageSquare class="w-4 h-4" />
</button>
<button v-if="player.currentSong && !download.isDownloaded(player.currentSong!.id) && !download.isDownloading(player.currentSong!.id)" @click="download.downloadSong(player.currentSong)" class="flex-shrink-0 text-content-3 hover:text-accent-text transition" title="下载">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<button v-if="player.currentSong && !download.isDownloaded(player.currentSong!.id) && !download.isDownloading(player.currentSong!.id)" @click="download.downloadSong(player.currentSong)" class="flex-shrink-0 transition" :class="drawerActive ? 'text-white/50 hover:text-white' : 'text-content-3 hover:text-accent-text'" title="下载">
<IconDownload class="w-4 h-4" />
</button>
<svg v-if="player.currentSong && download.isDownloading(player.currentSong!.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 animate-spin text-content-3"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<IconLoader2 v-if="player.currentSong && download.isDownloading(player.currentSong!.id)" class="w-4 h-4 flex-shrink-0 animate-spin" :class="drawerActive ? 'text-white/50' : 'text-content-3'" />
</div>
<div class="flex-1 flex flex-col items-center justify-center gap-1">
<div class="flex items-center gap-5">
<button @click="player.prev()" :disabled="player.isFmMode" :class="[
'transition',
player.isFmMode ? 'text-content-4 cursor-not-allowed' : 'text-content-2 hover:text-content',
player.isFmMode ? (drawerActive ? 'text-white/20 cursor-not-allowed' : 'text-content-4 cursor-not-allowed') : (drawerActive ? 'text-white/70 hover:text-white' : 'text-content-2 hover:text-content'),
]">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="19 20 9 12 19 4 19 20"/><line x1="5" y1="19" x2="5" y2="5"/></svg>
<IconSkipBack class="w-5 h-5" />
</button>
<button @click="player.toggle()"
class="w-9 h-9 flex items-center justify-center rounded-full bg-muted hover:bg-emphasis transition border border-emphasis">
<svg v-if="player.playing" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"
class="text-white">
<rect x="3" y="2" width="3" height="12" rx="0.5" />
<rect x="10" y="2" width="3" height="12" rx="0.5" />
</svg>
<svg v-else width="16" height="16" viewBox="0 0 16 16" fill="currentColor" class="text-white">
<path d="M4 2.5v11l9-5.5z" />
</svg>
class="w-9 h-9 flex items-center justify-center rounded-full transition"
:class="drawerActive ? 'bg-white/15 hover:bg-white/25 border border-white/20' : 'bg-muted hover:bg-emphasis border border-emphasis'">
<IconPause v-if="player.playing" class="w-4 h-4" :class="drawerActive ? 'text-white' : 'text-content'" />
<IconPlay v-else class="w-4 h-4" :class="drawerActive ? 'text-white' : 'text-content'" />
</button>
<button @click="player.next()" class="text-content-2 hover:text-content transition">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 4 15 12 5 20 5 4"/><line x1="19" y1="5" x2="19" y2="19"/></svg>
<button @click="player.next()" :class="drawerActive ? 'text-white/70 hover:text-white transition' : 'text-content-2 hover:text-content transition'">
<IconSkipForward class="w-5 h-5" />
</button>
<button v-if="player.isFmMode && player.currentSong" @click="showDislikeModal = true" :class="drawerActive ? 'text-white/50 hover:text-danger transition' : 'text-content-3 hover:text-danger transition'" title="减少推荐">
<IconHeartOff class="w-[18px] h-[18px]" />
</button>
</div>
<div class="flex items-center gap-2 text-xs text-content-2">
<div class="flex items-center gap-2 text-xs" :class="drawerActive ? 'text-white/70' : 'text-content-2'">
<span>{{ formatTime(player.currentTime) }}</span>
<span>/</span>
<span>{{ formatTime(player.duration) }}</span>
@ -78,33 +86,60 @@
<div class="w-56 flex justify-end items-center gap-2">
<div class="flex items-center gap-1">
<button @click="toggleMute" class="text-content-2 hover:text-content transition">
<svg v-if="player.volume === 0" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/><line x1="23" y1="9" x2="17" y2="15"/><line x1="17" y1="9" x2="23" y2="15"/></svg>
<svg v-else width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/><path d="M19.07 4.93a10 10 0 010 14.14M15.54 8.46a5 5 0 010 7.07"/></svg>
<button @click="toggleMute" :class="drawerActive ? 'text-white/70 hover:text-white transition' : 'text-content-2 hover:text-content transition'">
<IconVolumeX v-if="player.volume === 0" class="w-[18px] h-[18px]" />
<IconVolume2 v-else class="w-[18px] h-[18px]" />
</button>
<div class="relative w-20 h-6 flex items-center">
<input ref="volumeSlider" type="range" min="0" max="100" :value="player.volume"
:style="{ background: volumeBarBg }" @input="handleVolumeChange"
class="vol-slider w-full h-1.5 rounded-full appearance-none cursor-pointer bg-emphasis outline-none" />
class="vol-slider w-full h-1.5 rounded-full appearance-none cursor-pointer outline-none"
:class="drawerActive ? 'bg-white/20' : 'bg-emphasis'" />
</div>
</div>
<button @click="togglePlayMode" class="text-content-2 hover:text-content transition" :title="modeTitle">
<svg v-if="player.playMode === 'loop'" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 014-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 01-4 4H3"/></svg>
<svg v-else-if="player.playMode === 'shuffle'" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 3 21 3 21 8"/><line x1="4" y1="20" x2="21" y2="3"/><polyline points="21 16 21 21 16 21"/><line x1="15" y1="15" x2="21" y2="21"/><line x1="4" y1="4" x2="9" y2="9"/></svg>
<svg v-else width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 014-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 01-4 4H3"/><text x="11" y="15" font-size="8" fill="currentColor" stroke="none" font-weight="bold">1</text></svg>
<button @click="togglePlayMode" :class="drawerActive ? 'text-white/70 hover:text-white transition' : 'text-content-2 hover:text-content transition'" :title="modeTitle">
<IconRepeat v-if="player.playMode === 'loop'" class="w-[18px] h-[18px]" />
<IconShuffle v-else-if="player.playMode === 'shuffle'" class="w-[18px] h-[18px]" />
<IconRepeat1 v-else class="w-[18px] h-[18px]" />
</button>
<button @click="showQueuePanel = !showQueuePanel"
class="text-content-2 hover:text-content transition relative" title="播放列表">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
<span v-if="player.queue.length > 0"
class="absolute -top-1 -right-1 bg-accent text-content text-xs rounded-full w-4 h-4 flex items-center justify-center">
{{ player.queue.length }}
</span>
:class="drawerActive ? 'text-white/70 hover:text-white transition' : 'text-content-2 hover:text-content transition'" title="播放列表">
<IconListMusic class="w-[18px] h-[18px]" />
</button>
</div>
</div>
<Teleport to="body">
<Transition name="queue-fade">
<div v-if="showDislikeModal && player.currentSong" class="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm" @click.self="showDislikeModal = false">
<div class="bg-surface border border-line rounded-2xl shadow-2xl w-80 p-5 select-auto">
<h2 class="text-base font-semibold text-content mb-1">减少推荐</h2>
<p class="text-xs text-content-3 mb-4">选择要减少的推荐类型</p>
<div class="flex flex-col gap-2 mb-4">
<button @click="dislikeSong"
class="w-full flex items-center gap-3 px-4 py-3 rounded-xl bg-muted hover:bg-emphasis transition text-left">
<IconMusic class="w-[18px] h-[18px] text-content-2 flex-shrink-0" />
<div>
<p class="text-sm font-medium">不推荐这首歌曲</p>
<p class="text-xs text-content-3 truncate max-w-[200px]">{{ player.currentSong.name }}</p>
</div>
</button>
<button v-if="dislikeArtistName" @click="dislikeArtist"
class="w-full flex items-center gap-3 px-4 py-3 rounded-xl bg-muted hover:bg-emphasis transition text-left">
<IconUserRound class="w-[18px] h-[18px] text-content-2 flex-shrink-0" />
<div>
<p class="text-sm font-medium">不推荐这个歌手</p>
<p class="text-xs text-content-3 truncate max-w-[200px]">{{ dislikeArtistName }}</p>
</div>
</button>
</div>
<button @click="showDislikeModal = false"
class="w-full py-2 rounded-lg bg-muted hover:bg-emphasis text-sm text-content-2 transition">
取消
</button>
</div>
</div>
</Transition>
<Transition name="queue-fade">
<div v-if="showQueuePanel" class="fixed inset-0 z-[55] bg-black/40 backdrop-blur-[2px]" @click="showQueuePanel = false"></div>
</Transition>
@ -125,7 +160,7 @@
</button>
<button @click="showQueuePanel = false"
class="w-7 h-7 flex items-center justify-center rounded-lg text-content-3 hover:text-content hover:bg-subtle transition">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
<IconX class="w-4 h-4" />
</button>
</div>
</div>
@ -135,50 +170,30 @@
<div ref="queueListEl" class="flex-1 overflow-y-auto px-3 py-2 relative">
<div v-if="player.queue.length === 0" class="flex flex-col items-center justify-center h-full text-content-4 gap-3">
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="opacity-40">
<path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/>
</svg>
<IconMusic class="w-10 h-10 opacity-40" />
<p class="text-sm">播放列表为空</p>
<p class="text-xs text-content-4">去发现好听的音乐吧</p>
</div>
<div v-for="(song, idx) in player.queue" :key="song.id + '-' + idx" :id="'queue-item-' + idx"
@click="playFromQueue(idx)" :class="[
'flex items-center gap-3 px-3 py-2 rounded-lg cursor-pointer transition-all duration-200 group',
idx === player.currentIndex
? 'bg-muted'
: 'hover:bg-subtle',
]">
<div class="w-9 h-9 rounded-md overflow-hidden flex-shrink-0 relative">
<img v-if="song.al?.picUrl" :src="song.al.picUrl + '?param=80y80'" class="w-full h-full object-cover" loading="lazy" />
<div v-else class="w-full h-full bg-muted flex items-center justify-center">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="text-content-4"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
</div>
<div v-if="idx === player.currentIndex"
class="absolute inset-0 bg-black/30 flex items-center justify-center">
<div class="flex items-end gap-[2px] h-3">
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0s"></span>
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0.12s"></span>
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0.24s"></span>
</div>
</div>
</div>
<div class="flex-1 min-w-0">
<p class="text-sm truncate" :class="idx === player.currentIndex ? 'text-accent-text font-medium' : 'text-content-2'">
{{ song.name }}
</p>
<p class="text-xs text-content-3 truncate mt-0.5">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-4">/</span>
<span>{{ a.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.removeFromQueue(idx)"
class="w-6 h-6 flex items-center justify-center rounded-md text-content-4 hover:text-danger hover:bg-danger-dim transition opacity-0 group-hover:opacity-100 flex-shrink-0">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
</div>
<SongListItem
v-for="(song, idx) in player.queue" :key="song.id + '-' + idx"
:id="'queue-item-' + idx"
:song="song"
:index="idx"
:is-current="idx === player.currentIndex"
show-playing-overlay
cover-size="w-9 h-9"
cover-size-param="?param=80y80"
:container-class="idx === player.currentIndex ? 'bg-muted hover:bg-muted gap-3 px-3 py-2 rounded-lg' : 'hover:bg-subtle gap-3 px-3 py-2 rounded-lg'"
@click="playFromQueue(idx)"
>
<template #actions>
<button @click.stop="player.removeFromQueue(idx)"
class="w-6 h-6 flex items-center justify-center rounded-md text-content-4 hover:text-danger hover:bg-danger-dim transition opacity-0 group-hover:opacity-100 flex-shrink-0">
<IconX class="w-3 h-3" />
</button>
</template>
</SongListItem>
<div class="h-2"></div>
@ -186,7 +201,7 @@
@click="scrollToCurrent"
class="sticky bottom-3 float-right mr-1 w-9 h-9 flex items-center justify-center rounded-full bg-surface/90 backdrop-blur shadow-lg shadow-black/30 text-content-3 hover:text-accent-text hover:bg-accent-dim/50 transition-all duration-300"
title="定位到正在播放">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/></svg>
<IconCrosshair class="w-[18px] h-[18px]" />
</button>
</div>
</div>
@ -200,14 +215,38 @@ import { ref, computed, watch, onBeforeUnmount, onMounted, nextTick } from 'vue'
import { usePlayerStore, PlayMode } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatTime } from '../utils/format';
import { getCoverUrl } from '../utils/song';
import { invoke } from '@tauri-apps/api/core';
import { showToast } from '../composables/useToast';
import { listen } from '@tauri-apps/api/event';
import { useRouter } from 'vue-router';
import SongListItem from './SongListItem.vue';
import IconSkipBack from '~icons/lucide/skip-back';
import IconPlay from '~icons/lucide/play';
import IconPause from '~icons/lucide/pause';
import IconSkipForward from '~icons/lucide/skip-forward';
import IconHeartOff from '~icons/lucide/heart-off';
import IconVolumeX from '~icons/lucide/volume-x';
import IconVolume2 from '~icons/lucide/volume-2';
import IconRepeat from '~icons/lucide/repeat';
import IconShuffle from '~icons/lucide/shuffle';
import IconRepeat1 from '~icons/lucide/repeat-1';
import IconListMusic from '~icons/lucide/list-music';
import IconMessageSquare from '~icons/lucide/message-square';
import IconDownload from '~icons/lucide/download';
import IconLoader2 from '~icons/lucide/loader-2';
import IconHeart from '~icons/lucide/heart';
import IconX from '~icons/lucide/x';
import IconMusic from '~icons/lucide/music';
import IconCrosshair from '~icons/lucide/crosshair';
import IconUserRound from '~icons/lucide/user-round';
const router = useRouter();
const player = usePlayerStore();
const download = useDownload();
const drawerActive = computed(() => player.showRoamDrawer && !!player.dominantColor);
const showQueuePanel = ref(false);
const showDislikeModal = ref(false);
const queueListEl = ref<HTMLElement | null>(null);
const currentSongVisible = ref(true);
const progressBar = ref<HTMLElement | null>(null);
@ -228,7 +267,17 @@ onBeforeUnmount(() => {
if (unlistenCache) unlistenCache();
});
const modeTexts = { loop: '列表循环', shuffle: '随机播放', 'repeat-one': '单曲循环' };
watch(() => player.currentSong, (song) => {
if (!song) {
cacheProgress.value = 0;
} else if (song.localPath) {
cacheProgress.value = 100;
} else {
cacheProgress.value = 0;
}
});
const modeTexts: Record<PlayMode, string> = { loop: '列表循环', shuffle: '随机播放', 'repeat-one': '单曲循环' };
const modeTitle = computed(() => modeTexts[player.playMode] || '列表循环');
function togglePlayMode() {
const modes: PlayMode[] = ['loop', 'shuffle', 'repeat-one'];
@ -301,6 +350,26 @@ function playFromQueue(index: number) {
player.playCurrent();
}
const dislikeArtistName = computed(() => {
const song = player.currentSong;
if (!song?.ar?.length) return '';
return song.ar.map(a => a.name).join(' / ');
});
async function dislikeSong() {
if (!player.currentSong) return;
showDislikeModal.value = false;
await player.fmTrash(player.currentSong.id);
showToast('已减少该歌曲推荐', 'success');
}
async function dislikeArtist() {
if (!player.currentSong) return;
showDislikeModal.value = false;
await player.fmTrash(player.currentSong.id);
showToast('已减少该歌手推荐', 'success');
}
function scrollToCurrent() {
const el = document.getElementById('queue-item-' + player.currentIndex);
if (el) {
@ -354,7 +423,8 @@ async function handleVolumeChange(e: Event) {
const volumeBarBg = computed(() => {
const pct = player.volume;
return `linear-gradient(to right, var(--c-accent) 0%, var(--c-accent) ${pct}%, var(--c-muted) ${pct}%)`;
const track = drawerActive.value ? 'rgba(255,255,255,0.2)' : 'var(--c-muted)';
return `linear-gradient(to right, var(--c-accent) 0%, var(--c-accent) ${pct}%, ${track} ${pct}%)`;
});
</script>
@ -414,12 +484,4 @@ const volumeBarBg = computed(() => {
transform: translateX(100%);
}
@keyframes eq-bounce-sm {
0%, 100% { height: 2px; }
50% { height: 10px; }
}
.eq-bar-sm {
animation: eq-bounce-sm 0.6s ease-in-out infinite;
}
</style>

View File

@ -1,12 +1,12 @@
<template>
<div class="relative flex-shrink-0" ref="menuRef">
<button @click.stop="toggle" class="text-content-3 hover:text-content transition p-1 rounded-md hover:bg-subtle">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="5" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="12" cy="19" r="2"/></svg>
<IconEllipsis class="w-4 h-4 fill-current" />
</button>
<div v-if="open"
class="absolute right-0 top-full mt-1 bg-surface border border-line rounded-xl shadow-xl z-50 py-1 min-w-[120px]">
<button @click.stop="handleComment" class="w-full flex items-center gap-2 px-3 py-2 text-sm text-content-2 hover:bg-subtle hover:text-content transition">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
<IconMessageSquare style="font-size: 14px" />
评论
</button>
</div>
@ -16,6 +16,8 @@
<script setup lang="ts">
import { ref, onBeforeUnmount, onMounted } from 'vue';
import { usePlayerStore } from '../stores/player';
import IconEllipsis from '~icons/lucide/ellipsis';
import IconMessageSquare from '~icons/lucide/message-square';
const player = usePlayerStore();
const props = defineProps<{ songId: number }>();

View File

@ -0,0 +1,115 @@
<template>
<div :class="['flex items-center gap-4 p-3 rounded-xl cursor-pointer transition group', containerClass]">
<slot name="index" :index="index" :is-current="isCurrent">
<div v-if="showIndex" class="w-6 text-right flex-shrink-0 flex items-center justify-end h-5">
<div v-if="isCurrent && showPlayingOverlay" class="flex items-center justify-end">
<div class="flex items-center gap-[3px] h-4">
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 50%; animation-delay: 0ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 100%; animation-delay: 150ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 35%; animation-delay: 300ms"></span>
</div>
</div>
<template v-else>
<span class="text-xs text-content-3 group-hover:hidden">{{ index + 1 }}</span>
<IconPlay class="hidden group-hover:block text-content" style="font-size: 14px" />
</template>
</div>
</slot>
<div :class="['rounded-md overflow-hidden flex-shrink-0 relative', coverClass]">
<img v-if="coverSrc" :src="coverSrc" class="w-full h-full object-cover" loading="lazy" />
<div v-else class="w-full h-full bg-muted flex items-center justify-center">
<IconMusic style="font-size: 14px" class="text-content-4" />
</div>
<div v-if="isCurrent && showPlayingOverlay"
class="absolute inset-0 bg-black/30 flex items-center justify-center">
<div class="flex items-end gap-[2px] h-3">
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0s"></span>
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0.12s"></span>
<span class="eq-bar-sm w-[2px] bg-white rounded-full" style="animation-delay: 0.24s"></span>
</div>
</div>
</div>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate" :class="nameClass">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-if="song.ar?.length">
<template v-for="(a, i) in song.ar" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<slot name="actions">
<button v-if="showLike" @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<IconHeart v-if="player.isLiked(song.id)" class="w-4 h-4 text-danger [&>path]:fill-current [&>path]:stroke-0" />
<IconHeart v-else class="w-4 h-4" />
</button>
<button v-if="showDownload" @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<IconLoader2 v-if="download.isDownloading(song.id)" class="w-4 h-4 animate-spin" />
<IconCheck v-else-if="download.isDownloaded(song.id)" class="w-4 h-4 text-accent-text" />
<IconDownload v-else class="w-4 h-4" />
</button>
<SongItemMenu v-if="showMenu" :song-id="song.id" />
</slot>
<span v-if="showDuration && song.dt" class="text-xs text-content-3 flex-shrink-0">{{ formatDuration(song.dt) }}</span>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useRouter } from 'vue-router';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { getCoverUrl, type Song } from '../utils/song';
import { formatDuration } from '../utils/format';
import SongItemMenu from './SongItemMenu.vue';
import IconPlay from '~icons/lucide/play';
import IconMusic from '~icons/lucide/music';
import IconHeart from '~icons/lucide/heart';
import IconLoader2 from '~icons/lucide/loader-2';
import IconCheck from '~icons/lucide/check';
import IconDownload from '~icons/lucide/download';
const router = useRouter();
const player = usePlayerStore();
const download = useDownload();
const props = withDefaults(defineProps<{
song: Song;
index: number;
isCurrent?: boolean;
showIndex?: boolean;
showLike?: boolean;
showDownload?: boolean;
showMenu?: boolean;
showDuration?: boolean;
showPlayingOverlay?: boolean;
coverSize?: string;
coverSizeParam?: string;
containerClass?: string;
}>(), {
isCurrent: false,
showIndex: false,
showLike: false,
showDownload: false,
showMenu: false,
showDuration: false,
showPlayingOverlay: false,
coverSize: 'w-10 h-10',
coverSizeParam: '',
containerClass: 'hover:bg-subtle',
});
const coverClass = computed(() => props.coverSize);
const coverSrc = computed(() => getCoverUrl(props.song, props.coverSizeParam));
const nameClass = computed(() => props.isCurrent ? 'text-accent-text' : '');
</script>

View File

@ -5,7 +5,7 @@
<div class="p-6 pb-4">
<div class="flex items-center gap-3 mb-1">
<div class="w-10 h-10 rounded-xl bg-accent/15 flex items-center justify-center flex-shrink-0">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<IconDownload class="w-5 h-5 text-accent-text" />
</div>
<div>
<h2 class="text-lg font-semibold text-content">发现新版本</h2>
@ -54,6 +54,7 @@
<script setup lang="ts">
import type { UpdateInfo } from '../composables/useUpdater'
import IconDownload from '~icons/lucide/download'
const props = defineProps<{
visible: boolean

View File

@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';
import { useSettingsStore } from '../stores/settings';
import { showToast } from '../composables/useToast';
import { getCoverUrl, type Song } from '../utils/song';
interface DownloadTask {
id: number;
@ -46,7 +47,7 @@ async function refreshLocalIds() {
for (const s of list) {
localSongIds.add(s.id);
}
} catch {}
} catch { /* 忽略 */ }
}
function ensureStoreSetup() {
@ -72,7 +73,7 @@ function getDownloadProgress(songId: number): number {
return task?.progress ?? 0;
}
async function downloadSong(song: { id: number; name: string; ar?: { name: string }[]; artists?: { name: string }[]; al?: { picUrl?: string; name?: string }; album?: { picUrl?: string; name?: string }; dt?: number; duration?: number }) {
async function downloadSong(song: Song) {
if (downloadingIds.has(song.id)) return;
if (localSongIds.has(song.id)) {
showToast(`${song.name} 已下载`, 'info');
@ -80,10 +81,10 @@ async function downloadSong(song: { id: number; name: string; ar?: { name: strin
}
const settings = useSettingsStore();
const artist = song.ar?.map(a => a.name).join(' / ') || song.artists?.map(a => a.name).join(' / ') || '未知';
const albumName = song.al?.name || song.album?.name || null;
const durationVal = song.dt || song.duration || null;
const coverUrl = song.al?.picUrl || song.album?.picUrl || null;
const artist = song.ar?.map(a => a.name).join(' / ') || '未知';
const albumName = song.al?.name || null;
const durationVal = song.dt || null;
const coverUrl = getCoverUrl(song) || null;
downloadingIds.add(song.id);
tasks.push({ id: song.id, name: song.name, progress: 0 });

View File

@ -0,0 +1,30 @@
import { ref, onMounted, onBeforeUnmount } from 'vue';
const isOnline = ref(navigator.onLine);
function update() {
isOnline.value = navigator.onLine;
}
let refCount = 0;
export function useOnlineStatus() {
onMounted(() => {
refCount++;
if (refCount === 1) {
window.addEventListener('online', update);
window.addEventListener('offline', update);
}
});
onBeforeUnmount(() => {
refCount--;
if (refCount <= 0) {
refCount = 0;
window.removeEventListener('online', update);
window.removeEventListener('offline', update);
}
});
return { isOnline };
}

View File

@ -0,0 +1,30 @@
const cache = new Map<string, { data: any; ts: number }>();
const TTL = 5 * 60 * 1000;
export function pageCacheGet(key: string): any | null {
const entry = cache.get(key);
if (!entry) return null;
if (Date.now() - entry.ts > TTL) {
cache.delete(key);
return null;
}
return entry.data;
}
export function pageCacheSet(key: string, data: any) {
cache.set(key, { data, ts: Date.now() });
}
export function pageCacheDelete(key: string) {
cache.delete(key);
}
export function pageCacheInvalidate(key: string) {
cache.delete(key);
}
export function pageCacheIsStale(key: string): boolean {
const entry = cache.get(key);
if (!entry) return true;
return Date.now() - entry.ts > TTL;
}

View File

@ -39,7 +39,7 @@ export function useUpdater() {
function setIgnoredVersion(version: string) {
try {
localStorage.setItem(IGNORED_VERSION_KEY, version)
} catch {}
} catch { /* 忽略 */ }
}
async function checkForUpdate(silent = false): Promise<UpdateInfo | null> {
@ -65,8 +65,7 @@ export function useUpdater() {
}
const ignored = getIgnoredVersion()
if (info.version === ignored) {
if (!silent) error.value = '当前已是最新版本'
if (info.version === ignored && silent) {
return null
}

View File

@ -4,29 +4,22 @@ import './style.css';
import router from './router';
import { createPinia } from 'pinia';
// ---------- 彻底阻止双指拖动和手势 ----------
const preventGesture = (e: Event) => e.preventDefault();
// 阻止 iOS / macOS 手势缩放和页面拖动
document.addEventListener('gesturestart', preventGesture, { passive: false });
document.addEventListener('gesturechange', preventGesture, { passive: false });
document.addEventListener('gestureend', preventGesture, { passive: false });
// 阻止触控板双指水平滑动(若仍存在)
window.addEventListener('wheel', (e: WheelEvent) => {
// 只阻止水平方向,保留垂直滚动(内部容器会处理)
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
e.preventDefault();
}
}, { passive: false });
// 阻止移动端双指触摸移动(不影响单指滚动)
window.addEventListener('touchmove', (e: TouchEvent) => {
if (e.touches.length >= 2) {
e.preventDefault();
}
}, { passive: false });
// -------------------------------------------
const app = createApp(App);
app.use(router);

View File

@ -9,24 +9,36 @@ import DailySongs from '@/views/DailySongs.vue';
import LocalMusic from '@/views/LocalMusic.vue';
import Settings from '@/views/Settings.vue';
const routes = [
{ path: '/', name: 'home', component: Home },
{ path: '/discover', name: 'discover', component: Discover },
{ path: '/search', name: 'search', component: Discover },
{ path: '/roam', name: 'roam', component: () => import('@/views/Roam.vue') },
{ path: '/favorites', name: 'favorites', component: FavoriteSongs },
{ path: '/recent', name: 'recent', component: RecentPlays },
{ path: '/daily', name: 'daily', component: DailySongs },
{ path: '/local-music', name: 'local-music', component: LocalMusic },
{ path: '/login', name: 'login', component: Login },
{ path: '/login', name: 'login', component: Login, meta: { guest: true } },
{ path: '/playlist/:id', name: 'playlist', component: PlaylistDetail },
{ path: '/artist/:id', name: 'artist', component: () => import('@/views/ArtistDetail.vue') },
{ path: '/album/:id', name: 'album', component: () => import('@/views/AlbumDetail.vue') },
{ path: '/settings', name: 'settings', component: Settings },
];
export default createRouter({
const router = createRouter({
history: createWebHistory(),
routes,
});
});
router.beforeEach((to) => {
if (to.meta.guest) {
const raw = localStorage.getItem('user');
if (raw) {
try {
const data = JSON.parse(raw);
if (data?.userId) return { name: 'home' };
} catch { /* 忽略 */ }
}
}
});
export default router;

5
src/shims-icons.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare module '~icons/lucide/*' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

View File

@ -1,41 +1,22 @@
import { defineStore } from 'pinia';
import { ref, watch, nextTick } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { normalizeSong } from '../utils/song';
import { normalizeSong, type Song } from '../utils/song';
import { useSettingsStore } from './settings';
import { useUserStore } from './user';
import { showToast } from '../composables/useToast';
export type PlayMode = 'loop' | 'shuffle' | 'repeat-one';
export type { Song };
export interface Song {
id: number;
name: string;
ar: { id?: number; name: string }[];
al: { id?: number; picUrl: string; name?: string };
dt?: number;
album?: { picUrl?: string; name?: string };
artists?: { name: string }[];
duration?: number;
localPath?: string;
}
const cacheProgress = ref(0);
import { listen } from '@tauri-apps/api/event';
export function setupCacheProgressListener() {
listen<number>('cache-progress', (event) => {
cacheProgress.value = event.payload;
});
}
import { listen, emit } from '@tauri-apps/api/event';
import { getCurrentWindow } from '@tauri-apps/api/window';
function loadRecentLocal(): Song[] {
try {
const raw = localStorage.getItem('recent_local');
if (raw) return JSON.parse(raw);
} catch {}
} catch { /* 忽略 */ }
return [];
}
@ -43,7 +24,7 @@ function loadLikedIdsFromStorage(): Set<number> {
try {
const raw = localStorage.getItem('liked_ids');
if (raw) return new Set(JSON.parse(raw));
} catch {}
} catch { /* 忽略 */ }
return new Set();
}
@ -55,15 +36,40 @@ export const usePlayerStore = defineStore('player', () => {
const queue = ref<Song[]>([]);
const currentIndex = ref(-1);
const volume = ref(100);
const settings = useSettingsStore();
const volume = ref(settings.volume);
watch(volume, (val) => { settings.volume = val; });
let tickInterval: ReturnType<typeof setInterval> | null = null;
function clearTick() {
if (tickInterval) { clearInterval(tickInterval); tickInterval = null; }
}
function setTick(v: ReturnType<typeof setInterval>) {
tickInterval = v;
}
const recentLocal = ref<Song[]>(loadRecentLocal());
const MAX_RECENT = 200;
const likedIds = ref<Set<number>>(loadLikedIdsFromStorage());
function emitPlaybackState() {
const song = currentSong.value;
const status = playing.value ? 'playing' : (song ? 'paused' : 'stopped');
emit('playback-state', {
status,
title: song?.name || '',
album: song?.al?.name || '',
artists: song?.ar?.map(a => a.name) || [],
coverUrl: song?.al?.picUrl || '',
durationUs: (song?.dt || 0) * 1000,
positionUs: Math.round(currentTime.value * 1_000_000),
volume: volume.value / 100,
});
}
function isLiked(songId: number): boolean {
return likedIds.value.has(songId);
}
@ -110,8 +116,37 @@ export const usePlayerStore = defineStore('player', () => {
}, { deep: true });
const isFmMode = ref(false);
const fmQueue: Song[] = [];
let fmNextCallback: (() => void) | null = null;
const fmMode = ref<string>('DEFAULT');
const fmSubMode = ref<string>('');
let lastScrobbleId: number | null = null;
let lastScrobbleStartTime: number = 0;
function reportScrobble() {
const song = currentSong.value;
if (!song || song.localPath || song.id == null) {
lastScrobbleId = null;
return;
}
if (lastScrobbleId === song.id && lastScrobbleStartTime > 0) {
const playedSec = Math.round((Date.now() - lastScrobbleStartTime) / 1000);
if (playedSec > 5) {
invoke('scrobble', {
query: {
id: song.id,
sourceid: isFmMode.value ? String(song.id) : '',
time: playedSec,
},
}).catch(() => {});
}
}
lastScrobbleId = song.id;
lastScrobbleStartTime = Date.now();
}
function enableFmMode(onNext: () => void) {
isFmMode.value = true;
fmNextCallback = onNext;
@ -120,13 +155,49 @@ export const usePlayerStore = defineStore('player', () => {
function disableFmMode() {
isFmMode.value = false;
fmNextCallback = null;
fmQueue.length = 0;
fmMode.value = 'DEFAULT';
fmSubMode.value = '';
fmSong.value = null;
fmPlaying.value = false;
}
function clearFmQueue() {
fmQueue.length = 0;
}
async function fmTrash(songId: number) {
try {
await invoke('fm_trash', { query: { id: songId, time: 25 } });
} catch (e) {
console.error('fm_trash 失败', e);
}
await nextFm();
}
async function fetchFmBatch(): Promise<Song[]> {
const isDefault = fmMode.value === 'DEFAULT' && !fmSubMode.value;
const jsonStr: string = isDefault
? await invoke('personal_fm')
: await invoke('personal_fm_mode', {
query: {
mode: fmMode.value,
subMode: fmSubMode.value,
limit: 3,
},
});
const data = JSON.parse(jsonStr);
const raw = data.data || data;
if (!Array.isArray(raw) || raw.length === 0) return [];
return raw.map((s: any) => normalizeSong(s));
}
let fmVipSkipCount = 0;
const MAX_FM_VIP_SKIP = 10;
async function playFmSong(song: any) {
if (tickInterval) { clearInterval(tickInterval); tickInterval = null; }
async function playFmSong(song: Song) {
clearTick();
reportScrobble();
if (!song.dt || song.dt === 0) {
try {
const jsonStr: string = await invoke('get_song_detail', { id: String(song.id) });
@ -137,7 +208,7 @@ export const usePlayerStore = defineStore('player', () => {
song.al = full.al || song.al;
song.ar = full.ar || song.ar;
}
} catch (e) { /* 忽略 */ }
} catch { /* 忽略 */ }
}
await invoke('stop_audio');
@ -148,7 +219,6 @@ export const usePlayerStore = defineStore('player', () => {
fmSong.value = song;
currentSong.value = song;
try {
const settings = useSettingsStore();
const jsonStr: string = await invoke('get_song_url', { query: { id: Number(song.id), level: settings.audioQuality, fm_mode: true } });
const data = JSON.parse(jsonStr);
const url: string | undefined = data.url;
@ -180,6 +250,7 @@ export const usePlayerStore = defineStore('player', () => {
currentTime.value = 0;
startTick();
addRecent(song);
emitPlaybackState();
} catch (e) {
console.error('FM播放失败', e);
playing.value = false;
@ -195,6 +266,15 @@ export const usePlayerStore = defineStore('player', () => {
disableFmMode();
const idx = queue.value.findIndex(s => s.id === song.id);
if (idx !== -1 && idx === currentIndex.value && currentSong.value?.id === song.id) {
if (!playing.value) {
await invoke('resume_audio');
playing.value = true;
startTick();
}
return;
}
if (idx === -1) {
queue.value.push(song);
currentIndex.value = queue.value.length - 1;
@ -207,6 +287,21 @@ export const usePlayerStore = defineStore('player', () => {
async function playFromList(songs: Song[], startIndex: number) {
disableFmMode();
if (songs.length === 0) return;
const targetSong = songs[startIndex];
if (targetSong && currentSong.value?.id === targetSong.id && currentIndex.value >= 0) {
const sameQueue = queue.value.length === songs.length
&& queue.value.every((s, i) => s.id === songs[i].id);
if (sameQueue) {
if (!playing.value) {
await invoke('resume_audio');
playing.value = true;
startTick();
}
return;
}
}
queue.value = [...songs];
currentIndex.value = Math.max(0, Math.min(startIndex, songs.length - 1));
await playCurrent();
@ -215,23 +310,15 @@ export const usePlayerStore = defineStore('player', () => {
let vipSkipCount = 0;
const MAX_VIP_SKIP = 10;
let audioStartedResolve: (() => void) | null = null;
listen('audio-started', () => {
if (audioStartedResolve) {
audioStartedResolve();
audioStartedResolve = null;
}
});
function waitForAudioStart(): Promise<void> {
return new Promise<void>((resolve) => {
audioStartedResolve = resolve;
_audioStartedResolve = resolve;
});
}
async function playCurrent() {
if (tickInterval) { clearInterval(tickInterval); tickInterval = null; }
clearTick();
reportScrobble();
const song = queue.value[currentIndex.value];
if (!song?.id) {
console.error('无效的歌曲数据', song);
@ -242,18 +329,18 @@ export const usePlayerStore = defineStore('player', () => {
currentSong.value = song;
playing.value = false;
currentTime.value = 0;
duration.value = (song.dt || song.duration || 0) / 1000;
duration.value = (song.dt || 0) / 1000;
if (song.localPath) {
await invoke('play_local_audio', { path: song.localPath });
await waitForAudioStart();
playing.value = true;
startTick();
addRecent(song);
return;
}
startTick();
addRecent(song);
emitPlaybackState();
return;
}
const settings = useSettingsStore();
const jsonStr: string = await invoke('get_song_url', { query: { id: Number(song.id), level: settings.audioQuality } });
const data = JSON.parse(jsonStr);
const url: string | undefined = data.url;
@ -282,24 +369,56 @@ export const usePlayerStore = defineStore('player', () => {
startTick();
addRecent(song);
vipSkipCount = 0;
emitPlaybackState();
} catch (e) {
console.error('播放失败', e);
playing.value = false;
}
}
let onSeekStart: (() => void) | null = null;
function startTick() {
if (tickInterval) clearInterval(tickInterval);
tickInterval = setInterval(() => {
clearTick();
let seekGuard = false;
onSeekStart = () => { seekGuard = true; };
let syncCounter = 1;
let lastSyncPos = -1;
let backendFrozen = false;
setTick(setInterval(async () => {
if (playing.value && duration.value > 0) {
if (currentTime.value < duration.value) {
currentTime.value += 0.25;
if (currentTime.value > duration.value) {
currentTime.value = duration.value;
if (seekGuard) return;
syncCounter++;
if (syncCounter >= 2) {
syncCounter = 0;
try {
const pos = await invoke<number>('get_audio_position');
if (pos >= currentTime.value - 0.5) {
currentTime.value = pos;
}
if (lastSyncPos < 0) {
lastSyncPos = pos;
} else if (pos <= lastSyncPos + 0.05) {
backendFrozen = true;
lastSyncPos = pos;
} else {
backendFrozen = false;
lastSyncPos = pos;
}
} catch { /* 忽略 */ }
} else {
if (!backendFrozen) {
const next = currentTime.value + 0.25;
if (next <= duration.value) {
currentTime.value = next;
}
}
}
if (currentTime.value > duration.value) {
currentTime.value = duration.value;
}
}
}, 250);
}, 250));
}
async function toggle() {
@ -310,6 +429,7 @@ export const usePlayerStore = defineStore('player', () => {
await invoke('resume_audio');
playing.value = true;
}
emitPlaybackState();
}
async function stop() {
@ -317,8 +437,9 @@ export const usePlayerStore = defineStore('player', () => {
playing.value = false;
currentSong.value = null;
currentTime.value = 0;
if (tickInterval) clearInterval(tickInterval);
clearTick();
disableFmMode();
emitPlaybackState();
}
@ -365,8 +486,11 @@ export const usePlayerStore = defineStore('player', () => {
async function seek(time: number) {
try {
await invoke('seek_audio', { time });
currentTime.value = time;
if (onSeekStart) onSeekStart();
await invoke('seek_audio', { time });
startTick();
emitPlaybackState();
} catch (e) {
console.error('seek 失败', e);
}
@ -376,6 +500,7 @@ export const usePlayerStore = defineStore('player', () => {
const newVol = Math.max(0, Math.min(100, volume.value + delta));
volume.value = newVol;
await invoke('set_volume', { vol: newVol / 100 });
emitPlaybackState();
}
@ -418,6 +543,7 @@ export const usePlayerStore = defineStore('player', () => {
const showRoamDrawer = ref(false);
const roamInitialTab = ref<'lyric' | 'comment'>('lyric');
const commentSongId = ref<number | null>(null);
const dominantColor = ref('');
function openRoamDrawer(tab: 'lyric' | 'comment' = 'lyric') {
roamInitialTab.value = tab;
@ -440,12 +566,11 @@ export const usePlayerStore = defineStore('player', () => {
async function loadFirstFmSong() {
try {
const jsonStr: string = await invoke('personal_fm');
const data = JSON.parse(jsonStr);
const songs = data.data || data;
if (songs && songs.length > 0) {
const song = normalizeSong(songs[0]);
enableFmMode(() => loadFirstFmSong());
const batch = await fetchFmBatch();
if (batch.length > 0) {
fmQueue.push(...batch);
const song = fmQueue.shift()!;
enableFmMode(nextFm);
await playFmSong(song);
return true;
}
@ -455,22 +580,23 @@ export const usePlayerStore = defineStore('player', () => {
return false;
}
// -------- FM 专属状态 --------
const fmSong = ref<any>(null);
const fmSong = ref<Song | null>(null);
const fmPlaying = ref(false);
async function loadFm() {
try {
const jsonStr: string = await invoke('personal_fm');
const data = JSON.parse(jsonStr);
const songs = data.data || data;
if (songs && songs.length > 0) {
const song = normalizeSong(songs[0]);
fmSong.value = song;
enableFmMode(nextFm);
await playFmSong(song);
fmPlaying.value = true;
if (fmQueue.length === 0) {
const batch = await fetchFmBatch();
if (batch.length === 0) return;
fmQueue.push(...batch);
}
const song = fmQueue.shift()!;
fmSong.value = song;
enableFmMode(nextFm);
await playFmSong(song);
fmPlaying.value = true;
if (fmQueue.length <= 1) {
fetchFmBatch().then(batch => { fmQueue.push(...batch); }).catch(() => {});
}
} catch (e) {
console.error('FM加载失败', e);
@ -498,12 +624,60 @@ async function nextFm() {
await loadFm();
}
let _audioStartedResolve: (() => void) | null = null;
listen('audio-started', () => {
if (_audioStartedResolve) {
_audioStartedResolve();
_audioStartedResolve = null;
}
});
listen('audio-ended', () => {
if (tickInterval) { clearInterval(tickInterval); tickInterval = null; }
if (isFmMode.value && fmNextCallback) {
fmNextCallback();
} else {
next();
const player = usePlayerStore();
player.clearTick();
player.reportScrobble();
player.next();
});
listen<string>('mpris-command', (event) => {
const cmd = event.payload;
const player = usePlayerStore();
if (cmd === 'Next') {
player.next();
} else if (cmd === 'Previous') {
player.prev();
} else if (cmd === 'PlayPause') {
player.toggle();
} else if (cmd === 'Play') {
if (!player.playing) player.toggle();
} else if (cmd === 'Pause') {
if (player.playing) player.toggle();
} else if (cmd === 'Stop') {
player.stop();
} else if (cmd.startsWith('SetVolume:')) {
const vol = parseFloat(cmd.slice(10));
if (!isNaN(vol)) {
player.volume = Math.round(vol * 100);
invoke('set_volume', { vol }).catch(() => {});
}
} else if (cmd.startsWith('Seek:')) {
const offsetUs = parseInt(cmd.slice(5), 10);
const offsetSec = offsetUs / 1_000_000;
const newPos = Math.max(0, Math.min(player.currentTime + offsetSec, player.duration));
player.seek(newPos);
} else if (cmd.startsWith('SetPosition:')) {
const posUs = parseInt(cmd.slice(13), 10);
const posSec = posUs / 1_000_000;
if (posSec < 1 && player.currentTime > 5) {
return;
}
player.seek(posSec);
} else if (cmd === 'Raise') {
getCurrentWindow().show().catch(() => {});
getCurrentWindow().setFocus().catch(() => {});
} else if (cmd === 'Quit') {
getCurrentWindow().close().catch(() => {});
}
});
@ -561,14 +735,23 @@ watch(playing, (val) => {
showRoamDrawer,
roamInitialTab,
commentSongId,
dominantColor,
openCommentForSong,
openRoamDrawer,
closeRoamDrawer,
toggleRoamDrawer,
loadFirstFmSong,
fetchFmBatch,
clearFmQueue,
fmTrash,
reportScrobble,
clearTick,
fmSong,
fmPlaying,
fmMode,
fmSubMode,
loadFm,
toggleFm,
nextFm,

View File

@ -1,30 +1,36 @@
import { defineStore } from 'pinia';
import { ref, watch } from 'vue';
import { ref, watch, computed } from 'vue';
export type AudioQuality = 'standard' | 'higher' | 'exhigh' | 'lossless' | 'hires';
export type ThemeName = 'green' | 'rose' | 'blue' | 'violet' | 'orange' | 'cyan' | 'pink';
export type ThemeColor = 'blue' | 'green' | 'rose' | 'violet' | 'orange' | 'cyan' | 'pink';
export type Appearance = 'dark' | 'light';
export type CloseAction = 'ask' | 'minimize' | 'exit';
export const themeLabels: Record<ThemeName, string> = {
export const themeLabels: Record<ThemeColor, string> = {
blue: '天蓝',
green: '翠绿',
rose: '玫红',
blue: '天蓝',
violet: '紫罗兰',
orange: '橙色',
cyan: '青色',
pink: '粉色',
};
export const themeColors: Record<ThemeName, string> = {
export const themeColors: Record<ThemeColor, string> = {
blue: '#3b82f6',
green: '#22c55e',
rose: '#f43f5e',
blue: '#3b82f6',
violet: '#8b5cf6',
orange: '#f97316',
cyan: '#06b6d4',
pink: '#ec4899',
};
export const appearanceLabels: Record<Appearance, string> = {
dark: '深色',
light: '浅色',
};
export const qualityLabels: Record<AudioQuality, string> = {
standard: '标准',
higher: '较高',
@ -50,20 +56,22 @@ export const defaultShortcuts: Record<string, ShortcutBinding> = {
next: { key: 'Control+ArrowRight', label: '下一首' },
volUp: { key: 'Control+ArrowUp', label: '音量增加' },
volDown: { key: 'Control+ArrowDown', label: '音量减小' },
globalPlayPause: { key: 'Alt+Control+KeyP', label: '播放/暂停(全局)' },
globalPrev: { key: 'Alt+Control+ArrowLeft', label: '上一首(全局)' },
globalNext: { key: 'Alt+Control+ArrowRight', label: '下一首(全局)' },
globalVolUp: { key: 'Alt+Control+ArrowUp', label: '音量增加(全局)' },
globalVolDown: { key: 'Alt+Control+ArrowDown', label: '音量减小(全局)' },
globalPlayPause: { key: 'Control+Alt+KeyP', label: '播放/暂停(全局)' },
globalPrev: { key: 'Control+Alt+ArrowLeft', label: '上一首(全局)' },
globalNext: { key: 'Control+Alt+ArrowRight', label: '下一首(全局)' },
globalVolUp: { key: 'Control+Alt+ArrowUp', label: '音量增加(全局)' },
globalVolDown: { key: 'Control+Alt+ArrowDown', label: '音量减小(全局)' },
};
interface SettingsData {
audioQuality: AudioQuality;
downloadPath: string;
theme: ThemeName;
theme: ThemeColor;
appearance: Appearance;
closeAction: CloseAction;
shortcuts: Record<string, ShortcutBinding>;
outputDevice: string | null;
volume: number;
}
function loadSettings(): SettingsData {
@ -71,25 +79,43 @@ function loadSettings(): SettingsData {
const raw = localStorage.getItem('app_settings');
if (raw) {
const parsed = JSON.parse(raw);
const theme = parsed.theme || parsed.accentColor || 'green';
const validThemes: ThemeName[] = ['green', 'rose', 'blue', 'violet', 'orange', 'cyan', 'pink'];
const theme = parsed.theme || parsed.accentColor || 'blue';
const validThemes: ThemeColor[] = ['blue', 'green', 'rose', 'violet', 'orange', 'cyan', 'pink'];
const validAppearances: Appearance[] = ['dark', 'light'];
const appearance = validAppearances.includes(parsed.appearance) ? parsed.appearance : 'dark';
if (parsed.theme && parsed.theme.startsWith('light-')) {
return {
audioQuality: parsed.audioQuality || 'standard',
downloadPath: parsed.downloadPath || '',
theme: validThemes.includes(parsed.theme.slice(6)) ? parsed.theme.slice(6) : 'blue',
appearance: 'light',
closeAction: parsed.closeAction || 'ask',
shortcuts: { ...defaultShortcuts, ...(parsed.shortcuts || {}) },
outputDevice: parsed.outputDevice || null,
volume: typeof parsed.volume === 'number' ? parsed.volume : 100,
};
}
return {
audioQuality: parsed.audioQuality || 'standard',
downloadPath: parsed.downloadPath || '',
theme: validThemes.includes(theme) ? theme : 'green',
theme: validThemes.includes(theme) ? theme : 'blue',
appearance,
closeAction: parsed.closeAction || 'ask',
shortcuts: { ...defaultShortcuts, ...(parsed.shortcuts || {}) },
outputDevice: parsed.outputDevice || null,
volume: typeof parsed.volume === 'number' ? parsed.volume : 100,
};
}
} catch {}
} catch { /* 忽略 */ }
return {
audioQuality: 'standard',
downloadPath: '',
theme: 'green',
theme: 'blue',
appearance: 'dark',
closeAction: 'ask',
shortcuts: { ...defaultShortcuts },
outputDevice: null,
volume: 100,
};
}
@ -98,10 +124,16 @@ export const useSettingsStore = defineStore('settings', () => {
const audioQuality = ref<AudioQuality>(saved.audioQuality);
const downloadPath = ref<string>(saved.downloadPath);
const theme = ref<ThemeName>(saved.theme);
const theme = ref<ThemeColor>(saved.theme);
const appearance = ref<Appearance>(saved.appearance);
const closeAction = ref<CloseAction>(saved.closeAction || 'ask');
const shortcuts = ref<Record<string, ShortcutBinding>>(saved.shortcuts);
const outputDevice = ref<string | null>(saved.outputDevice);
const volume = ref<number>(saved.volume);
const dataTheme = computed(() =>
appearance.value === 'light' ? `light-${theme.value}` : theme.value
);
function setAudioQuality(q: AudioQuality) {
audioQuality.value = q;
@ -111,10 +143,14 @@ export const useSettingsStore = defineStore('settings', () => {
downloadPath.value = p;
}
function setTheme(t: ThemeName) {
function setTheme(t: ThemeColor) {
theme.value = t;
}
function setAppearance(a: Appearance) {
appearance.value = a;
}
function setCloseAction(a: CloseAction) {
closeAction.value = a;
}
@ -134,20 +170,24 @@ export const useSettingsStore = defineStore('settings', () => {
function resetAll() {
audioQuality.value = 'standard';
downloadPath.value = '';
theme.value = 'green';
theme.value = 'blue';
appearance.value = 'dark';
closeAction.value = 'ask';
shortcuts.value = { ...defaultShortcuts };
outputDevice.value = null;
volume.value = 100;
}
watch([audioQuality, downloadPath, theme, closeAction, shortcuts, outputDevice], () => {
watch([audioQuality, downloadPath, theme, appearance, closeAction, shortcuts, outputDevice, volume], () => {
const data: SettingsData = {
audioQuality: audioQuality.value,
downloadPath: downloadPath.value,
theme: theme.value,
appearance: appearance.value,
closeAction: closeAction.value,
shortcuts: shortcuts.value,
outputDevice: outputDevice.value,
volume: volume.value,
};
localStorage.setItem('app_settings', JSON.stringify(data));
}, { deep: true });
@ -156,12 +196,16 @@ export const useSettingsStore = defineStore('settings', () => {
audioQuality,
downloadPath,
theme,
appearance,
dataTheme,
closeAction,
shortcuts,
outputDevice,
volume,
setAudioQuality,
setDownloadPath,
setTheme,
setAppearance,
setCloseAction,
setOutputDevice,
setShortcut,

View File

@ -21,7 +21,7 @@ export const useUserStore = defineStore('user', () => {
}
async function logout() {
try { await invoke('logout'); } catch {}
try { await invoke('logout'); } catch { /* 忽略 */ }
user.value = null;
isLoggedIn.value = false;
localStorage.removeItem('user_profile');

View File

@ -178,6 +178,160 @@
--c-info: #3b82f6;
}
[data-theme="light-green"] {
--c-bg: #f8faf9;
--c-surface: #ffffff;
--c-subtle: rgba(34, 197, 94, 0.06);
--c-muted: rgba(34, 197, 94, 0.10);
--c-emphasis: rgba(34, 197, 94, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #16a34a;
--c-accent-hover: #15803d;
--c-accent-text: #15803d;
--c-accent-dim: rgba(34, 197, 94, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
[data-theme="light-rose"] {
--c-bg: #faf8f9;
--c-surface: #ffffff;
--c-subtle: rgba(244, 63, 94, 0.06);
--c-muted: rgba(244, 63, 94, 0.10);
--c-emphasis: rgba(244, 63, 94, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #e11d48;
--c-accent-hover: #be123c;
--c-accent-text: #be123c;
--c-accent-dim: rgba(244, 63, 94, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
[data-theme="light-blue"] {
--c-bg: #f8f9fb;
--c-surface: #ffffff;
--c-subtle: rgba(59, 130, 246, 0.06);
--c-muted: rgba(59, 130, 246, 0.10);
--c-emphasis: rgba(59, 130, 246, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #2563eb;
--c-accent-hover: #1d4ed8;
--c-accent-text: #1d4ed8;
--c-accent-dim: rgba(59, 130, 246, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #7c3aed;
}
[data-theme="light-violet"] {
--c-bg: #f9f8fb;
--c-surface: #ffffff;
--c-subtle: rgba(139, 92, 246, 0.06);
--c-muted: rgba(139, 92, 246, 0.10);
--c-emphasis: rgba(139, 92, 246, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #7c3aed;
--c-accent-hover: #6d28d9;
--c-accent-text: #6d28d9;
--c-accent-dim: rgba(139, 92, 246, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
[data-theme="light-orange"] {
--c-bg: #faf9f8;
--c-surface: #ffffff;
--c-subtle: rgba(249, 115, 22, 0.06);
--c-muted: rgba(249, 115, 22, 0.10);
--c-emphasis: rgba(249, 115, 22, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #ea580c;
--c-accent-hover: #c2410c;
--c-accent-text: #c2410c;
--c-accent-dim: rgba(249, 115, 22, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
[data-theme="light-cyan"] {
--c-bg: #f8fbfb;
--c-surface: #ffffff;
--c-subtle: rgba(6, 182, 212, 0.06);
--c-muted: rgba(6, 182, 212, 0.10);
--c-emphasis: rgba(6, 182, 212, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #0891b2;
--c-accent-hover: #0e7490;
--c-accent-text: #0e7490;
--c-accent-dim: rgba(6, 182, 212, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
[data-theme="light-pink"] {
--c-bg: #faf8f9;
--c-surface: #ffffff;
--c-subtle: rgba(236, 72, 153, 0.06);
--c-muted: rgba(236, 72, 153, 0.10);
--c-emphasis: rgba(236, 72, 153, 0.16);
--c-content: #111827;
--c-content-2: #4b5563;
--c-content-3: #6b7280;
--c-content-4: #9ca3af;
--c-line: rgba(0, 0, 0, 0.08);
--c-line-2: rgba(0, 0, 0, 0.04);
--c-accent: #db2777;
--c-accent-hover: #be185d;
--c-accent-text: #be185d;
--c-accent-dim: rgba(236, 72, 153, 0.15);
--c-danger: #dc2626;
--c-danger-dim: rgba(220, 38, 38, 0.12);
--c-warning: #ca8a04;
--c-info: #2563eb;
}
html {
background: var(--c-bg);
overflow: hidden;
@ -195,6 +349,13 @@
overflow: hidden;
overscroll-behavior: none;
touch-action: none;
user-select: none;
-webkit-user-select: none;
}
input, textarea, [contenteditable="true"] {
user-select: text;
-webkit-user-select: text;
}
::-webkit-scrollbar {

View File

@ -12,9 +12,18 @@ export function formatTime(sec: number): string {
return `${m}:${s.toString().padStart(2, '0')}`;
}
const YI = 100_000_000;
const WAN = 10_000;
export function formatPlayCount(count: number): string {
if (!count) return '0';
if (count >= 100000000) return (count / 100000000).toFixed(1) + '亿';
if (count >= 10000) return (count / 10000).toFixed(1) + '万';
if (count >= YI) return (count / YI).toFixed(1) + '亿';
if (count >= WAN) return (count / WAN).toFixed(1) + '万';
return count.toString();
}
export function formatDate(ts: number): string {
if (!ts) return '';
const d = new Date(ts);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}

View File

@ -1,22 +1,79 @@
/**
* 统一规范化歌曲对象,确保 al.picUrl、ar、dt 字段存在且合理
*/
export function normalizeSong(song: any) {
const normalized = { ...song };
if (!normalized.al?.picUrl && normalized.album?.picUrl) {
normalized.al = { ...normalized.al, picUrl: normalized.album.picUrl };
export interface Song {
id: number;
name: string;
ar: { id?: number; name: string }[];
al: { id?: number; picUrl: string; name?: string };
dt?: number;
localPath?: string;
}
export function normalizeSong(song: any): Song {
const al = {
id: song.al?.id || song.album?.id,
picUrl: song.al?.picUrl || song.album?.picUrl || '',
name: song.al?.name || song.album?.name,
};
const ar = (song.ar && song.ar.length > 0) ? song.ar : (song.artists || []);
let dt = song.dt || song.duration || 0;
if (dt < 100 || dt > 7200000) dt = 0;
return {
id: song.id,
name: song.name,
ar,
al,
dt,
localPath: song.localPath,
};
}
export function getCoverUrl(song: Song | null, sizeParam = ''): string {
if (!song) return '';
const raw = song.al?.picUrl || '';
if (!raw) return '';
if (!sizeParam || raw.startsWith('data:')) return raw;
return raw + sizeParam;
}
const colorCache = new Map<string, string>();
export function extractDominantColor(imageUrl: string): Promise<string> {
if (colorCache.has(imageUrl)) {
return Promise.resolve(colorCache.get(imageUrl)!);
}
if (!normalized.al?.name && normalized.album?.name) {
normalized.al = { ...normalized.al, name: normalized.album.name };
}
if (!normalized.al?.id && normalized.album?.id) {
normalized.al = { ...normalized.al, id: normalized.album.id };
}
if (!normalized.ar || normalized.ar.length === 0) {
normalized.ar = normalized.artists || [];
}
if (!normalized.dt || normalized.dt < 100 || normalized.dt > 7200000) {
normalized.dt = 0;
}
return normalized;
}
return new Promise((resolve) => {
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
try {
const canvas = document.createElement('canvas');
const size = 8;
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext('2d');
if (!ctx) { resolve(''); return; }
ctx.drawImage(img, 0, 0, size, size);
const data = ctx.getImageData(0, 0, size, size).data;
let r = 0, g = 0, b = 0, count = 0;
for (let i = 0; i < data.length; i += 4) {
r += data[i];
g += data[i + 1];
b += data[i + 2];
count++;
}
r = Math.round(r / count);
g = Math.round(g / count);
b = Math.round(b / count);
const color = `rgb(${r}, ${g}, ${b})`;
colorCache.set(imageUrl, color);
resolve(color);
} catch {
resolve('');
}
};
img.onerror = () => resolve('');
img.src = imageUrl;
});
}

View File

@ -9,11 +9,11 @@
<div class="flex flex-col justify-between min-w-0">
<div>
<h1 class="text-2xl font-bold leading-tight">{{ album.name }}</h1>
<div v-if="album.artists?.length" class="flex items-center gap-1 mt-2 text-sm text-content-2">
<div v-if="album.artists?.length" class="flex flex-wrap items-center gap-x-1 gap-y-0.5 mt-2 text-sm text-content-2">
<template v-for="(ar, idx) in album.artists" :key="ar.id">
<span v-if="idx > 0" class="text-content-3">/</span>
<span v-if="(idx as number) > 0" class="text-content-3">/</span>
<span
class="hover:text-accent-text cursor-pointer transition"
class="hover:text-accent-text cursor-pointer transition whitespace-nowrap"
@click="ar.id && router.push({ name: 'artist', params: { id: ar.id } })"
>{{ ar.name }}</span>
</template>
@ -27,7 +27,7 @@
@click="playAll"
class="px-5 py-2 bg-accent hover:bg-accent-hover rounded-full text-white font-medium transition flex items-center gap-2"
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
<IconPlay class="w-4 h-4 fill-current" />
播放全部
</button>
</div>
@ -37,52 +37,21 @@
<div v-if="loading" class="text-content-2">加载中...</div>
<div v-else class="space-y-1">
<div
<SongListItem
v-for="(song, index) in songs"
:key="song.id"
@click="playSingle(song)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer group"
:class="{ 'bg-accent-dim': isCurrentSong(song.id) }"
>
<div class="w-6 text-right flex-shrink-0 flex items-center justify-end h-5">
<div v-if="isCurrentSong(song.id)" class="flex items-center justify-end">
<div class="flex items-center gap-[3px] h-4">
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 50%; animation-delay: 0ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 100%; animation-delay: 150ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 35%; animation-delay: 300ms"></span>
</div>
</div>
<template v-else>
<span class="text-xs text-content-3 group-hover:hidden">{{ index + 1 }}</span>
<svg class="hidden group-hover:block text-content" width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
</template>
</div>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover flex-shrink-0" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate" :class="isCurrentSong(song.id) ? 'text-accent-text' : ''">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt) }}</span>
</div>
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(songs, index)"
/>
</div>
</div>
</template>
@ -92,25 +61,19 @@ import { ref, onMounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatDuration } from '../utils/format';
import SongItemMenu from '../components/SongItemMenu.vue';
import { normalizeSong, type Song } from '../utils/song';
import { formatDate } from '../utils/format';
import SongListItem from '../components/SongListItem.vue';
import IconPlay from '~icons/lucide/play';
const route = useRoute();
const router = useRouter();
const player = usePlayerStore();
const download = useDownload();
const album = ref<any>(null);
const songs = ref<any[]>([]);
const songs = ref<Song[]>([]);
const loading = ref(true);
function formatDate(ts: number): string {
if (!ts) return '';
const d = new Date(ts);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
async function fetchAlbum(id: number) {
loading.value = true;
album.value = null;
@ -118,13 +81,8 @@ async function fetchAlbum(id: number) {
try {
const jsonStr: string = await invoke('album_detail', { id });
const data = JSON.parse(jsonStr);
const a = data.album;
if (a) {
delete a.uid;
if (a.artists) a.artists.forEach((ar: any) => delete ar.uid);
}
album.value = a;
songs.value = data.songs || [];
album.value = data.album;
songs.value = (data.songs || []).map(normalizeSong);
} catch (e) {
console.error(e);
} finally {
@ -140,15 +98,6 @@ watch(() => route.params.id, (newId) => {
if (newId) fetchAlbum(Number(newId));
});
function isCurrentSong(songId: number): boolean {
return player.currentSong?.id === songId;
}
async function playSingle(song: any) {
const idx = songs.value.findIndex((s: any) => s.id === song.id);
player.playFromList(songs.value, idx >= 0 ? idx : 0);
}
function playAll() {
if (songs.value.length === 0) return;
player.playAll(songs.value);

View File

@ -18,7 +18,7 @@
@click="playAll"
class="px-5 py-2 bg-accent hover:bg-accent-hover rounded-full text-white font-medium transition flex items-center gap-2"
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
<IconPlay class="w-4 h-4 fill-current" />
播放全部
</button>
</div>
@ -41,52 +41,21 @@
<template v-else>
<div v-if="activeTab === 'songs'" class="space-y-1">
<div
<SongListItem
v-for="(song, index) in songs"
:key="song.id"
@click="playSingle(song)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer group"
:class="{ 'bg-accent-dim': isCurrentSong(song.id) }"
>
<div class="w-6 text-right flex-shrink-0 flex items-center justify-end h-5">
<div v-if="isCurrentSong(song.id)" class="flex items-center justify-end">
<div class="flex items-center gap-[3px] h-4">
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 50%; animation-delay: 0ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 100%; animation-delay: 150ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 35%; animation-delay: 300ms"></span>
</div>
</div>
<template v-else>
<span class="text-xs text-content-3 group-hover:hidden">{{ index + 1 }}</span>
<svg class="hidden group-hover:block text-content" width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
</template>
</div>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover flex-shrink-0" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate" :class="isCurrentSong(song.id) ? 'text-accent-text' : ''">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt) }}</span>
</div>
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(songs, index)"
/>
</div>
<div v-if="activeTab === 'albums'" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
@ -99,7 +68,7 @@
<img :src="album.picUrl" class="w-full aspect-square object-cover" />
<div class="p-3">
<p class="text-sm font-medium truncate">{{ album.name }}</p>
<p class="text-xs text-content-2 mt-1">{{ formatAlbumDate(album.publishTime) }}</p>
<p class="text-xs text-content-2 mt-1">{{ formatDate(album.publishTime) }}</p>
</div>
</div>
</div>
@ -116,17 +85,17 @@ import { ref, onMounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatDuration, formatPlayCount } from '../utils/format';
import SongItemMenu from '../components/SongItemMenu.vue';
import { formatPlayCount, formatDate } from '../utils/format';
import { normalizeSong, type Song } from '../utils/song';
import SongListItem from '../components/SongListItem.vue';
import IconPlay from '~icons/lucide/play';
const route = useRoute();
const router = useRouter();
const player = usePlayerStore();
const download = useDownload();
const artist = ref<any>(null);
const songs = ref<any[]>([]);
const songs = ref<Song[]>([]);
const albums = ref<any[]>([]);
const briefDesc = ref('');
const loading = ref(true);
@ -154,15 +123,9 @@ async function fetchArtist(id: number) {
const detailData = JSON.parse(detailStr);
artist.value = detailData.artist;
const songsData = JSON.parse(songsStr);
songs.value = songsData.songs || [];
songs.value = (songsData.songs || []).map(normalizeSong);
const albumData = JSON.parse(albumStr);
const rawAlbums = albumData.hotAlbums || [];
rawAlbums.forEach((a: any) => {
delete a.uid;
if (a.artist) delete a.artist.uid;
if (a.artists) a.artists.forEach((ar: any) => delete ar.uid);
});
albums.value = rawAlbums;
albums.value = albumData.hotAlbums || [];
const descData = JSON.parse(descStr);
briefDesc.value = descData.briefDesc || '';
} catch (e) {
@ -180,21 +143,6 @@ watch(() => route.params.id, (newId) => {
if (newId) fetchArtist(Number(newId));
});
function formatAlbumDate(ts: number): string {
if (!ts) return '';
const d = new Date(ts);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
}
function isCurrentSong(songId: number): boolean {
return player.currentSong?.id === songId;
}
async function playSingle(song: any) {
const idx = songs.value.findIndex((s: any) => s.id === song.id);
player.playFromList(songs.value, idx >= 0 ? idx : 0);
}
function playAll() {
if (songs.value.length === 0) return;
player.playAll(songs.value);

View File

@ -15,84 +15,75 @@
</div>
<div v-if="loading" class="text-content-2">加载中...</div>
<div v-else class="space-y-2">
<div
<SongListItem
v-for="(song, index) in songs"
:key="song.id"
:song="song"
:index="index"
:is-current="isCurrentSong(song.id)"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="isCurrentSong(song.id) ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(songs, index)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer group"
:class="{ 'bg-accent-dim': isCurrentSong(song.id) }"
>
<div class="w-6 text-right flex-shrink-0 flex items-center justify-end h-5">
<div v-if="isCurrentSong(song.id)" class="flex items-center justify-end">
<div class="flex items-center gap-[3px] h-4">
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 50%; animation-delay: 0ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 100%; animation-delay: 150ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 35%; animation-delay: 300ms"></span>
</div>
</div>
<template v-else>
<span class="text-xs text-content-3 group-hover:hidden">{{ index + 1 }}</span>
<svg class="hidden group-hover:block text-content" width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
</template>
</div>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover flex-shrink-0" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate" :class="isCurrentSong(song.id) ? 'text-accent-text' : ''">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt) }}</span>
</div>
/>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ref, onMounted, onActivated, watch } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import SongItemMenu from '../components/SongItemMenu.vue';
import SongListItem from '../components/SongListItem.vue';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatDuration } from '../utils/format';
import { pageCacheGet, pageCacheSet, pageCacheInvalidate, pageCacheIsStale } from '../composables/usePageCache';
import { normalizeSong, type Song } from '../utils/song';
import { useOnlineStatus } from '../composables/useOnlineStatus';
defineOptions({ name: 'DailySongsView' });
const player = usePlayerStore();
const download = useDownload();
const router = useRouter();
const songs = ref<any[]>([]);
const { isOnline } = useOnlineStatus();
const songs = ref<Song[]>([]);
const loading = ref(true);
function isCurrentSong(songId: number): boolean {
return player.currentSong?.id === songId;
}
onMounted(async () => {
async function loadData() {
const cached = pageCacheGet('dailySongs');
if (cached) {
songs.value = cached;
loading.value = false;
return;
}
loading.value = true;
try {
const jsonStr: string = await invoke('recommend_songs');
const data = JSON.parse(jsonStr);
songs.value = data.data?.dailySongs || [];
songs.value = (data.data?.dailySongs || []).map(normalizeSong);
pageCacheSet('dailySongs', songs.value);
} catch (e) {
console.error(e);
} finally {
loading.value = false;
}
}
onMounted(loadData);
onActivated(() => {
if (pageCacheIsStale('dailySongs')) loadData();
});
watch(isOnline, (val, old) => {
if (val && !old && songs.value.length === 0) {
pageCacheInvalidate('dailySongs');
loadData();
}
});
</script>

View File

@ -1,16 +1,56 @@
<template>
<div class="p-8 text-content">
<h1 class="text-2xl font-bold mb-4">发现音乐</h1>
<div class="p-8 text-content" @click="showSuggestions = false">
<div class="relative mb-6" @click.stop>
<div class="flex items-center gap-3">
<div class="relative flex-1">
<IconSearch class="absolute left-3.5 top-1/2 -translate-y-1/2 text-content-3 w-[18px] h-[18px]" />
<input
ref="searchInput"
v-model="keyword"
@input="onInputChange"
@keydown.enter="handleSearch"
@focus="onInputFocus"
placeholder="搜索歌曲、歌手、专辑..."
class="w-full rounded-xl bg-muted pl-10 pr-10 py-3 text-content placeholder-content-3 outline-none focus:bg-subtle focus:ring-1 focus:ring-accent/30 transition"
/>
<button v-if="keyword" @click="clearSearch" class="absolute right-3 top-1/2 -translate-y-1/2 text-content-3 hover:text-content transition">
<IconX class="w-4 h-4" />
</button>
</div>
</div>
<!-- 搜索框 -->
<input
v-model="keyword"
@keyup.enter="handleSearch"
placeholder="搜索歌曲、歌手、专辑..."
class="mb-4 w-full rounded-xl bg-muted p-3 text-content placeholder-content-2 outline-none backdrop-blur"
/>
<div v-if="showSuggestions && !hasSearched"
class="absolute z-30 left-0 right-0 top-full mt-2 bg-surface border border-line-2 rounded-xl shadow-xl overflow-hidden max-h-[60vh] overflow-y-auto">
<div v-if="suggestions.length" class="p-2">
<p class="text-xs text-content-3 px-3 py-1.5">搜索建议</p>
<button v-for="s in suggestions" :key="s" @click="searchTag(s)"
class="w-full text-left px-3 py-2 rounded-lg text-sm hover:bg-muted transition flex items-center gap-2">
<IconSearch style="font-size: 14px" class="text-content-3 flex-shrink-0" />
<span>{{ s }}</span>
</button>
</div>
<div v-if="searchHistory.length && !suggestions.length" class="p-2">
<div class="flex items-center justify-between px-3 py-1.5">
<p class="text-xs text-content-3">搜索历史</p>
<button @click.stop="clearHistory" class="text-xs text-content-3 hover:text-danger transition">清空</button>
</div>
<button v-for="h in searchHistory" :key="h" @click="searchTag(h)"
class="w-full text-left px-3 py-2 rounded-lg text-sm hover:bg-muted transition flex items-center gap-2">
<IconHistory style="font-size: 14px" class="text-content-3 flex-shrink-0" />
<span>{{ h }}</span>
</button>
</div>
<div v-if="hotTags.length && !suggestions.length && !searchHistory.length" class="p-2">
<p class="text-xs text-content-3 px-3 py-1.5">热门搜索</p>
<button v-for="tag in hotTags" :key="tag.searchWord" @click="searchTag(tag.searchWord)"
class="w-full text-left px-3 py-2 rounded-lg text-sm hover:bg-muted transition flex items-center gap-2">
<IconClock style="font-size: 14px" class="text-content-3 flex-shrink-0" />
<span>{{ tag.searchWord }}</span>
</button>
</div>
</div>
</div>
<!-- 热门搜索标签仅在没有搜索且未显示结果时出现 -->
<div v-if="!hasSearched && !loading && hotTags.length" class="mb-6">
<h2 class="text-sm font-semibold mb-3">🔥 热门搜索</h2>
<div class="flex flex-wrap gap-2">
@ -18,53 +58,84 @@
v-for="tag in hotTags"
:key="tag.searchWord"
@click="searchTag(tag.searchWord)"
class="px-3 py-1 rounded-full bg-muted hover:bg-emphasis cursor-pointer transition text-sm"
class="px-3 py-1.5 rounded-full bg-muted hover:bg-emphasis cursor-pointer transition text-sm"
>
{{ tag.searchWord }}
</span>
</div>
</div>
<!-- 输出设备选择 -->
<!-- <div class="mb-4">
<label class="mr-2 text-sm text-content-2">输出设备</label>
<select v-model="selectedDevice" @change="changeDevice" class="bg-muted text-white rounded p-1 text-sm">
<option :value="null">跟随系统默认</option>
<option v-for="dev in devices" :key="dev" :value="dev">{{ dev }}</option>
</select>
</div> -->
<!-- 搜索结果 -->
<div v-if="loading" class="text-content-2">搜索中...</div>
<div v-else class="space-y-3">
<div
v-for="(song, index) in results"
:key="song.id"
@click="playSong(song, index)"
class="flex items-center gap-4 p-3 rounded-xl backdrop-blur-md bg-subtle hover:bg-muted border border-line-2 cursor-pointer transition"
>
<img :src="song.al?.picUrl" class="w-12 h-12 rounded-lg object-cover" />
<div class="flex-1 min-w-0">
<p class="font-medium truncate">{{ song.name }}</p>
<p class="text-sm text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<div v-if="hasSearched">
<div class="flex items-center gap-1 mb-4 bg-muted rounded-lg p-1 w-fit">
<button v-for="tab in tabs" :key="tab.type" @click="switchTab(tab.type)"
:class="['px-4 py-1.5 rounded-md text-sm font-medium transition', activeTab === tab.type ? 'bg-surface text-content shadow-sm' : 'text-content-2 hover:text-content']">
{{ tab.label }}
<span v-if="resultCache.has(tab.type) && resultCache.get(tab.type)!.count > 0" class="text-xs text-content-3 ml-1">{{ resultCache.get(tab.type)!.count }}</span>
</button>
<SongItemMenu :song-id="song.id" />
</div>
<p v-if="!loading && hasSearched && results.length === 0" class="text-content-2">无结果</p>
<div v-if="loading" class="flex items-center justify-center py-12">
<div class="flex items-end gap-1 h-6">
<span class="eq-bar w-[3px] bg-accent rounded-full" style="animation-delay: 0s"></span>
<span class="eq-bar w-[3px] bg-accent rounded-full" style="animation-delay: 0.12s"></span>
<span class="eq-bar w-[3px] bg-accent rounded-full" style="animation-delay: 0.24s"></span>
</div>
</div>
<template v-else>
<div v-if="activeTab === 1">
<div v-if="currentResults.length" class="space-y-2">
<SongListItem
v-for="(song, index) in currentResults"
:key="song.id"
:song="song"
:index="index"
show-download
show-menu
cover-size="w-12 h-12"
container-class="bg-subtle hover:bg-muted border border-line-2"
@click="player.playFromList(currentResults, index)"
/>
</div>
<p v-else class="text-content-2 text-center py-8">{{ cacheError ? '搜索失败,点击其他标签页刷新重试' : '未找到相关歌曲' }}</p>
</div>
<div v-else-if="activeTab === 100">
<div v-if="currentResults.length" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<div v-for="artist in currentResults" :key="artist.id" @click="router.push({ name: 'artist', params: { id: artist.id } })"
class="bg-subtle hover:bg-muted border border-line-2 rounded-xl p-4 cursor-pointer transition flex items-center gap-3">
<img v-if="artist.picUrl" :src="artist.picUrl + '?param=100y100'" class="w-14 h-14 rounded-full object-cover flex-shrink-0" />
<div v-else class="w-14 h-14 rounded-full bg-muted flex items-center justify-center flex-shrink-0">
<IconUserRound class="w-5 h-5 text-content-3" />
</div>
<div class="min-w-0">
<p class="text-sm font-medium truncate">{{ artist.name }}</p>
<p v-if="artist.alias?.length" class="text-xs text-content-3 truncate">{{ artist.alias[0] }}</p>
<p v-if="artist.musicSize" class="text-xs text-content-3">{{ artist.musicSize }} 首歌曲</p>
</div>
</div>
</div>
<p v-else class="text-content-2 text-center py-8">{{ cacheError ? '搜索失败,点击其他标签页刷新重试' : '未找到相关歌手' }}</p>
</div>
<div v-else-if="activeTab === 10">
<div v-if="currentResults.length" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4">
<div v-for="album in currentResults" :key="album.id" @click="router.push({ name: 'album', params: { id: album.id } })"
class="bg-subtle hover:bg-muted border border-line-2 rounded-xl overflow-hidden cursor-pointer transition">
<img v-if="album.picUrl" :src="album.picUrl + '?param=200y200'" class="w-full aspect-square object-cover" />
<div v-else class="w-full aspect-square bg-muted flex items-center justify-center">
<IconDisc class="w-8 h-8 text-content-3" />
</div>
<div class="p-3">
<p class="text-sm font-medium truncate">{{ album.name }}</p>
<p class="text-xs text-content-2 truncate mt-0.5">{{ album.artist?.name || '' }}</p>
<p v-if="album.publishTime" class="text-xs text-content-3 mt-0.5">{{ formatDate(album.publishTime) }}</p>
</div>
</div>
</div>
<p v-else class="text-content-2 text-center py-8">{{ cacheError ? '搜索失败,点击其他标签页刷新重试' : '未找到相关专辑' }}</p>
</div>
</template>
</div>
</div>
</template>
@ -72,38 +143,127 @@
<script setup lang="ts">
defineOptions({ name: 'DiscoverView' });
import { ref, onMounted } from 'vue';
import { ref, computed, onMounted, onActivated, watch, nextTick } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import SongItemMenu from '../components/SongItemMenu.vue';
import SongListItem from '../components/SongListItem.vue';
import { normalizeSong, type Song } from '../utils/song';
import { formatDate } from '../utils/format';
import { pageCacheGet, pageCacheSet, pageCacheInvalidate, pageCacheIsStale } from '../composables/usePageCache';
import { useOnlineStatus } from '../composables/useOnlineStatus';
import IconSearch from '~icons/lucide/search';
import IconX from '~icons/lucide/x';
import IconHistory from '~icons/lucide/history';
import IconClock from '~icons/lucide/clock';
import IconUserRound from '~icons/lucide/user-round';
import IconDisc from '~icons/lucide/disc';
const router = useRouter();
const route = useRoute();
const player = usePlayerStore();
const download = useDownload();
const { isOnline } = useOnlineStatus();
const searchInput = ref<HTMLInputElement | null>(null);
const keyword = ref('');
const results = ref<any[]>([]);
const loading = ref(false);
const hasSearched = ref(false);
const hotTags = ref<any[]>([]);
const suggestions = ref<string[]>([]);
const showSuggestions = ref(false);
const activeTab = ref(1);
const cacheError = ref(false);
const devices = ref<string[]>([]);
interface CacheEntry {
data: Song[] | any[];
count: number;
dirty: boolean;
}
const resultCache = ref<Map<number, CacheEntry>>(new Map());
const lastSearchKeyword = ref('');
const currentResults = computed(() => {
const entry = resultCache.value.get(activeTab.value);
return entry ? entry.data : [];
});
const tabs = [
{ type: 1, label: '歌曲' },
{ type: 100, label: '歌手' },
{ type: 10, label: '专辑' },
];
const HISTORY_KEY = 'search_history';
const MAX_HISTORY = 15;
function loadSearchHistory(): string[] {
try {
const raw = localStorage.getItem(HISTORY_KEY);
if (raw) return JSON.parse(raw);
} catch { /* 忽略 */ }
return [];
}
function saveSearchHistory(q: string) {
let history = loadSearchHistory();
history = history.filter(h => h !== q);
history.unshift(q);
if (history.length > MAX_HISTORY) history = history.slice(0, MAX_HISTORY);
localStorage.setItem(HISTORY_KEY, JSON.stringify(history));
}
const searchHistory = ref<string[]>(loadSearchHistory());
function clearHistory() {
searchHistory.value = [];
localStorage.removeItem(HISTORY_KEY);
}
let suggestTimer: ReturnType<typeof setTimeout> | null = null;
function onInputChange() {
if (suggestTimer) clearTimeout(suggestTimer);
if (!keyword.value.trim()) {
suggestions.value = [];
showSuggestions.value = true;
return;
}
suggestTimer = setTimeout(async () => {
try {
const jsonStr: string = await invoke('search_suggest', { query: { keyword: keyword.value.trim() } });
const data = JSON.parse(jsonStr);
const all = data.result?.allMatch || [];
suggestions.value = all.map((m: any) => m.keyword).slice(0, 8);
showSuggestions.value = true;
} catch {
suggestions.value = [];
}
}, 300);
}
function onInputFocus() {
if (!hasSearched.value) {
showSuggestions.value = true;
}
}
async function loadHotTags() {
const cached = pageCacheGet('discover_hotTags');
if (cached) {
hotTags.value = cached;
} else {
try {
const json = await invoke('get_hot_search');
const data = JSON.parse(json as string);
hotTags.value = (data.data || []).slice(0, 12);
pageCacheSet('discover_hotTags', hotTags.value);
} catch { /* 忽略 */ }
}
}
onMounted(async () => {
// 获取输出设备列表
try { devices.value = await invoke('get_output_devices'); } catch {}
// 获取热门搜索
try {
const json = await invoke('get_hot_search');
const data = JSON.parse(json as string);
hotTags.value = (data.data || []).slice(0, 12);
} catch {}
// 检查路由是否有查询关键词,自动搜索
await loadHotTags();
const q = route.query.q as string;
if (q) {
keyword.value = q;
@ -112,35 +272,99 @@ onMounted(async () => {
}
});
onActivated(async () => {
if (pageCacheIsStale('discover_hotTags')) loadHotTags();
const q = route.query.q as string;
if (q && q !== lastSearchKeyword.value) {
keyword.value = q;
await handleSearch();
router.replace({ query: {} });
}
});
watch(isOnline, (val, old) => {
if (val && !old && hotTags.value.length === 0) {
pageCacheInvalidate('discover_hotTags');
loadHotTags();
}
});
async function handleSearch() {
if (!keyword.value.trim()) return;
loading.value = true;
const q = keyword.value.trim();
if (!q) return;
showSuggestions.value = false;
hasSearched.value = true;
cacheError.value = false;
saveSearchHistory(q);
searchHistory.value = loadSearchHistory();
if (q === lastSearchKeyword.value && resultCache.value.size > 0) return;
lastSearchKeyword.value = q;
resultCache.value.clear();
await Promise.all([
fetchTabResults(1),
fetchTabResults(100),
fetchTabResults(10),
]);
}
async function fetchTabResults(type: number) {
const entry = resultCache.value.get(type);
if (entry && !entry.dirty) return;
loading.value = true;
cacheError.value = false;
try {
const jsonStr: string = await invoke('search_songs', { query: { keyword: keyword.value } });
const jsonStr: string = await invoke('cloudsearch', {
query: { keyword: lastSearchKeyword.value, searchType: type, limit: 30 }
});
const data = JSON.parse(jsonStr);
results.value = data.result?.songs || [];
const result = data.result || {};
let items: any[] = [];
if (type === 1) {
items = (result.songs || []).map(normalizeSong);
} else if (type === 100) {
items = result.artists || [];
} else if (type === 10) {
items = result.albums || [];
}
resultCache.value.set(type, { data: items, count: items.length, dirty: false });
} catch (e) {
console.error('搜索出错:', e);
resultCache.value.set(type, { data: [], count: 0, dirty: true });
cacheError.value = true;
} finally {
loading.value = false;
}
}
async function switchTab(type: number) {
if (type === activeTab.value) return;
activeTab.value = type;
const entry = resultCache.value.get(type);
if (!entry || entry.dirty) {
await fetchTabResults(type);
}
}
function searchTag(tag: string) {
keyword.value = tag;
handleSearch();
}
async function playSong(_song: any, index: number) {
const normalized = results.value.map((s: any) => ({
id: s.id,
name: s.name,
ar: s.ar || s.artists || [],
al: s.al || s.album || { picUrl: '' },
dt: s.dt || 0,
}));
player.playFromList(normalized, index);
function clearSearch() {
keyword.value = '';
hasSearched.value = false;
resultCache.value.clear();
lastSearchKeyword.value = '';
cacheError.value = false;
suggestions.value = [];
showSuggestions.value = true;
nextTick(() => searchInput.value?.focus());
}
</script>

View File

@ -3,13 +3,14 @@
<button @click="$router.back()" class="mb-4 text-content-2 hover:text-content transition">
返回
</button>
<div class="flex items-center gap-4 mb-6">
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold">我喜欢的音乐</h1>
<button
v-if="songs.length"
@click="player.playAll(songs)"
class="px-4 py-1.5 bg-muted hover:bg-emphasis rounded-full text-sm transition"
class="px-5 py-2 bg-accent hover:bg-accent-hover rounded-full text-white font-medium transition flex items-center gap-2"
>
<IconPlay class="w-4 h-4 fill-current" />
播放全部
</button>
</div>
@ -18,67 +19,57 @@
</div>
<div v-else-if="loading" class="text-content-2">加载中...</div>
<div v-else-if="songs.length === 0" class="text-content-2">暂无喜欢的音乐</div>
<div v-else class="space-y-2">
<div
<div v-else class="space-y-1">
<SongListItem
v-for="(song, index) in songs"
:key="song.id"
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(songs, index)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer"
>
<span class="text-xs text-content-3 w-6 text-right">{{ index + 1 }}</span>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt) }}</span>
</div>
/>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ref, onMounted, onActivated, watch } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import SongItemMenu from '../components/SongItemMenu.vue';
import SongListItem from '../components/SongListItem.vue';
import { usePlayerStore } from '../stores/player';
import { useUserStore } from '../stores/user';
import { useDownload } from '../composables/useDownload';
import { normalizeSong } from '../utils/song';
import { formatDuration } from '../utils/format';
import { normalizeSong, type Song } from '../utils/song';
import { pageCacheGet, pageCacheSet, pageCacheInvalidate, pageCacheIsStale } from '../composables/usePageCache';
import { useOnlineStatus } from '../composables/useOnlineStatus';
import IconPlay from '~icons/lucide/play';
defineOptions({ name: 'FavoriteSongsView' });
const player = usePlayerStore();
const userStore = useUserStore();
const download = useDownload();
const router = useRouter();
const songs = ref<any[]>([]);
const { isOnline } = useOnlineStatus();
const songs = ref<Song[]>([]);
const loading = ref(true);
onMounted(async () => {
async function loadData() {
if (!userStore.isLoggedIn) {
loading.value = false;
return;
}
const cached = pageCacheGet('favoriteSongs');
if (cached) {
songs.value = cached;
loading.value = false;
return;
}
loading.value = true;
try {
const playlistJson: string = await invoke('user_playlist', { uid: userStore.user!.userId });
const playlistData = JSON.parse(playlistJson);
@ -91,10 +82,24 @@ onMounted(async () => {
const trackJson: string = await invoke('playlist_track_all', { query: { id: likePlaylistId } });
const trackData = JSON.parse(trackJson);
songs.value = (trackData.songs || []).map(normalizeSong);
pageCacheSet('favoriteSongs', songs.value);
} catch (e) {
console.error(e);
} finally {
loading.value = false;
}
}
onMounted(loadData);
onActivated(() => {
if (pageCacheIsStale('favoriteSongs')) loadData();
});
watch(isOnline, (val, old) => {
if (val && !old && userStore.isLoggedIn && songs.value.length === 0) {
pageCacheInvalidate('favoriteSongs');
loadData();
}
});
</script>

View File

@ -11,9 +11,9 @@
<div class="relative z-10 p-6 flex flex-col justify-between h-full">
<div>
<p class="text-xs text-white/60 mb-1">📅 {{ todayStr }}</p>
<h2 class="text-2xl font-bold">每日推荐</h2>
<h2 class="text-2xl font-bold text-white">每日推荐</h2>
</div>
<p class="text-xs text-white/60">根据你的口味生成每天 6:00 更新</p>
<p class="text-xs text-white/60">根据你的口味生成每天凌晨更新</p>
</div>
<div class="absolute right-4 top-1/2 -translate-y-1/2 text-6xl opacity-20">🎧</div>
</div>
@ -33,15 +33,15 @@
<div class="relative z-10 h-full flex flex-col justify-between p-6">
<div class="flex items-center gap-2">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-white/50"><path d="M4.9 19.1C1 15.2 1 8.8 4.9 4.9"/><path d="M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.4"/><path d="M16.2 7.8c2.3 2.3 2.3 6.1 0 8.4"/><path d="M19.1 4.9C23 8.8 23 15.1 19.1 19"/></svg>
<IconRadio class="w-4 h-4 text-white/50" />
<span class="text-xs text-white/50 font-medium">私人漫游</span>
</div>
<div class="flex items-end justify-between gap-4">
<div class="min-w-0 flex-1">
<h2 class="text-xl font-bold" v-if="!player.fmSong && userStore.isLoggedIn">发现新音乐</h2>
<h2 class="text-xl font-bold" v-else-if="!userStore.isLoggedIn">私人漫游</h2>
<h2 class="text-lg font-bold truncate" v-else>{{ fmDisplayName }}</h2>
<h2 class="text-xl font-bold text-white" v-if="!player.fmSong && userStore.isLoggedIn">发现新音乐</h2>
<h2 class="text-xl font-bold text-white" v-else-if="!userStore.isLoggedIn">私人漫游</h2>
<h2 class="text-lg font-bold truncate text-white" v-else>{{ fmDisplayName }}</h2>
<p v-if="!userStore.isLoggedIn" class="text-xs text-white/50 mt-1">登录后开启沉浸式音乐探索</p>
<p v-else-if="!player.fmSong" class="text-xs text-white/50 mt-1">根据你的喜好为你推荐意想不到的好歌</p>
<p v-else class="text-xs text-white/60 truncate mt-1">{{ fmDisplayArtists }}</p>
@ -50,24 +50,17 @@
<button v-if="userStore.isLoggedIn && !player.fmSong"
@click.stop="startFmPlay"
class="w-10 h-10 flex items-center justify-center rounded-full bg-white/15 hover:bg-white/25 backdrop-blur-sm transition">
<svg width="18" height="18" viewBox="0 0 16 16" fill="currentColor" class="text-white">
<path d="M4 2.5v11l9-5.5z" />
</svg>
<IconPlay class="w-4 h-4 fill-current text-white" />
</button>
<template v-if="player.fmSong">
<button @click.stop="player.toggleFm"
class="w-10 h-10 flex items-center justify-center rounded-full bg-white/15 hover:bg-white/25 backdrop-blur-sm transition">
<svg v-if="player.fmPlaying" width="18" height="18" viewBox="0 0 16 16" fill="currentColor" class="text-white">
<rect x="3" y="2" width="3" height="12" rx="0.5" />
<rect x="10" y="2" width="3" height="12" rx="0.5" />
</svg>
<svg v-else width="18" height="18" viewBox="0 0 16 16" fill="currentColor" class="text-white">
<path d="M4 2.5v11l9-5.5z" />
</svg>
<IconPause v-if="player.fmPlaying" class="w-[18px] h-[18px] fill-current text-white" />
<IconPlay v-else class="w-[18px] h-[18px] fill-current text-white" />
</button>
<button @click.stop="player.nextFm"
class="w-8 h-8 flex items-center justify-center rounded-full bg-white/10 hover:bg-white/20 backdrop-blur-sm transition">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="text-white"><polygon points="5 4 15 12 5 20 5 4"/><line x1="19" y1="5" x2="19" y2="19"/></svg>
<IconSkipForward class="w-[14px] h-[14px] text-white" />
</button>
</template>
</div>
@ -80,9 +73,9 @@
<!-- 第二行为你推荐需登录 -->
<div v-if="userStore.isLoggedIn && recPlaylists.length" class="mb-10">
<h2 class="text-xl font-semibold mb-4">🎯 为你推荐</h2>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4">
<div v-for="pl in recPlaylists" :key="pl.id" @click="goPlaylist(pl.id)"
class="bg-subtle rounded-xl overflow-hidden hover:bg-muted transition cursor-pointer">
class="bg-subtle rounded-xl overflow-hidden hover:bg-muted transition cursor-pointer max-w-[220px] justify-self-center w-full">
<img :src="pl.picUrl" class="w-full aspect-square object-cover" />
<div class="p-3">
<p class="text-sm font-medium truncate">{{ pl.name }}</p>
@ -95,9 +88,9 @@
<!-- 第三行热门歌单排行榜 -->
<div>
<h2 class="text-xl font-semibold mb-4">📈 热门歌单</h2>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4">
<div v-for="pl in rankPlaylists" :key="pl.id" @click="goPlaylist(pl.id)"
class="bg-subtle rounded-xl overflow-hidden hover:bg-muted transition cursor-pointer backdrop-blur-sm">
class="bg-subtle rounded-xl overflow-hidden hover:bg-muted transition cursor-pointer backdrop-blur-sm max-w-[220px] justify-self-center w-full">
<img :src="pl.coverImgUrl" class="w-full aspect-square object-cover" />
<div class="p-3">
<p class="text-sm font-medium truncate">{{ pl.name }}</p>
@ -109,15 +102,21 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ref, onMounted, onActivated, watch } from 'vue';
import { useRouter } from 'vue-router';
import { invoke } from '@tauri-apps/api/core';
import { useUserStore } from '../stores/user';
import { usePlayerStore } from '../stores/player';
import { pageCacheGet, pageCacheSet, pageCacheInvalidate, pageCacheIsStale } from '../composables/usePageCache';
import { useOnlineStatus } from '../composables/useOnlineStatus';
import { getCoverUrl } from '../utils/song';
defineOptions({ name: 'HomeView' });
const player = usePlayerStore();
const router = useRouter();
const userStore = useUserStore();
const { isOnline } = useOnlineStatus();
const rankPlaylists = ref<any[]>([]);
const recPlaylists = ref<any[]>([]);
@ -125,20 +124,22 @@ const todayStr = ref('');
const RANK_IDS = [3778678, 3779629, 19723756, 2884035];
import { computed } from 'vue';
import IconRadio from '~icons/lucide/radio';
import IconPlay from '~icons/lucide/play';
import IconPause from '~icons/lucide/pause';
import IconSkipForward from '~icons/lucide/skip-forward';
const fmCoverUrl = computed(() => {
return player.fmSong?.al?.picUrl || player.fmSong?.album?.picUrl || '';
return getCoverUrl(player.fmSong) || '';
});
const fmDisplayName = computed(() => player.fmSong?.name || '私人漫游');
const fmDisplayArtists = computed(() => {
if (!player.fmSong) return '';
return player.fmSong.ar?.map((a: any) => a.name).join(' / ') ||
player.fmSong.artists?.map((a: any) => a.name).join(' / ') || '';
return player.fmSong.ar?.map((a: { name: string }) => a.name).join(' / ') || '';
});
// 首次点击播放按钮:开始 FM 并播放
async function startFmPlay() {
if (!player.fmSong) {
await player.loadFm();
@ -159,11 +160,14 @@ function onFmCardClick() {
player.openRoamDrawer();
}
onMounted(async () => {
const d = new Date();
todayStr.value = `${d.getMonth() + 1}${d.getDate()}`;
async function loadData() {
const cached = pageCacheGet('home');
if (cached) {
rankPlaylists.value = cached.rankPlaylists || [];
recPlaylists.value = cached.recPlaylists || [];
return;
}
// 排行榜
const results = await Promise.allSettled(
RANK_IDS.map(id => invoke('get_playlist_detail', { id }))
);
@ -175,13 +179,31 @@ onMounted(async () => {
})
.filter(Boolean);
// 推荐歌单(需登录)
if (userStore.isLoggedIn) {
try {
const json = await invoke('recommend_resource');
const data = JSON.parse(json as string);
recPlaylists.value = data.recommend || [];
} catch { }
} catch { /* 忽略 */ }
}
pageCacheSet('home', { rankPlaylists: rankPlaylists.value, recPlaylists: recPlaylists.value });
}
onMounted(async () => {
const d = new Date();
todayStr.value = `${d.getMonth() + 1}${d.getDate()}`;
await loadData();
});
onActivated(() => {
if (pageCacheIsStale('home')) loadData();
});
watch(isOnline, (val, old) => {
if (val && !old && rankPlaylists.value.length === 0 && recPlaylists.value.length === 0) {
pageCacheInvalidate('home');
loadData();
}
});

View File

@ -7,7 +7,6 @@
<h1 class="text-2xl font-bold">本地音乐</h1>
<span v-if="songs.length" class="text-xs text-content-3">{{ songs.length }} </span>
<button
v-if="songs.length"
@click="refresh"
class="px-3 py-1 bg-muted hover:bg-emphasis rounded-full text-xs transition"
>
@ -19,46 +18,39 @@
当前文件夹下没有音乐文件支持 mp3flacwavoggaacm4a 格式
</div>
<div v-else class="space-y-2">
<div
v-for="(song, index) in songs"
<SongListItem
v-for="(song, index) in normalizedSongs"
:key="song.id + '-' + index"
@click="playLocalSong(song, index)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer"
:class="{ 'bg-subtle': player.currentSong?.id === song.id }"
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(normalizedSongs, index)"
>
<span class="text-xs text-content-3 w-6 text-right flex-shrink-0">{{ index + 1 }}</span>
<div class="w-10 h-10 rounded-lg overflow-hidden flex-shrink-0 bg-muted">
<img v-if="song.cover" :src="song.cover" class="w-full h-full object-cover" />
<div v-else class="w-full h-full flex items-center justify-center">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-content-3"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
<template #actions>
<span class="text-xs text-content-3 flex-shrink-0">{{ formatFileSize(songs[index].fileSize) }}</span>
<div class="relative flex-shrink-0">
<button
@click.stop="toggleMenu(songs[index].id)"
class="text-content-3 hover:text-content transition p-1 rounded hover:bg-muted"
title="更多"
>
<IconEllipsis class="w-4 h-4 fill-current" />
</button>
<Transition name="fade">
<div v-if="openMenuId === songs[index].id" class="absolute right-0 top-full mt-1 w-44 bg-surface border border-line rounded-xl shadow-2xl overflow-hidden z-50" @click.stop>
<button @click="confirmDelete(songs[index])" class="w-full flex items-center gap-2.5 px-4 py-2.5 text-sm text-danger/80 hover:bg-danger/10 transition">
<IconTrash2 style="font-size: 14px" />
从磁盘中删除
</button>
</div>
</Transition>
</div>
</div>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
{{ song.artist }}<template v-if="song.album"> · {{ song.album }}</template>
</p>
</div>
<span class="text-xs text-content-3 flex-shrink-0">{{ formatDuration(song.duration) }}</span>
<span class="text-xs text-content-3 flex-shrink-0">{{ formatFileSize(song.fileSize) }}</span>
<div class="relative flex-shrink-0">
<button
@click.stop="toggleMenu(song.id)"
class="text-content-3 hover:text-content transition p-1 rounded hover:bg-muted"
title="更多"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="19" cy="12" r="1.5"/></svg>
</button>
<Transition name="fade">
<div v-if="openMenuId === song.id" class="absolute right-0 top-full mt-1 w-44 bg-surface border border-line rounded-xl shadow-2xl overflow-hidden z-50" @click.stop>
<button @click="confirmDelete(song)" class="w-full flex items-center gap-2.5 px-4 py-2.5 text-sm text-danger/80 hover:bg-danger/10 transition">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/></svg>
从磁盘中删除
</button>
</div>
</Transition>
</div>
</div>
</template>
</SongListItem>
</div>
<Transition name="fade">
@ -83,12 +75,19 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { ref, computed, onMounted, onActivated, onBeforeUnmount, watch } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore, type Song } from '../stores/player';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { useSettingsStore } from '../stores/settings';
import { showToast } from '../composables/useToast';
import { pageCacheSet, pageCacheInvalidate, pageCacheIsStale } from '../composables/usePageCache';
import SongListItem from '../components/SongListItem.vue';
import IconEllipsis from '~icons/lucide/ellipsis';
import IconTrash2 from '~icons/lucide/trash-2';
import type { Song } from '../utils/song';
defineOptions({ name: 'LocalMusicView' });
const player = usePlayerStore();
const download = useDownload();
@ -113,6 +112,8 @@ const showDeleteConfirm = ref(false);
const deleteTarget = ref<LocalSong | null>(null);
const openMenuId = ref<number | null>(null);
const normalizedSongs = computed(() => songs.value.map(toSong));
function toggleMenu(id: number) {
openMenuId.value = openMenuId.value === id ? null : id;
}
@ -126,9 +127,11 @@ onBeforeUnmount(() => { document.removeEventListener('click', closeMenu); });
async function refresh() {
loading.value = true;
pageCacheInvalidate('localMusic');
try {
const list = await invoke<LocalSong[]>('list_local_songs', { downloadPath: settings.downloadPath || null });
songs.value = list;
pageCacheSet('localMusic', list);
fetchMissingCovers();
} catch (e) {
console.error(e);
@ -153,11 +156,17 @@ async function fetchMissingCovers() {
const url = detailMap.get(song.id);
if (url) song.cover = url;
}
} catch {}
} catch { /* 忽略 */ }
}
onMounted(refresh);
onActivated(() => {
if (pageCacheIsStale('localMusic')) refresh();
});
watch(() => settings.downloadPath, () => { refresh(); });
function formatFileSize(bytes: number): string {
if (bytes === 0) return '0 B';
const units = ['B', 'KB', 'MB', 'GB'];
@ -165,14 +174,6 @@ function formatFileSize(bytes: number): string {
return (bytes / Math.pow(1024, i)).toFixed(i > 0 ? 1 : 0) + ' ' + units[i];
}
function formatDuration(ms: number): string {
if (!ms || ms === 0) return '--:--';
const totalSec = Math.floor(ms / 1000);
const min = Math.floor(totalSec / 60);
const sec = totalSec % 60;
return `${min}:${sec.toString().padStart(2, '0')}`;
}
function toSong(local: LocalSong): Song {
return {
id: local.id,
@ -180,18 +181,10 @@ function toSong(local: LocalSong): Song {
ar: local.artist ? [{ name: local.artist }] : [],
al: { picUrl: local.cover || '', name: local.album || undefined },
dt: local.duration || undefined,
artists: local.artist ? [{ name: local.artist }] : [],
album: { picUrl: local.cover || undefined, name: local.album || undefined },
duration: local.duration || undefined,
localPath: local.path,
};
}
async function playLocalSong(_song: LocalSong, index: number) {
const normalized = songs.value.map(s => toSong(s));
player.playFromList(normalized, index);
}
function confirmDelete(song: LocalSong) {
openMenuId.value = null;
deleteTarget.value = song;

View File

@ -88,7 +88,7 @@ function startPolling() {
statusColor.value = 'text-content-2';
} else if (code === 802) {
statusText.value = '请在手机上确认登录';
statusColor.value = 'text-warning';
statusColor.value = 'text-yellow-400';
} else if (code === 803) {
clearInterval(pollTimer!);
statusText.value = '登录成功!';

View File

@ -23,7 +23,7 @@
@click="playAll"
class="px-5 py-2 bg-accent hover:bg-accent-hover rounded-full text-white font-medium transition flex items-center gap-2"
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
<IconPlay class="w-4 h-4 fill-current" />
播放全部
</button>
<button
@ -32,10 +32,7 @@
class="px-4 py-2 bg-muted hover:bg-emphasis rounded-full text-sm transition flex items-center gap-2"
:class="subscribed ? 'text-accent-text' : 'text-content/70'"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path v-if="subscribed" d="M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"/>
<path v-else d="M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z"/>
</svg>
<IconBookmark class="w-4 h-4" :class="subscribed ? 'fill-current' : ''" />
{{ subscribed ? '已收藏' : '收藏歌单' }}
</button>
</div>
@ -45,52 +42,21 @@
<div v-if="loading" class="text-content-2">加载中...</div>
<div v-else class="space-y-1">
<div
<SongListItem
v-for="(song, index) in songs"
:key="song.id"
@click="playSingle(song)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer group"
:class="{ 'bg-accent-dim': isCurrentSong(song.id) }"
>
<div class="w-6 text-right flex-shrink-0 flex items-center justify-end h-5">
<div v-if="isCurrentSong(song.id)" class="flex items-center justify-end">
<div class="flex items-center gap-[3px] h-4">
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 50%; animation-delay: 0ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 100%; animation-delay: 150ms"></span>
<span class="w-[3px] bg-accent-text rounded-full animate-bounce" style="height: 35%; animation-delay: 300ms"></span>
</div>
</div>
<template v-else>
<span class="text-xs text-content-3 group-hover:hidden">{{ index + 1 }}</span>
<svg class="hidden group-hover:block text-content" width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z"/></svg>
</template>
</div>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover flex-shrink-0" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate" :class="isCurrentSong(song.id) ? 'text-accent-text' : ''">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt) }}</span>
</div>
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(songs, index)"
/>
</div>
<div v-if="playlist" class="mt-8">
@ -101,24 +67,24 @@
<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useRoute } from 'vue-router';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore } from '../stores/player';
import { useUserStore } from '../stores/user';
import { useDownload } from '../composables/useDownload';
import { showToast } from '../composables/useToast';
import { formatDuration, formatPlayCount } from '../utils/format';
import SongItemMenu from '../components/SongItemMenu.vue';
import { formatPlayCount } from '../utils/format';
import { normalizeSong, type Song } from '../utils/song';
import SongListItem from '../components/SongListItem.vue';
import CommentSection from '../components/CommentSection.vue';
import IconPlay from '~icons/lucide/play';
import IconBookmark from '~icons/lucide/bookmark';
const route = useRoute();
const router = useRouter();
const player = usePlayerStore();
const userStore = useUserStore();
const download = useDownload();
const playlist = ref<any>(null);
const songs = ref<any[]>([]);
const songs = ref<Song[]>([]);
const loading = ref(true);
const subscribed = ref(false);
@ -135,7 +101,7 @@ async function fetchPlaylist(id: number) {
const jsonStr: string = await invoke('get_playlist_detail', { id });
const data = JSON.parse(jsonStr);
playlist.value = data.playlist;
songs.value = data.playlist.tracks || [];
songs.value = (data.playlist.tracks || []).map(normalizeSong);
subscribed.value = data.playlist.subscribed || false;
} catch (e) {
console.error(e);
@ -153,15 +119,6 @@ watch(() => route.params.id, (newId) => {
if (newId) fetchPlaylist(Number(newId));
});
function isCurrentSong(songId: number): boolean {
return player.currentSong?.id === songId;
}
async function playSingle(song: any) {
const idx = songs.value.findIndex((s: any) => s.id === song.id);
player.playFromList(songs.value, idx >= 0 ? idx : 0);
}
function playAll() {
if (songs.value.length === 0) return;
player.playAll(songs.value);

View File

@ -6,51 +6,28 @@
<h1 class="text-2xl font-bold mb-6">最近播放</h1>
<div v-if="player.recentLocal.length === 0" class="text-content-3">还没有播放记录去听首歌吧</div>
<div v-else class="space-y-2">
<div
<SongListItem
v-for="(song, index) in player.recentLocal"
:key="song.id"
:song="song"
:index="index"
:is-current="player.currentSong?.id === song.id"
show-index
show-like
show-download
show-menu
show-duration
show-playing-overlay
:container-class="player.currentSong?.id === song.id ? 'bg-accent-dim hover:bg-accent-dim' : 'hover:bg-subtle'"
@click="player.playFromList(player.recentLocal, index)"
class="flex items-center gap-4 p-3 rounded-xl hover:bg-subtle transition cursor-pointer"
>
<span class="text-xs text-content-3 w-6 text-right">{{ index + 1 }}</span>
<img :src="song.al?.picUrl" class="w-10 h-10 rounded object-cover" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium truncate">{{ song.name }}</p>
<p class="text-xs text-content-2 truncate">
<template v-for="(a, i) in song.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="song.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click.stop="song.al.id && router.push({ name: 'album', params: { id: song.al.id } })">{{ song.al.name }}</span>
</template>
</p>
</div>
<button @click.stop="player.toggleLike(song.id)" class="text-content-3 hover:text-danger transition flex-shrink-0">
<svg v-if="player.isLiked(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" class="text-danger"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>
</button>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<SongItemMenu :song-id="song.id" />
<span class="text-xs text-content-3">{{ formatDuration(song.dt ?? 0) }}</span>
</div>
/>
</div>
</div>
</template>
<script setup lang="ts">
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { formatDuration } from '../utils/format';
import { useRouter } from 'vue-router';
import SongItemMenu from '../components/SongItemMenu.vue';
import SongListItem from '../components/SongListItem.vue';
const player = usePlayerStore();
const download = useDownload();
const router = useRouter();
</script>

View File

@ -1,112 +0,0 @@
<template>
<div class="p-8 text-content flex flex-col items-center justify-center min-h-full">
<div v-if="!currentSong" class="text-center">
<p class="text-content-2 mb-4">私人漫游未启动</p>
<button
@click="startFm"
class="px-6 py-2 bg-muted hover:bg-emphasis rounded-full transition"
>
开始漫游
</button>
</div>
<template v-else>
<img
v-if="coverUrl && !coverError"
:src="coverUrl"
class="w-80 h-80 rounded-3xl object-cover shadow-2xl mb-8"
@error="coverError = true"
/>
<div
v-else
class="w-80 h-80 rounded-3xl bg-muted flex items-center justify-center shadow-2xl mb-8"
>
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="text-content-3"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
</div>
<h1 class="text-3xl font-bold mb-2">{{ currentSong.name }}</h1>
<p class="text-lg text-content-2 mb-8">
<template v-for="(a, i) in currentSong.ar || []" :key="a.id || i">
<span v-if="i > 0" class="text-content-3">/</span>
<span class="hover:text-accent-text cursor-pointer transition" @click="a.id && router.push({ name: 'artist', params: { id: a.id } })">{{ a.name }}</span>
</template>
<template v-if="currentSong.al?.name">
<span class="text-content-3 mx-1">·</span>
<span class="hover:text-accent-text cursor-pointer transition" @click="currentSong.al.id && router.push({ name: 'album', params: { id: currentSong.al.id } })">{{ currentSong.al.name }}</span>
</template>
</p>
<div class="flex items-center gap-8">
<button
@click="player.toggle()"
class="w-16 h-16 flex items-center justify-center rounded-full bg-muted hover:bg-emphasis transition border border-emphasis"
>
<svg v-if="player.playing" width="28" height="28" viewBox="0 0 16 16" fill="currentColor">
<rect x="3" y="2" width="3" height="12" rx="0.5" />
<rect x="10" y="2" width="3" height="12" rx="0.5" />
</svg>
<svg v-else width="28" height="28" viewBox="0 0 16 16" fill="currentColor">
<path d="M4 2.5v11l9-5.5z" />
</svg>
</button>
<button
@click="nextSong"
class="text-content-2 hover:text-content transition"
>
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 4 15 12 5 20 5 4"/><line x1="19" y1="5" x2="19" y2="19"/></svg>
</button>
</div>
</template>
</div>
</template>
<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue';
import { usePlayerStore } from '../stores/player';
import { invoke } from '@tauri-apps/api/core';
import { normalizeSong } from '../utils/song';
import { useRouter } from 'vue-router';
const player = usePlayerStore();
const router = useRouter();
const coverError = ref(false);
const currentSong = computed(() => {
if (player.isFmMode && player.currentSong) {
return player.currentSong;
}
return null;
});
const coverUrl = computed(() => {
if (!currentSong.value) return '';
return currentSong.value.al?.picUrl || currentSong.value.album?.picUrl || '';
});
watch(coverUrl, () => { coverError.value = false; });
onMounted(async () => {
if (!player.isFmMode || !player.currentSong) {
await startFm();
}
});
async function startFm() {
try {
const jsonStr: string = await invoke('personal_fm');
const data = JSON.parse(jsonStr);
const songs = data.data || data;
if (songs && songs.length > 0) {
const song = normalizeSong(songs[0]);
player.enableFmMode(nextSong);
await player.playFmSong(song);
}
} catch (e) {
console.error('启动漫游失败', e);
}
}
async function nextSong() {
await startFm();
}
</script>

View File

@ -1,106 +0,0 @@
<template>
<div class="text-content">
<h1 class="text-2xl font-bold mb-4">搜索</h1>
<input
v-model="keyword"
@keyup.enter="handleSearch"
placeholder="搜索歌曲..."
class="mb-6 w-full rounded-xl bg-muted p-3 text-content placeholder-content-2 outline-none backdrop-blur"
/>
<div v-if="loading" class="text-content-2">搜索中...</div>
<div v-else class="space-y-3">
<div
v-for="(song, index) in results"
:key="song.id"
@click="playSong(song, index)"
class="flex items-center gap-4 p-3 rounded-xl backdrop-blur-md bg-subtle hover:bg-muted border border-line-2 cursor-pointer transition-all duration-200 hover:scale-[1.01] active:scale-95"
>
<img :src="song.al?.picUrl" class="w-12 h-12 rounded-lg object-cover" />
<div class="flex-1 min-w-0">
<p class="font-medium truncate">{{ song.name }}</p>
<p class="text-sm text-content-2 truncate">
{{ song.ar?.map((a: any) => a.name).join(' / ') }}
</p>
</div>
<button @click.stop="download.downloadSong(song)" class="text-content-3 hover:text-accent-text transition flex-shrink-0" :title="download.isDownloaded(song.id) ? '已下载' : '下载'">
<svg v-if="download.isDownloading(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="animate-spin"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<svg v-else-if="download.isDownloaded(song.id)" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-accent-text"><polyline points="20 6 9 17 4 12"/></svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
</div>
<p v-if="!loading && hasSearched && results.length === 0" class="text-content-2">无结果</p>
</div>
</div>
</template>
<script setup lang="ts">
defineOptions({ name: 'SearchView' });
import { useRoute } from 'vue-router';
import { watch } from 'vue';
import { ref, onMounted } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { usePlayerStore } from '../stores/player';
import { useDownload } from '../composables/useDownload';
import { useRouter } from 'vue-router';
const router = useRouter();
const keyword = ref('');
const results = ref<any[]>([]);
const loading = ref(false);
const hasSearched = ref(false);
const player = usePlayerStore();
const download = useDownload();
const route = useRoute();
watch(
() => route.query.q,
(newQ) => {
if (newQ) {
keyword.value = newQ as string;
handleSearch();
router.replace({ query: {} });
}
},
{ immediate: true }
);
async function handleSearch() {
if (!keyword.value.trim()) return;
loading.value = true;
hasSearched.value = true;
try {
const jsonStr: string = await invoke('search_songs', { query: { keyword: keyword.value } });
const data = JSON.parse(jsonStr);
results.value = data.result?.songs || [];
} catch (e) {
console.error('搜索出错:', e);
} finally {
loading.value = false;
}
}
async function playSong(_song: any, index: number) {
try {
const normalized = results.value.map((s: any) => ({
id: s.id,
name: s.name,
ar: s.ar || s.artists || [],
al: s.al || s.album || { picUrl: '' },
dt: s.dt || 0,
}));
await player.playFromList(normalized, index);
} catch (e) {
alert('暂无播放源或需登录');
}
}
const devices = ref<string[]>([]);
onMounted(async () => {
devices.value = await invoke('get_output_devices');
});
</script>

View File

@ -28,19 +28,37 @@
<section class="mb-8">
<h2 class="text-sm text-content-2 uppercase tracking-wider mb-4">外观</h2>
<div>
<p class="text-sm font-medium mb-3">主题色</p>
<div class="grid grid-cols-4 gap-3">
<button
v-for="(color, key) in themeColors"
:key="key"
@click="settings.setTheme(key)"
class="flex flex-col items-center gap-2 p-3 rounded-xl transition-all border-2"
:class="settings.theme === key ? 'border-white/30 bg-white/5 scale-[1.02]' : 'border-transparent bg-subtle hover:bg-muted'"
>
<div class="w-8 h-8 rounded-full shadow-md" :style="{ backgroundColor: color }"></div>
<span class="text-xs" :class="settings.theme === key ? 'text-content font-medium' : 'text-content-3'">{{ themeLabels[key] }}</span>
</button>
<div class="space-y-5">
<div>
<p class="text-sm font-medium mb-3">外观模式</p>
<div class="flex gap-3">
<button
v-for="(label, key) in appearanceLabels"
:key="key"
@click="settings.setAppearance(key)"
class="flex items-center gap-2 px-4 py-2.5 rounded-xl transition-all border-2"
:class="settings.appearance === key ? 'border-accent/40 bg-accent/10 scale-[1.02]' : 'border-transparent bg-subtle hover:bg-muted'"
>
<IconSun v-if="key === 'light'" class="w-4 h-4" :class="settings.appearance === key ? 'text-accent-text' : 'text-content-3'" />
<IconMoon v-else class="w-4 h-4" :class="settings.appearance === key ? 'text-accent-text' : 'text-content-3'" />
<span class="text-sm" :class="settings.appearance === key ? 'text-content font-medium' : 'text-content-3'">{{ label }}</span>
</button>
</div>
</div>
<div>
<p class="text-sm font-medium mb-3">主题色</p>
<div class="grid grid-cols-4 gap-3">
<button
v-for="(color, key) in themeColors"
:key="key"
@click="settings.setTheme(key)"
class="flex flex-col items-center gap-2 p-3 rounded-xl transition-all border-2"
:class="settings.theme === key ? 'border-accent/40 bg-accent/10 scale-[1.02]' : 'border-transparent bg-subtle hover:bg-muted'"
>
<div class="w-8 h-8 rounded-full shadow-md" :style="{ backgroundColor: color }"></div>
<span class="text-xs" :class="settings.theme === key ? 'text-content font-medium' : 'text-content-3'">{{ themeLabels[key] }}</span>
</button>
</div>
</div>
</div>
</section>
@ -105,18 +123,18 @@
<div class="flex items-center gap-1.5">
<button
v-if="sc.key !== defaultShortcuts[id]?.key"
@click="settings.setShortcut(id, defaultShortcuts[id].key)"
@click="settings.setShortcut(String(id), defaultShortcuts[id].key)"
class="w-6 h-6 flex items-center justify-center rounded-md text-content-4 hover:text-danger hover:bg-danger/10 transition"
title="恢复默认"
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
<IconX style="font-size: 14px" />
</button>
<button
@click="startRecording(id)"
@click="startRecording(String(id))"
class="px-3 py-1.5 rounded-lg text-sm transition min-w-[120px] text-center"
:class="recordingId === id ? 'bg-accent text-white' : 'bg-muted hover:bg-emphasis text-content-2'"
:class="recordingId === String(id) ? 'bg-accent text-white' : 'bg-muted hover:bg-emphasis text-content-2'"
>
{{ recordingId === id ? '按下新快捷键...' : formatShortcut(sc.key) }}
{{ recordingId === String(id) ? '按下新快捷键...' : formatShortcut(sc.key) }}
</button>
</div>
</div>
@ -167,8 +185,8 @@
:disabled="updater.checking.value"
class="flex items-center gap-2 px-4 py-2 bg-subtle hover:bg-muted rounded-lg text-sm transition"
>
<svg v-if="!updater.checking.value" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
<svg v-else class="animate-spin" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12a9 9 0 11-6.22-8.56"/></svg>
<IconFileText v-if="!updater.checking.value" class="w-4 h-4" />
<IconLoader2 v-else class="w-4 h-4 animate-spin" />
{{ updater.checking.value ? '检查中...' : '检查更新' }}
</button>
<button
@ -176,7 +194,7 @@
:disabled="fetchingChangelog"
class="flex items-center gap-2 px-4 py-2 bg-subtle hover:bg-muted rounded-lg text-sm transition"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
<IconFileText class="w-4 h-4" />
{{ fetchingChangelog ? '获取中...' : '更新日志' }}
</button>
</div>
@ -237,7 +255,7 @@
<script setup lang="ts">
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
import { useSettingsStore, qualityLabels, closeActionLabels, defaultShortcuts, themeLabels, themeColors, type CloseAction } from '../stores/settings';
import { useSettingsStore, qualityLabels, closeActionLabels, defaultShortcuts, themeLabels, themeColors, appearanceLabels, type CloseAction } from '../stores/settings';
import { useToast } from '../composables/useToast';
import { useUpdater } from '../composables/useUpdater';
import { invoke } from '@tauri-apps/api/core';
@ -245,6 +263,11 @@ import { getVersion } from '@tauri-apps/api/app';
import { openUrl } from '@tauri-apps/plugin-opener';
import { open } from '@tauri-apps/plugin-dialog';
import CustomSelect from '../components/CustomSelect.vue';
import IconX from '~icons/lucide/x';
import IconFileText from '~icons/lucide/file-text';
import IconLoader2 from '~icons/lucide/loader-2';
import IconSun from '~icons/lucide/sun';
import IconMoon from '~icons/lucide/moon';
const settings = useSettingsStore();
const { showToast } = useToast();
@ -287,7 +310,7 @@ onMounted(async () => {
appVersion.value = await getVersion();
try {
defaultDownloadPath.value = await invoke<string>('get_default_download_path');
} catch { }
} catch { /* 忽略 */ }
loadDevices();
});
@ -361,6 +384,7 @@ function formatShortcut(key: string): string {
.replace('ArrowRight', '→')
.replace('ArrowUp', '↑')
.replace('ArrowDown', '↓')
.replace(/Key([A-Z])/g, '$1')
.replace(/\+/g, ' + ');
}