From 885a7dabab2e2784e107e444baaa67e0a2072bf6 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Wed, 28 May 2025 12:34:14 +1000 Subject: [PATCH] feat(PreferencePanel, usePreferences): add PreferencePanel component and integrate preference settings --- src/App.vue | 14 ++- src/components/PreferencePanel.vue | 144 +++++++++++++++++++++++++++++ src/stores/usePreferences.ts | 12 ++- 3 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 src/components/PreferencePanel.vue diff --git a/src/App.vue b/src/App.vue index 1045013..2e9a08f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,13 +1,23 @@ \ No newline at end of file diff --git a/src/components/PreferencePanel.vue b/src/components/PreferencePanel.vue new file mode 100644 index 0000000..7aacc0a --- /dev/null +++ b/src/components/PreferencePanel.vue @@ -0,0 +1,144 @@ + + + + + \ No newline at end of file diff --git a/src/stores/usePreferences.ts b/src/stores/usePreferences.ts index 7590a73..dd074a9 100644 --- a/src/stores/usePreferences.ts +++ b/src/stores/usePreferences.ts @@ -11,6 +11,7 @@ declare global { export const usePreferences = defineStore('preferences', () => { const displayTimeLeft = ref(false) const presentLyrics = ref(false) + const autoRedirect = ref(true) const isLoaded = ref(false) const storageType = ref<'chrome' | 'localStorage' | 'memory'>('chrome') @@ -18,7 +19,8 @@ export const usePreferences = defineStore('preferences', () => { // 默认偏好设置 const defaultPreferences = { displayTimeLeft: false, - presentLyrics: false + presentLyrics: false, + autoRedirect: true } // 检测可用的 API @@ -140,7 +142,8 @@ export const usePreferences = defineStore('preferences', () => { const savePreferences = async () => { const preferences = { displayTimeLeft: displayTimeLeft.value, - presentLyrics: presentLyrics.value + presentLyrics: presentLyrics.value, + autoRedirect: autoRedirect.value } await setStoredValue('preferences', preferences) } @@ -151,16 +154,18 @@ export const usePreferences = defineStore('preferences', () => { const preferences = await getPreferences() displayTimeLeft.value = preferences.displayTimeLeft presentLyrics.value = preferences.presentLyrics + autoRedirect.value = preferences.autoRedirect isLoaded.value = true } catch (error) { displayTimeLeft.value = false presentLyrics.value = false + autoRedirect.value = true isLoaded.value = true } } // 监听变化并保存 - watch([displayTimeLeft, presentLyrics], async () => { + watch([displayTimeLeft, presentLyrics, autoRedirect], async () => { if (isLoaded.value) { try { await savePreferences() @@ -176,6 +181,7 @@ export const usePreferences = defineStore('preferences', () => { return { displayTimeLeft, presentLyrics, + autoRedirect, isLoaded, storageType, initializePreferences,