feat(task-retry): 重试按钮推广到相似ASIN与采集数据

同类问题一起修:这两个模块与外观专利共用同一条自动重试(原先也克隆重试)。
- 新增通用端点 POST /api/tasks/{taskId}/retry(模块无关,从任务行取 moduleType)
- 两页失败任务在「删除」前显示「重试」,调用后在原任务上复位续跑
- catch 棘轮 308→310,两处均 ElMessage 可见出口
This commit is contained in:
2026-11-01 00:46:08 +08:00
parent 0a467793ac
commit 96b090dfd5
6 changed files with 133 additions and 1 deletions
@@ -120,11 +120,15 @@
history-empty-text="暂无历史记录"
>
<template #item-actions="{ item }">
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
<template #history-item-actions="{ item }">
<button v-if="canDownload(itemSource(item))" type="button" class="download"
@click="downloadResult(itemSource(item))">下载</button>
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
@click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
@@ -139,6 +143,7 @@
import { computed, onBeforeUnmount, onMounted, reactive, ref, shallowRef, triggerRef } from 'vue'
import { userNotice } from '@/shared/utils/user-notice'
import { ElMessage } from 'element-plus'
import { retryClientTask } from '@/shared/api/task-retry'
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
@@ -491,6 +496,26 @@ async function pushToPythonQueue() {
}
}
/**
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
*/
function canRetryTask(item: CollectDataHistoryItem | null | undefined): boolean {
return Boolean(item?.taskId) && normalizeTaskStatus(item as CollectDataHistoryItem) === 'FAILED'
}
async function retryTaskRecord(item: CollectDataHistoryItem | null | undefined) {
const taskId = item?.taskId
if (!taskId) return
try {
await retryClientTask(taskId)
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
await refreshBoard()
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '重试失败')
}
}
function normalizeTaskStatus(item: CollectDataHistoryItem) {
return (item.taskStatus || '').toUpperCase()
}
@@ -109,11 +109,15 @@
<div v-if="pendingResultHint(itemSource(item))" class="files result-hint">{{ pendingResultHint(itemSource(item)) }}</div>
</template>
<template #item-actions="{ item }">
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
<template #history-item-actions="{ item }">
<button v-if="canDownload(itemSource(item))" type="button" class="download"
@click="downloadResult(itemSource(item))">下载</button>
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
@click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
@@ -129,6 +133,7 @@
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { userNotice } from '@/shared/utils/user-notice'
import { ElMessage } from 'element-plus'
import { retryClientTask } from '@/shared/api/task-retry'
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
@@ -369,6 +374,26 @@ function isResultPreparing(item: SimilarAsinHistoryItem) {
return true
}
/**
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
*/
function canRetryTask(item: SimilarAsinHistoryItem | null | undefined): boolean {
return Boolean(item?.taskId) && normalizeTaskStatus(item as SimilarAsinHistoryItem) === 'FAILED'
}
async function retryTaskRecord(item: SimilarAsinHistoryItem | null | undefined) {
const taskId = item?.taskId
if (!taskId) return
try {
await retryClientTask(taskId)
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
await refreshBoard()
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '重试失败')
}
}
function normalizeTaskStatus(item: SimilarAsinHistoryItem) {
const taskStatus = (item.taskStatus || '').toUpperCase()
if (taskStatus !== 'FAILED' && isResultFileComplete(item)) return 'SUCCESS'