mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
优化webdav相关
This commit is contained in:
@@ -81,6 +81,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
import { useI18n } from '@/composables/useI18n'
|
import { useI18n } from '@/composables/useI18n'
|
||||||
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -95,13 +96,11 @@ import { Label } from '@/components/ui/label'
|
|||||||
import { Loader2 } from 'lucide-vue-next'
|
import { Loader2 } from 'lucide-vue-next'
|
||||||
import {
|
import {
|
||||||
type WebDAVConfig,
|
type WebDAVConfig,
|
||||||
getWebDAVConfig,
|
|
||||||
saveWebDAVConfig,
|
|
||||||
clearWebDAVConfig,
|
|
||||||
testWebDAVConnection
|
testWebDAVConnection
|
||||||
} from '@/services/webdavService'
|
} from '@/services/webdavService'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const gameStore = useGameStore()
|
||||||
|
|
||||||
const isOpen = defineModel<boolean>('open', { default: false })
|
const isOpen = defineModel<boolean>('open', { default: false })
|
||||||
|
|
||||||
@@ -130,7 +129,7 @@ const isConfigValid = computed(() => {
|
|||||||
// 加载已保存的配置
|
// 加载已保存的配置
|
||||||
watch(isOpen, (open) => {
|
watch(isOpen, (open) => {
|
||||||
if (open) {
|
if (open) {
|
||||||
const saved = getWebDAVConfig()
|
const saved = gameStore.webdavConfig
|
||||||
if (saved) {
|
if (saved) {
|
||||||
config.value = { ...saved }
|
config.value = { ...saved }
|
||||||
hasExistingConfig.value = true
|
hasExistingConfig.value = true
|
||||||
@@ -163,14 +162,14 @@ const handleTest = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
saveWebDAVConfig(config.value)
|
gameStore.webdavConfig = { ...config.value }
|
||||||
hasExistingConfig.value = true
|
hasExistingConfig.value = true
|
||||||
emit('saved', config.value)
|
emit('saved', config.value)
|
||||||
isOpen.value = false
|
isOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClear = () => {
|
const handleClear = () => {
|
||||||
clearWebDAVConfig()
|
gameStore.webdavConfig = null
|
||||||
hasExistingConfig.value = false
|
hasExistingConfig.value = false
|
||||||
config.value = {
|
config.value = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* WebDAV 同步服务
|
* WebDAV 同步服务
|
||||||
* 支持将存档上传到 WebDAV 服务器(如坚果云、Nextcloud、NAS等)
|
* 支持将存档上传到 WebDAV 服务器(如坚果云、Nextcloud、NAS等)
|
||||||
|
* 注意:WebDAV 配置存储在 gameStore.webdavConfig 中,与用户数据一起持久化
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface WebDAVConfig {
|
import type { WebDAVConfig } from '@/types/game'
|
||||||
serverUrl: string // WebDAV 服务器地址
|
|
||||||
username: string // 用户名
|
// 重新导出类型以保持向后兼容
|
||||||
password: string // 密码或应用专用密码
|
export type { WebDAVConfig }
|
||||||
basePath: string // 存档存放路径
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebDAVFile {
|
export interface WebDAVFile {
|
||||||
name: string
|
name: string
|
||||||
@@ -61,31 +60,6 @@ export interface WebDAVResult {
|
|||||||
files?: WebDAVFile[]
|
files?: WebDAVFile[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const STORAGE_KEY = 'ogame-webdav-config'
|
|
||||||
|
|
||||||
// 获取保存的 WebDAV 配置
|
|
||||||
export const getWebDAVConfig = (): WebDAVConfig | null => {
|
|
||||||
try {
|
|
||||||
const saved = localStorage.getItem(STORAGE_KEY)
|
|
||||||
if (saved) {
|
|
||||||
return JSON.parse(saved)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load WebDAV config:', e)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存 WebDAV 配置
|
|
||||||
export const saveWebDAVConfig = (config: WebDAVConfig): void => {
|
|
||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(config))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清除 WebDAV 配置
|
|
||||||
export const clearWebDAVConfig = (): void => {
|
|
||||||
localStorage.removeItem(STORAGE_KEY)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建 Authorization header
|
// 构建 Authorization header
|
||||||
const buildAuthHeader = (config: WebDAVConfig): string => {
|
const buildAuthHeader = (config: WebDAVConfig): string => {
|
||||||
const credentials = btoa(`${config.username}:${config.password}`)
|
const credentials = btoa(`${config.username}:${config.password}`)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import type {
|
|||||||
IncomingFleetAlert,
|
IncomingFleetAlert,
|
||||||
MissileAttack,
|
MissileAttack,
|
||||||
AchievementStats,
|
AchievementStats,
|
||||||
AchievementProgress
|
AchievementProgress,
|
||||||
|
WebDAVConfig
|
||||||
} from '@/types/game'
|
} from '@/types/game'
|
||||||
import { TechnologyType, OfficerType } from '@/types/game'
|
import { TechnologyType, OfficerType } from '@/types/game'
|
||||||
import { initializeAchievementStats, initializeAchievements } from '@/logic/achievementLogic'
|
import { initializeAchievementStats, initializeAchievements } from '@/logic/achievementLogic'
|
||||||
@@ -61,7 +62,8 @@ export const useGameStore = defineStore('game', {
|
|||||||
research: true,
|
research: true,
|
||||||
unlock: true
|
unlock: true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
webdavConfig: null as WebDAVConfig | null
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async requestBrowserPermission(): Promise<boolean> {
|
async requestBrowserPermission(): Promise<boolean> {
|
||||||
|
|||||||
@@ -1226,3 +1226,11 @@ export interface QuestNotification {
|
|||||||
rewards?: QuestReward
|
rewards?: QuestReward
|
||||||
read?: boolean
|
read?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebDAV 配置
|
||||||
|
export interface WebDAVConfig {
|
||||||
|
serverUrl: string // WebDAV 服务器地址
|
||||||
|
username: string // 用户名
|
||||||
|
password: string // 密码或应用专用密码
|
||||||
|
basePath: string // 存档存放路径
|
||||||
|
}
|
||||||
|
|||||||
@@ -334,7 +334,7 @@
|
|||||||
<PrivacyDialog v-model:open="showPrivacyDialog" />
|
<PrivacyDialog v-model:open="showPrivacyDialog" />
|
||||||
|
|
||||||
<!-- WebDAV 配置对话框 -->
|
<!-- WebDAV 配置对话框 -->
|
||||||
<WebDAVConfigDialog v-model:open="showWebDAVConfig" @saved="onWebDAVConfigSaved" />
|
<WebDAVConfigDialog v-model:open="showWebDAVConfig" />
|
||||||
|
|
||||||
<!-- WebDAV 文件列表对话框 -->
|
<!-- WebDAV 文件列表对话框 -->
|
||||||
<WebDAVFileListDialog v-model:open="showWebDAVFiles" :config="webdavConfig" @select="handleWebDAVDownload" />
|
<WebDAVFileListDialog v-model:open="showWebDAVFiles" :config="webdavConfig" @select="handleWebDAVDownload" />
|
||||||
@@ -389,12 +389,7 @@
|
|||||||
import WebDAVConfigDialog from '@/components/settings/WebDAVConfigDialog.vue'
|
import WebDAVConfigDialog from '@/components/settings/WebDAVConfigDialog.vue'
|
||||||
import WebDAVFileListDialog from '@/components/settings/WebDAVFileListDialog.vue'
|
import WebDAVFileListDialog from '@/components/settings/WebDAVFileListDialog.vue'
|
||||||
import { useHints } from '@/composables/useHints'
|
import { useHints } from '@/composables/useHints'
|
||||||
import {
|
import { uploadToWebDAV, downloadFromWebDAV } from '@/services/webdavService'
|
||||||
type WebDAVConfig,
|
|
||||||
getWebDAVConfig,
|
|
||||||
uploadToWebDAV,
|
|
||||||
downloadFromWebDAV
|
|
||||||
} from '@/services/webdavService'
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { hintsEnabled, setHintsEnabled, resetHints } = useHints()
|
const { hintsEnabled, setHintsEnabled, resetHints } = useHints()
|
||||||
@@ -415,7 +410,7 @@
|
|||||||
// WebDAV 相关状态
|
// WebDAV 相关状态
|
||||||
const showWebDAVConfig = ref(false)
|
const showWebDAVConfig = ref(false)
|
||||||
const showWebDAVFiles = ref(false)
|
const showWebDAVFiles = ref(false)
|
||||||
const webdavConfig = ref<WebDAVConfig | null>(getWebDAVConfig())
|
const webdavConfig = computed(() => gameStore.webdavConfig)
|
||||||
const isWebDAVUploading = ref(false)
|
const isWebDAVUploading = ref(false)
|
||||||
|
|
||||||
// 确保通知设置存在
|
// 确保通知设置存在
|
||||||
@@ -758,11 +753,6 @@
|
|||||||
gameStore.player.backgroundEnabled = val
|
gameStore.player.backgroundEnabled = val
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebDAV 配置保存回调
|
|
||||||
const onWebDAVConfigSaved = () => {
|
|
||||||
webdavConfig.value = getWebDAVConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WebDAV 上传
|
// WebDAV 上传
|
||||||
const handleWebDAVUpload = async () => {
|
const handleWebDAVUpload = async () => {
|
||||||
if (!webdavConfig.value) return
|
if (!webdavConfig.value) return
|
||||||
|
|||||||
Reference in New Issue
Block a user