优化
This commit is contained in:
@@ -236,5 +236,5 @@ test('keeps failed order loads distinct from empty results', () => {
|
||||
assert.match(storeSource, /const loadError = ref\(''\)/)
|
||||
assert.match(storeSource, /orderResult\.reason instanceof Error/)
|
||||
assert.match(storeSource, /warehouseLoadError/)
|
||||
assert.match(storeSource, /return \{ orders, orderDetails, total, queueCounts, queryChannelNames, warehouses, loading, loadedFromApi, loadError, warehouseLoadError/)
|
||||
assert.match(storeSource, /return \{ orders, orderDetails, total, queueCounts, orderProgress, queryChannelNames, warehouses, loading, loadedFromApi, loadError, warehouseLoadError/)
|
||||
})
|
||||
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
getMerchantOrderWorkbench,
|
||||
type MerchantUnifiedOrderDetail,
|
||||
type MerchantOrderWorkbenchQuery,
|
||||
type MerchantOrderProgress,
|
||||
type OrderQueueCounts,
|
||||
type MerchantUnifiedOrderRow,
|
||||
} from '@/modules/first-leg/api/unifiedOrders'
|
||||
import type { MerchantTenantStatus } from '@/modules/tenant-management/public'
|
||||
@@ -396,7 +398,8 @@ export const useFirstLegOrdersStore = defineStore('client-first-leg-orders', ()
|
||||
const orders = ref<FirstLegOrder[]>([])
|
||||
const orderDetails = ref<Record<string, FirstLegOrder>>({})
|
||||
const total = ref(0)
|
||||
const queueCounts = ref({ all: 0, fee: 0, customs: 0, draft: 0 })
|
||||
const queueCounts = ref<OrderQueueCounts>({ all: 0, fee: 0, customs: 0, draft: 0, loaded: 0, declared: 0, cleared: 0, scheduled: 0, delivering: 0, delivered: 0 })
|
||||
const orderProgress = ref<Record<string, MerchantOrderProgress>>({})
|
||||
const queryChannelNames = ref<string[]>([])
|
||||
let listRequest = 0
|
||||
const pendingSubmissions = new Map<string, { key: string; payload: { expectedVersion: number } }>()
|
||||
@@ -451,7 +454,8 @@ export const useFirstLegOrdersStore = defineStore('client-first-leg-orders', ()
|
||||
loadError.value = ''
|
||||
orders.value = []
|
||||
total.value = 0
|
||||
queueCounts.value = { all: 0, fee: 0, customs: 0, draft: 0 }
|
||||
queueCounts.value = { all: 0, fee: 0, customs: 0, draft: 0, loaded: 0, declared: 0, cleared: 0, scheduled: 0, delivering: 0, delivered: 0 }
|
||||
orderProgress.value = {}
|
||||
const [orderResult, warehouseResult] = await Promise.allSettled([
|
||||
getMerchantOrderWorkbench(query), loadWarehouseType('DOMESTIC'),
|
||||
])
|
||||
@@ -466,14 +470,19 @@ export const useFirstLegOrdersStore = defineStore('client-first-leg-orders', ()
|
||||
|| Number(result.page.size) !== size || Number(result.page.pages) !== pages
|
||||
|| result.page.records.length !== Math.min(size, Math.max(0, count - (expectedPage - 1) * size))
|
||||
|| new Set(result.page.records.map(row => String(row.orderId))).size !== result.page.records.length
|
||||
|| ['all', 'fee', 'customs', 'draft'].some(key => { const value = result.queues[key as keyof typeof result.queues]; return !Number.isSafeInteger(Number(value)) || Number(value) < 0 })
|
||||
|| ['all', 'fee', 'customs', 'draft', 'loaded', 'declared', 'cleared', 'scheduled', 'delivering', 'delivered'].some(key => { const value = result.queues[key as keyof typeof result.queues]; return !Number.isSafeInteger(Number(value)) || Number(value) < 0 })
|
||||
|| Number(result.queues[query.queue ?? 'all']) !== count
|
||||
|| !Array.isArray(result.progress) || result.progress.length !== result.page.records.length
|
||||
|| new Set(result.progress.map(p => String(p.orderId))).size !== result.progress.length
|
||||
|| result.progress.some(p => !result.page.records.some(row => String(row.orderId) === String(p.orderId))
|
||||
|| !['none', 'loaded', 'declared', 'cleared', 'scheduled', 'delivering', 'delivered'].includes(p.stage) || typeof p.partial !== 'boolean')
|
||||
|| !Array.isArray(result.channelNames)) {
|
||||
loadError.value = '订单分页数据不完整,请重新加载'
|
||||
} else {
|
||||
orders.value = result.page.records.map(item => mapUnifiedOrderRow(item, warehouses.value))
|
||||
total.value = count
|
||||
queueCounts.value = { all: Number(result.queues.all), fee: Number(result.queues.fee), customs: Number(result.queues.customs), draft: Number(result.queues.draft) }
|
||||
queueCounts.value = Object.fromEntries(Object.entries(result.queues).map(([key, value]) => [key, Number(value)])) as OrderQueueCounts
|
||||
orderProgress.value = Object.fromEntries(result.progress.map(p => [String(p.orderId), p]))
|
||||
queryChannelNames.value = result.channelNames
|
||||
}
|
||||
} catch { loadError.value = '订单分页数据不完整,请重新加载' }
|
||||
@@ -629,5 +638,5 @@ export const useFirstLegOrdersStore = defineStore('client-first-leg-orders', ()
|
||||
return loadOrderAggregate(id)
|
||||
}
|
||||
|
||||
return { orders, orderDetails, total, queueCounts, queryChannelNames, warehouses, loading, loadedFromApi, loadError, warehouseLoadError, getById, load, loadDetail, loadDraftDetail, loadWarehouseDetail, loadWarehouseType, beginDraftEdit, saveDraft, prepareCancellation, cancelOrder, saveDraftBatch, submitSaved, hasPendingSubmission, isSubmissionRetry, beginNewSubmissionEdit, saveDraftForSubmission }
|
||||
return { orders, orderDetails, total, queueCounts, orderProgress, queryChannelNames, warehouses, loading, loadedFromApi, loadError, warehouseLoadError, getById, load, loadDetail, loadDraftDetail, loadWarehouseDetail, loadWarehouseType, beginDraftEdit, saveDraft, prepareCancellation, cancelOrder, saveDraftBatch, submitSaved, hasPendingSubmission, isSubmissionRetry, beginNewSubmissionEdit, saveDraftForSubmission }
|
||||
})
|
||||
|
||||
@@ -11,7 +11,8 @@ const row = (id, mainStatus = 'LOADED') => ({ orderId: String(id), orderNo: `FL-
|
||||
function result(page = 1, size = 10, total = 215) {
|
||||
return {
|
||||
page: { page, size, total, pages: Math.ceil(total / size), records: Array.from({ length: Math.min(size, Math.max(0, total - (page - 1) * size)) }, (_, i) => row((page - 1) * size + i + 1)) },
|
||||
queues: { all: total, fee: 2, customs: 1, draft: 3 }, channelNames: ['AIR', 'SEA'],
|
||||
queues: { all: total, fee: 2, customs: 1, draft: 3, loaded: 0, declared: 0, cleared: 0, scheduled: 0, delivering: 0, delivered: 0 }, channelNames: ['AIR', 'SEA'],
|
||||
progress: Array.from({ length: Math.min(size, Math.max(0, total - (page - 1) * size)) }, (_, i) => ({ orderId: String((page - 1) * size + i + 1), stage: 'loaded', partial: false })),
|
||||
}
|
||||
}
|
||||
function deferred() { let resolve, reject; const promise = new Promise((a, b) => { resolve = a; reject = b }); return { promise, resolve, reject } }
|
||||
@@ -44,7 +45,7 @@ test('loads beyond 200 with server totals and forwards every filter using one re
|
||||
assert.equal(h.store.orders[0].id, '201')
|
||||
assert.equal(h.store.total, 215)
|
||||
assert.deepEqual(h.calls, [query])
|
||||
assert.deepEqual(h.store.queueCounts, { all: 215, fee: 2, customs: 1, draft: 3 })
|
||||
assert.deepEqual(h.store.queueCounts, { all: 215, fee: 2, customs: 1, draft: 3, loaded: 0, declared: 0, cleared: 0, scheduled: 0, delivering: 0, delivered: 0 })
|
||||
assert.deepEqual(h.store.queryChannelNames, ['AIR', 'SEA'])
|
||||
await h.store.load({ page: 22, size: 10 })
|
||||
assert.deepEqual(h.store.orders.map(item => item.id), ['211', '212', '213', '214', '215'])
|
||||
@@ -109,9 +110,24 @@ test('draft and cancelled rows retain authoritative versions; off-page detail ca
|
||||
|
||||
test('queue total is checked against the selected queue rather than all orders', async t => {
|
||||
const response = result(1, 10, 2)
|
||||
response.queues = { all: 215, fee: 2, customs: 1, draft: 3 }
|
||||
response.queues = { all: 215, fee: 2, customs: 1, draft: 3, loaded: 0, declared: 0, cleared: 0, scheduled: 0, delivering: 0, delivered: 0 }
|
||||
const h = harness(t, () => response)
|
||||
await h.store.load({ queue: 'fee' })
|
||||
assert.equal(h.store.total, 2); assert.equal(h.store.queueCounts.all, 215)
|
||||
assert.equal(h.store.loadError, '')
|
||||
})
|
||||
|
||||
|
||||
test('retains server progress and rejects missing or foreign progress without inferring milestones', async t => {
|
||||
let response = result()
|
||||
response.progress[0] = { orderId: '1', stage: 'scheduled', partial: true }
|
||||
const h = harness(t, () => response)
|
||||
await h.store.load()
|
||||
assert.deepEqual(h.store.orderProgress['1'], response.progress[0])
|
||||
response = result(); response.progress[0].orderId = 'foreign'
|
||||
await h.store.load()
|
||||
assert.match(h.store.loadError, /分页数据不完整/)
|
||||
assert.deepEqual(h.store.orderProgress, {})
|
||||
response = result(); delete response.queues.cleared
|
||||
await h.store.load(); assert.match(h.store.loadError, /分页数据不完整/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user