fix(pda): guard duplicate submission and invalidate hidden task requests

This commit is contained in:
2026-10-02 11:12:53 +08:00
parent 7ba6a24505
commit 8d2d80ec11
4 changed files with 155 additions and 17 deletions
+8 -3
View File
@@ -36,12 +36,14 @@ test('duplicate onShow shares one load chain while background return refreshes a
const page = await read('../pages/picking/picking.vue')
const show = page.match(/async onShow\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
const hide = page.match(/onHide\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
assert.ok(show && hide)
const hooks = new Function('requireSession', 'session', `return ({${show}${hide}})`)(() => true, { currentUser: { id: '7' } })
const invalidate = page.match(/invalidateTaskSync\(\) \{[^\r\n]+\},/)?.[0]
assert.ok(show && hide && invalidate)
const hooks = new Function('requireSession', 'session', `return ({${show}${hide}${invalidate}})`)(() => true, { currentUser: { id: '7' } })
const calls = []
let release
const pending = new Promise((resolve) => { release = resolve })
const context = { startHardwareScanner() {}, stopHardwareScanner() {}, async refreshAvailableBoxes() { calls.push('pending'); await pending }, async syncRemoteTask() { calls.push('detail+evidence') } }
const context = { taskRequestId: 0, invalidateTaskSync: hooks.invalidateTaskSync,
startHardwareScanner() {}, stopHardwareScanner() {}, async refreshAvailableBoxes() { calls.push('pending'); await pending }, async syncRemoteTask() { calls.push('detail+evidence') } }
const first = hooks.onShow.call(context)
const duplicate = hooks.onShow.call(context)
assert.deepEqual(calls, ['pending'])
@@ -51,6 +53,9 @@ test('duplicate onShow shares one load chain while background return refreshes a
await hooks.onShow.call(context)
assert.equal(calls.length, 2)
hooks.onHide.call(context)
assert.equal(context.taskRequestId, 1)
assert.equal(context.remoteLoading, false)
assert.equal(context._showRefreshPromise, null)
await hooks.onShow.call(context)
assert.deepEqual(calls, ['pending', 'detail+evidence', 'pending', 'detail+evidence'])
const onLoad = page.match(/onLoad\(options = \{\}\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]