33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
/**
|
|
* 发票资料完整分页加载;e(page, 50) 返回 {list, count?},保留字符串形式的资料 id。
|
|
* 去重后仍达不到 count 且本页没有新记录时失败,避免将不完整资料当成完整列表。
|
|
*/
|
|
async function e(e) {
|
|
let t = [],
|
|
n = new Set();
|
|
for (let r = 1; ; r++) {
|
|
let i = await e(r, 50);
|
|
if (!i || !Array.isArray(i.list))
|
|
throw Error(`发票资料格式异常,请重新加载`);
|
|
let a = i.count === void 0 ? null : Number(i.count);
|
|
if (a !== null && (!Number.isSafeInteger(a) || a < 0))
|
|
throw Error(`发票资料分页信息异常,请重新加载`);
|
|
let o = t.length;
|
|
for (let e of i.list) {
|
|
if (
|
|
!e ||
|
|
![`number`, `string`].includes(typeof e.id) ||
|
|
!String(e.id).trim()
|
|
)
|
|
throw Error(`发票资料格式异常,请重新加载`);
|
|
let r = String(e.id);
|
|
n.has(r) || (n.add(r), t.push(e));
|
|
}
|
|
if ((a !== null && t.length >= a) || (a === null && i.list.length < 50))
|
|
return t;
|
|
if (t.length === o)
|
|
throw Error(`未能加载完整发票资料,分页数据可能已变化,请重试`);
|
|
}
|
|
}
|
|
export { e as t };
|