import * as React from "react"; import {action} from "mobx"; import {observer} from "mobx-react/index"; import {PropertyEditorProps} from "./editor-props"; import {Property} from "../../../items/properties/Property"; import {ReportItemBase} from "../../../items/ReportItemBase"; import {Unit} from "../../../drawing/Unit"; import {DesignerHost} from "../../DesignerHost"; @observer export default class Editor extends React.Component { getValue(){ return this.getValueByProperty(this.props.property); } protected getValueByProperty(property:Property){ const {items} = this.props; const values = items.map(item => item.getPropertyValue(property)); let val = values[0]; for (var value of values) { //如果是unit类型,根据pixels进行判断 if(value instanceof Unit){ if(val.pixels != value.pixels){ val = Unit.Empty; break; } //基本类型直接进行比较 }else{ if (val != value) { val = null; break; } } } return val; } setValue(value:any){ return this.setValueByProperty(value, this.props.property); } @action setValueByProperty(value:any, property:Property){ const {items} = this.props; items.map((item:ReportItemBase) => { item.setPropertyValue(property, value); }); DesignerHost.instance().historyService.snap(); } render():JSX.Element { const property:Property = this.props.property; return (
{property.label}
{this.renderValueEditor()}
); // return ( //
//
//
//
//
//
// {property.label} //
//
//
// {this.renderValueEditor()} //
//
//
//
//
// ) } protected renderValueEditor() { } }