function setListRowSpan(source, name, ...link) {
const setRowSpan = (source, name, ...link) => {
let linkHead = null;
if (link && link.length > 0) {
linkHead = link[0];
}
let data = JSON.parse(JSON.stringify(source));
const rowSpan = `${name}RowSpan`;
let titleRow = data[0];
titleRow[rowSpan] = 1;
data.forEach((row, index) => {
if (linkHead) row[name + linkHead] = row[name] + "-" + row[linkHead];
const nextRow = data[index + 1];
if (!nextRow) return;
if (row[name] === nextRow[name]) {
titleRow[rowSpan] += 1;
nextRow[rowSpan] = 0;
} else {
titleRow = nextRow;
titleRow[rowSpan] = 1;
}
});
if (linkHead && link.length > 1) {
data = setRowSpan(data, name + linkHead, link.slice(1));
}
return data;
};
const dataList = setRowSpan(source, name, ...link);
const res = setRowSpan(dataList, [name, ...link].join(""));
return res;
}