/** * 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 rulerWidth = RULE_WIDTH; const rulerHeight = designer.bandBottom; const zoom = designer.zoom; let top = 0; if (props.lineType === "top") { top = designer.report.topMargin.pixels * zoom; } else { top = rulerHeight * zoom; } const styles = { root: { position: "absolute", width: rulerWidth, cursor: "ns-resize", top: top, left: 0 }, svg: { width: rulerWidth, height: DRAG_LINE_WIDTH, top: 0, position: "absolute" }, 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, topMargin: reportModel.topMargin, bottomMargin: reportModel.bottomMargin, lastPoint: {} }; }, }; const collect: DragSourceCollector = (connect, monitor) => ({ connectDragSource: connect.dragSource(), connectDragPreview: connect.dragPreview(), isDragging: monitor.isDragging() }); @observer class VerticalDragableLine extends React.Component { 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)(VerticalDragableLine);