From c90cfbf3cdd39a21ce2ecbfdd649bbea32bc413b Mon Sep 17 00:00:00 2001 From: algerkong Date: Wed, 23 Apr 2025 09:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=BC=98=E5=8C=96=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=90=88=E5=B9=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=AE=BE=E7=BD=AE=E4=B8=8E=E5=AD=98=E5=82=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/store/modules/settings.ts | 35 +++++++++++++++++--------- src/renderer/views/set/index.vue | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/renderer/store/modules/settings.ts b/src/renderer/store/modules/settings.ts index 58f0c10..51846f1 100644 --- a/src/renderer/store/modules/settings.ts +++ b/src/renderer/store/modules/settings.ts @@ -1,4 +1,4 @@ -import { cloneDeep } from 'lodash'; +import { cloneDeep, merge } from 'lodash'; import { defineStore } from 'pinia'; import { ref } from 'vue'; @@ -7,17 +7,6 @@ import { isElectron } from '@/utils'; import { applyTheme, getCurrentTheme, ThemeType } from '@/utils/theme'; export const useSettingsStore = defineStore('settings', () => { - // 初始化时先从存储中读取设置 - const getInitialSettings = () => { - if (isElectron) { - const savedSettings = window.electron.ipcRenderer.sendSync('get-store-value', 'set'); - return savedSettings || setDataDefault; - } - const savedSettings = localStorage.getItem('appSettings'); - return savedSettings ? JSON.parse(savedSettings) : setDataDefault; - }; - - const setData = ref(getInitialSettings()); const theme = ref(getCurrentTheme()); const isMobile = ref(false); const isMiniMode = ref(false); @@ -28,7 +17,11 @@ export const useSettingsStore = defineStore('settings', () => { { label: '系统默认', value: 'system-ui' } ]); const showDownloadDrawer = ref(false); + + // 先声明 setData ref 但不初始化 + const setData = ref({}); + // 先定义 setSetData 函数 const setSetData = (data: any) => { // 合并现有设置和新设置 const mergedData = { @@ -44,6 +37,24 @@ export const useSettingsStore = defineStore('settings', () => { setData.value = cloneDeep(mergedData); }; + // 初始化时先从存储中读取设置 + const getInitialSettings = () => { + // 从存储中获取保存的设置 + const savedSettings = isElectron + ? window.electron.ipcRenderer.sendSync('get-store-value', 'set') + : JSON.parse(localStorage.getItem('appSettings') || '{}'); + + // 合并默认设置和保存的设置 + const mergedSettings = merge({}, setDataDefault, savedSettings); + + // 更新设置并返回 + setSetData(mergedSettings); + return mergedSettings; + }; + + // 初始化 setData + setData.value = getInitialSettings(); + const toggleTheme = () => { theme.value = theme.value === 'dark' ? 'light' : 'dark'; applyTheme(theme.value); diff --git a/src/renderer/views/set/index.vue b/src/renderer/views/set/index.vue index b1653c2..3645b3c 100644 --- a/src/renderer/views/set/index.vue +++ b/src/renderer/views/set/index.vue @@ -575,7 +575,7 @@ import config from '../../../../package.json'; // 手动定义Platform类型,避免从主进程导入的问题 type Platform = 'qq' | 'migu' | 'kugou' | 'pyncmd' | 'joox' | 'kuwo' | 'bilibili' | 'youtube' | 'gdmusic'; // 所有平台 -const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'pyncmd', 'kuwo', 'bilibili', 'youtube', 'gdmusic']; +const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'pyncmd', 'bilibili', 'youtube']; const settingsStore = useSettingsStore(); const userStore = useUserStore();