From ed77cc4fb4b2403a569222671d836b9e0537eedb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Sep 2024 21:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=A1=B9=E7=9B=AE=E5=87=BA=E7=8E=B0=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/item/data.ts | 29 +++++++++++++++++++++++++++++ electron/main/item/ipcEvent.ts | 20 +++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/electron/main/item/data.ts b/electron/main/item/data.ts index f601fcd..c074304 100644 --- a/electron/main/item/data.ts +++ b/electron/main/item/data.ts @@ -323,6 +323,34 @@ function del(id: number) { } } +/** + * 批量删除 + */ +function batchDel(idList: Array) { + // 批量查询 + 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(); + itemList.forEach((item) => { + classificationIdList.add(item.classificationId); + }); + // 更新序号 + classificationIdList.forEach((classificationId) => { + reorder(classificationId); + }); + return true; + } else { + return false; + } +} + /** * 删除 * @param classificationId @@ -419,6 +447,7 @@ export { batchAdd, update, del, + batchDel, selectById, selectByIdList, deleteByClassificationId, diff --git a/electron/main/item/ipcEvent.ts b/electron/main/item/ipcEvent.ts index bdc29d8..8e70977 100644 --- a/electron/main/item/ipcEvent.ts +++ b/electron/main/item/ipcEvent.ts @@ -28,7 +28,15 @@ import { getStartMenuItemList, getSystemItemList, } 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 { getFileExtname, isAbsolutePath } from "../../../commons/utils/common"; import { @@ -579,12 +587,10 @@ export default function () { [global.language.ok, global.language.cancel] ); if (res === 0) { - for (const id of batchSelectedIdList) { - // 删除数据 - del(id); - // 快捷键 - setShortcutKey(); - } + // 批量删除 + batchDel(batchSelectedIdList); + // 快捷键 + setShortcutKey(); // 通知前端删除数据 sendToWebContent( "mainWindow",