mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
feat: 支持Android返回键退出确认与多语言提示
新增Android端返回键退出确认弹窗,防止误触直接退出应用。各语言包补充退出确认标题与提示语,提升多语言体验。依赖新增@capacitor/app,样式与主题适配同步优化。
This commit is contained in:
38
src/App.vue
38
src/App.vue
@@ -428,6 +428,20 @@
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</SidebarProvider>
|
||||
|
||||
<!-- Android 退出确认对话框 -->
|
||||
<AlertDialog v-model:open="exitDialogOpen">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{{ t('common.exitConfirmTitle') }}</AlertDialogTitle>
|
||||
<AlertDialogDescription>{{ t('common.exitConfirmMessage') }}</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{{ t('common.cancel') }}</AlertDialogCancel>
|
||||
<AlertDialogAction @click="exitApp">{{ t('common.confirm') }}</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -528,6 +542,8 @@
|
||||
import { checkLatestVersion } from '@/utils/versionCheck'
|
||||
import { StarsBackground } from '@/components/ui/bg-stars'
|
||||
import { ParticlesBg } from '@/components/ui/particles-bg'
|
||||
import { App as CapacitorApp } from '@capacitor/app'
|
||||
import { Capacitor } from '@capacitor/core'
|
||||
|
||||
// 执行数据迁移(在 store 初始化之前)
|
||||
migrateGameData()
|
||||
@@ -570,6 +586,8 @@
|
||||
const renameDialogOpen = ref(false)
|
||||
const renamingPlanetId = ref<string | null>(null)
|
||||
const newPlanetName = ref('')
|
||||
// Android 退出确认对话框状态
|
||||
const exitDialogOpen = ref(false)
|
||||
// 功能解锁要求配置
|
||||
const featureRequirements: Record<string, { building: BuildingType; level: number }> = {
|
||||
'/research': { building: BuildingType.ResearchLab, level: 1 },
|
||||
@@ -2072,6 +2090,17 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
// Android 返回键退出确认
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
CapacitorApp.addListener('backButton', ({ canGoBack }) => {
|
||||
if (canGoBack) {
|
||||
router.back()
|
||||
} else {
|
||||
exitDialogOpen.value = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 启动版本检查定时器(每5分钟被动检查一次)
|
||||
versionCheckInterval.value = setInterval(async () => {
|
||||
const versionInfo = await checkLatestVersion(gameStore.player.lastVersionCheckTime || 0, (time: number) => {
|
||||
@@ -2107,7 +2136,16 @@
|
||||
// 移除队列取消事件监听
|
||||
window.removeEventListener('cancel-build', handleCancelBuildEvent as EventListener)
|
||||
window.removeEventListener('cancel-research', handleCancelResearchEvent as EventListener)
|
||||
// 移除 Android 返回键监听
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
CapacitorApp.removeAllListeners()
|
||||
}
|
||||
})
|
||||
|
||||
// Android 退出应用
|
||||
const exitApp = () => {
|
||||
CapacitorApp.exitApp()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -46,7 +46,9 @@ export default {
|
||||
current: 'Aktuell',
|
||||
level: 'Stufe',
|
||||
gmModeActivated: 'GM-Modus aktiviert! Überprüfen Sie das Navigationsmenü.',
|
||||
view: 'Anzeigen'
|
||||
view: 'Anzeigen',
|
||||
exitConfirmTitle: 'Spiel beenden',
|
||||
exitConfirmMessage: 'Möchten Sie das Spiel wirklich beenden? Ihr Fortschritt wird automatisch gespeichert.'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: 'Anforderungen nicht erfüllt',
|
||||
|
||||
@@ -45,7 +45,9 @@ export default {
|
||||
current: 'Current',
|
||||
level: 'Level',
|
||||
gmModeActivated: 'GM Mode Activated! Check the navigation menu.',
|
||||
view: 'View'
|
||||
view: 'View',
|
||||
exitConfirmTitle: 'Exit Game',
|
||||
exitConfirmMessage: 'Are you sure you want to exit? Your progress is saved automatically.'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: 'Requirements not met',
|
||||
|
||||
@@ -46,7 +46,9 @@ export default {
|
||||
current: '現在',
|
||||
level: 'レベル',
|
||||
gmModeActivated: 'GMモードが有効になりました!ナビゲーションメニューをご確認ください。',
|
||||
view: '表示'
|
||||
view: '表示',
|
||||
exitConfirmTitle: 'ゲーム終了',
|
||||
exitConfirmMessage: 'ゲームを終了しますか?進行状況は自動的に保存されます。'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: '前提条件を満たしていません',
|
||||
|
||||
@@ -46,7 +46,9 @@ export default {
|
||||
current: '현재',
|
||||
level: '레벨',
|
||||
gmModeActivated: 'GM 모드가 활성화되었습니다! 탐색 메뉴를 확인하세요.',
|
||||
view: '보기'
|
||||
view: '보기',
|
||||
exitConfirmTitle: '게임 종료',
|
||||
exitConfirmMessage: '게임을 종료하시겠습니까? 진행 상황은 자동으로 저장됩니다.'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: '전제 조건 미충족',
|
||||
|
||||
@@ -46,7 +46,9 @@ export default {
|
||||
current: 'Текущий',
|
||||
level: 'Уровень',
|
||||
gmModeActivated: 'Режим GM активирован! Проверьте навигационное меню.',
|
||||
view: 'Просмотр'
|
||||
view: 'Просмотр',
|
||||
exitConfirmTitle: 'Выйти из игры',
|
||||
exitConfirmMessage: 'Вы уверены, что хотите выйти? Прогресс сохраняется автоматически.'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: 'Требования не выполнены',
|
||||
|
||||
@@ -45,7 +45,9 @@ export default {
|
||||
current: '当前',
|
||||
level: '等级',
|
||||
gmModeActivated: 'GM 模式已激活!请查看导航菜单。',
|
||||
view: '查看'
|
||||
view: '查看',
|
||||
exitConfirmTitle: '退出游戏',
|
||||
exitConfirmMessage: '确定要退出游戏吗?游戏进度会自动保存。'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: '不满足前置条件',
|
||||
|
||||
@@ -46,7 +46,9 @@ export default {
|
||||
current: '當前',
|
||||
level: '等級',
|
||||
gmModeActivated: 'GM 模式已啟用!請查看導航選單。',
|
||||
view: '查看'
|
||||
view: '查看',
|
||||
exitConfirmTitle: '退出遊戲',
|
||||
exitConfirmMessage: '確定要退出遊戲嗎?遊戲進度會自動儲存。'
|
||||
},
|
||||
errors: {
|
||||
requirementsNotMet: '不滿足前置條件',
|
||||
|
||||
@@ -126,11 +126,6 @@
|
||||
line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
/* Android/Capacitor 安全区域适配 - 额外增加 8px 避免太靠近状态栏 */
|
||||
padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
|
||||
padding-bottom: env(safe-area-inset-bottom, 0);
|
||||
padding-left: env(safe-area-inset-left, 0);
|
||||
padding-right: env(safe-area-inset-right, 0);
|
||||
}
|
||||
|
||||
/* 平滑过渡 */
|
||||
|
||||
Reference in New Issue
Block a user