feat(用户管理): 添加用户锁定/解锁功能
- 新增 unlock_user.js 脚本用于解锁被锁定的用户 - 在用户管理页面添加锁定/解锁操作按钮 - 移除不再使用的 compression 依赖 - 添加 winston 日志库用于后续日志记录
This commit is contained in:
@@ -151,6 +151,23 @@ const UserManagement = () => {
|
||||
}
|
||||
}, [fetchUsers]);
|
||||
|
||||
const handleLockUnlock = useCallback(async (record) => {
|
||||
try {
|
||||
const newStatus = record.status === 'locked' ? 'active' : 'locked';
|
||||
const response = await userAPI.update(record.userId, {
|
||||
status: newStatus
|
||||
});
|
||||
if (response.success) {
|
||||
message.success(record.status === 'locked' ? '解锁成功' : '锁定成功');
|
||||
fetchUsers();
|
||||
} else {
|
||||
message.error(response.message || '操作失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('操作失败');
|
||||
}
|
||||
}, [fetchUsers]);
|
||||
|
||||
const handleSubmit = useCallback(async (values) => {
|
||||
try {
|
||||
let response;
|
||||
@@ -285,8 +302,7 @@ const UserManagement = () => {
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
{title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<Space size="small">
|
||||
@@ -304,6 +320,20 @@ const UserManagement = () => {
|
||||
onClick={() => handleResetPassword(record)}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Popconfirm
|
||||
title={record.status === 'locked' ? '确定要解锁此用户吗?' : '确定要锁定此用户吗?'}
|
||||
onConfirm={() => handleLockUnlock(record)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Tooltip title={record.status === 'locked' ? '解锁' : '锁定'}>
|
||||
<Button
|
||||
type="text"
|
||||
icon={record.status === 'locked' ? <ReloadOutlined /> : <LockOutlined />}
|
||||
style={{ color: record.status === 'locked' ? '#52c41a' : '#faad14' }}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
<Popconfirm
|
||||
title="确定要删除此用户吗?"
|
||||
onConfirm={() => handleDelete(record.userId)}
|
||||
@@ -317,7 +347,7 @@ const UserManagement = () => {
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
], [handleAvatarClick, handleEdit, handleResetPassword, handleDelete]);
|
||||
], [handleAvatarClick, handleEdit, handleResetPassword, handleDelete, handleLockUnlock]);
|
||||
|
||||
const pageHeaderStyle = {
|
||||
marginBottom: '24px',
|
||||
|
||||
Reference in New Issue
Block a user