/** * Created by guopeng on 16/7/4. * 横行标尺调整边距拖动线 */ import * as React from "react"; import {observer} from "mobx-react/index"; import {DragSource} from "react-dnd"; import DragSourceCollector = __ReactDnd.DragSourceCollector; import DragSourceMonitor = __ReactDnd.DragSourceMonitor; import {DND_TYPES_HORIZON_RULER_LINE} from "../../../dnd/constants"; const getEmptyImage = require("react-dnd-html5-backend").getEmptyImage; import {Report as ReportModel} from "../../../items/Report"; import {DesignerHost} from "../../DesignerHost"; import {RULE_WIDTH} from "./consts"; const DRAG_LINE_WIDTH = 5; function getStyles(props) { const designer = DesignerHost.instance().designReport; const rulerHeight = RULE_WIDTH; const rulerWidth = designer.report.width.pixels; const zoom = designer.zoom; let left = 0; if (props.lineType === "left") { left = designer.report.leftMargin.pixels * zoom; } else { left = (rulerWidth - designer.report.rightMargin.pixels) * zoom; } const styles = { root: { position: "absolute", height: rulerHeight, cursor: "ew-resize", top: 0, left: left }, svg: { width: DRAG_LINE_WIDTH, height: rulerHeight }, line: { stroke: "red", strokeWidth: "1px", strokeDasharray: "5, 1" } }; return styles; } interface DragableLineProps { lineType: string; reportModel: ReportModel, connectDragSource: Function; connectDragPreview: Function; isDragging: boolean; } const dragSource = { beginDrag(props, monitor, component) { const reportModel = props.reportModel; return { lineType: props.lineType, leftMargin: reportModel.leftMargin, rightMargin: reportModel.rightMargin, lastPoint: {} }; }, }; const collect: DragSourceCollector = (connect, monitor) => ({ connectDragSource: connect.dragSource(), connectDragPreview: connect.dragPreview(), isDragging: monitor.isDragging() }); @observer class HorizonDragableLine extends React.Component { // protected reportModel: ReportModel; constructor(props, context){ super(props, context); // reportModel = props.reportModel; } render(): JSX.Element { const styles = getStyles.call(this, this.props); return this.props.connectDragSource(
); } componentDidMount(): void { this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true }); } } export default DragSource(DND_TYPES_HORIZON_RULER_LINE, dragSource, collect)(HorizonDragableLine);