Skip to content

Commit fba5f09

Browse files
committed
fix build error
1 parent 59bf78d commit fba5f09

File tree

3 files changed

+169
-130
lines changed

3 files changed

+169
-130
lines changed

apps/web/src/components/editor/DocumentStorageDialog.vue

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import { toTypedSchema } from '@vee-validate/yup'
33
import { Field, Form } from 'vee-validate'
44
import * as yup from 'yup'
5-
import { documentStorage } from '@/utils/documentStorage'
6-
import { store } from '@/utils'
75
import { usePostStore } from '@/stores/post'
6+
import { store } from '@/utils'
7+
import { documentStorage } from '@/utils/documentStorage'
88
9-
const emit = defineEmits([`close`])
109
const isOpen = defineModel<boolean>(`open`, { default: false })
1110
1211
const postStore = usePostStore()
@@ -95,14 +94,8 @@ async function changeDocStorage() {
9594
}
9695
9796
// 确认切换
98-
const confirmed = await new Promise((resolve) => {
99-
if (window.confirm(`切换存储平台将同步当前数据到新平台,是否继续?`)) {
100-
resolve(true)
101-
}
102-
else {
103-
resolve(false)
104-
}
105-
})
97+
// eslint-disable-next-line no-alert
98+
const confirmed = window.confirm(`切换存储平台将同步当前数据到新平台,是否继续?`)
10699
107100
if (!confirmed) {
108101
// 回滚选择
@@ -170,7 +163,7 @@ async function manualSync() {
170163
// 同步文档和配置
171164
await documentStorage.saveDocuments(currentDocuments)
172165
await documentStorage.saveCurrentDocumentId(currentId)
173-
166+
174167
if (config) {
175168
await documentStorage.saveProjectConfig(config)
176169
toast.success(`文档和配置已同步到云端`)
@@ -194,14 +187,8 @@ async function loadFromCloud() {
194187
return
195188
}
196189
197-
const confirmed = await new Promise((resolve) => {
198-
if (window.confirm(`从云端加载将覆盖本地所有数据(包括文档和配置),是否继续?`)) {
199-
resolve(true)
200-
}
201-
else {
202-
resolve(false)
203-
}
204-
})
190+
// eslint-disable-next-line no-alert
191+
const confirmed = window.confirm(`从云端加载将覆盖本地所有数据(包括文档和配置),是否继续?`)
205192
206193
if (!confirmed) {
207194
return
@@ -226,7 +213,7 @@ async function loadFromCloud() {
226213
const localEngine = new (await import('@/utils/documentStorage')).LocalStorageDocumentEngine()
227214
await localEngine.saveProjectConfig(result.config)
228215
console.log('配置已保存到 localStorage')
229-
216+
230217
toast.success(`文档和配置已从云端加载,刷新页面以应用配置`)
231218
}
232219
else {
@@ -323,7 +310,7 @@ onMounted(async () => {
323310
</Alert>
324311

325312
<div v-if="docStorageType !== 'localStorage'" class="flex gap-2">
326-
<Button @click="testConnection" :disabled="isSyncing">
313+
<Button :disabled="isSyncing" @click="testConnection">
327314
测试连接
328315
</Button>
329316
<Badge v-if="connectionStatus === true" variant="success">
@@ -484,7 +471,7 @@ onMounted(async () => {
484471
</div>
485472

486473
<div class="flex flex-col gap-2">
487-
<Button @click="manualSync" :disabled="isSyncing || docStorageType === 'localStorage'">
474+
<Button :disabled="isSyncing || docStorageType === 'localStorage'" @click="manualSync">
488475
<template v-if="isSyncing">
489476
同步中...
490477
</template>
@@ -493,7 +480,7 @@ onMounted(async () => {
493480
</template>
494481
</Button>
495482

496-
<Button variant="outline" @click="loadFromCloud" :disabled="isSyncing || docStorageType === 'localStorage'">
483+
<Button variant="outline" :disabled="isSyncing || docStorageType === 'localStorage'" @click="loadFromCloud">
497484
从云端加载
498485
</Button>
499486
</div>
@@ -504,7 +491,7 @@ onMounted(async () => {
504491
</AlertDescription>
505492
</Alert>
506493

507-
<Alert variant="warning">
494+
<Alert>
508495
<AlertDescription>
509496
<strong>注意:</strong>从云端加载会覆盖本地所有文档数据,请谨慎操作!
510497
</AlertDescription>

apps/web/src/stores/post.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import type { DocumentData } from '@/utils/documentStorage'
12
import { v4 as uuid } from 'uuid'
23
import DEFAULT_CONTENT from '@/assets/example/markdown.md?raw'
3-
import { addPrefix, store } from '@/utils'
4+
import { store } from '@/utils'
45
import { documentStorage } from '@/utils/documentStorage'
5-
import type { DocumentData } from '@/utils/documentStorage'
66

77
/**
88
* Post 结构接口
@@ -52,6 +52,22 @@ export const usePostStore = defineStore(`post`, () => {
5252
// 预备弃用的旧字段(用于迁移)
5353
const editorContent = store.reactive(`__editor_content`, DEFAULT_CONTENT)
5454

55+
// 保存到存储
56+
const saveToStorage = async () => {
57+
// 只有在数据加载完成后才保存,避免覆盖云端数据
58+
if (!isLoaded.value) {
59+
return
60+
}
61+
62+
try {
63+
await documentStorage.saveDocuments(posts.value as DocumentData[])
64+
await documentStorage.saveCurrentDocumentId(currentPostId.value)
65+
}
66+
catch (error) {
67+
console.error(`Failed to save to storage:`, error)
68+
}
69+
}
70+
5571
// 从存储加载数据
5672
const loadFromStorage = async () => {
5773
// 避免重复加载
@@ -63,7 +79,7 @@ export const usePostStore = defineStore(`post`, () => {
6379

6480
try {
6581
await documentStorage.init()
66-
82+
6783
const storedDocuments = await documentStorage.getDocuments()
6884
const storedCurrentId = await documentStorage.getCurrentDocumentId()
6985

@@ -104,22 +120,6 @@ export const usePostStore = defineStore(`post`, () => {
104120
}
105121
}
106122

107-
// 保存到存储
108-
const saveToStorage = async () => {
109-
// 只有在数据加载完成后才保存,避免覆盖云端数据
110-
if (!isLoaded.value) {
111-
return
112-
}
113-
114-
try {
115-
await documentStorage.saveDocuments(posts.value as DocumentData[])
116-
await documentStorage.saveCurrentDocumentId(currentPostId.value)
117-
}
118-
catch (error) {
119-
console.error(`Failed to save to storage:`, error)
120-
}
121-
}
122-
123123
// 监听数据变化,自动保存
124124
watch(posts, () => {
125125
saveToStorage()

0 commit comments

Comments
 (0)