Files
console-dev/app/lib/complete-list.js
T
2026-11-06 00:04:38 +08:00

45 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
async function e(e, t = () => !0) {
let n = [],
r = new Set();
for (let i = 1; ; i++) {
if (!t()) return [];
let a = await e(i, 100);
if (!t()) return [];
if (!a || !Array.isArray(a.list)) throw Error(`列表响应无效,请重试`);
let o = a.count === void 0 ? null : Number(a.count);
if (o !== null && (!Number.isSafeInteger(o) || o < 0))
throw Error(`分页信息无效,请重试`);
let s = n.length;
for (let e of a.list) {
if (!e || !Number.isSafeInteger(Number(e.id)) || Number(e.id) <= 0)
throw Error(`列表项目无效,请重试`);
r.has(String(e.id)) || (r.add(String(e.id)), n.push(e));
}
if (o === null ? a.list.length < 100 : n.length >= o) return n;
if (s === n.length) throw Error(`未能加载完整列表,请刷新重试`);
}
}
function t(e, t) {
let n = (
Array.isArray(e) ? e : e && typeof e == `object` && `id` in e ? [e] : []
).filter((e) => !!e && typeof e == `object`),
r = [],
i = [],
a = [];
for (let e of t) {
let t = n.filter((t) => Number(t.id) === e);
t.length === 1 && Number(t[0].status) === 200
? r.push(e)
: (i.push(e),
a.push(
`#${e}:${t.length === 1 ? String(t[0].msg || `关联失败`) : `未取得明确结果,请刷新核对`}`,
));
}
return {
succeeded: r,
failed: i,
details: a,
};
}
export { e as n, t };