fix(qc,production): 我的任务列表改为按工单服务端分页

避免前端循环拉取全部任务再本地分页,翻页只请求当前页工单卡片及下属任务。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-12-02 16:11:55 +08:00
1 parent 0807ee9b4a
commit 9984d73989
11 files changed
+575 -203

No files matched your search

@@ -17,10 +17,13 @@ export type ProductionTaskMineFilters = {
keyword?: string
taskStatus?: string
productionCategory?: string
workOrderStatus?: string
tabKey: ProductionWorkOrderTabKey
excludeVoidProtocol?: boolean
plannedStartTimeStart?: string
plannedStartTimeEnd?: string
page?: number
pageSize?: number
}
export type MineWorkOrderSearchFilters = {
@@ -143,55 +146,53 @@ export function buildPresetTasksMap(
return map
}
async function fetchMineTasksByScope(
scope: 'current' | 'history',
/** 按工单卡片分页拉取「我的生产任务」(合并 current+history,单次请求) */
export async function fetchMineProductionTasksByWorkOrderPage(
filters: ProductionTaskMineFilters
): Promise<ProductionTaskRow[]> {
): Promise<{ list: ProductionTaskRow[]; total: number }> {
const tab = getProductionWorkOrderTab(filters.tabKey)!
const listQuery = isAllProductionWorkOrderTab(filters.tabKey)
? toAllTabListQuery(filters.productionCategory || '')
: toWorkOrderListQuery(tab)
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
let page = 1
const all: ProductionTaskRow[] = []
let total = 0
while (true) {
const res = await fetchMyProductionTasks({
scope,
page,
pageSize,
keyword: filters.keyword || undefined,
taskStatus: filters.taskStatus || undefined,
workOrderType: listQuery.workOrderType,
receptionSource: listQuery.receptionSource,
bizType: listQuery.bizType,
includeStepSummary: true,
excludeVoidProtocol: filters.excludeVoidProtocol,
plannedStartTimeStart: filters.plannedStartTimeStart,
plannedStartTimeEnd: filters.plannedStartTimeEnd
})
const list = res.list || []
all.push(...list)
total = res.total || 0
if (!list.length || all.length >= total) break
page += 1
}
return all
const res = await fetchMyProductionTasks({
scope: 'all',
pageBy: 'workOrder',
page: Math.max(1, filters.page || 1),
pageSize: Math.min(100, Math.max(1, filters.pageSize || 10)),
keyword: filters.keyword || undefined,
taskStatus: filters.taskStatus || undefined,
workOrderType: listQuery.workOrderType,
receptionSource: listQuery.receptionSource,
bizType: listQuery.bizType,
workOrderStatus: filters.workOrderStatus || undefined,
includeStepSummary: true,
excludeVoidProtocol: filters.excludeVoidProtocol,
plannedStartTimeStart: filters.plannedStartTimeStart,
plannedStartTimeEnd: filters.plannedStartTimeEnd
})
return { list: res.list || [], total: res.total || 0 }
}
/** 合并当前负责人任务与曾转发任务(方案 C:单列表) */
/** @deprecated 保留兼容;新列表请用 fetchMineProductionTasksByWorkOrderPage */
export async function fetchAllMineProductionTasks(
filters: ProductionTaskMineFilters
): Promise<ProductionTaskRow[]> {
const [current, history] = await Promise.all([
fetchMineTasksByScope('current', filters),
fetchMineTasksByScope('history', filters)
])
const map = new Map<string, ProductionTaskRow>()
for (const row of [...current, ...history]) {
if (row.id) map.set(row.id, row)
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
let page = 1
const all: ProductionTaskRow[] = []
while (true) {
const res = await fetchMineProductionTasksByWorkOrderPage({
...filters,
page,
pageSize
})
const list = res.list || []
all.push(...list)
if (!list.length || list.length < pageSize) break
page += 1
if (page > 50) break
}
return [...map.values()]
return all
}
export async function enrichMineEntriesWithWorkOrders(
+51 -16
View File
@@ -29,6 +29,17 @@ export type QcTaskMineFilters = {
taskStatus?: string
/** 科研捐赠:协议状态逗号串;''=不限制;缺省不传 */
protocolStatus?: string
workOrderStatus?: string
triggerSource?: string
sampleTypeId?: string
/** 「所有」Tab 的质检类型子筛选 */
qcCategory?: string
createTimeStart?: string
createTimeEnd?: string
infusionTimeStart?: string
infusionTimeEnd?: string
page?: number
pageSize?: number
tabKey: QcWorkOrderTabKey
}
@@ -138,38 +149,62 @@ export function filterMineEntriesByWorkOrderSearch(
})
}
/** @deprecated 保留兼容;新列表请用 fetchMineTasksByWorkOrderPage */
export async function fetchAllMineTasks(filters: QcTaskMineFilters): Promise<QcTask[]> {
const tab = getQcWorkOrderTab(filters.tabKey)!
const listQuery = isAllQcWorkOrderTab(filters.tabKey)
? toAllTabListQuery('')
: toWorkOrderListQuery(tab)
const pageSize = MINE_TASK_FETCH_PAGE_SIZE
let page = 1
const all: QcTask[] = []
let total = 0
const protocolStatusParam =
filters.tabKey === 'inbound_research_donation' ? (filters.protocolStatus ?? '') : undefined
while (true) {
const res = await fetchMyQcTaskList({
const res = await fetchMineTasksByWorkOrderPage({
...filters,
page,
pageSize,
keyword: filters.keyword || undefined,
taskType: filters.taskType || undefined,
taskStatus: filters.taskStatus || undefined,
qcBizType: listQuery.workOrderType,
receptionSource: listQuery.receptionSource,
bizType: listQuery.bizType,
...(protocolStatusParam !== undefined ? { protocolStatus: protocolStatusParam } : {})
pageSize
})
const list = res.list || []
all.push(...list)
total = res.total || 0
if (!list.length || all.length >= total) break
// 旧全量语义:按任务条数拼满;pageBy=workOrder 时 total 为工单数,这里用 list 耗尽结束
if (!list.length) break
if (list.length < pageSize) break
page += 1
if (page > 50) break
}
return all
}
/** 按工单卡片分页拉取「我的质检任务」(单次请求,不再循环全量) */
export async function fetchMineTasksByWorkOrderPage(
filters: QcTaskMineFilters
): Promise<{ list: QcTask[]; total: number }> {
const tab = getQcWorkOrderTab(filters.tabKey)!
const listQuery = isAllQcWorkOrderTab(filters.tabKey)
? toAllTabListQuery(filters.qcCategory || '')
: toWorkOrderListQuery(tab)
const protocolStatusParam =
filters.tabKey === 'inbound_research_donation' ? (filters.protocolStatus ?? '') : undefined
const res = await fetchMyQcTaskList({
page: Math.max(1, filters.page || 1),
pageSize: Math.min(100, Math.max(1, filters.pageSize || 10)),
pageBy: 'workOrder',
keyword: filters.keyword || undefined,
taskType: filters.taskType || undefined,
taskStatus: filters.taskStatus || undefined,
qcBizType: listQuery.workOrderType,
receptionSource: listQuery.receptionSource,
bizType: listQuery.bizType,
workOrderStatus: filters.workOrderStatus || undefined,
triggerSource: filters.triggerSource || undefined,
sampleTypeId: filters.sampleTypeId || undefined,
createTimeStart: filters.createTimeStart || undefined,
createTimeEnd: filters.createTimeEnd || undefined,
infusionTimeStart: filters.infusionTimeStart || undefined,
infusionTimeEnd: filters.infusionTimeEnd || undefined,
...(protocolStatusParam !== undefined ? { protocolStatus: protocolStatusParam } : {})
})
return { list: res.list || [], total: res.total || 0 }
}
export async function enrichMineEntriesWithWorkOrders(
entries: MineWorkOrderEntry[]
): Promise<MineWorkOrderEntry[]> {