diff --git a/pages/picking/picking.vue b/pages/picking/picking.vue index f0488f3..7a723b5 100644 --- a/pages/picking/picking.vue +++ b/pages/picking/picking.vue @@ -516,6 +516,10 @@ if (!requireSession()) return this.currentUser = session.currentUser if (options.taskId) { + // Session display state can belong to the task opened before this route. + // Only the scoped draft restored after loading this task may restore its history. + this.scanValue = '' + this.scanHistory = [] // A local completion marker belongs to the previously opened task. The // canonical server detail decides whether this task is complete. this.completedBoxes = {} diff --git a/tests/picking-refresh-route.test.mjs b/tests/picking-refresh-route.test.mjs index c294492..128999d 100644 --- a/tests/picking-refresh-route.test.mjs +++ b/tests/picking-refresh-route.test.mjs @@ -4,6 +4,34 @@ import { readFile } from 'node:fs/promises' const read = (path) => readFile(new URL(path, import.meta.url), 'utf8') +test('opening another task clears prior scan display without deleting scoped draft or submission identity', async () => { + const page = await read('../pages/picking/picking.vue') + const load = page.match(/onLoad\(options = \{\}\) \{[\s\S]*?\r?\n\t\t\},/)?.[0] + const record = page.match(/recordScanResult\([^\n]+\) \{[\s\S]*?\r?\n\t\t\t\},/)?.[0] + assert.ok(load && record) + const hooks = new Function('requireSession', 'session', `return ({${load}${record}})`)(() => true, { currentUser: { id: '7' } }) + const savedDraft = { 0: { scannedBoxCodes: { 'DP-OLD': 'old-item' }, itemStates: { 'old-item': 'picked' } } } + const context = { scanValue: 'DP-OLD', scanHistory: [{ id: 'old', boxCode: 'DP-OLD', title: '整托已记入草稿' }], + boxDrafts: savedDraft, submitId: 'existing-operation', itemStates: { 'old-item': 'picked' } } + hooks.onLoad.call(context, { taskId: 'new-task', warehouseId: 'warehouse' }) + assert.equal(context.scanValue, '') + assert.deepEqual(context.scanHistory, []) + assert.equal(context.remoteTaskId, 'new-task') + assert.equal(context.boxDrafts, savedDraft) + assert.equal(context.submitId, 'existing-operation') + assert.deepEqual(context.itemStates, { 'old-item': 'picked' }) + hooks.recordScanResult.call(context, 'success', '整托已记入草稿', 'DP-NEW', '整托 1 箱,提交后保存') + assert.equal(context.scanHistory.length, 1) + assert.equal(context.scanHistory[0].boxCode, 'DP-NEW') + // A same-task route reopen also clears input; canonical scoped restoration still owns draft history. + hooks.onLoad.call(context, { taskId: 'new-task', warehouseId: 'warehouse' }) + assert.deepEqual(context.scanHistory, []) + assert.equal(context.boxDrafts, savedDraft) + const restore = page.match(/restoreRemoteDraft\(\) \{[\s\S]*?\r?\n\t\t\t\},/)?.[0] || '' + assert.match(restore, /restorePickingSession\(this\.draftIdentity\(\)\)/) + assert.match(restore, /this\.scanHistory = this\.normalizeScanHistory\(restored\.scanHistory\)/) +}) + test('duplicate onShow shares one load chain while background return refreshes again', async () => { const page = await read('../pages/picking/picking.vue') const show = page.match(/async onShow\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]