2018-10-18 17:35:01 +08:00
|
|
|
import { ControlPanel } from "./designerClasses";
|
|
|
|
|
2018-10-16 16:32:22 +08:00
|
|
|
// 表格类
|
|
|
|
class Table {
|
|
|
|
rowLength: number;
|
|
|
|
columnLength: number;
|
|
|
|
selectedRow: string;
|
|
|
|
selectedCell: string;
|
|
|
|
instanceOfCells: any;
|
|
|
|
constructor(rowLength: number, columnLength: number, instanceOfCells: any) {
|
|
|
|
this.rowLength = rowLength;
|
|
|
|
this.columnLength = columnLength;
|
2018-10-18 17:35:01 +08:00
|
|
|
|
2018-10-16 16:32:22 +08:00
|
|
|
this.selectedRow;
|
|
|
|
this.selectedCell;
|
|
|
|
}
|
2018-10-18 17:35:01 +08:00
|
|
|
render(instanceOfCells) {
|
|
|
|
var myNode = document.getElementById("table");
|
|
|
|
while (myNode.firstChild) {
|
|
|
|
myNode.removeChild(myNode.firstChild);
|
|
|
|
}
|
|
|
|
var cellIndex = -1;
|
|
|
|
for (var i = 0; i < this.rowLength; i++) {
|
|
|
|
var table: HTMLTableElement = <HTMLTableElement>(
|
|
|
|
document.getElementById("table")
|
|
|
|
);
|
|
|
|
var row = table.insertRow(-1);
|
|
|
|
|
|
|
|
for (var j = 0; j < this.columnLength; j++) {
|
|
|
|
var letter = String.fromCharCode("A".charCodeAt(0) + j - 1);
|
|
|
|
|
|
|
|
const instanceOfCell = instanceOfCells[(cellIndex += 1)];
|
|
|
|
const cellElement = instanceOfCell.CreateCellElement();
|
|
|
|
row.appendChild(cellElement);
|
|
|
|
|
|
|
|
cellElement.addEventListener("dblclick", () => {
|
|
|
|
cellElement.className = "highlight";
|
|
|
|
this.showDesignerInfo(instanceOfCell);
|
|
|
|
});
|
|
|
|
|
|
|
|
cellElement.innerHTML = i && j ? instanceOfCell.cellId : i || letter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showDesignerInfo(instanceOfCell) {
|
|
|
|
const cellInfoElements = document
|
|
|
|
.getElementById("cell-info")
|
|
|
|
.getElementsByTagName("input");
|
|
|
|
for (let i = 0; i < cellInfoElements.length; i++) {
|
|
|
|
for (const key of Object.keys(instanceOfCell)) {
|
|
|
|
if (key === cellInfoElements[i].name) {
|
|
|
|
cellInfoElements[i].value = instanceOfCell[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 09:26:28 +08:00
|
|
|
deleteCurrentRow() {}
|
|
|
|
deleteCurrenCol() {}
|
|
|
|
insertColToLeft() {}
|
|
|
|
insertColToRight() {}
|
|
|
|
insertRowToTop() {}
|
|
|
|
insertRowToBottom() {}
|
|
|
|
mergeRightCell() {}
|
|
|
|
mergeBottomCell() {}
|
|
|
|
|
|
|
|
addTemplate() {}
|
|
|
|
addFormHeader() {}
|
|
|
|
addSplitedGroupHeader() {}
|
|
|
|
addBanCaiDetails() {}
|
|
|
|
addSplitedGroupFooter() {}
|
|
|
|
addFormFooter() {}
|
2018-10-16 16:32:22 +08:00
|
|
|
}
|
2018-10-18 09:26:28 +08:00
|
|
|
|
2018-10-16 16:32:22 +08:00
|
|
|
// 单元类
|
|
|
|
class Cell {
|
|
|
|
cellId: string;
|
2018-10-17 15:20:24 +08:00
|
|
|
font: string;
|
2018-10-16 16:32:22 +08:00
|
|
|
fontSize: string;
|
2018-10-17 15:20:24 +08:00
|
|
|
fontColor: string;
|
|
|
|
fontWeight: string;
|
|
|
|
fontStyle: string;
|
|
|
|
textDecoration: string; // underline or line throught
|
|
|
|
border: string;
|
|
|
|
backgroundColor: string;
|
|
|
|
textAlign: string;
|
2018-10-18 17:35:01 +08:00
|
|
|
className: string;
|
2018-10-16 16:32:22 +08:00
|
|
|
constructor(id) {
|
|
|
|
this.cellId = id;
|
2018-10-17 15:20:24 +08:00
|
|
|
this.font = "Serif";
|
2018-10-16 16:32:22 +08:00
|
|
|
this.fontSize = "12";
|
2018-10-17 15:20:24 +08:00
|
|
|
this.fontColor = "black";
|
|
|
|
this.fontWeight = "normal";
|
|
|
|
this.fontStyle = "normal";
|
|
|
|
this.textDecoration = "";
|
|
|
|
this.border = "";
|
|
|
|
this.backgroundColor = "";
|
|
|
|
this.textAlign = "left";
|
2018-10-18 17:35:01 +08:00
|
|
|
this.className = "normal";
|
2018-10-16 16:32:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateCellElement() {
|
|
|
|
let tdElement = document.createElement("td");
|
2018-10-17 15:20:24 +08:00
|
|
|
|
|
|
|
tdElement.style.fontFamily = this.font;
|
|
|
|
tdElement.style.backgroundColor = this.backgroundColor;
|
|
|
|
|
2018-10-16 16:32:22 +08:00
|
|
|
tdElement.style.border = this.border + "px solid";
|
|
|
|
tdElement.style.fontSize = this.fontSize + "px";
|
2018-10-17 15:20:24 +08:00
|
|
|
tdElement.style.color = this.fontColor;
|
|
|
|
tdElement.style.fontWeight = this.fontWeight;
|
|
|
|
tdElement.style.fontStyle = this.fontStyle;
|
|
|
|
tdElement.style.textDecoration = this.textDecoration;
|
|
|
|
tdElement.style.textAlign = this.textAlign;
|
|
|
|
tdElement.innerHTML = "cell";
|
2018-10-18 17:35:01 +08:00
|
|
|
tdElement.className = this.className;
|
2018-10-16 16:32:22 +08:00
|
|
|
|
|
|
|
return tdElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { Table, Cell };
|