report-design/src/assets/methodTool.ts

67 lines
1.6 KiB
TypeScript
Raw Normal View History

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