From 6a7e52312eec2afbaf549b1fc25b8c097cc53013 Mon Sep 17 00:00:00 2001 From: zhang1106 <849185023@qq.com> Date: Thu, 9 Apr 2026 16:27:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=97=A5=E5=BF=97):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端添加删除日志的API接口,前端在日志列表中添加删除按钮和确认弹窗 --- backend/routes/consumables.js | 22 ++++++++++++++++++ frontend/src/pages/ConsumableLogs.jsx | 32 ++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/backend/routes/consumables.js b/backend/routes/consumables.js index 72a2237..54e902f 100644 --- a/backend/routes/consumables.js +++ b/backend/routes/consumables.js @@ -1461,6 +1461,28 @@ router.put('/logs/:id', async (req, res) => { } }); +// 删除日志记录 +router.delete('/logs/:id', async (req, res) => { + const transaction = await sequelize.transaction(); + try { + const { id } = req.params; + + const log = await ConsumableLog.findByPk(id, { transaction }); + if (!log) { + await transaction.rollback(); + return res.status(404).json({ error: '日志记录不存在' }); + } + + await log.destroy({ transaction }); + await transaction.commit(); + + res.json({ message: '日志删除成功' }); + } catch (error) { + await transaction.rollback(); + res.status(500).json({ error: error.message }); + } +}); + // 获取日志修改历史 router.get('/logs/:id/history', async (req, res) => { try { diff --git a/frontend/src/pages/ConsumableLogs.jsx b/frontend/src/pages/ConsumableLogs.jsx index ef190f3..0ee9026 100644 --- a/frontend/src/pages/ConsumableLogs.jsx +++ b/frontend/src/pages/ConsumableLogs.jsx @@ -22,6 +22,7 @@ import { Statistic, Divider, Popover, + Popconfirm, } from 'antd'; import { HistoryOutlined, @@ -35,6 +36,7 @@ import { EditOutlined, EyeOutlined, PlusOutlined, + DeleteOutlined, } from '@ant-design/icons'; import axios from 'axios'; import CloseButton from '../components/CloseButton'; @@ -317,7 +319,7 @@ function ConsumableLogs() { { title: '操作', key: 'action', - width: 120, + width: 150, fixed: 'right', render: (_, record) => ( @@ -339,6 +341,23 @@ function ConsumableLogs() { onClick={() => handleViewHistory(record)} /> + handleDeleteLog(record.id)} + okText="删除" + cancelText="取消" + okButtonProps={{ danger: true }} + > + +