刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
type RecordId = number | string;
 
interface BatchSavedRow {
  clientRowId: string;
  id: RecordId;
}
 
/** ID 仅传入本次后置事件,不改变表单的新增/编辑状态或原参数引用。 */
export function buildAfterSubmitParameter<T extends { formData?: { id?: RecordId } }>(parameter: T, id?: RecordId) {
  return { ...parameter, id: id ?? parameter.formData?.id ?? '' };
}
 
/** 批量响应按客户端行标识关联,不依赖服务端返回顺序。 */
export function getBatchSubmitRecordIds(rows: { __batchRowId?: string; id?: RecordId; jnpfId?: string }[], savedRows: BatchSavedRow[] = [], isEdit = false) {
  const ids = new Map(savedRows.map((row) => [row.clientRowId, row.id]));
  return rows.map((row) => ids.get(row.__batchRowId || row.jnpfId || '') ?? (isEdit ? (row.id ?? '') : ''));
}