flat: 暂存

This commit is contained in:
史典卓
2025-05-13 11:10:38 +08:00
parent 582e432e6a
commit fd74b7d4df
109 changed files with 8644 additions and 5205 deletions

View File

@@ -250,6 +250,46 @@ class IndexedDBHelper {
request.onerror = (event) => reject(`Delete Error: ${event.target.error}`);
});
}
/**
* 根据条件删除所有匹配的数据
* @param {string} storeName - 数据仓库名
* @param {function} conditionFn - 判断是否删除 (record) => boolean
* @returns {Promise}
*/
deleteByCondition(storeName, conditionFn) {
return new Promise((resolve, reject) => {
if (!this.db) {
reject('Database not initialized');
return;
}
const transaction = this.db.transaction([storeName], 'readwrite');
const store = transaction.objectStore(storeName);
const request = store.openCursor();
request.onsuccess = (event) => {
const cursor = event.target.result;
if (cursor && cursor.value) {
try {
// console.log(cursor.value)
const shouldDelete = conditionFn(cursor.value);
if (shouldDelete) {
cursor.delete();
}
} catch (err) {
console.error('Condition function error:', err);
}
cursor.continue();
} else {
resolve('All matching records deleted successfully');
}
};
request.onerror = (event) => {
reject(`Delete by condition failed: ${event.target.error}`);
};
});
}
/**
* 通过索引查询数据