/**
|
* 根据对象内两个数组的笛卡尔积生成新数组
|
* @param form 原始对象
|
* @param array1Key 第一个数组的键名
|
* @param array2Key 第二个数组的键名
|
* @param keysFromArray2 需要从第二个数组元素中获取值的键名数组
|
* @returns 生成的新数组
|
*/
|
export function generateCartesianArray(form: any, array1Key: string, array2Key: string, keysFromArray2: string[]): any[] {
|
const result: any[] = [];
|
const array1 = form[array1Key] || [];
|
const array2 = form[array2Key] || [];
|
|
// 遍历第一个数组
|
for (const item1 of array1) {
|
// 遍历第二个数组
|
for (const item2 of array2) {
|
// 创建一个包含原对象所有属性的新对象
|
const newObj = { ...form };
|
|
// 设置第一个数组对应的属性
|
newObj[array1Key] = item1;
|
|
// 设置第二个数组对应的属性
|
newObj[array2Key] = item2;
|
|
// 设置需要从第二个数组元素中获取值的属性
|
if (typeof item2 === 'object') {
|
keysFromArray2.forEach(key => {
|
if (key in item2) {
|
newObj[key] = item2[key];
|
}
|
});
|
}
|
|
result.push(newObj);
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 处理检查计划数据,根据planMonth和checkdIds生成笛卡尔积数组
|
* @param form 检查计划表单数据
|
* @returns 生成的新数组
|
*/
|
export function processCheckPlanForm(form: any): any[] {
|
// 确保form对象存在并且两个数组有效
|
if (!form || !Array.isArray(form.planMonth) || !Array.isArray(form.checkdIds)) {
|
return [];
|
}
|
|
// 需要从checkdIds数组元素中获取值的属性
|
const keysFromCheckdIds = ['checkdIds', 'companyName', 'companyCode', 'applyDeptNames'];
|
|
return generateCartesianArray(form, 'planMonth', 'checkdIds', keysFromCheckdIds);
|
}
|