fix(dispatch): reject stale loading document upload rounds
This commit is contained in:
@@ -44,20 +44,23 @@ function photosFor(slot: LoadingPhotoSlot) { return snapshot.value?.photos.filte
|
||||
async function upload(slot: LoadingPhotoSlot, event: Event, replaceFileId?: string) {
|
||||
const input = event.target as HTMLInputElement, files = Array.from(input.files || []); input.value = ''
|
||||
if (!files.length || busy.value || !editable.value) return
|
||||
const reviewRound = snapshot.value!.reviewRound
|
||||
const capacity = replaceFileId ? 1 : 5 - photosFor(slot).length
|
||||
if (files.length > capacity) { ElMessage.warning(`本次最多可选择${capacity}张图片`); return }
|
||||
if (files.some(file => !(['image/jpeg','image/png'].includes(file.type) || slot === 'LOADING_SCENE' && file.type === 'application/pdf') || !file.size || file.size > 10 * 1024 * 1024)) { ElMessage.warning('请选择不超过10MiB的JPG或PNG,司机驾驶证也支持PDF'); return }
|
||||
busy.value = true; error.value = null
|
||||
let saved = 0, reconciled = false, bindingFailed = false
|
||||
let saved = 0, reconciled = false, bindingFailed = false, roundChanged = false
|
||||
try {
|
||||
ensureScope()
|
||||
for (const file of files) {
|
||||
const photo = await uploadLoadingPhoto(number, slot, file, crypto.randomUUID()); ensureScope()
|
||||
const uploadKey = crypto.randomUUID()
|
||||
const photo = await uploadLoadingPhoto(number, slot, file, uploadKey, reviewRound); ensureScope()
|
||||
const latest = await getLoadingDocuments(number); accept(latest)
|
||||
if (latest.reviewRound !== reviewRound) { reconciled = true; roundChanged = true; throw new Error('审核轮次已变化,请核对新车辆、司机后重新选择资料') }
|
||||
if (!latest.editable) throw new Error('当前状态不允许修改照片')
|
||||
if (photo.slot !== slot || !photo.fileId) throw new Error('上传结果与照片类别不一致')
|
||||
try {
|
||||
accept(await bindLoadingPhoto(number, slot, { recordVersion: latest.recordVersion, idempotencyKey: crypto.randomUUID(), fileId: photo.fileId, ...(replaceFileId ? { replaceFileId } : {}) }))
|
||||
accept(await bindLoadingPhoto(number, slot, { recordVersion: latest.recordVersion, idempotencyKey: crypto.randomUUID(), fileId: photo.fileId, uploadKey, ...(replaceFileId ? { replaceFileId } : {}) }))
|
||||
} catch (cause) {
|
||||
// 保存可能已经提交;先核对当前事实,不重放请求或继续后续图片。
|
||||
bindingFailed = true
|
||||
@@ -73,7 +76,7 @@ async function upload(slot: LoadingPhotoSlot, event: Event, replaceFileId?: stri
|
||||
}
|
||||
ElMessage.success(`已保存${saved}张照片`)
|
||||
} catch (cause) {
|
||||
if (active) error.value = getApiErrorDetails(cause, bindingFailed
|
||||
if (active) error.value = getApiErrorDetails(cause, roundChanged ? '审核轮次已变化,请核对新车辆、司机后重新选择资料' : bindingFailed
|
||||
? needsRefresh.value ? '保存结果尚未核实,请重新读取资料' : '保存响应未确认,已读取最新资料,请核对已保存图片后继续'
|
||||
: '图片上传失败,已保存照片保留,请重新选择图片')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user