2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { formatIdReference } from '../../helpers/safeDisplay.js';
|
|
|
|
export function latestTierURL(filters = {}, page = 1, snapshot = {}) {
|
|
const params = new URLSearchParams({
|
|
view: 'latest',
|
|
p: String(page),
|
|
page_size: String(filters.pageSize ?? 100),
|
|
});
|
|
if (filters.query?.trim()) params.set('q', filters.query.trim());
|
|
if (filters.type) params.set('source_type', filters.type);
|
|
const status =
|
|
{ enabled: 'active', scheduled: 'pending' }[filters.status] ||
|
|
filters.status;
|
|
if (status && status !== 'all') params.set('status', status);
|
|
if (snapshot.as_of) params.set('as_of', String(snapshot.as_of));
|
|
if (snapshot.revision != null)
|
|
params.set('revision', String(snapshot.revision));
|
|
return `/api/commission/v2/tiers?${params}`;
|
|
}
|
|
|
|
export async function fetchAllLatestTiers(fetchJSON, filters = {}) {
|
|
const rows = [];
|
|
let snapshot;
|
|
let total;
|
|
for (let page = 1; ; page++) {
|
|
const result = await fetchJSON(
|
|
latestTierURL({ ...filters, pageSize: 100 }, page, snapshot),
|
|
);
|
|
if (!snapshot) {
|
|
snapshot = { as_of: result.as_of, revision: result.revision };
|
|
total = result.total;
|
|
}
|
|
if (
|
|
result.as_of !== snapshot.as_of ||
|
|
result.revision !== snapshot.revision ||
|
|
result.total !== total
|
|
)
|
|
throw new Error('档位配置已变化,请重新加载或重新导出');
|
|
if (
|
|
!Array.isArray(result.items) ||
|
|
(rows.length < total && !result.items.length)
|
|
)
|
|
throw new Error('无法取得完整档位列表,请重试');
|
|
rows.push(...result.items);
|
|
if (rows.length === total) return rows;
|
|
if (rows.length > total) throw new Error('档位配置已变化,请重新导出');
|
|
}
|
|
}
|
|
|
|
export function mergeIdentityOptions(previous, next, selected) {
|
|
return [
|
|
...new Map(
|
|
[...(selected ? [selected] : []), ...previous, ...next].map((item) => [
|
|
Number(item.id),
|
|
item,
|
|
]),
|
|
).values(),
|
|
];
|
|
}
|
|
|
|
export function createRequestGeneration() {
|
|
let generation = 0;
|
|
return { next: () => ++generation, current: (value) => generation === value };
|
|
}
|
|
|
|
export function identityOptionLabel(item) {
|
|
const name =
|
|
item.name || item.display_name || item.username || item.code || '';
|
|
const identifier = item.name ? item.code : item.username;
|
|
return `${name}${identifier && identifier !== name ? ` · ${identifier}` : ''} (${formatIdReference(item.id)})${item.disabled_reason ? ` · ${item.disabled_reason}` : ''}`;
|
|
}
|