Files
report-design-javascript/src/script/designerClasses.ts

156 lines
3.6 KiB
TypeScript
Raw Normal View History

2018-10-16 16:32:22 +08:00
// 控制面板类
class ControlPanel {
2018-10-17 15:20:24 +08:00
instanceOfCell: HTMLElement;
2018-10-16 16:32:22 +08:00
constructor(cell) {
this.instanceOfCell = cell;
}
2018-10-17 15:20:24 +08:00
render() {}
setFont() {}
setFontSize() {}
setFontColor() {}
setFontWeight() {}
setTextUnderline() {}
setTextDecoration() {}
setBorder() {}
setTextLineThrough() {}
setBackgroupColor() {}
setTextLeft() {}
setTextCenter() {}
setTextRight() {}
resetTextStyle() {}
insertTable() {}
tablePreview() {}
exportPdf() {}
exportExcel() {}
2018-10-16 16:32:22 +08:00
}
// 数据源类
class DataResource {
2018-10-17 10:33:04 +08:00
data: OrderDetailsFormat;
constructor(orderDetails: OrderDetailsFormat) {
this.data = orderDetails;
}
getOrderNo() {
return this.data.orderNo;
}
getClientName() {
return this.data.clientName;
}
getSoldDate() {
return this.data.soldDate;
}
getContactName() {
return this.data.contactName;
}
getContactNo() {
return this.data.contactNo;
}
getDeliveryAddress() {
return this.data.deliveryAddress;
}
getAddOn() {
return this.data.addOn;
}
getBoards() {
return this.data.boards;
}
getBoardMaterial() {
const BoardMaterial = [];
for (let item of this.data.boards) {
BoardMaterial.push(item.material);
}
return BoardMaterial; // BoardMaterial=['string', 'string']
}
getBoardColor() {
const BoardColor = [];
for (let item of this.data.boards) {
BoardColor.push(item.color);
}
return BoardColor; // BoardColor=['string', 'string']
}
getBoardInfo(key: string) {
const houseName = [];
for (const board of this.data.boards) {
const tem = [];
for (const boardInfo of board.boardInfos) {
if (Object.keys(boardInfo).indexOf(key) !== -1) {
tem.push(boardInfo[key]);
} else {
console.log("没有找到对应的key");
return;
}
}
houseName.push(tem);
}
return houseName; // 返回数据结构hosueName=[['string||number''string||number'],[]]
}
getEachBanCaiToTal(boardKey: string) {
const banCaiTotalArray = [];
for (const board of this.data.boards) {
let tem = 0;
for (const boardInfo of board.boardInfos) {
if (
Object.keys(boardInfo).indexOf(boardKey) !== -1 &&
typeof boardInfo[boardKey] === "number"
) {
tem += Number(boardInfo[boardKey]);
}
}
banCaiTotalArray.push(tem);
}
return banCaiTotalArray; // 返回数据类型 eg :banCaiTotal=[number,number,....]
}
getAllBanCaiTotal(boardKey: string) {
let banCaiTotal = 0;
for (const board of this.data.boards) {
for (const boardInfo of board.boardInfos) {
if (
Object.keys(boardInfo).indexOf(boardKey) !== -1 &&
typeof boardInfo[boardKey] === "number"
) {
banCaiTotal += Number(boardInfo[boardKey]);
}
}
}
return banCaiTotal; // 返回数据类型 eg :banCaiTotal:80
2018-10-16 16:32:22 +08:00
}
}
// typescript 类型定义
2018-10-17 10:33:04 +08:00
interface OrderDetailsFormat {
2018-10-16 16:32:22 +08:00
[index: string]: string | object;
orderNo: string;
clientName: string;
soldDate: string;
contactName: string;
contactNo: string;
deliveryAddress: string;
addOn: string;
boards: Array<{
[index: string]: number | string | object;
id: number;
material: string;
color: string;
boardInfos: Array<{
houseName: string;
closetName: string;
boardNo: string;
boardName: string;
length: number;
width: number;
thickness: number;
quantity: number;
area: number;
mutation: string;
shape: string;
direction: string;
stripe: string;
boardAddOn: string;
[index: string]: number | string;
}>;
}>;
}