优化
This commit is contained in:
+13
-2
@@ -19,6 +19,10 @@ const EVIDENCE_SLOTS = Object.freeze([
|
||||
// inbound-scoped task and evidence operations. No local task is promoted to a
|
||||
// server success when any required identifier or version is absent.
|
||||
|
||||
function debugLog(event, payload = {}) {
|
||||
try { console.info(`[PDA] ${event}`, payload) } catch (_) { /* console may be unavailable on a device */ }
|
||||
}
|
||||
|
||||
function request(options) {
|
||||
requireOnline()
|
||||
const baseUrl = session.apiBase || '/api/platform/v1'
|
||||
@@ -27,6 +31,7 @@ function request(options) {
|
||||
if (session.requestId) headers['X-Request-Id'] = session.requestId
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
debugLog('api.request', { method: options.method || 'GET', url: options.url })
|
||||
uni.request({
|
||||
...options,
|
||||
url: `${baseUrl}${options.url}`,
|
||||
@@ -34,6 +39,12 @@ function request(options) {
|
||||
success(response) {
|
||||
const body = response.data || {}
|
||||
const code = String(body.code ?? response.statusCode)
|
||||
debugLog('api.response', {
|
||||
method: options.method || 'GET', url: options.url, statusCode: response.statusCode, code,
|
||||
message: body.message || '', 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'] || '',
|
||||
dataKeys: body.data && typeof body.data === 'object' ? Object.keys(body.data) : []
|
||||
})
|
||||
if (code !== '200') {
|
||||
const error = new Error(body.message || '服务端请求失败')
|
||||
error.code = body.code || response.statusCode
|
||||
@@ -46,6 +57,7 @@ function request(options) {
|
||||
resolve(body.data)
|
||||
},
|
||||
fail(error) {
|
||||
debugLog('api.network-error', { method: options.method || 'GET', url: options.url, errMsg: error.errMsg || '' })
|
||||
const next = new Error(error.errMsg || '网络连接失败')
|
||||
next.network = true
|
||||
reject(next)
|
||||
@@ -80,7 +92,7 @@ export function isRemoteReady(inboundId) {
|
||||
}
|
||||
|
||||
export function getContainerPickingTask(identity, warehouseId) {
|
||||
const selector = typeof identity === 'object' && identity !== null ? identity : { containerNo: identity }
|
||||
const selector = typeof identity === 'object' && identity !== null ? identity : {}
|
||||
const taskId = selector.taskId ?? selector.id
|
||||
if (taskId) {
|
||||
if (!warehouseId) throw new Error('缺少作业仓库标识,无法请求现场任务')
|
||||
@@ -92,7 +104,6 @@ export function getContainerPickingTask(identity, warehouseId) {
|
||||
const query = []
|
||||
if (selector.cabinetNo) query.push(`cabinetNo=${encodeURIComponent(selector.cabinetNo)}`)
|
||||
else if (selector.loadingPlanId) query.push(`loadingPlanId=${encodeURIComponent(selector.loadingPlanId)}`)
|
||||
else if (selector.containerNo) query.push(`containerNo=${encodeURIComponent(selector.containerNo)}`)
|
||||
else throw new Error('缺少稳定柜次标识,无法请求现场任务')
|
||||
if (warehouseId) query.push(`warehouseId=${encodeURIComponent(warehouseId)}`)
|
||||
if (session.tenantId) query.push(`tenantId=${encodeURIComponent(session.tenantId)}`)
|
||||
|
||||
Reference in New Issue
Block a user