mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-09-07 00:16:39 +08:00
refactor(app): 修复取消按钮重复点击问题
This commit is contained in:
+38
-43
@@ -458,63 +458,58 @@ async function handleBatchRegistration(requestData) {
|
|||||||
|
|
||||||
// 取消任务
|
// 取消任务
|
||||||
async function handleCancelTask() {
|
async function handleCancelTask() {
|
||||||
if (isBatchMode && currentBatch) {
|
// 禁用取消按钮,防止重复点击
|
||||||
// 优先通过 WebSocket 取消批量任务
|
elements.cancelBtn.disabled = true;
|
||||||
if (batchWebSocket && batchWebSocket.readyState === WebSocket.OPEN) {
|
addLog('info', '[系统] 正在提交取消请求...');
|
||||||
cancelBatchViaWebSocket();
|
|
||||||
addLog('warning', '[警告] 批量任务取消请求已提交');
|
try {
|
||||||
toast.info('任务取消请求已提交');
|
// 批量任务取消(包括普通批量模式和 Outlook 批量模式)
|
||||||
} else {
|
if (currentBatch && (isBatchMode || isOutlookBatchMode)) {
|
||||||
// 降级到 REST API
|
// 优先通过 WebSocket 取消
|
||||||
try {
|
if (batchWebSocket && batchWebSocket.readyState === WebSocket.OPEN) {
|
||||||
await api.post(`/registration/batch/${currentBatch.batch_id}/cancel`);
|
batchWebSocket.send(JSON.stringify({ type: 'cancel' }));
|
||||||
|
addLog('warning', '[警告] 批量任务取消请求已提交');
|
||||||
|
toast.info('任务取消请求已提交');
|
||||||
|
} else {
|
||||||
|
// 降级到 REST API
|
||||||
|
const endpoint = isOutlookBatchMode
|
||||||
|
? `/registration/outlook-batch/${currentBatch.batch_id}/cancel`
|
||||||
|
: `/registration/batch/${currentBatch.batch_id}/cancel`;
|
||||||
|
|
||||||
|
await api.post(endpoint);
|
||||||
addLog('warning', '[警告] 批量任务取消请求已提交');
|
addLog('warning', '[警告] 批量任务取消请求已提交');
|
||||||
toast.info('任务取消请求已提交');
|
toast.info('任务取消请求已提交');
|
||||||
stopBatchPolling();
|
stopBatchPolling();
|
||||||
resetButtons();
|
resetButtons();
|
||||||
} catch (error) {
|
|
||||||
addLog('error', `[错误] 取消失败: ${error.message}`);
|
|
||||||
toast.error(error.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isOutlookBatchMode && currentBatch) {
|
// 单次任务取消
|
||||||
// Outlook 批量任务取消
|
else if (currentTask) {
|
||||||
if (batchWebSocket && batchWebSocket.readyState === WebSocket.OPEN) {
|
// 优先通过 WebSocket 取消
|
||||||
cancelBatchViaWebSocket();
|
if (webSocket && webSocket.readyState === WebSocket.OPEN) {
|
||||||
addLog('warning', '[警告] Outlook 批量任务取消请求已提交');
|
webSocket.send(JSON.stringify({ type: 'cancel' }));
|
||||||
toast.info('任务取消请求已提交');
|
addLog('warning', '[警告] 任务取消请求已提交');
|
||||||
} else {
|
|
||||||
// 降级到 REST API
|
|
||||||
try {
|
|
||||||
await api.post(`/registration/outlook-batch/${currentBatch.batch_id}/cancel`);
|
|
||||||
addLog('warning', '[警告] Outlook 批量任务取消请求已提交');
|
|
||||||
toast.info('任务取消请求已提交');
|
toast.info('任务取消请求已提交');
|
||||||
stopBatchPolling();
|
} else {
|
||||||
resetButtons();
|
// 降级到 REST API
|
||||||
} catch (error) {
|
|
||||||
addLog('error', `[错误] 取消失败: ${error.message}`);
|
|
||||||
toast.error(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (currentTask) {
|
|
||||||
// 优先通过 WebSocket 取消
|
|
||||||
if (useWebSocket && webSocket && webSocket.readyState === WebSocket.OPEN) {
|
|
||||||
cancelViaWebSocket();
|
|
||||||
addLog('warning', '[警告] 任务取消请求已提交');
|
|
||||||
toast.info('任务取消请求已提交');
|
|
||||||
} else {
|
|
||||||
// 降级到 REST API
|
|
||||||
try {
|
|
||||||
await api.post(`/registration/tasks/${currentTask.task_uuid}/cancel`);
|
await api.post(`/registration/tasks/${currentTask.task_uuid}/cancel`);
|
||||||
addLog('warning', '[警告] 任务已取消');
|
addLog('warning', '[警告] 任务已取消');
|
||||||
toast.info('任务已取消');
|
toast.info('任务已取消');
|
||||||
stopLogPolling();
|
stopLogPolling();
|
||||||
resetButtons();
|
resetButtons();
|
||||||
} catch (error) {
|
|
||||||
addLog('error', `[错误] 取消失败: ${error.message}`);
|
|
||||||
toast.error(error.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 没有活动任务
|
||||||
|
else {
|
||||||
|
addLog('warning', '[警告] 没有活动的任务可以取消');
|
||||||
|
toast.warning('没有活动的任务');
|
||||||
|
resetButtons();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
addLog('error', `[错误] 取消失败: ${error.message}`);
|
||||||
|
toast.error(error.message);
|
||||||
|
// 恢复取消按钮,允许重试
|
||||||
|
elements.cancelBtn.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user