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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
const subList = (compCodes: string[], compDatas: JDV.State['compDatas']): AssistStruct[] => { let groupStack: GroupStack[] = []; const resultData: AssistStruct[] = [];
const stackPop = (groupCode?: string) => { let len = groupStack.length - 1; while (len >= 0) { if (groupStack[len].groupCode !== groupCode) { groupStack.pop(); } else { break; } len--; } };
const setResult = (result: AssistStruct[], groupStack: GroupStack[], groupCode: string, value: AssistStruct) => { groupStack.forEach((item, index) => { if (!result) { return null; } if (!result[item.index]) { return; } if (result[item.index].code !== groupCode) { return setResult(result[item.index].children as AssistStruct[], groupStack.slice(index + 1), groupCode, value); } else { if (result[item.index].children) { (result[item.index].children as AssistStruct[]).push(value); item.offsetNumber += 1; } else { result[item.index].children = [value]; } } }); };
compCodes.forEach((item, index) => { const hasGroup = compDatas[item] ? compDatas[item].config.groupCode : undefined; stackPop(hasGroup); if (compDatas[item].compCode === 'group') { if (hasGroup) { setResult(resultData, groupStack.slice(0), hasGroup, { code: item, children: [], });
groupStack.push({ groupCode: item, index: groupStack.length ? groupStack[groupStack.length - 1].offsetNumber - 1 : index, offsetNumber: 0, }); } else { groupStack = []; resultData.push({ code: item, children: [], }); groupStack.push({ groupCode: item, index: resultData.length - 1, offsetNumber: 0, }); } } else { if (hasGroup) { setResult(resultData, groupStack.slice(0), hasGroup, { code: item, }); } else { groupStack = []; resultData.push({ code: item, }); } } }); return resultData;
|