缩短装柜完成等待并保留权威状态查询
This commit is contained in:
@@ -349,7 +349,7 @@
|
||||
import { isOnline } from '@/utils/network.js'
|
||||
import { stableOperationId } from '@/utils/idempotency.js'
|
||||
import { stableTaskOperationIdentity } from '@/utils/task-identity.js'
|
||||
import { COMPLETION_PHASE, completionPresentation, resolveCompletionPhase, shouldReconcileCompletion } from '@/utils/loading-completion-state.js'
|
||||
import { COMPLETION_PHASE, completionPresentation, observeLoadingCompletion, resolveCompletionPhase, shouldReconcileCompletion } from '@/utils/loading-completion-state.js'
|
||||
import { containerReference, formatApiError, sanitizeUserMessage } from '@/utils/user-facing.js'
|
||||
import ScanTargetInput from '@/components/ScanTargetInput.vue'
|
||||
import PopupHeader from '@/components/PopupHeader.vue'
|
||||
@@ -1435,6 +1435,8 @@
|
||||
const completionAttempt = { operationId, expectedTaskVersion, remark: savedAttempt?.remark || 'PDA确认装柜完成' }
|
||||
saveLoadingCompletionAttempt(this.draftIdentity(), completionAttempt)
|
||||
this.submitting = true
|
||||
const started = Date.now()
|
||||
let accepted = false
|
||||
try {
|
||||
const completedTask = await completeContainerPickingTask(this.remoteTaskId, {
|
||||
expectedTaskVersion,
|
||||
@@ -1442,21 +1444,56 @@
|
||||
remark: completionAttempt.remark
|
||||
})
|
||||
if (!this.isEvidenceContextActive(contextId, identity)) return
|
||||
accepted = true
|
||||
this.debugSubmit('complete.accepted', { elapsedMs: Date.now() - started, taskStatus: completedTask?.taskStatus })
|
||||
if (!completedTask) throw new Error('服务端未返回装柜完成结果,请刷新任务')
|
||||
if (completedTask) {
|
||||
this.remotePick = normalizePickingTask({ ...this.remotePick, ...completedTask })
|
||||
this.pickingVersion = this.remotePick.pickingVersion ?? this.remotePick.version ?? this.pickingVersion
|
||||
}
|
||||
const phase = resolveCompletionPhase({ taskStatus: completedTask?.taskStatus, commandStatus: completedTask?.commandStatus })
|
||||
// 已受理后保留处理中门禁,查询权威任务;不等待整页证据和库存重新加载。
|
||||
this.submitting = false
|
||||
const finalTask = await observeLoadingCompletion({
|
||||
initialTask: completedTask,
|
||||
isActive: () => this._pageVisible === true && this.isEvidenceContextActive(contextId, identity),
|
||||
readTask: async () => {
|
||||
const readStarted = Date.now()
|
||||
const task = await getContainerPickingTask({ taskId: identity.taskId }, identity.warehouseId)
|
||||
this.debugSubmit('complete.query', { elapsedMs: Date.now() - readStarted, taskStatus: task?.taskStatus })
|
||||
if (String(task?.taskId || task?.id || '') !== String(identity.taskId)) throw new Error('装柜完成状态尚未同步,请刷新任务')
|
||||
return task
|
||||
},
|
||||
onTask: (task) => {
|
||||
this.remotePick = normalizePickingTask({ ...this.remotePick, ...task })
|
||||
this.pickingVersion = this.remotePick.pickingVersion ?? this.remotePick.version ?? this.pickingVersion
|
||||
}
|
||||
})
|
||||
if (!this.isEvidenceContextActive(contextId, identity) || !finalTask) return
|
||||
const phase = resolveCompletionPhase({ taskStatus: finalTask.taskStatus || finalTask.workflowStatus,
|
||||
commandStatus: finalTask.completionCommand?.status || finalTask.commandStatus })
|
||||
this.debugSubmit('complete.observed', { elapsedMs: Date.now() - started, phase })
|
||||
if (phase === COMPLETION_PHASE.PROCESSING) {
|
||||
this.showToast('完成命令已受理,后台处理中', 'success')
|
||||
this.remoteError = '完成命令仍在处理中,请稍后刷新任务确认'
|
||||
this.showToast('完成处理中,请稍后刷新', 'warning')
|
||||
this.persistSession()
|
||||
navigateBackOr('/pages/tasks/tasks')
|
||||
return
|
||||
}
|
||||
if (phase === COMPLETION_PHASE.COMPLETED) clearLoadingCompletionAttempt(this.draftIdentity())
|
||||
if (phase !== COMPLETION_PHASE.COMPLETED) {
|
||||
this.remoteError = phase === COMPLETION_PHASE.FAILED ? '装柜完成失败,可使用原操作重试完成' : '提交结果待确认,请刷新任务'
|
||||
this.showToast(phase === COMPLETION_PHASE.FAILED ? '装柜完成失败' : '提交结果待确认', 'warning')
|
||||
return
|
||||
}
|
||||
clearLoadingCompletionAttempt(this.draftIdentity())
|
||||
this.remoteError = ''
|
||||
this.showToast('装柜已完成', 'success')
|
||||
} catch (error) {
|
||||
if (!this.isEvidenceContextActive(contextId, identity)) return
|
||||
if (accepted) {
|
||||
this.debugSubmit('complete.unconfirmed', { elapsedMs: Date.now() - started, code: error.code || '', requestId: error.requestId || '', traceId: error.traceId || '' })
|
||||
this.remoteError = '完成命令已受理,结果待确认,请刷新任务'
|
||||
this.showToast('提交结果待确认', 'warning')
|
||||
return
|
||||
}
|
||||
if (shouldReconcileCompletion(error)) {
|
||||
this.remoteError = '提交结果待确认,请返回任务列表刷新'
|
||||
this.showToast('提交结果待确认', 'warning')
|
||||
|
||||
Reference in New Issue
Block a user