feat(pda): connect overseas inbound receiving

This commit is contained in:
2026-08-24 15:25:36 +08:00
parent 6de0884205
commit 690d3086d4
8 changed files with 166 additions and 35 deletions
+15
View File
@@ -0,0 +1,15 @@
import { overseasRequest, overseasUpload } from '@/api/overseas.js'
function scope(customerId) { return `?customerId=${encodeURIComponent(customerId)}` }
function base(planNo) { return `/pda/v1/last-leg/inbound-plans/${encodeURIComponent(planNo)}` }
export const getInboundTask = (planNo, customerId) => overseasRequest('GET', `${base(planNo)}${scope(customerId)}`)
export const pushInboundTask = (planNo, customerId, request) => overseasRequest('POST', `${base(planNo)}/push${scope(customerId)}`, request)
export const assignInboundPallet = (planNo, customerId, planPalletId, request) => overseasRequest('POST', `${base(planNo)}/pallets/${encodeURIComponent(planPalletId)}/assign${scope(customerId)}`, request)
export const countInboundPackages = (planNo, customerId, allocationId, request) => overseasRequest('POST', `${base(planNo)}/allocations/${encodeURIComponent(allocationId)}/count${scope(customerId)}`, request)
export const pickInboundPackages = (planNo, customerId, allocationId, request) => overseasRequest('POST', `${base(planNo)}/allocations/${encodeURIComponent(allocationId)}/pick${scope(customerId)}`, request)
export const scanInboundCarton = (planNo, customerId, request) => overseasRequest('POST', `${base(planNo)}/cartons/scan${scope(customerId)}`, request)
export const removeInboundCarton = (planNo, customerId, request) => overseasRequest('POST', `${base(planNo)}/cartons/remove${scope(customerId)}`, request)
export const bindUnloadPhotos = (planNo, customerId, request) => overseasRequest('POST', `${base(planNo)}/unload-photos${scope(customerId)}`, request)
export const completeInboundTask = (planNo, customerId) => overseasRequest('POST', `${base(planNo)}/complete${scope(customerId)}`)
export const uploadUnloadPhotoFile = (planNo, customerId, filePath) => overseasUpload(`${base(planNo)}/unload-photos/files${scope(customerId)}`, filePath)
+71
View File
@@ -0,0 +1,71 @@
import { refresh } from '@/api/auth.js'
import { session, replaceTokens } from '@/stores/session.js'
let refreshPromise = null
function errorFrom(response, fallback) {
const body = response?.data || {}
const error = new Error(body.message || fallback)
error.code = body.code || response?.statusCode
error.requestId = body.requestId || response?.header?.['x-request-id'] || response?.header?.['X-Request-Id']
error.traceId = body.traceId || response?.header?.['x-trace-id'] || response?.header?.['X-Trace-Id']
return error
}
function unauthorized(response) {
const code = String(response?.data?.code || response?.statusCode || '')
return response?.statusCode === 401 || code === 'A0401'
}
async function refreshOverseasToken() {
if (!session.refreshToken) throw new Error('登录状态已过期,请重新登录')
if (!refreshPromise) {
refreshPromise = refresh(session.refreshToken).then((tokens) => { replaceTokens(tokens); return session.token })
.finally(() => { refreshPromise = null })
}
return refreshPromise
}
function rawRequest(method, path, data, token) {
return new Promise((resolve, reject) => {
uni.request({
url: `${session.apiBase}${path}`,
method,
data,
header: { Accept: 'application/json', Authorization: `Bearer ${token}` },
success: resolve,
fail: (cause) => reject(Object.assign(new Error(cause.errMsg || '海外服务网络连接失败'), { network: true }))
})
})
}
export async function overseasRequest(method, path, data, retry = true) {
let response = await rawRequest(method, path, data, session.token)
if (retry && unauthorized(response)) {
await refreshOverseasToken()
response = await rawRequest(method, path, data, session.token)
}
const body = response?.data || {}
if (response.statusCode !== 200 || String(body.code) !== '200') throw errorFrom(response, '海外作业请求失败')
return body.data
}
export function overseasUpload(path, filePath, name = 'file') {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: `${session.apiBase}${path}`,
filePath,
name,
header: { Authorization: `Bearer ${session.token}` },
success(response) {
let body = null
try { body = JSON.parse(response.data || '{}') } catch (_) { /* handled below */ }
if (response.statusCode !== 200 || String(body?.code) !== '200') {
reject(errorFrom({ ...response, data: body }, '卸柜照片上传失败')); return
}
resolve(body.data)
},
fail: (cause) => reject(Object.assign(new Error(cause.errMsg || '卸柜照片上传失败'), { network: true }))
})
})
}