merge overseas PDA frontend changes

This commit is contained in:
2026-10-08 15:45:25 +08:00
26 changed files with 890 additions and 67 deletions
+31 -2
View File
@@ -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]
+5
View File
@@ -5,6 +5,8 @@ import { resetFulfillmentSession } from './fulfillment.js'
import { resetWarehouseWork } from './warehouse-work.js'
const SESSION_KEY = 'overseas-pda-auth-session'
let sessionRevision = 0
export function getSessionRevision() { return sessionRevision }
export const PDA_ROLE = 'OVERSEAS_WAREHOUSE_PDA_OPERATOR'
export const PDA_AUTHORITY = 'lastleg:pda:operate'
@@ -108,6 +110,7 @@ function persistSession() {
}
export function signIn(account, warehouse, options = {}) {
sessionRevision += 1
session.currentUser = { id: String(account.id), name: account.name, role: account.role, roles: account.roles || [], warehouse,
warehouseId: account.warehouseId || null, warehouseCode: account.warehouseCode || '', warehouseName: account.warehouseName || '' }
session.token = options.token || account.token || ''
@@ -184,6 +187,7 @@ export function restoreSession() {
currentUser: userFromClaims(pair, saved.currentUser), tenantId: claimId(pair.claims, 'tenant_id'),
apiBase: API_ROOT, authorization: pair.authorization
})
sessionRevision += 1
return true
} catch (_) {
signOut()
@@ -192,6 +196,7 @@ export function restoreSession() {
}
export function signOut() {
sessionRevision += 1
session.currentUser = null
session.token = ''
session.refreshToken = ''