feat(日志): 添加删除日志记录功能
后端添加删除日志的API接口,前端在日志列表中添加删除按钮和确认弹窗
This commit is contained in:
@@ -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) => {
|
router.get('/logs/:id/history', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
Statistic,
|
Statistic,
|
||||||
Divider,
|
Divider,
|
||||||
Popover,
|
Popover,
|
||||||
|
Popconfirm,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
HistoryOutlined,
|
HistoryOutlined,
|
||||||
@@ -35,6 +36,7 @@ import {
|
|||||||
EditOutlined,
|
EditOutlined,
|
||||||
EyeOutlined,
|
EyeOutlined,
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
|
DeleteOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import CloseButton from '../components/CloseButton';
|
import CloseButton from '../components/CloseButton';
|
||||||
@@ -317,7 +319,7 @@ function ConsumableLogs() {
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 120,
|
width: 150,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space>
|
<Space>
|
||||||
@@ -339,6 +341,23 @@ function ConsumableLogs() {
|
|||||||
onClick={() => handleViewHistory(record)}
|
onClick={() => handleViewHistory(record)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除"
|
||||||
|
description="确定要删除这条日志记录吗?此操作不可恢复。"
|
||||||
|
onConfirm={() => handleDeleteLog(record.id)}
|
||||||
|
okText="删除"
|
||||||
|
cancelText="取消"
|
||||||
|
okButtonProps={{ danger: true }}
|
||||||
|
>
|
||||||
|
<Tooltip title="删除">
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</Popconfirm>
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -587,6 +606,17 @@ function ConsumableLogs() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 删除日志
|
||||||
|
const handleDeleteLog = async logId => {
|
||||||
|
try {
|
||||||
|
await axios.delete(`/api/consumables/logs/${logId}`);
|
||||||
|
message.success('日志删除成功');
|
||||||
|
fetchLogs(pagination.current, pagination.pageSize);
|
||||||
|
} catch (error) {
|
||||||
|
message.error(error.response?.data?.error || '删除失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 手动添加日志
|
// 手动添加日志
|
||||||
const handleAddLog = () => {
|
const handleAddLog = () => {
|
||||||
addForm.resetFields();
|
addForm.resetFields();
|
||||||
|
|||||||
Reference in New Issue
Block a user