适配PDA稳定柜次身份契约
This commit is contained in:
+10
-14
@@ -1,5 +1,6 @@
|
||||
import { createBoxes } from '@/data/demo-data.js'
|
||||
import { createItemStates } from '@/utils/picking-state.js'
|
||||
import { stableTaskIdentity, stableTaskIdentityKey } from '@/utils/task-identity.js'
|
||||
|
||||
function clone(value) {
|
||||
return JSON.parse(JSON.stringify(value))
|
||||
@@ -23,25 +24,18 @@ function storageAvailable() {
|
||||
return typeof uni !== 'undefined' && typeof uni.getStorageSync === 'function' && typeof uni.setStorageSync === 'function'
|
||||
}
|
||||
|
||||
function identityValue(identity = {}) {
|
||||
const operatorId = identity.operatorId ?? identity.accountId ?? identity.userId
|
||||
const taskId = identity.taskId ?? identity.inboundId
|
||||
const containerNo = identity.containerNo ?? identity.boxNo
|
||||
return { operatorId: operatorId == null ? '' : String(operatorId), taskId: taskId == null ? '' : String(taskId), containerNo: containerNo == null ? '' : String(containerNo) }
|
||||
}
|
||||
|
||||
export function getPickingDraftKey(identity = {}) {
|
||||
const value = identityValue(identity)
|
||||
if (!value.operatorId || !value.taskId || !value.containerNo) return ''
|
||||
return `${STORAGE_PREFIX}:${encodeURIComponent(value.operatorId)}:${encodeURIComponent(value.taskId)}:${encodeURIComponent(value.containerNo)}`
|
||||
const identityKey = stableTaskIdentityKey(identity)
|
||||
return identityKey ? `${STORAGE_PREFIX}:${identityKey}` : ''
|
||||
}
|
||||
|
||||
function draftPayload(nextState, identity) {
|
||||
const value = identityValue(identity)
|
||||
const value = stableTaskIdentity(identity)
|
||||
return {
|
||||
operatorId: value.operatorId,
|
||||
taskId: value.taskId,
|
||||
containerNo: value.containerNo,
|
||||
loadingPlanId: value.loadingPlanId,
|
||||
containerBookingId: value.containerBookingId,
|
||||
warehouseId: identity.warehouseId ?? null,
|
||||
currentBoxIndex: nextState.currentBoxIndex,
|
||||
itemStates: nextState.itemStates,
|
||||
@@ -68,11 +62,13 @@ export function restorePickingSession(identity = {}) {
|
||||
const key = getPickingDraftKey(identity)
|
||||
if (!key || !storageAvailable()) return null
|
||||
const saved = uni.getStorageSync(key)
|
||||
if (!saved || saved.operatorId !== identityValue(identity).operatorId || saved.taskId !== identityValue(identity).taskId || saved.containerNo !== identityValue(identity).containerNo) return null
|
||||
const expected = stableTaskIdentity(identity)
|
||||
if (!saved || saved.operatorId !== expected.operatorId || saved.taskId !== expected.taskId || saved.loadingPlanId !== expected.loadingPlanId || saved.containerBookingId !== expected.containerBookingId) return null
|
||||
const restored = { ...state, ...clone(saved) }
|
||||
delete restored.operatorId
|
||||
delete restored.taskId
|
||||
delete restored.containerNo
|
||||
delete restored.loadingPlanId
|
||||
delete restored.containerBookingId
|
||||
delete restored.warehouseId
|
||||
delete restored.updatedAt
|
||||
state = restored
|
||||
|
||||
Reference in New Issue
Block a user