fix: 修复批量删除 undefined/失败问题(POST 替代 DELETE body)
Deploy to Server / deploy (push) Successful in 1m38s
Deploy to Server / deploy (push) Successful in 1m38s
- 批量删除改走 POST /users/batch-remove(稳定保证 body 可被 Express 解析),同时增强 DELETE /batch 兼容 query string 回退 - 前端 usersApi.batchRemove 改用 POST 请求;批量删除函数新增 ok 标志位校验 + ?? 0 防 undefined,catch 分支带前缀明确提示失败原因 - npm run build 通过
This commit is contained in:
@@ -66,11 +66,7 @@ export const usersApi = {
|
||||
results: Array<{ idx: number; ok: boolean; id?: number; error?: string; item: any }>;
|
||||
}>('/users/batch', { items }).then(r => r.data),
|
||||
batchRemove: (ids: number[]) =>
|
||||
api.request<{ ok: boolean; deleted: number; total: number }>({
|
||||
url: '/users/batch',
|
||||
method: 'DELETE',
|
||||
data: { ids },
|
||||
}).then(r => r.data),
|
||||
api.post<{ ok: boolean; deleted: number; total: number }>('/users/batch-remove', { ids }).then(r => r.data),
|
||||
};
|
||||
|
||||
export const activitiesApi = {
|
||||
|
||||
@@ -165,11 +165,15 @@ export default function Users() {
|
||||
if (!confirm(`确认删除选中的 ${selectedCount} 名部员?相关的时长登记也会一并删除,此操作不可撤销。`)) return;
|
||||
try {
|
||||
const result = await usersApi.batchRemove(Array.from(selectedIds));
|
||||
alert(`批量删除完成:共提交 ${result.total} 条,实际删除 ${result.deleted} 条`);
|
||||
if (!result || result.ok === false) {
|
||||
alert('批量删除失败:' + ((result as any)?.error || '未知错误'));
|
||||
return;
|
||||
}
|
||||
alert(`批量删除完成:共提交 ${result.total ?? 0} 条,实际删除 ${result.deleted ?? 0} 条`);
|
||||
clearSelection();
|
||||
load();
|
||||
} catch (e) {
|
||||
alert(errMsg(e));
|
||||
alert('批量删除失败:' + errMsg(e));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user