/** * Created by W.X. on 16/7/26. */ import * as React from "react"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import {DesignerHost} from '../../DesignerHost'; import {Report} from "../../../items/Report"; import ExportBandItem from './ExportBandItem'; import ExportItem from './ExportItem'; import {ReportRootDesigner} from "../../designer/ReportRootDesigner"; import {SelectionService} from "../../behavior/SelectionService"; @observer class ExportView extends React.Component<{}, {}> { private _host: DesignerHost; private _selectionService: SelectionService; private _bandListTop: Array; private _bandListBottom: Array; private _itemList: Array; private _itemIndex: number; constructor(props:{}, context:any) { super(props, context); this._host = DesignerHost.instance(); this._selectionService = DesignerHost.instance().getService(SelectionService); this._bandListTop = [ 'TitleBand', 'PageHeaderBand', 'ColumnHeaderBand' ]; this._bandListBottom = [ 'ColumnFooterBand', 'PageFooterBand' ]; this.renderTree = this.renderTree.bind(this); } private get report():Report { return this._host.designReport.report; } render(): JSX.Element { const inspectorShowView = DesignerHost.instance().uiModel.inspectorModel.inspectorView; const className = (inspectorShowView === 'export' ? 'rd-inspector-view' : 'rd-inspector-view-hide') + ' rd-export-view'; const selectionLen = this._selectionService.getSelectionCount(); const rootPointClass = "rootPoint" + (selectionLen === 0 ? " rootPointSelected" : ""); const groupUseable = !this._host.config.blockBands.Group; this._itemList = []; this._itemIndex = 0; this.renderBands(this._bandListTop); groupUseable ? this.renderGroups() : this.renderDetail(); this.renderBands(this._bandListBottom); return (
层面板
{ groupUseable &&
Group
Detail
}
{this.report.displayName()}
{this._itemList}
); } renderBands(list:Array) { list.map( band => { const blockBands = this._host.config.blockBands; if (blockBands[band]) return; const bandItems = this.getBandItems(band); if(bandItems.length>0){ bandItems.map( band => { const bandItem = { type: "band", item: band }; this._itemList.push(); if(band.items && band.items.length>0){ this._itemList.push(this.renderTree(band.items)); } }); } else{ const bandItem = { type: "blank-band", item: band }; this._itemList.push(); } }); } renderGroups() { const groups = this.report.groups; const maxIndex = groups.length-1; const render = (index:number) => { const group = groups[index]; //groupHeader const groupHeader = group.groupHeader; const headerItem = { type : groupHeader ? "group" : "blank-band", item : groupHeader || "GroupHeaderBand", group: group, groupIndex: index, maxIndex: maxIndex, }; this._itemList.push(); if(groupHeader && groupHeader.items && groupHeader.items.length>0){ this._itemList.push(this.renderTree(groupHeader.items)); } //如果还有下一个group,则进先输出group,如果没有,开始输出detail if(groups[index+1]){ render(index+1); } else{ this.renderDetail(); } //groupFooter const groupFooter = group.groupFooter; const footerItem = { type : groupFooter ? "group" : "blank-band", item : groupFooter || "GroupFooterBand", group: group, groupIndex: index, maxIndex: maxIndex, }; this._itemList.push(); if(groupFooter && groupFooter.items && groupFooter.items.length>0){ this._itemList.push(this.renderTree(groupFooter.items)); } }; if(groups.length>0){ render(0); } else{ this.renderDetail(); } } renderDetail() { let hasDetail = false; // const items = ReportRootDesigner.getBandOrderd(this.report); const items = this.report.detailBands; const maxIndex = items.length-1; items.map( (item, index) => { const itemName = item.constructor.name; if(itemName === "DetailBand"){ hasDetail = true; const bandItem = { type: "DetailBand", item: item, detailIndex: index, maxIndex: maxIndex, }; this._itemList.push(); if(item.items && item.items.length>0){ this._itemList.push(this.renderTree(item.items)); } } }); if(!hasDetail){ const bandItem = { type: "blank-band", item: "DetailBand" }; this._itemList.push(); } } getBandItems(bandName:string) { const items = []; const bands = ReportRootDesigner.getBandOrderd(this.report); bands.map( band => { if( band.constructor.name === bandName){ items.push(band); } }); return items; } renderTree(items:Array): JSX.Element { const mapItems = items => { const el = []; items.map( item => { el.push(); if(item.items && item.items.length>0){ el.push(mapItems(item.items)); } }); return (
{el}
); }; return mapItems(items); } @autobind onAddGroupBand(){ this.report.addGroup(); } @autobind onAddDetailBand(){ this.report.addBand("DetailBand"); } } export default ExportView;