移出player

This commit is contained in:
StarsEnd
2025-12-18 02:21:00 +08:00
parent d2465b5d4b
commit 0da82802b8
4 changed files with 37 additions and 39 deletions

View File

@@ -508,7 +508,7 @@
const updateInfo = ref<VersionInfo | null>(null)
const handleNotification = (type: string, itemType: string, level?: number) => {
const settings = gameStore.player.notificationSettings
const settings = gameStore.notificationSettings
if (!settings) return
// 检查主开关

View File

@@ -41,7 +41,11 @@ export const useGameStore = defineStore('game', {
giftRejectedNotifications: [],
points: 0,
isGMEnabled: false, // 明确设置 GM 模式默认为 false
lastVersionCheckTime: 0, // 最后一次检查版本的时间戳默认为0
lastVersionCheckTime: 0 // 最后一次检查版本的时间戳默认为0
} as Player,
currentPlanetId: '',
isDark: '',
locale: 'zh-CN' as Locale,
notificationSettings: {
browser: false,
inApp: true,
@@ -51,10 +55,6 @@ export const useGameStore = defineStore('game', {
research: true
}
}
} as Player,
currentPlanetId: '',
isDark: '',
locale: 'zh-CN' as Locale
}),
actions: {
async requestBrowserPermission(): Promise<boolean> {

View File

@@ -574,8 +574,6 @@ export interface Player {
diplomaticReports?: DiplomaticReport[] // 外交变化报告
// 新手引导字段
tutorialProgress?: TutorialProgress // 新手引导进度
// 通知设置
notificationSettings?: NotificationSettings
}
export interface NotificationSettings {

View File

@@ -103,16 +103,16 @@
<h3 class="font-medium">{{ t('settings.browserNotifications') }}</h3>
<p class="text-sm text-muted-foreground">{{ t('settings.browserPermission') }}</p>
</div>
<Switch :checked="gameStore.player.notificationSettings?.browser" @update:checked="handleBrowserSwitch" />
<Switch :checked="gameStore.notificationSettings?.browser" @update:checked="handleBrowserSwitch" />
</div>
<!-- 页面聚焦时不发送 -->
<div class="flex items-center justify-between pl-4 border-l-2" :class="{ 'opacity-50 pointer-events-none': !gameStore.player.notificationSettings?.browser }">
<div class="flex items-center justify-between pl-4 border-l-2" :class="{ 'opacity-50 pointer-events-none': !gameStore.notificationSettings?.browser }">
<Label class="font-normal">{{ t('settings.suppressInFocus') }}</Label>
<Switch
:checked="gameStore.player.notificationSettings?.suppressInFocus"
:checked="gameStore.notificationSettings?.suppressInFocus"
@update:checked="updateSuppressSetting"
:disabled="!gameStore.player.notificationSettings?.browser"
:disabled="!gameStore.notificationSettings?.browser"
/>
</div>
</div>
@@ -124,7 +124,7 @@
<p class="text-sm text-muted-foreground">{{ t('settings.inAppNotificationsDesc') || t('settings.inAppNotifications') }}</p>
</div>
<Switch
:checked="gameStore.player.notificationSettings?.inApp"
:checked="gameStore.notificationSettings?.inApp"
@update:checked="(val: boolean) => updateInAppSetting(val)"
/>
</div>
@@ -151,7 +151,7 @@
<div class="flex items-center justify-between">
<Label class="font-normal cursor-pointer" @click="toggleType('construction')">{{ t('settings.constructionComplete') }}</Label>
<Switch
:checked="gameStore.player.notificationSettings?.types.construction"
:checked="gameStore.notificationSettings?.types.construction"
@update:checked="(val: boolean) => updateTypeSetting('construction', val)"
/>
</div>
@@ -159,7 +159,7 @@
<div class="flex items-center justify-between">
<Label class="font-normal cursor-pointer" @click="toggleType('research')">{{ t('settings.researchComplete') }}</Label>
<Switch
:checked="gameStore.player.notificationSettings?.types.research"
:checked="gameStore.notificationSettings?.types.research"
@update:checked="(val: boolean) => updateTypeSetting('research', val)"
/>
</div>
@@ -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
}
}