/** * Created by W.X. on 16/7/26. */ import * as React from "react"; import {observer} from "mobx-react/index"; import {IObservableArray, IArraySplice, observe, observable, action} from "mobx/lib/mobx"; import {DesignerHost} from '../../DesignerHost'; import UIModel from '../../UIModel'; import SelectionModel from '../ui-model/SelectionModel'; import {LAYOUT_KEY} from "../../../items/constants"; import {LayoutSection, LayoutProperty, LayoutSectionKeyEnum} from "../../../items/layout/LayoutSection"; import {ReportItemBase} from "../../../items/ReportItemBase"; import {Layout} from "../../../items/layout/Layout"; class PropertySection extends React.Component< { section: Object, items: Array, hideDetail: boolean, onToggle: Function }, {} >{ state = { showDetail: true } componentWillReceiveProps(){ // this.state.showDetail = true; } toggleDetail = () => { this.props.onToggle(); } renderProperties(section:Object, items:Array) { return (
{this.renderProperty(section, items)}
) } renderProperty(section, items:Array) { const editors = []; var index = 0; section.properties.map(item => { const layoutProperty:LayoutProperty = item['layoutProperty']; const Editor = layoutProperty.property.editor; editors.push( ); }); return editors; } render(){ const {section, items, hideDetail} = this.props; const iconClass = 'rd-group-header-icon ' + (hideDetail ? 'down' : 'up'); const detailStyle = { display: hideDetail? 'none': 'block' }; return (
{LayoutSection.LAYOUT_SECTION[section["key"]].label}
{this.renderProperties(section, items)}
); } } @observer class PropertyView extends React.Component<{}, {}> { private _host:DesignerHost; private _model:UIModel; private _selectionModel:SelectionModel; private _selectItems:IObservableArray; private _toggleStatus:{key?: LayoutSectionKeyEnum, value?: boolean} = {}; constructor(props:{}, context:any) { super(props, context); this._host = DesignerHost.instance(); this._model = this._host.uiModel; this._selectionModel = this._model.selectionModel; this._selectItems = this._selectionModel.selectItems; } getLayout(item:ReportItemBase):Layout { return item.getDesignerLayout(); } onToggle = (key: LayoutSectionKeyEnum) => { this._toggleStatus[key] = !this._toggleStatus[key]; this.forceUpdate(); } //渲染所有section renderSections(sections:Array, items:Array) { const elements = sections.map((section, index) => { const key = section['key']; return ; }); return (
{elements}
); } // 根据当前选中的元素, 进行section和properties遍历, 找出公用属性. private calculateProperties():Array { const items = this.getItems(); const totalCount = items.length; let sections:Array = []; items.forEach(item => { this.getLayout(item) .getSections(item) .forEach(section => { const {key} = section; let _section = sections.find(obj => obj["key"] == key); if (!_section) { _section = { key: key, properties: [], __count: 0 }; sections.push(_section); } _section["__count"]++; section.properties .filter(layoutProperty => layoutProperty.hidden === false) .map(layoutProperty => { let _property = _section["properties"].find((obj:any) => obj.layoutProperty.property == layoutProperty.property); if (!_property) { _property = { layoutProperty: layoutProperty, __count: 0 }; _section["properties"].push(_property); } _property.__count++; }); }) }); /* 遍历所有选中元素的layout信息, 统计所有section和property出现的次数, 最后获得一个格式如下的数组: [ { key:string, //section对应的key properties:[ //包含的属性集合 { property:Property, //对应属性对象 __count:number //统计属性出现的次数 } ], __count:number //统计section出现的次数 } ] */ // layouts.map(layout => { // // //遍历layout中的section, 统计section出现次数 // layout.getSections().map // // }); // 获得以上对象后, 先对第一层section进行过滤 sections = sections.filter(section => section["__count"] == totalCount); // 在对剩下的section的properties进行过滤 sections.map(section => { section["properties"] = section["properties"].filter((property:any) => property.__count == totalCount); }); // 至此, sections中剩余的section和properties就是共有属性. return sections; } private getItems():Array { //如果selectionService中没有选中元素, 则显示报表的属性 if (this._selectItems.length > 0) { return this._selectItems; } else { return [DesignerHost.instance().designReport.report]; } } render():JSX.Element { const inspectorVisible = DesignerHost.instance().uiModel.inspectorModel.inspectorVisible; if (!inspectorVisible) { return null; } //获取共有属性, 进行渲染 const section = this.calculateProperties(); const items = this.getItems().map(item=>item); const inspectorShowView = DesignerHost.instance().uiModel.inspectorModel.inspectorView; const className = (inspectorShowView === 'property' ? 'rd-inspector-view' : 'rd-inspector-view-hide') + ' rd-property-view'; return (
属性面板
{this.renderSections(section, items)}
); } } export default PropertyView;