feat: complete overseas PDA warehouse operations

This commit is contained in:
2026-09-04 12:42:17 +08:00
parent e8f5d053ee
commit f960b9fe5f
18 changed files with 678 additions and 66 deletions
+2
View File
@@ -2,6 +2,7 @@ import { reactive } from 'vue'
import { OVERSEAS_API_ROOT } from '../config/runtime.js'
import { resetReceivingSession } from './receiving.js'
import { resetFulfillmentSession } from './fulfillment.js'
import { resetWarehouseWork } from './warehouse-work.js'
const SESSION_KEY = 'overseas-pda-auth-session'
export const PDA_ROLE = 'OVERSEAS_WAREHOUSE_PDA_OPERATOR'
@@ -181,6 +182,7 @@ export function signOut() {
if (typeof uni !== 'undefined' && typeof uni.removeStorageSync === 'function') uni.removeStorageSync(SESSION_KEY)
resetReceivingSession()
resetFulfillmentSession()
resetWarehouseWork()
}
export function requireSession() {
+74
View File
@@ -0,0 +1,74 @@
import { reactive } from 'vue'
const STORAGE_KEY = 'overseas-pda-warehouse-work-v1'
const blankState = () => ({
scopeKey: '',
stocktake: { taskNo: '', scopeType: 'LOCATION', scopeCode: '', reason: '', pendingKeys: {} },
move: { sourcePalletCode: '', targetLocationCode: '', reason: '', pendingKeys: {} },
relabel: { currentNo: '', oldLabel: '', newLabel: '', action: 'RELABEL', reason: '', remark: '', photoFileIds: [], photoNames: [], pendingKeys: {} },
query: { inventoryCode: '', locationCode: '', palletCode: '' }
})
export const warehouseWork = reactive(blankState())
function storageAvailable() {
return typeof uni !== 'undefined' && typeof uni.setStorageSync === 'function' && typeof uni.getStorageSync === 'function'
}
function domain(value, fallback) { return { ...fallback, ...(value || {}), pendingKeys: { ...(value?.pendingKeys || {}) } } }
export function persistWarehouseWork() {
if (!storageAvailable() || !warehouseWork.scopeKey) return
uni.setStorageSync(STORAGE_KEY, JSON.parse(JSON.stringify(warehouseWork)))
}
export function restoreWarehouseWork(scopeKey) {
const expected = String(scopeKey || '')
if (!expected) return false
const saved = storageAvailable() ? uni.getStorageSync(STORAGE_KEY) : null
const fresh = blankState()
if (!saved || saved.scopeKey !== expected) {
Object.assign(warehouseWork, fresh, { scopeKey: expected })
if (storageAvailable()) uni.removeStorageSync(STORAGE_KEY)
return false
}
Object.assign(warehouseWork, fresh, {
scopeKey: expected,
stocktake: domain(saved.stocktake, fresh.stocktake), move: domain(saved.move, fresh.move),
relabel: domain(saved.relabel, fresh.relabel), query: { ...fresh.query, ...(saved.query || {}) }
})
return true
}
export function updateWarehouseWork(name, patch) {
if (!warehouseWork[name]) throw new Error('未知海外仓现场作业')
Object.assign(warehouseWork[name], patch)
persistWarehouseWork()
}
export function warehouseIdempotencyKey(name, action, payload = {}) {
const target = warehouseWork[name]
if (!target?.pendingKeys) throw new Error('当前作业不支持写操作')
const signature = `${action}:${JSON.stringify(payload)}`
if (!target.pendingKeys[signature]) target.pendingKeys[signature] = `pda-${name}-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
persistWarehouseWork()
return { signature, value: target.pendingKeys[signature] }
}
export function releaseWarehouseKey(name, signature) {
if (!warehouseWork[name]?.pendingKeys) return
delete warehouseWork[name].pendingKeys[signature]
persistWarehouseWork()
}
export function resetWarehouseDomain(name) {
const fresh = blankState()
if (!fresh[name]) return
warehouseWork[name] = fresh[name]
persistWarehouseWork()
}
export function resetWarehouseWork() {
Object.assign(warehouseWork, blankState())
if (typeof uni !== 'undefined' && typeof uni.removeStorageSync === 'function') uni.removeStorageSync(STORAGE_KEY)
}