fix: 批量删除用户改用 ConfirmDialog 替代浏览器原生 confirm()

- handleBatchAction 删除分支改为 setDeleteConfirm 弹 ConfirmDialog
- 确认后执行删除,取消则关闭弹框
This commit is contained in:
logan committed 2026-05-31 14:34:21 +08:00
1 parent 6a53eb8bdf
commit c5270f82c1
1 file changed
+14 -4
+14 -4
View File
@@ -216,7 +216,20 @@ export default function UsersPage() {
const handleBatchAction = async (action: string) => { const handleBatchAction = async (action: string) => {
const ids = Array.from(selectedIds); const ids = Array.from(selectedIds);
if (ids.length === 0) return; if (ids.length === 0) return;
if (action === 'delete' && !confirm(`确定删除选中的 ${ids.length} 个用户?此操作不可恢复。`)) return; if (action === 'delete') {
setDeleteConfirm({
msg: `确定删除选中的 ${ids.length} 个用户?此操作不可恢复。`,
onConfirm: async () => {
try {
await Promise.all(ids.map(id => userApi.delete(id)));
toast('success', `已删除 ${ids.length} 个用户`);
setSelectedIds(new Set());
fetchUsers();
} catch { toast('error', '批量删除失败'); }
},
});
return;
}
try { try {
if (action === 'enable') { if (action === 'enable') {
await Promise.all(ids.map(id => userApi.update(id, { is_active: true }))); await Promise.all(ids.map(id => userApi.update(id, { is_active: true })));
@@ -224,9 +237,6 @@ export default function UsersPage() {
} else if (action === 'disable') { } else if (action === 'disable') {
await Promise.all(ids.map(id => userApi.update(id, { is_active: false }))); await Promise.all(ids.map(id => userApi.update(id, { is_active: false })));
toast('success', `已禁用 ${ids.length} 个用户`); toast('success', `已禁用 ${ids.length} 个用户`);
} else if (action === 'delete') {
await Promise.all(ids.map(id => userApi.delete(id)));
toast('success', `已删除 ${ids.length} 个用户`);
} }
setSelectedIds(new Set()); setSelectedIds(new Set());
fetchUsers(); fetchUsers();