fix: 打卡后即时推送 + 设置页展示自动同步失败原因

This commit is contained in:
root
2026-10-16 15:09:03 +08:00
parent aaf8ea602c
commit 04ae06ec1c
8 changed files with 50 additions and 34 deletions
+10 -1
View File
@@ -13,7 +13,7 @@ import { downloadCsv } from '../lib/csv'
import { hhmm, parseDateStr, todayStr } from '../lib/date'
import { computeDay } from '../domain/attendance'
import { changeLoginPassword, deleteCurrentUser, getSession } from '../db/auth'
import { ensureCloudBinding, getSyncBase, getSyncLastTime, syncWithStoredConfig, type SyncResult } from '../sync/engine'
import { ensureCloudBinding, getSyncBase, getSyncLastTime, syncWithStoredConfig, syncLastError, enableRealtimeSync, stopRealtime, type SyncResult } from '../sync/engine'
import { getCloudCreds } from '../db/auth'
import { showToast } from '../lib/toast'
@@ -41,6 +41,7 @@ const syncBase = ref('')
const cloudUser = ref('')
const syncStatus = ref('')
const syncError = ref('')
const autoSyncErr = ref('')
const syncing = ref(false)
const lastSync = ref('')
@@ -48,8 +49,12 @@ async function loadSyncInfo() {
syncBase.value = await getSyncBase()
cloudUser.value = getCloudCreds()?.username || ''
lastSync.value = await getSyncLastTime()
loadError.value = syncLastError.value
const conf = await isSyncConfigured()
autoOn.value = conf
}
async function saveSyncConfig() {
await setSetting('sync_base_url', syncBase.value.trim())
showToast('同步地址已保存')
@@ -68,12 +73,14 @@ async function rebindCloud() {
async function doSyncNow() {
if (syncing.value) return
syncError.value = ''
autoSyncErr.value = syncLastError.value
syncing.value = true
try {
await saveSyncConfig()
const result: SyncResult = await syncWithStoredConfig()
lastSync.value = result.at
syncStatus.value = '推送 ' + result.pushed + ' 条 · 拉取 ' + result.pulled + ' 条 · 删除 ' + result.removed + ' 条'
autoSyncErr.value = ''
showToast('同步完成')
} catch (e) {
syncError.value = e instanceof Error ? e.message : '同步失败'
@@ -357,6 +364,8 @@ async function doImport() {
</div>
<div v-if="syncStatus" class="muted acc-line">上次同步:{{ lastSync || '--' }} · {{ syncStatus }}</div>
<div v-if="syncError" class="form-error">{{ syncError }}</div>
<div v-if="autoSyncErr" class="form-error">最近自动同步失败:{{ autoSyncErr }}</div>
<div v-if="autoSyncErr" class="form-error">最近自动同步失败:{{ autoSyncErr }}(可点「立即同步」重试)</div>
</div>
<div class="card section">