import * as React from "react"; import * as ReactDOM from "react-dom"; import {observer} from "mobx-react/index"; import {DropTarget} from "react-dnd"; import DropTargetCollector = __ReactDnd.DropTargetCollector; import DropTargetMonitor = __ReactDnd.DropTargetMonitor; import DropTargetConnector = __ReactDnd.DropTargetConnector; import DragableLine from "./VerticalDragableLine"; import TopPaddingBlock from "./TopMarginBlock"; import BottomPaddingBlock from "./BottomMarginBlock"; import {DND_TYPES_HORIZON_RULER_LINE} from "../../../dnd/constants"; import {DesignerHost} from "../../DesignerHost"; import UIModel from "../../UIModel"; import DNDManager from "../../../dnd/DndManager" import {RULE_WIDTH} from "./consts"; import {ReportRootDesigner} from "../../designer/ReportRootDesigner"; import {Unit} from "../../../drawing/Unit"; function getStyles(props, context) { const reportDesigner = DesignerHost.instance().designReport; const rulerHeight = reportDesigner.viewPortSize.height; const rulerWidth = RULE_WIDTH; return { root: { top: RULE_WIDTH - reportDesigner.viewPortScrollTop, width: rulerWidth, height: rulerHeight, backgroundColor: "#fefefe" } }; } interface Props { connectDropTarget: Function; itemTypes: string | string[]; } @observer class VerticalRuler extends React.Component { public uiModel: UIModel; private dndManager: DNDManager; private _host: DesignerHost; constructor(props: Props, context: any) { super(props, context); this._host = DesignerHost.instance(); this.uiModel = this._host.uiModel; this.dndManager = DNDManager.instance(); } render(): JSX.Element { // console.log("render horizonRuler"); const styles = getStyles.call(this, this.props, this.context); return this.props.connectDropTarget(
{this.renderTickMark()} {this.renderDragableLines()}
); } /** * 渲染标尺的拖动线 * @returns {any} */ renderDragableLines(): JSX.Element { // console.log("render marker"); const reportModel = this._host.designReport.report; return (
); } /** * 渲染刻度线 * @returns {any} */ renderTickMark(): JSX.Element { const reportDesigner: ReportRootDesigner = DesignerHost.instance().getDesigner(this._host.designReport.report); const paperHeight = reportDesigner.viewPortSize.height; const heightPx = paperHeight; const heightMm = Unit.mm(paperHeight).value; const svgStyle = { width: `20px`, height: `${heightPx}px` }; let lines = []; let texts = []; let i = 0; for (let y = 0; (heightMm - y) > 0; y += 1, i++) { const w = (i % 10 > 0) ? (i % 5 > 0 ? "80%" : "60%") : "40%"; const yp = y * 3.779527559 * reportDesigner.zoom; const line = ; lines.push(line); if (w === "40%") { const tick = i / 10; const _y = tick === 0 ? 8 : (yp + (tick > 9 ? 8 : 4)) const text = {tick} texts.push(text); } } return (
{lines} {texts}
); } } const dropTarget = { drop(props, monitor, component) { if (monitor.didDrop()) { // If you want, you can check whether some nested // target already handled drop return; } component.dndManager.verticalRulerDrop(props, monitor, component); }, hover(props, monitor, component): void { component.dndManager.verticalRulerHover(props, monitor, component); } }; const collect: DropTargetCollector = (connect, monitor) => ({ connectDropTarget: connect.dropTarget(), // You can ask the monitor about the current drag state: isOver: monitor.isOver(), isOverCurrent: monitor.isOver({shallow: true}), canDrop: monitor.canDrop(), }); export default DropTarget(DND_TYPES_HORIZON_RULER_LINE, dropTarget, collect)(VerticalRuler);