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

View File

@@ -41,27 +41,27 @@ export const useGameStore = defineStore('game', {
giftRejectedNotifications: [], giftRejectedNotifications: [],
points: 0, points: 0,
isGMEnabled: false, // 明确设置 GM 模式默认为 false isGMEnabled: false, // 明确设置 GM 模式默认为 false
lastVersionCheckTime: 0, // 最后一次检查版本的时间戳默认为0 lastVersionCheckTime: 0 // 最后一次检查版本的时间戳默认为0
notificationSettings: {
browser: false,
inApp: true,
suppressInFocus: false,
types: {
construction: true,
research: true
}
}
} as Player, } as Player,
currentPlanetId: '', currentPlanetId: '',
isDark: '', isDark: '',
locale: 'zh-CN' as Locale locale: 'zh-CN' as Locale,
notificationSettings: {
browser: false,
inApp: true,
suppressInFocus: false,
types: {
construction: true,
research: true
}
}
}), }),
actions: { actions: {
async requestBrowserPermission(): Promise<boolean> { async requestBrowserPermission(): Promise<boolean> {
if (!('Notification' in window)) return false if (!('Notification' in window)) return false
if (Notification.permission === 'granted') return true if (Notification.permission === 'granted') return true
const permission = await Notification.requestPermission() const permission = await Notification.requestPermission()
return permission === 'granted' return permission === 'granted'
} }

View File

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

View File

@@ -103,16 +103,16 @@
<h3 class="font-medium">{{ t('settings.browserNotifications') }}</h3> <h3 class="font-medium">{{ t('settings.browserNotifications') }}</h3>
<p class="text-sm text-muted-foreground">{{ t('settings.browserPermission') }}</p> <p class="text-sm text-muted-foreground">{{ t('settings.browserPermission') }}</p>
</div> </div>
<Switch :checked="gameStore.player.notificationSettings?.browser" @update:checked="handleBrowserSwitch" /> <Switch :checked="gameStore.notificationSettings?.browser" @update:checked="handleBrowserSwitch" />
</div> </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> <Label class="font-normal">{{ t('settings.suppressInFocus') }}</Label>
<Switch <Switch
:checked="gameStore.player.notificationSettings?.suppressInFocus" :checked="gameStore.notificationSettings?.suppressInFocus"
@update:checked="updateSuppressSetting" @update:checked="updateSuppressSetting"
:disabled="!gameStore.player.notificationSettings?.browser" :disabled="!gameStore.notificationSettings?.browser"
/> />
</div> </div>
</div> </div>
@@ -124,7 +124,7 @@
<p class="text-sm text-muted-foreground">{{ t('settings.inAppNotificationsDesc') || t('settings.inAppNotifications') }}</p> <p class="text-sm text-muted-foreground">{{ t('settings.inAppNotificationsDesc') || t('settings.inAppNotifications') }}</p>
</div> </div>
<Switch <Switch
:checked="gameStore.player.notificationSettings?.inApp" :checked="gameStore.notificationSettings?.inApp"
@update:checked="(val: boolean) => updateInAppSetting(val)" @update:checked="(val: boolean) => updateInAppSetting(val)"
/> />
</div> </div>
@@ -151,7 +151,7 @@
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<Label class="font-normal cursor-pointer" @click="toggleType('construction')">{{ t('settings.constructionComplete') }}</Label> <Label class="font-normal cursor-pointer" @click="toggleType('construction')">{{ t('settings.constructionComplete') }}</Label>
<Switch <Switch
:checked="gameStore.player.notificationSettings?.types.construction" :checked="gameStore.notificationSettings?.types.construction"
@update:checked="(val: boolean) => updateTypeSetting('construction', val)" @update:checked="(val: boolean) => updateTypeSetting('construction', val)"
/> />
</div> </div>
@@ -159,7 +159,7 @@
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<Label class="font-normal cursor-pointer" @click="toggleType('research')">{{ t('settings.researchComplete') }}</Label> <Label class="font-normal cursor-pointer" @click="toggleType('research')">{{ t('settings.researchComplete') }}</Label>
<Switch <Switch
:checked="gameStore.player.notificationSettings?.types.research" :checked="gameStore.notificationSettings?.types.research"
@update:checked="(val: boolean) => updateTypeSetting('research', val)" @update:checked="(val: boolean) => updateTypeSetting('research', val)"
/> />
</div> </div>
@@ -279,8 +279,8 @@
const isTypesExpanded = ref(false) const isTypesExpanded = ref(false)
// Ensure notification settings exist // Ensure notification settings exist
if (!gameStore.player.notificationSettings) { if (!gameStore.notificationSettings) {
gameStore.player.notificationSettings = { gameStore.notificationSettings = {
browser: false, browser: false,
inApp: true, inApp: true,
suppressInFocus: false, suppressInFocus: false,
@@ -289,7 +289,7 @@
} }
const areMainSwitchesOff = computed(() => { const areMainSwitchesOff = computed(() => {
const s = gameStore.player.notificationSettings const s = gameStore.notificationSettings
return !s?.browser && !s?.inApp return !s?.browser && !s?.inApp
}) })
@@ -299,44 +299,44 @@
// }) // })
const updateInAppSetting = (val: boolean) => { const updateInAppSetting = (val: boolean) => {
if (gameStore.player.notificationSettings) { if (gameStore.notificationSettings) {
gameStore.player.notificationSettings.inApp = val gameStore.notificationSettings.inApp = val
} }
} }
const updateSuppressSetting = (val: boolean) => { const updateSuppressSetting = (val: boolean) => {
if (gameStore.player.notificationSettings) { if (gameStore.notificationSettings) {
gameStore.player.notificationSettings.suppressInFocus = val gameStore.notificationSettings.suppressInFocus = val
} }
} }
const updateTypeSetting = (key: string, val: boolean) => { const updateTypeSetting = (key: string, val: boolean) => {
if (gameStore.player.notificationSettings) { if (gameStore.notificationSettings) {
gameStore.player.notificationSettings.types[key] = val gameStore.notificationSettings.types[key] = val
} }
} }
const toggleType = (key: string) => { const toggleType = (key: string) => {
if (gameStore.player.notificationSettings) { if (gameStore.notificationSettings) {
const current = gameStore.player.notificationSettings.types[key] const current = gameStore.notificationSettings.types[key]
gameStore.player.notificationSettings.types[key] = !current gameStore.notificationSettings.types[key] = !current
} }
} }
const handleBrowserSwitch = async (checked: boolean) => { const handleBrowserSwitch = async (checked: boolean) => {
if (!gameStore.player.notificationSettings) return if (!gameStore.notificationSettings) return
if (checked) { if (checked) {
const granted = await gameStore.requestBrowserPermission() const granted = await gameStore.requestBrowserPermission()
if (granted) { if (granted) {
gameStore.player.notificationSettings.browser = true gameStore.notificationSettings.browser = true
toast.success(t('settings.permissionGranted')) toast.success(t('settings.permissionGranted'))
} else { } else {
gameStore.player.notificationSettings.browser = false gameStore.notificationSettings.browser = false
toast.error(t('settings.permissionDenied')) toast.error(t('settings.permissionDenied'))
} }
} else { } else {
gameStore.player.notificationSettings.browser = false gameStore.notificationSettings.browser = false
} }
} }