import { Menu, Popover } from 'antd'; import React, { Component } from 'react'; import { DraggableData, DraggableEvent } from 'react-draggable'; import { Rnd, RndResizeCallback } from 'react-rnd'; import { GlobalItemProp } from '../../../App'; import { PositionProp } from '../../../component/ComponentHOC.d'; import { DragEndParam, ResizeParam } from "./dragItem.d"; import DragContext from './dragContext'; import styles from "./dragContext.module.css"; import ChartsFactory from '../../../component/chartsFactory'; interface Prop { times : number ; data : GlobalItemProp ; itemKey : string ; selected : boolean ; enableDrag : boolean ; enableResize: boolean ; debug : boolean ; onDelete ?: (data:GlobalItemProp,key:string)=>void ; onCopy ?: (data:GlobalItemProp,key:string)=>void ; onDownLayer ?:(data:GlobalItemProp,key:string)=>void ; onResize ?: (data:ResizeParam)=>void ; onDragEnd ?: (data:DragEndParam)=>void ; onClick ?: (data:GlobalItemProp,key:string,e:any)=>void; onChartClick?: (res:any)=>void ; } interface State { x : number ; y : number ; showPosition : boolean; } export default class DragItem extends Component { state:State = { x : 0, y :0 , showPosition : false, } renderMenu = (data:GlobalItemProp,key:string)=>{ return ( this.deleteLayer(data,key)}>删除图层 this.copyLayer(data,key)}>复制图层 this.downLayer(data,key)}>下移图层 ) } deleteLayer= (data:GlobalItemProp,key:string)=>{ this.props.onDelete && this.props.onDelete(data,key); } copyLayer = (data:GlobalItemProp,key:string)=>{ this.props.onCopy && this.props.onCopy(data,key); } downLayer= (data:GlobalItemProp,key:string)=>{ this.props.onDownLayer && this.props.onDownLayer(data,key); } onResize = (param:ResizeParam)=>{ this.props.onResize && this.props.onResize(param); } onDragEnd = (param:DragEndParam)=>{ this.props.onDragEnd && this.props.onDragEnd(param); this.setState({showPosition : false}) } onDrag = (e:DraggableEvent,d:DraggableData)=>{ console.log(d.x*this.props.times); this.setState({ x : d.x * this.props.times, y : d.y * this.props.times , showPosition : true, }) } onClick = (e:any)=>{ const {data,itemKey} = this.props; this.props.onClick && this.props.onClick(data,itemKey,e); } onChartClick =(res:any)=>{ this.props.onChartClick && this.props.onChartClick(res); } render(){ const {data,times,itemKey,selected,enableDrag,enableResize,debug} = this.props; const originPosition : PositionProp = DragContext.getSizeFromGlobal(data,1); const scalePosition : PositionProp = DragContext.getSizeFromGlobal(data,times); const zIndex : number = data.index; const {showPosition,x,y} = this.state; return ( this.renderMenu(data,itemKey)} trigger={debug?"contextMenu":""}> this.onResize({e,dir,elementRef,delta,position,key:itemKey})} onDragStop={(de:DraggableEvent,dd:DraggableData)=>this.onDragEnd({de,dd,key:itemKey})} style={{backgroundColor:selected?'rgba(19,152,232,0.4)':'',zIndex : zIndex,}} position={{x:scalePosition.x,y:scalePosition.y}} size={{width:originPosition.w/times,height:originPosition.h/times}} disableDragging={!enableDrag} enableResizing={enableResize && selected} // onDrag={this.onDrag} > { !showPosition ? null :
x={x}
y={y}
}
) } }