fix(pda): preserve scoped receipt photos and stop hidden scan queues
This commit is contained in:
+31
-2
@@ -8,6 +8,28 @@ export const receiving = reactive({
|
||||
})
|
||||
|
||||
const idempotencyKeys = new Map()
|
||||
let previewOwner = ''
|
||||
const previewRequests = new WeakMap()
|
||||
|
||||
function photoOwner(value, owner) {
|
||||
if (!owner || !value?.containerNo || !value?.preparedAt) return ''
|
||||
return JSON.stringify([owner, value.containerNo, value.preparedAt, value.overseasWarehouseId,
|
||||
(value.inbounds || []).map(row => [row.customerId || '', row.inboundCode || '']).sort()])
|
||||
}
|
||||
|
||||
export async function restoreReceivingPhoto(photo, download) {
|
||||
if (!photo?.downloadPath || photo.localPath) return photo?.localPath || ''
|
||||
if (previewRequests.has(photo)) return previewRequests.get(photo)
|
||||
photo.status = 'loading'
|
||||
const request = Promise.resolve().then(() => download(photo.downloadPath)).then(path => {
|
||||
if (!path) throw new Error('照片加载失败')
|
||||
photo.localPath = path; photo.status = 'success'; photo.errorMessage = ''
|
||||
return path
|
||||
}).catch(error => { photo.status = 'error'; photo.errorMessage = error.message || '照片加载失败'; throw error })
|
||||
.finally(() => previewRequests.delete(photo))
|
||||
previewRequests.set(photo, request)
|
||||
return request
|
||||
}
|
||||
|
||||
export function receivingPhase(session = receiving.current) {
|
||||
if (!session) return 'candidates'
|
||||
@@ -23,16 +45,23 @@ export function receivingProgress(session = receiving.current) {
|
||||
return { total, received, pending: Math.max(0, Number(session?.pendingPackages ?? total - received)), percent: total ? Math.min(100, Math.round(received / total * 100)) : 0 }
|
||||
}
|
||||
|
||||
export function setCurrentReceiving(value) {
|
||||
export function setCurrentReceiving(value, owner = '') {
|
||||
const nextOwner = photoOwner(value, owner)
|
||||
const previous = previewOwner && previewOwner === nextOwner ? receiving.photoSlots : []
|
||||
previewOwner = nextOwner
|
||||
receiving.current = value || null
|
||||
receiving.selected = value || null
|
||||
receiving.photoSlots = RECEIVING_PHOTO_ROLES.map((role) => {
|
||||
const photo = (value?.photos || []).find((item) => item.role === role)
|
||||
return photo ? { ...photo, fileId: String(photo.fileId), role, uploaded: true, status: 'success' } : null
|
||||
if (!photo) return null
|
||||
const old = previous.find(item => item?.role === role && String(item.fileId) === String(photo.fileId)
|
||||
&& item.downloadPath === photo.downloadPath)
|
||||
return old || { ...photo, fileId: String(photo.fileId), role, localPath: '', uploaded: true, status: 'idle' }
|
||||
})
|
||||
}
|
||||
|
||||
export function resetReceivingDraft({ keepCurrent = false } = {}) {
|
||||
previewOwner = ''
|
||||
receiving.selected = keepCurrent ? receiving.current : null
|
||||
if (!keepCurrent) receiving.current = null
|
||||
receiving.photoSlots = [null, null, null]
|
||||
|
||||
Reference in New Issue
Block a user