优化
This commit is contained in:
+14
-12
@@ -1,15 +1,17 @@
|
||||
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)}` }
|
||||
const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers'
|
||||
const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}`
|
||||
|
||||
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)
|
||||
export const listReceivingCandidates = () => overseasRequest('GET', `${RECEIVING_BASE}/candidates`)
|
||||
export const getReceivingContainer = (containerNo) => overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`)
|
||||
export const prepareReceivingContainer = (containerNo, request) => overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request)
|
||||
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
|
||||
export const signCurrentReceiving = (request) => overseasRequest('POST', current('/sign'), request)
|
||||
export const getCurrentReceiving = () => overseasRequest('GET', current())
|
||||
export const resolveCurrentCarton = (cartonMark) => overseasRequest('POST', current('/cartons/resolve'), { cartonMark })
|
||||
export const resolveCurrentSku = (skuCode) => overseasRequest('POST', current('/skus/resolve'), { skuCode })
|
||||
export const resolveCurrentPallet = (palletCode, inboundCode) => overseasRequest('POST', current('/pallets/resolve'), { palletCode, inboundCode })
|
||||
export const receiveCurrentBulk = (request) => overseasRequest('POST', current('/receipts/bulk'), request)
|
||||
export const receiveCurrentCarton = (request) => overseasRequest('POST', current('/receipts/carton'), request)
|
||||
export const completeCurrentReceiving = (request) => overseasRequest('POST', current('/complete'), request)
|
||||
|
||||
+21
-11
@@ -17,6 +17,10 @@ function unauthorized(response) {
|
||||
return response?.statusCode === 401 || code === 'A0401'
|
||||
}
|
||||
|
||||
function successful(response, body) {
|
||||
return response?.statusCode === 200 && ['00000', '200'].includes(String(body?.code))
|
||||
}
|
||||
|
||||
async function refreshOverseasToken() {
|
||||
if (!session.refreshToken) throw new Error('登录状态已过期,请重新登录')
|
||||
if (!refreshPromise) {
|
||||
@@ -46,26 +50,32 @@ export async function overseasRequest(method, path, data, retry = true) {
|
||||
response = await rawRequest(method, path, data, session.token)
|
||||
}
|
||||
const body = response?.data || {}
|
||||
if (response.statusCode !== 200 || String(body.code) !== '200') throw errorFrom(response, '海外作业请求失败')
|
||||
if (!successful(response, body)) throw errorFrom(response, '海外作业请求失败')
|
||||
return body.data
|
||||
}
|
||||
|
||||
export function overseasUpload(path, filePath, name = 'file') {
|
||||
function rawUpload(path, filePath, name, token) {
|
||||
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)
|
||||
},
|
||||
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) {
|
||||
let response = await rawUpload(path, filePath, name, session.token)
|
||||
let body = null
|
||||
try { body = JSON.parse(response.data || '{}') } catch (_) { /* handled below */ }
|
||||
if (retry && unauthorized({ ...response, data: body })) {
|
||||
await refreshOverseasToken()
|
||||
response = await rawUpload(path, filePath, name, session.token)
|
||||
try { body = JSON.parse(response.data || '{}') } catch (_) { body = null }
|
||||
}
|
||||
if (!successful(response, body)) throw errorFrom({ ...response, data: body }, '卸柜照片上传失败')
|
||||
return body.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user