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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./web-BiiYhJWj.js","./index-DJcQg2vq.js","./index-vDZJrZrZ.css"])))=>i.map(i=>d[i]);
import{r as s,_ as i}from"./index-DJcQg2vq.js";var t;(function(e){e.Documents="DOCUMENTS",e.Data="DATA",e.Library="LIBRARY",e.Cache="CACHE",e.External="EXTERNAL",e.ExternalStorage="EXTERNAL_STORAGE"})(t||(t={}));var a;(function(e){e.UTF8="utf8",e.ASCII="ascii",e.UTF16="utf16"})(a||(a={}));const E=s("Filesystem",{web:()=>i(()=>import("./web-BiiYhJWj.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>new e.FilesystemWeb)});export{t as Directory,a as Encoding,E as Filesystem};
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./web-Cr7cLzMr.js","./index-D4g5kDSe.js","./index-B9eVtom_.css"])))=>i.map(i=>d[i]);
import{r as s,_ as i}from"./index-D4g5kDSe.js";var t;(function(e){e.Documents="DOCUMENTS",e.Data="DATA",e.Library="LIBRARY",e.Cache="CACHE",e.External="EXTERNAL",e.ExternalStorage="EXTERNAL_STORAGE"})(t||(t={}));var a;(function(e){e.UTF8="utf8",e.ASCII="ascii",e.UTF16="utf16"})(a||(a={}));const E=s("Filesystem",{web:()=>i(()=>import("./web-Cr7cLzMr.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>new e.FilesystemWeb)});export{t as Directory,a as Encoding,E as Filesystem};
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -8,8 +8,8 @@
<link rel="icon" href="./icons/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="./icons/icon-192.png" />
<title>实习工作日志</title>
<script type="module" crossorigin src="./assets/index-DJcQg2vq.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-vDZJrZrZ.css">
<script type="module" crossorigin src="./assets/index-D4g5kDSe.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-B9eVtom_.css">
</head>
<body>
<div id="app"></div>
+1
View File
@@ -24,6 +24,7 @@ const toasts = useToasts()
const session = ref<Session | null>(getSession())
async function onLogin(s: Session) {
session.value = s
openUserDatabase(s.userId)
location.hash = '#/calendar'
route.value = 'calendar'
await refreshClock()
+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()
+5
View File
@@ -2,6 +2,11 @@ import { createApp } from 'vue'
import App from './App.vue'
import './styles/tokens.css'
import { showFatalError } from './lib/errOverlay'
import { getSession, openUserDatabase } from './db/auth'
// 持久会话恢复:必须在任何视图挂载并读取数据之前绑定用户数据库
const restoredSession = getSession()
if (restoredSession) openUserDatabase(restoredSession.userId)
const app = createApp(App)