diff --git a/src/utils/pagedRequest.js b/src/utils/pagedRequest.js new file mode 100644 index 0000000..e8a7711 --- /dev/null +++ b/src/utils/pagedRequest.js @@ -0,0 +1,45 @@ +const DEFAULT_PAGE_SIZE = 200 +const DEFAULT_MAX_PAGES = 1000 + +/** + * Loads every page from a standard TableDataInfo endpoint. Endpoints that ignore + * page parameters are also supported because their first response already reaches total. + */ +export async function fetchAllPagedRows(fetchPage, params = {}, options = {}) { + const pageSize = Math.max(1, Number(options.pageSize || DEFAULT_PAGE_SIZE)) + const maxPages = Math.max(1, Number(options.maxPages || DEFAULT_MAX_PAGES)) + const rows = [] + const seenIds = new Set() + let lastResponse = { code: 200, rows: [], total: 0 } + + for (let pageNum = 1; pageNum <= maxPages; pageNum += 1) { + const response = await fetchPage({ ...params, pageNum, pageSize }) + lastResponse = response || lastResponse + const batch = Array.isArray(response?.rows) ? response.rows : [] + let addedCount = 0 + batch.forEach((row) => { + const id = row?.id + if (id !== undefined && id !== null && id !== '') { + const key = String(id) + if (seenIds.has(key)) return + seenIds.add(key) + } + rows.push(row) + addedCount += 1 + }) + + const total = Number(response?.total) + const hasTotal = Number.isFinite(total) && total >= 0 + if (addedCount === 0 && hasTotal && rows.length < total) { + throw new Error('日志分页没有返回新记录,无法保证数据完整') + } + if (batch.length === 0 + || addedCount === 0 + || (hasTotal && rows.length >= total) + || (!hasTotal && batch.length < pageSize)) { + return { ...lastResponse, rows, total: hasTotal ? total : rows.length } + } + } + + throw new Error(`日志记录超过 ${pageSize * maxPages} 条,未能完整加载`) +} diff --git a/src/views/flow/components/ActionQueueSingleRun.vue b/src/views/flow/components/ActionQueueSingleRun.vue index 3a6d054..993e7f6 100644 --- a/src/views/flow/components/ActionQueueSingleRun.vue +++ b/src/views/flow/components/ActionQueueSingleRun.vue @@ -15,6 +15,19 @@
{{ getActionQueueStepName(step, index) }} · {{ actionName(step.type) }}
+ + + @@ -44,7 +57,7 @@ diff --git a/src/views/flow/components/params/ActionQueueParams.vue b/src/views/flow/components/params/ActionQueueParams.vue index ac97d9d..6571a2c 100644 --- a/src/views/flow/components/params/ActionQueueParams.vue +++ b/src/views/flow/components/params/ActionQueueParams.vue @@ -33,6 +33,9 @@ {{ actionLabel(step.type) }}
+ + + @@ -141,7 +144,7 @@