fix: 修复数据库回调异常

This commit is contained in:
blacktunes 2024-01-27 14:39:40 +08:00
parent 7cd7111fbf
commit ae8e315f14

View File

@ -84,6 +84,7 @@ export class IndexedDB {
console.log(`正在加${this.alias}数据库...`)
return new Promise<void>((resolve, reject) => {
this.cb = () => resolve()
try {
const _db = window.indexedDB.open(this.name)
_db.onsuccess = (event) => {
@ -93,14 +94,11 @@ export class IndexedDB {
this.db.transaction('data', 'readonly').objectStore('data').get(key).onsuccess = (
res
) => {
try {
const data = (res.target as IDBRequest).result
if (data) {
this.DBList[key].data[this.DBList[key].key] = data
}
} finally {
this.setWatch(key)
const data = (res.target as IDBRequest).result
if (data) {
this.DBList[key].data[this.DBList[key].key] = data
}
this.setWatch(key)
}
}
} else {
@ -109,7 +107,6 @@ export class IndexedDB {
this.setWatch(key)
}
}
this.cb = () => resolve()
}
_db.onupgradeneeded = (event) => {