优化
This commit is contained in:
@@ -19,6 +19,7 @@ function createInitialState() {
|
||||
let state = createInitialState()
|
||||
|
||||
const STORAGE_PREFIX = 'pda-picking-draft'
|
||||
const COMPLETION_PREFIX = 'pda-loading-completion'
|
||||
|
||||
function storageAvailable() {
|
||||
return typeof uni !== 'undefined' && typeof uni.getStorageSync === 'function' && typeof uni.setStorageSync === 'function'
|
||||
@@ -80,6 +81,34 @@ export function clearPickingDraft(identity = {}) {
|
||||
if (key && typeof uni !== 'undefined' && typeof uni.removeStorageSync === 'function') uni.removeStorageSync(key)
|
||||
}
|
||||
|
||||
function completionKey(identity = {}) {
|
||||
const identityKey = stableTaskIdentityKey(identity)
|
||||
return identityKey ? `${COMPLETION_PREFIX}:${identityKey}` : ''
|
||||
}
|
||||
|
||||
export function saveLoadingCompletionAttempt(identity = {}, attempt = {}) {
|
||||
const key = completionKey(identity)
|
||||
if (!key || !storageAvailable() || !attempt.operationId) return
|
||||
uni.setStorageSync(key, {
|
||||
operationId: String(attempt.operationId),
|
||||
expectedTaskVersion: Number(attempt.expectedTaskVersion),
|
||||
remark: attempt.remark || '',
|
||||
updatedAt: new Date().toISOString()
|
||||
})
|
||||
}
|
||||
|
||||
export function restoreLoadingCompletionAttempt(identity = {}) {
|
||||
const key = completionKey(identity)
|
||||
if (!key || !storageAvailable()) return null
|
||||
const saved = uni.getStorageSync(key)
|
||||
return saved?.operationId && Number.isInteger(Number(saved.expectedTaskVersion)) ? clone(saved) : null
|
||||
}
|
||||
|
||||
export function clearLoadingCompletionAttempt(identity = {}) {
|
||||
const key = completionKey(identity)
|
||||
if (key && typeof uni !== 'undefined' && typeof uni.removeStorageSync === 'function') uni.removeStorageSync(key)
|
||||
}
|
||||
|
||||
export function resetPickingSession() {
|
||||
state = createInitialState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user