优化批量删除项目出现卡顿的问题。

This commit is contained in:
unknown 2024-09-13 21:06:19 +08:00
parent 0327dfc0cc
commit ed77cc4fb4
2 changed files with 42 additions and 7 deletions

View File

@ -323,6 +323,34 @@ function del(id: number) {
} }
} }
/**
*
*/
function batchDel(idList: Array<number>) {
// 批量查询
let itemList = selectByIdList(true, idList);
// 参数
let params = itemList.map((item) => item.id).join(",");
// SQL
let sql = `DELETE FROM ${tableName} WHERE id in (?)`;
// 运行
let res = db.prepare(sql).run(params).changes > 0;
if (res) {
// 提取分类ID
let classificationIdList = new Set<number>();
itemList.forEach((item) => {
classificationIdList.add(item.classificationId);
});
// 更新序号
classificationIdList.forEach((classificationId) => {
reorder(classificationId);
});
return true;
} else {
return false;
}
}
/** /**
* *
* @param classificationId * @param classificationId
@ -419,6 +447,7 @@ export {
batchAdd, batchAdd,
update, update,
del, del,
batchDel,
selectById, selectById,
selectByIdList, selectByIdList,
deleteByClassificationId, deleteByClassificationId,

View File

@ -28,7 +28,15 @@ import {
getStartMenuItemList, getStartMenuItemList,
getSystemItemList, getSystemItemList,
} from "./commons"; } from "./commons";
import { add, del, list, selectById, update, updateOrder } from "./data"; import {
add,
batchDel,
del,
list,
selectById,
update,
updateOrder,
} from "./data";
import { Item } from "../../../types/item"; import { Item } from "../../../types/item";
import { getFileExtname, isAbsolutePath } from "../../../commons/utils/common"; import { getFileExtname, isAbsolutePath } from "../../../commons/utils/common";
import { import {
@ -579,12 +587,10 @@ export default function () {
[global.language.ok, global.language.cancel] [global.language.ok, global.language.cancel]
); );
if (res === 0) { if (res === 0) {
for (const id of batchSelectedIdList) { // 批量删除
// 删除数据 batchDel(batchSelectedIdList);
del(id); // 快捷键
// 快捷键 setShortcutKey();
setShortcutKey();
}
// 通知前端删除数据 // 通知前端删除数据
sendToWebContent( sendToWebContent(
"mainWindow", "mainWindow",