diff --git a/src/api/bookRecord/recordIndex.js b/src/api/bookRecord/recordIndex.js index eb673fa..98d94be 100644 --- a/src/api/bookRecord/recordIndex.js +++ b/src/api/bookRecord/recordIndex.js @@ -33,3 +33,14 @@ export function del(params) { }) } + +// 分批导出复用列表接口,沿用登录凭证和筛选条件。 +export function exportList(params) { + return request({ + url: '/api/admin/borrow-log/index', + method: 'get', + params, + timeout: 60000, + isLoading: false + }) +} diff --git a/src/api/bookStore/bookIndex.js b/src/api/bookStore/bookIndex.js index 288fc34..875ea0f 100644 --- a/src/api/bookStore/bookIndex.js +++ b/src/api/bookStore/bookIndex.js @@ -87,3 +87,14 @@ export function delDetail(params) { params }) } + +// 分批导出复用列表接口,沿用登录凭证和筛选条件。 +export function exportList(params) { + return request({ + url: '/api/admin/book/index', + method: 'get', + params, + timeout: 60000, + isLoading: false + }) +} diff --git a/src/utils/exportList.js b/src/utils/exportList.js new file mode 100644 index 0000000..218acdd --- /dev/null +++ b/src/utils/exportList.js @@ -0,0 +1,22 @@ +// 使用后端实际返回的分页信息,避免固定大页数造成遗漏。 +export async function fetchAllForExport(fetchPage, filters) { + const params = { ...filters, page: 1, page_size: 500 } + const rows = [] + let total + while (total === undefined || rows.length < total) { + const result = await fetchPage({ ...params }) + if (!result || !Array.isArray(result.data) || !Number.isFinite(Number(result.total))) { + throw new Error('导出数据格式异常') + } + if (total === undefined) total = Number(result.total) + if (Number(result.total) !== total) { + throw new Error('导出期间数据发生变化,请重试') + } + rows.push(...result.data) + if ((!result.data.length && rows.length < total) || rows.length > total) { + throw new Error('导出数据不完整,请重试') + } + params.page += 1 + } + return rows +} diff --git a/src/views/bookRecord/recordIndex.vue b/src/views/bookRecord/recordIndex.vue index ce4f1fe..21408a7 100644 --- a/src/views/bookRecord/recordIndex.vue +++ b/src/views/bookRecord/recordIndex.vue @@ -15,6 +15,7 @@ + @@ -46,6 +47,7 @@