refactor: 第一批低风险收敛——任务缓存服务泛型化 + 前端死代码清理与状态映射统一

This commit is contained in:
2026-10-01 14:05:30 +08:00
parent 2f5e0d7b17
commit 16e2c9a5e7
74 changed files with 873 additions and 3566 deletions
@@ -167,6 +167,7 @@ import {
type VariantTaskListItem,
} from '@/shared/bridges/pywebview'
import { saveUrlWithProgress } from '@/shared/utils/download-progress'
import { taskStatusClass, taskStatusText, type TaskStatusOptions } from '@/shared/utils/task-status-text'
/** 本地任务记录:桥接返回的列表项 + 前端维护字段 */
type VariantEntry = VariantTaskListItem & {
@@ -222,12 +223,32 @@ function taskMeta(item: VariantEntry) {
return item.meta || {}
}
// 数字状态(0-3) + 字符串状态的混合映射,与统一默认表不一致,整体走 overrides
const VARIANT_STATUS_OVERRIDES: TaskStatusOptions = {
text: {
'': '排队中',
'0': '排队中',
'1': '执行中',
'2': '已完成',
'3': '失败',
PENDING: '排队中',
PROCESSING: '执行中',
DONE: '已完成',
ERROR: '失败',
STOPPED: '已取消',
},
classMap: {
'1': 'running',
'2': 'success',
'3': 'failed',
DONE: 'success',
ERROR: 'failed',
CANCELLED: 'pending',
},
}
function statusClass(status?: number | string) {
const numeric = Number(status)
if (numeric === 1 || /running|processing/i.test(String(status))) return 'running'
if (numeric === 2 || /success|completed|done/i.test(String(status))) return 'success'
if (numeric === 3 || /failed|error/i.test(String(status))) return 'failed'
return 'pending'
return taskStatusClass(String(status ?? ''), VARIANT_STATUS_OVERRIDES)
}
let autoTimer: number | null = null
@@ -247,14 +268,11 @@ function baseName(path: string) {
}
function statusText(status?: number | string) {
const numeric = Number(status)
if (numeric === 0 || String(status).toLowerCase() === 'pending' || String(status).toLowerCase() === 'queued') return '排队中'
if (numeric === 1 || String(status).toLowerCase() === 'running' || String(status).toLowerCase() === 'processing') return '执行中'
if (numeric === 2 || ['success', 'completed', 'done'].includes(String(status).toLowerCase())) return '已完成'
if (numeric === 3 || ['failed', 'error'].includes(String(status).toLowerCase())) return '失败'
if (['cancelled', 'stopped'].includes(String(status).toLowerCase())) return '已取消'
if (status === 0 || status === 1 || status === 2 || status === 3) return statusText(String(status))
return String(status ?? '未知')
if (status === undefined || status === null) return '未知'
return taskStatusText(String(status), {
...VARIANT_STATUS_OVERRIDES,
textFallback: String(status),
})
}
function isBusy(status?: number | string) {