软件前端更新
This commit is contained in:
@@ -192,6 +192,7 @@ const dashboard = ref<AppearancePatentDashboardVo>({
|
||||
failedTaskCount: 0,
|
||||
})
|
||||
const historyItems = ref<AppearancePatentHistoryItem[]>([])
|
||||
const liveProgressItems = ref<Record<number, AppearancePatentHistoryItem>>({})
|
||||
|
||||
const visibleTaskSummary = computed(() => parseResult.value || queuedTaskSummary.value)
|
||||
const pendingParseItem = computed<AppearancePatentHistoryItem | null>(() => {
|
||||
@@ -209,10 +210,21 @@ const pendingParseItem = computed<AppearancePatentHistoryItem | null>(() => {
|
||||
})
|
||||
const currentItems = computed(() => {
|
||||
const activeIds = new Set([...pollingTaskIds.value, ...pendingFileTaskIds.value])
|
||||
const activeItems = historyItems.value.filter((item) => {
|
||||
const status = normalizeTaskStatus(item)
|
||||
return item.taskId != null && (activeIds.has(item.taskId) || status === 'RUNNING' || status === 'PENDING')
|
||||
})
|
||||
const activeItems = historyItems.value
|
||||
.filter((item) => {
|
||||
const status = normalizeTaskStatus(item)
|
||||
return item.taskId != null && (activeIds.has(item.taskId) || status === 'RUNNING' || status === 'PENDING')
|
||||
})
|
||||
.map((item) => mergeCurrentTaskItem(item))
|
||||
for (const [taskIdText, liveItem] of Object.entries(liveProgressItems.value)) {
|
||||
const taskId = Number(taskIdText)
|
||||
if (!Number.isFinite(taskId) || taskId <= 0) continue
|
||||
if (!activeIds.has(taskId) && normalizeTaskStatus(liveItem) !== 'RUNNING' && normalizeTaskStatus(liveItem) !== 'PENDING') {
|
||||
continue
|
||||
}
|
||||
if (activeItems.some((item) => item.taskId === taskId)) continue
|
||||
activeItems.push(mergeCurrentTaskItem(liveItem))
|
||||
}
|
||||
if (!pendingParseItem.value) return activeItems
|
||||
const exists = activeItems.some((item) => item.taskId === pendingParseItem.value?.taskId)
|
||||
return exists ? activeItems : [pendingParseItem.value, ...activeItems]
|
||||
@@ -224,6 +236,20 @@ const historyOnlyItems = computed(() =>
|
||||
}),
|
||||
)
|
||||
|
||||
function mergeCurrentTaskItem(item: AppearancePatentHistoryItem) {
|
||||
if (item.taskId == null) return item
|
||||
const liveItem = liveProgressItems.value[item.taskId]
|
||||
if (!liveItem) return item
|
||||
return {
|
||||
...item,
|
||||
...liveItem,
|
||||
sourceFilename: liveItem.sourceFilename || item.sourceFilename,
|
||||
resultFilename: liveItem.resultFilename || item.resultFilename,
|
||||
rowCount: liveItem.rowCount ?? item.rowCount,
|
||||
createdAt: liveItem.createdAt || item.createdAt,
|
||||
}
|
||||
}
|
||||
|
||||
function effectiveAiPrompt() {
|
||||
return aiPrompt.value.trim() || defaultAiPrompt
|
||||
}
|
||||
@@ -460,6 +486,11 @@ function addPollingTask(taskId: number) {
|
||||
|
||||
function removePollingTask(taskId: number) {
|
||||
pollingTaskIds.value = pollingTaskIds.value.filter((id) => id !== taskId)
|
||||
if (!pendingFileTaskIds.value.includes(taskId)) {
|
||||
const next = { ...liveProgressItems.value }
|
||||
delete next[taskId]
|
||||
liveProgressItems.value = next
|
||||
}
|
||||
savePollingIds()
|
||||
}
|
||||
|
||||
@@ -473,6 +504,11 @@ function addPendingFileTask(taskId: number) {
|
||||
|
||||
function removePendingFileTask(taskId: number) {
|
||||
pendingFileTaskIds.value = pendingFileTaskIds.value.filter((id) => id !== taskId)
|
||||
if (!pollingTaskIds.value.includes(taskId)) {
|
||||
const next = { ...liveProgressItems.value }
|
||||
delete next[taskId]
|
||||
liveProgressItems.value = next
|
||||
}
|
||||
savePollingIds()
|
||||
}
|
||||
|
||||
@@ -525,7 +561,13 @@ async function refreshTaskProgress() {
|
||||
const task = detail.task
|
||||
if (!task?.id) continue
|
||||
const item = detail.items?.[0]
|
||||
if (item) mergeHistoryItem(item)
|
||||
if (item) {
|
||||
liveProgressItems.value = {
|
||||
...liveProgressItems.value,
|
||||
[task.id]: item,
|
||||
}
|
||||
mergeHistoryItem(item)
|
||||
}
|
||||
if (task.status === 'SUCCESS' || task.status === 'FAILED') {
|
||||
removePollingTask(task.id)
|
||||
shouldRefreshDashboard = true
|
||||
@@ -627,7 +669,7 @@ async function loadHistory(options: { force?: boolean } = {}) {
|
||||
if (historyInFlight) return historyInFlight
|
||||
historyInFlight = getAppearancePatentHistory()
|
||||
.then((res) => {
|
||||
historyItems.value = res.items || []
|
||||
historyItems.value = mergeHistoryItemsPreservingLiveProgress(historyItems.value, res.items || [])
|
||||
lastHistoryLoadedAt = Date.now()
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -636,6 +678,66 @@ async function loadHistory(options: { force?: boolean } = {}) {
|
||||
return historyInFlight
|
||||
}
|
||||
|
||||
function mergeHistoryItemsPreservingLiveProgress(
|
||||
previousItems: AppearancePatentHistoryItem[],
|
||||
incomingItems: AppearancePatentHistoryItem[],
|
||||
) {
|
||||
const previousByTaskId = new Map<number, AppearancePatentHistoryItem>()
|
||||
const previousByResultId = new Map<number, AppearancePatentHistoryItem>()
|
||||
for (const item of previousItems || []) {
|
||||
if (item.taskId != null) previousByTaskId.set(item.taskId, item)
|
||||
if (item.resultId != null) previousByResultId.set(item.resultId, item)
|
||||
}
|
||||
return (incomingItems || []).map((incoming) => {
|
||||
const previous = incoming.resultId != null
|
||||
? previousByResultId.get(incoming.resultId)
|
||||
: incoming.taskId != null
|
||||
? previousByTaskId.get(incoming.taskId)
|
||||
: undefined
|
||||
return mergeHistoryItemPreservingLiveProgress(previous, incoming)
|
||||
})
|
||||
}
|
||||
|
||||
function mergeHistoryItemPreservingLiveProgress(
|
||||
previous: AppearancePatentHistoryItem | undefined,
|
||||
incoming: AppearancePatentHistoryItem,
|
||||
) {
|
||||
if (!previous) return incoming
|
||||
const shouldPreserveLiveProgress =
|
||||
(normalizeTaskStatus(previous) === 'RUNNING' || isResultPreparing(previous) || showFileProgress(previous))
|
||||
&& !showFileProgress(incoming)
|
||||
&& !canDownload(incoming)
|
||||
|
||||
if (!shouldPreserveLiveProgress) {
|
||||
return incoming
|
||||
}
|
||||
|
||||
return {
|
||||
...incoming,
|
||||
fileJobId: incoming.fileJobId ?? previous.fileJobId,
|
||||
fileStatus: incoming.fileStatus || previous.fileStatus,
|
||||
fileError: incoming.fileError || previous.fileError,
|
||||
fileReady: incoming.fileReady || previous.fileReady,
|
||||
fileProgressPercent: hasMeaningfulProgressValue(incoming.fileProgressPercent)
|
||||
? incoming.fileProgressPercent
|
||||
: previous.fileProgressPercent,
|
||||
fileProgressCurrent: hasMeaningfulProgressValue(incoming.fileProgressCurrent)
|
||||
? incoming.fileProgressCurrent
|
||||
: previous.fileProgressCurrent,
|
||||
fileProgressTotal: hasMeaningfulProgressValue(incoming.fileProgressTotal)
|
||||
? incoming.fileProgressTotal
|
||||
: previous.fileProgressTotal,
|
||||
fileProgressMessage: (incoming.fileProgressMessage || '').trim()
|
||||
? incoming.fileProgressMessage
|
||||
: previous.fileProgressMessage,
|
||||
}
|
||||
}
|
||||
|
||||
function hasMeaningfulProgressValue(value: unknown) {
|
||||
const num = Number(value)
|
||||
return Number.isFinite(num) && num > 0
|
||||
}
|
||||
|
||||
function statusText(item: AppearancePatentHistoryItem) {
|
||||
const status = normalizeTaskStatus(item)
|
||||
if (status === 'RUNNING') return '执行中'
|
||||
|
||||
Reference in New Issue
Block a user