刘光辉
119 分钟以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { RecordBatchItem, RecordCreated } from '#/api/x/eln/records';
 
export class ElnRecordBatchParamError extends Error {}
 
export function resolveTestWorkItemIds(value: unknown): string[] {
  if (!Array.isArray(value) || !value.length) {
    throw new ElnRecordBatchParamError('请选择至少一个检验项');
  }
  const ids = value.map((item) => {
    if (typeof item !== 'string' || !item.trim()) {
      throw new ElnRecordBatchParamError('检验项选择无效');
    }
    return item.trim();
  });
  return [...new Set(ids)];
}
 
export function canOpenSingleRecord(testWorkItemIds: string[], item: RecordBatchItem | undefined): item is RecordBatchItem & { created: RecordCreated } {
  return testWorkItemIds.length === 1 && Boolean(item?.created) && ['CREATED', 'EXISTING'].includes(item?.status || '');
}
 
export function statusLabel(status: RecordBatchItem['status']) {
  if (status === 'CREATED') return '新建成功';
  if (status === 'EXISTING') return '已存在';
  return '创建失败';
}