architecture: 数据唯一权威迁至服务器——本地降级为实时缓存,写后即时推送+快照重建;账号登录转为云端原生(新增 /api/auth/password、/api/auth/delete、每日自动备份)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { createUser, legacyDataExists, login, type Session } from '../db/auth'
|
||||
import { createUser, login, type Session } from '../db/auth'
|
||||
|
||||
const emit = defineEmits<{ (e: 'login', s: Session): void }>()
|
||||
|
||||
@@ -9,15 +9,9 @@ const mode = ref<'login' | 'create'>('login')
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const password2 = ref('')
|
||||
const migrate = ref(true)
|
||||
const legacyExists = ref(false)
|
||||
const error = ref('')
|
||||
const busy = ref(false)
|
||||
|
||||
onMounted(async () => {
|
||||
legacyExists.value = await legacyDataExists()
|
||||
})
|
||||
|
||||
function switchMode(m: 'login' | 'create') {
|
||||
mode.value = m
|
||||
error.value = ''
|
||||
@@ -43,7 +37,7 @@ async function submit() {
|
||||
busy.value = false
|
||||
return
|
||||
}
|
||||
s = await createUser(username.value, password.value, migrate.value)
|
||||
s = await createUser(username.value, password.value)
|
||||
}
|
||||
emit('login', s)
|
||||
} catch (e) {
|
||||
@@ -60,7 +54,7 @@ async function submit() {
|
||||
<div class="brand-icon"><Icon name="calendar" :size="22" /></div>
|
||||
<div class="login-title">实习工作日志</div>
|
||||
<div class="muted login-sub">打卡 · 记录 · 总结 · 备忘录 · 密码库</div>
|
||||
<div class="muted login-sub">每位用户独立数据库,数据彼此隔离并保存在本机</div>
|
||||
<div class="muted login-sub">数据保存在云端服务器,所有设备登录同一账号即可实时同步</div>
|
||||
</div>
|
||||
<div class="seg">
|
||||
<button class="seg-btn" :class="{ active: mode === 'login' }" @click="switchMode('login')">登录</button>
|
||||
@@ -69,16 +63,12 @@ async function submit() {
|
||||
<input class="input" v-model="username" placeholder="用户名(2 到 20 个字符)" @keydown.enter="submit" />
|
||||
<input type="password" class="input" v-model="password" :placeholder="mode === 'login' ? '登录密码' : '设置登录密码(至少 6 位)'" @keydown.enter="submit" />
|
||||
<input v-if="mode === 'create'" type="password" class="input" v-model="password2" placeholder="再次输入密码" @keydown.enter="submit" />
|
||||
<label v-if="mode === 'create' && legacyExists" class="mig-row">
|
||||
<input type="checkbox" v-model="migrate" />
|
||||
<span>导入本机原有工作日志数据到此用户(原数据保留不删除)</span>
|
||||
</label>
|
||||
<div v-if="error" class="form-error">{{ error }}</div>
|
||||
<button class="btn btn-primary login-btn" :disabled="busy" @click="submit">
|
||||
{{ mode === 'login' ? '登录' : '创建并进入' }}
|
||||
</button>
|
||||
<div class="muted login-note">
|
||||
登录后自动开启云端同步(密码会保存在本机用于云同步);系统只保存密码哈希,忘记密码将无法访问该用户数据
|
||||
登录密码仅服务器保存哈希;本机保存加密的自动登录凭据,登录后无需重复输入
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +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 { setSyncBaseOverride } from '../lib/server'
|
||||
import { ensureCloudBinding, getSyncBase, getSyncLastTime, isSyncConfigured, syncWithStoredConfig, syncLastError, type SyncResult } from '../sync/engine'
|
||||
import { getCloudCreds } from '../db/auth'
|
||||
import { showToast } from '../lib/toast'
|
||||
@@ -55,7 +56,7 @@ watch(syncLastError, v => { autoSyncErr.value = v })
|
||||
|
||||
|
||||
async function saveSyncConfig() {
|
||||
await setSetting('sync_base_url', syncBase.value.trim())
|
||||
await setSyncBaseOverride(syncBase.value.trim())
|
||||
showToast('同步地址已保存')
|
||||
}
|
||||
|
||||
@@ -351,7 +352,7 @@ async function doImport() {
|
||||
|
||||
<div class="card section">
|
||||
<div class="section-title">多端数据同步</div>
|
||||
<div class="muted acc-line">云端账号:{{ cloudUser || '未绑定' }} · 登录即自动绑定并同步(变更实时推送 + 每 5 分钟兜底);密码库以密文同步,主密码永不出本机</div>
|
||||
<div class="muted acc-line">云端账号:{{ cloudUser || '未绑定' }} · 数据仅保存在服务器,本机只是实时缓存(变更 ~3 秒推上云端 + 其他端秒级自动刷新);密码库同步密文,主密码永不出本机</div>
|
||||
<div class="rule-item">
|
||||
<label>同步服务地址(默认即可)</label>
|
||||
<input class="input" v-model="syncBase" placeholder="https://daywk.linyux.cn" />
|
||||
@@ -416,7 +417,7 @@ async function doImport() {
|
||||
<ConfirmDialog
|
||||
:open="deleteAccConfirm"
|
||||
title="删除用户确认"
|
||||
:message="'将永久删除用户「' + username + '」及其全部数据:工作日志、考勤、备忘录、账号密码库都将被清除,且不可恢复。请确认。'"
|
||||
:message="'将永久删除云端账号「' + username + '」及其服务器上的全部数据:工作日志、考勤、备忘录、账号密码库都将被清除,任何设备都无法再取回,且不可恢复。请确认。'"
|
||||
confirm-text="永久删除" danger
|
||||
@cancel="deleteAccConfirm = false"
|
||||
@confirm="doDeleteAccount"
|
||||
|
||||
Reference in New Issue
Block a user