This commit is contained in:
2026-10-19 17:56:30 +08:00
parent e556d75081
commit 0cfefb327a
7 changed files with 399 additions and 427 deletions
+33 -3
View File
@@ -1,10 +1,10 @@
import { reactive } from 'vue'
const STORAGE_KEY = 'overseas-pda-fulfillment-draft-v1'
const STORAGE_KEY = 'overseas-pda-fulfillment-draft-v2'
const blankState = () => ({
scopeKey: '',
dispatch: { currentNo: '', palletCode: '', dispatchItemId: '', cartonCode: '', packages: 1, pendingKeys: {} },
dispatch: { currentNo: '', palletCode: '', dispatchItemId: '', cartonCode: '', packages: 1, pendingCommand: null },
outbound: { currentTaskNo: '', scanCode: '', packages: 1, pendingKeys: {} }
})
@@ -18,7 +18,7 @@ function safeDomain(value, fallback) {
return {
...fallback,
...(value || {}),
pendingKeys: { ...(value?.pendingKeys || {}) }
...(Object.hasOwn(fallback, 'pendingKeys') ? { pendingKeys: { ...(value?.pendingKeys || {}) } } : {})
}
}
@@ -57,6 +57,7 @@ function randomKey(domain, action) {
export function fulfillmentIdempotencyKey(domain, action, payload = {}) {
if (!fulfillment[domain]) throw new Error('未知海外 PDA 履约类型')
if (domain === 'dispatch') throw new Error('排车必须保存完整原命令,不能只生成请求键')
const signature = `${action}:${JSON.stringify(payload)}`
const pendingKeys = fulfillment[domain].pendingKeys
if (!pendingKeys[signature]) pendingKeys[signature] = randomKey(domain, action)
@@ -66,10 +67,39 @@ export function fulfillmentIdempotencyKey(domain, action, payload = {}) {
export function releaseFulfillmentKey(domain, signature) {
if (!fulfillment[domain]) return
if (domain === 'dispatch') throw new Error('排车原命令只能在服务端事实核对后清除')
delete fulfillment[domain].pendingKeys[signature]
persistFulfillmentDraft()
}
export function beginDispatchCommand(dispatchNo, action, body) {
if (!fulfillment.scopeKey) throw new Error('当前作业身份未恢复')
if (fulfillment.dispatch.pendingCommand) throw new Error('请先核对原排车操作结果')
const idempotencyKey = randomKey('dispatch', action)
fulfillment.dispatch.pendingCommand = { dispatchNo, action, body: JSON.parse(JSON.stringify({ ...body, idempotencyKey })), attempted: false, rejected: false, result: null }
persistFulfillmentDraft()
return fulfillment.dispatch.pendingCommand
}
export function patchDispatchCommand(patch) {
if (!fulfillment.dispatch.pendingCommand) throw new Error('原排车请求不存在')
Object.assign(fulfillment.dispatch.pendingCommand, patch)
persistFulfillmentDraft()
}
export function finishDispatchCommand(key) {
if (fulfillment.dispatch.pendingCommand?.body.idempotencyKey !== key) throw new Error('核对结果与原请求键不一致')
fulfillment.dispatch.pendingCommand = null
persistFulfillmentDraft()
}
export function discardRejectedDispatchCommand() {
if (fulfillment.dispatch.pendingCommand?.rejected === true) {
fulfillment.dispatch.pendingCommand = null
persistFulfillmentDraft()
}
}
export function resetFulfillmentDomain(domain) {
if (!fulfillment[domain]) return
fulfillment[domain] = blankState()[domain]