report-design/src/assets/methodTool.ts

67 lines
1.6 KiB
TypeScript

const Tool = {
addRow: (that: any, rowId: number) => {
if (that.selectedRow) {
for (const index in that.infos) {
if (that.selectedRow === that.infos[index].rowId) {
that.infos.splice(Number(index), 0, {
rowId,
rowTitle: rowId.toString(),
cells: [],
});
that.selectedRow = 0;
break;
}
}
} else {
that.infos.push({
rowId: (rowId += 1),
rowTitle: rowId.toString(),
cells: [],
});
}
},
deleteRow: (that: any) => {
if (!that.selectedRow) {
return alert('请选择要删除行');
}
that.infos = that.infos.filter(
(item: any) => item.rowId !== that.selectedRow,
);
that.selectedRow = 0;
},
addCell: (that: any, cellId: number) => {
if (!that.selectedRow) {
return alert('请选择要添加单元的行');
}
for (const row of that.infos) {
if (that.selectedRow === row.rowId) {
row.cells.push({
cellId,
title: '列' + cellId,
colspan: 0,
height: 30,
textAlign: 'center',
fontSize: 16,
fontStyle: 'normal',
});
}
}
},
deleteCell: (that: any) => {
// 9000 is initial cell Id.
if (that.selectedCell === 9000) {
return alert('请选择要删除的单元');
}
for (const row of that.infos) {
for (const cell in row.cells) {
if (row.cells[cell].cellId === that.selectedCell) {
row.cells.splice(Number(cell), 1);
}
}
}
that.selectedCell = 9000;
},
};
export { Tool };