fix: 应用启动即绑定用户数据库(修复刷新/登录后数据库未就绪的白屏)

This commit is contained in:
root
2026-10-16 14:32:38 +08:00
parent 8a0fde507f
commit 3f7b072ac6
8 changed files with 31 additions and 18 deletions
+7
View File
@@ -67,8 +67,13 @@ export function clearCloudCreds(): void {
localStorage.removeItem(CREDS_KEY)
}
let openedFor: string | null = null
export function openUserDatabase(userId: string): void {
if (openedFor === userId && db) return
if (db) unbindDatabase()
bindDatabase(new WorklogDB(LEGACY_DB_NAME + '_' + userId))
openedFor = userId
}
export async function createUser(username: string, password: string, migrateLegacy: boolean): Promise<Session> {
@@ -110,6 +115,7 @@ export async function login(username: string, password: string): Promise<Session
export async function logoutUser(): Promise<void> {
lockVault()
unbindDatabase()
openedFor = null
clearSession()
clearCloudCreds()
}
@@ -132,6 +138,7 @@ export async function deleteCurrentUser(): Promise<void> {
if (!s) throw new Error('未登录')
lockVault()
unbindDatabase()
openedFor = null
await Dexie.delete(LEGACY_DB_NAME + '_' + s.userId)
await registry.user.delete(s.userId)
clearSession()