diff --git a/src/App.vue b/src/App.vue index 6fad2df..230d9da 100644 --- a/src/App.vue +++ b/src/App.vue @@ -508,7 +508,7 @@ const updateInfo = ref(null) const handleNotification = (type: string, itemType: string, level?: number) => { - const settings = gameStore.player.notificationSettings + const settings = gameStore.notificationSettings if (!settings) return // 检查主开关 diff --git a/src/stores/gameStore.ts b/src/stores/gameStore.ts index 4e0cba9..67079e7 100644 --- a/src/stores/gameStore.ts +++ b/src/stores/gameStore.ts @@ -41,27 +41,27 @@ export const useGameStore = defineStore('game', { giftRejectedNotifications: [], points: 0, isGMEnabled: false, // 明确设置 GM 模式默认为 false - lastVersionCheckTime: 0, // 最后一次检查版本的时间戳,默认为0 - notificationSettings: { - browser: false, - inApp: true, - suppressInFocus: false, - types: { - construction: true, - research: true - } - } + lastVersionCheckTime: 0 // 最后一次检查版本的时间戳,默认为0 } as Player, currentPlanetId: '', isDark: '', - locale: 'zh-CN' as Locale + locale: 'zh-CN' as Locale, + notificationSettings: { + browser: false, + inApp: true, + suppressInFocus: false, + types: { + construction: true, + research: true + } + } }), actions: { async requestBrowserPermission(): Promise { if (!('Notification' in window)) return false - + if (Notification.permission === 'granted') return true - + const permission = await Notification.requestPermission() return permission === 'granted' } diff --git a/src/types/game.ts b/src/types/game.ts index 88df4a2..1611aec 100644 --- a/src/types/game.ts +++ b/src/types/game.ts @@ -574,8 +574,6 @@ export interface Player { diplomaticReports?: DiplomaticReport[] // 外交变化报告 // 新手引导字段 tutorialProgress?: TutorialProgress // 新手引导进度 - // 通知设置 - notificationSettings?: NotificationSettings } export interface NotificationSettings { diff --git a/src/views/SettingsView.vue b/src/views/SettingsView.vue index 42e0008..5f92226 100644 --- a/src/views/SettingsView.vue +++ b/src/views/SettingsView.vue @@ -103,16 +103,16 @@

{{ t('settings.browserNotifications') }}

{{ t('settings.browserPermission') }}

- + -
+
@@ -124,7 +124,7 @@

{{ t('settings.inAppNotificationsDesc') || t('settings.inAppNotifications') }}

@@ -151,7 +151,7 @@
@@ -159,7 +159,7 @@
@@ -279,8 +279,8 @@ const isTypesExpanded = ref(false) // Ensure notification settings exist - if (!gameStore.player.notificationSettings) { - gameStore.player.notificationSettings = { + if (!gameStore.notificationSettings) { + gameStore.notificationSettings = { browser: false, inApp: true, suppressInFocus: false, @@ -289,7 +289,7 @@ } const areMainSwitchesOff = computed(() => { - const s = gameStore.player.notificationSettings + const s = gameStore.notificationSettings return !s?.browser && !s?.inApp }) @@ -299,44 +299,44 @@ // }) const updateInAppSetting = (val: boolean) => { - if (gameStore.player.notificationSettings) { - gameStore.player.notificationSettings.inApp = val + if (gameStore.notificationSettings) { + gameStore.notificationSettings.inApp = val } } const updateSuppressSetting = (val: boolean) => { - if (gameStore.player.notificationSettings) { - gameStore.player.notificationSettings.suppressInFocus = val + if (gameStore.notificationSettings) { + gameStore.notificationSettings.suppressInFocus = val } } const updateTypeSetting = (key: string, val: boolean) => { - if (gameStore.player.notificationSettings) { - gameStore.player.notificationSettings.types[key] = val + if (gameStore.notificationSettings) { + gameStore.notificationSettings.types[key] = val } } const toggleType = (key: string) => { - if (gameStore.player.notificationSettings) { - const current = gameStore.player.notificationSettings.types[key] - gameStore.player.notificationSettings.types[key] = !current + if (gameStore.notificationSettings) { + const current = gameStore.notificationSettings.types[key] + gameStore.notificationSettings.types[key] = !current } } const handleBrowserSwitch = async (checked: boolean) => { - if (!gameStore.player.notificationSettings) return + if (!gameStore.notificationSettings) return if (checked) { const granted = await gameStore.requestBrowserPermission() if (granted) { - gameStore.player.notificationSettings.browser = true + gameStore.notificationSettings.browser = true toast.success(t('settings.permissionGranted')) } else { - gameStore.player.notificationSettings.browser = false + gameStore.notificationSettings.browser = false toast.error(t('settings.permissionDenied')) } } else { - gameStore.player.notificationSettings.browser = false + gameStore.notificationSettings.browser = false } }