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 }} + > + +