report-design/src/assets/methodTool.ts

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-10-08 17:36:24 +08:00
const Tool = {
addRow: (that, rowId) => {
if (that.selectedRow) {
for (const index in that.infos) {
if (that.selectedRow === that.infos[index].rowId) {
that.infos.splice(Number(index), 0, {
rowId: rowId,
rowTitle: rowId.toString(),
cells: [],
});
that.selectedRow = 0;
break;
}
}
} else {
that.infos.push({
rowId: (rowId += 1),
rowTitle: rowId.toString(),
cells: [],
});
}
},
deleteRow: (that) => {
if (!that.selectedRow) {
return alert('请选择要删除行');
}
that.infos = that.infos.filter((item) => item.rowId !== that.selectedRow);
that.selectedRow = 0;
},
addCell: (that, cellId) => {
if (!that.selectedRow) {
return alert('请选择要添加单元的行');
}
for (const row of that.infos) {
if (that.selectedRow === row.rowId) {
row.cells.push({
cellId: cellId,
title: '列' + cellId,
colspan: 0,
height: 30,
textAlign: 'center',
fontSize: 16,
fontStyle: 'normal',
});
}
}
},
deleteCell: (that) => {
// 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;
},
copySingleRow: (Id: number) => {
Id += 1;
},
};
export { Tool };