File size: 3,131 Bytes
40f23a9 25e7862 40f23a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import { defineStore } from 'pinia'
import { themeManager, THEME_IDS } from '@/styles/themes'
export const useSettingsStore = defineStore('settings', {
state: () => ({
settings: {
// 播放设置 - 根据需求文档
defaultQuality: '320', // 默认音质:128/192/320/740/999 (默认:320K)
defaultPlayMode: 'list', // 默认播放模式:list/random/single (默认:列表循环)
rememberProgress: true, // 记住播放进度:true/false (默认:开启)
autoNext: true, // 自动播放下一首
fadeEffect: true, // 淡入淡出效果
// 搜索设置 - 根据需求文档
defaultSource: 'joox', // 默认音乐源:joox (默认:JOOX音乐)
searchLimit: 20, // 搜索结果数量
saveSearchHistory: true, // 搜索历史:true/false (默认:保存)
// 外观设置 - 新的多主题系统
theme: 'light', // 主题模式:light/dark/orange/pink/purple/blue/green/gold/gray/wechat
showLyrics: true, // 显示歌词
lyricsFontSize: 18, // 歌词字体大小
// 通知设置
desktopNotification: true, // 桌面通知
mediaSession: true // 媒体控制
}
}),
actions: {
// 获取设置项
getSetting(key) {
return this.settings[key]
},
// 更新设置项
updateSetting(key, value) {
if (key in this.settings) {
this.settings[key] = value
// 特殊处理主题切换
if (key === 'theme') {
this.applyTheme(value)
}
this.saveSettings()
}
},
// 应用主题
applyTheme(themeId = null) {
const targetTheme = themeId || this.settings.theme || 'light'
try {
themeManager.applyTheme(targetTheme)
// 更新设置状态
if (themeId && themeId !== this.settings.theme) {
this.settings.theme = targetTheme
this.saveSettings()
}
console.log(`主题已切换到: ${targetTheme}`)
} catch (error) {
console.error('应用主题失败:', error)
// 回退到默认主题
if (targetTheme !== 'light') {
this.applyTheme('light')
}
}
},
// 获取所有可用主题
getAvailableThemes() {
return themeManager.getAllThemes()
},
// 保存设置到本地存储
saveSettings() {
try {
localStorage.setItem('music-settings', JSON.stringify({
settings: this.settings,
version: '1.0',
lastUpdated: Date.now()
}))
} catch (error) {
console.error('保存设置失败:', error)
}
},
// 从本地存储加载设置
loadSettings() {
try {
const saved = localStorage.getItem('music-settings')
if (saved) {
const data = JSON.parse(saved)
if (data.settings) {
this.settings = {
...this.settings,
...data.settings
}
}
}
} catch (error) {
console.error('加载设置失败:', error)
}
}
}
}) |