This commit is contained in:
2026-08-26 15:59:08 +08:00
parent ee83d87a85
commit 3c283ada46
19 changed files with 196 additions and 46 deletions
+7 -1
View File
@@ -2,12 +2,17 @@ import { API_ROOT } from '../config/runtime.js'
function authRequest(path, data) {
return new Promise((resolve, reject) => {
const url = `${API_ROOT}${path}`
console.info('[Overseas PDA auth] request', { method: 'POST', url })
uni.request({
url: `${API_ROOT}${path}`,
url,
method: 'POST',
data,
success(response) {
const body = response.data || {}
console.info('[Overseas PDA auth] response', { url, statusCode: response.statusCode, code: body.code,
requestId: body.requestId || response.header?.['X-Request-Id'] || response.header?.['x-request-id'],
traceId: body.traceId || response.header?.['X-Trace-Id'] || response.header?.['x-trace-id'] })
if (String(body.code ?? response.statusCode) !== '200') {
const error = new Error(body.message || '认证服务请求失败')
error.code = body.code || response.statusCode
@@ -19,6 +24,7 @@ function authRequest(path, data) {
resolve(body.data)
},
fail(error) {
console.error('[Overseas PDA auth] network failure', { url, errMsg: error.errMsg || 'unknown' })
const next = new Error(error.errMsg || '网络连接失败')
next.network = true
reject(next)
+2 -1
View File
@@ -1,4 +1,4 @@
import { overseasRequest, overseasUpload } from '@/api/overseas.js'
import { overseasDownload, overseasRequest, overseasUpload } from '@/api/overseas.js'
import { normalizeReceivingCandidate, normalizeReceivingSession } from '@/api/receiving-adapter.js'
const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers'
@@ -8,6 +8,7 @@ export const listReceivingCandidates = async () => (await overseasRequest('GET',
export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`))
export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request))
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
export const downloadCurrentUnloadPhoto = (downloadPath) => overseasDownload(downloadPath)
export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request))
export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current()))
export const resolveCurrentCarton = (cartonMark) => overseasRequest('POST', current('/cartons/resolve'), { cartonMark })
+32
View File
@@ -78,6 +78,25 @@ function rawUpload(path, filePath, name, token) {
})
}
function overseasUrl(path) {
const value = String(path || '')
const normalized = /\/(?:api|overseas-api)$/.test(session.apiBase)
? value.replace(/^\/api(?=\/)/, '')
: value
return `${session.apiBase}${normalized}`
}
function rawDownload(path, token) {
return new Promise((resolve, reject) => {
uni.downloadFile({
url: overseasUrl(path),
header: { Authorization: `Bearer ${token}` },
success: resolve,
fail: (cause) => reject(Object.assign(new Error(cause.errMsg || '签收照片下载失败'), { network: true }))
})
})
}
export async function overseasUpload(path, filePath, name = 'file', retry = true) {
const attemptedToken = session.token
let response = await rawUpload(path, filePath, name, attemptedToken)
@@ -92,4 +111,17 @@ export async function overseasUpload(path, filePath, name = 'file', retry = true
return body.data
}
export async function overseasDownload(path, retry = true) {
const attemptedToken = session.token
let response = await rawDownload(path, attemptedToken)
if (retry && unauthorized(response)) {
const replacementToken = await tokenAfterUnauthorized(attemptedToken)
response = await rawDownload(path, replacementToken)
}
if (response?.statusCode !== 200 || !response?.tempFilePath) {
throw errorFrom({ ...response, data: {} }, '签收照片下载失败')
}
return response.tempFilePath
}
export function resetOverseasRequestStateForTest() { refreshPromise = null }
+1 -1
View File
@@ -30,7 +30,7 @@ export function normalizeReceivingSession(value) {
: []
return {
...value,
photos: RECEIVING_PHOTO_ROLES.map((role) => photos.find((photo) => photo?.role === role)).filter(Boolean),
photos: RECEIVING_PHOTO_ROLES.map((role) => photos.find((photo) => photo?.role === role && photo?.fileId)).filter(Boolean),
totalPackages: number(value.totalPackages),
receivedPackages: number(value.receivedPackages),
pendingPackages: number(value.pendingPackages),