mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
移出player
This commit is contained in:
@@ -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
|
||||
|
||||
// 检查主开关
|
||||
|
||||
@@ -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<boolean> {
|
||||
if (!('Notification' in window)) return false
|
||||
|
||||
|
||||
if (Notification.permission === 'granted') return true
|
||||
|
||||
|
||||
const permission = await Notification.requestPermission()
|
||||
return permission === 'granted'
|
||||
}
|
||||
|
||||
@@ -574,8 +574,6 @@ export interface Player {
|
||||
diplomaticReports?: DiplomaticReport[] // 外交变化报告
|
||||
// 新手引导字段
|
||||
tutorialProgress?: TutorialProgress // 新手引导进度
|
||||
// 通知设置
|
||||
notificationSettings?: NotificationSettings
|
||||
}
|
||||
|
||||
export interface NotificationSettings {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user