import { Button, Radio, Slider, message, Modal } from 'antd'; import * as React from 'react'; import { WeaLocaleProvider, WeaInputSearch, WeaBrowser } from 'ecCom'; import D3Tree from './RectTree'; import { toJS } from 'mobx'; import { inject, observer } from 'mobx-react'; import './index.less'; const getLabel = WeaLocaleProvider.getLabel; @observer export default class MindMap extends React.Component { searchedNode = [] constructor(props) { super(props); this.state = { layout : '0', scale : 10 } } render() { const { store } = this.props; const { nodeForm, topButtons, hasChildren,path,canEdit } = this.props; const dataParams = path?{pathid:path.id,nodeid:nodeForm.id}:{}; return (
{topButtons.length > 0 && { topButtons } } {getLabel(22986, '左')} {getLabel(22988, '右')} {getLabel(31276, '上')} {getLabel(23010, '下')}
`${value * 10}%`} onChange={this.changeScale} >
{ this.props.pathType === 1 && store.d3Tree = ref} showMenu={true} menus={this.props.rightMenus} closeRight={(bool)=>{this.props.closeRight(bool)}} closeDialog={(bool)=>{this.props.closeDialog(bool)}} // onDelete={(readonly || !nodeForm.parentid) || this.deleteNode} // onAddChild={readonly || this.addChildren} // onDeleteChild={(readonly) || (hasChildren && this.deleteChildren)} // onSynchro={readonly || this.synchronize} showname={this.getShowname} desc="hrmNames" desc2="description" desc3="overstr" > }
) } getShowname = (d) => { return `${d.name}`; } changeSearchValue = () => { this.searchedNode = []; } searchNode = (value) => { const { store, params } = this.props; if (!value) { this.searchedNode = []; return; } if (store.d3Tree ) { if (this.searchedNode.length === 0) { this.timer = 0; this.searchedNode = store.d3Tree .searchNode(value.toLowerCase()); } const length = this.searchedNode.length; if (length > 0) { store.d3Tree .centerNode(this.searchedNode[this.timer % length]); this.timer++; } } } zoom = (scale) => { // this.props.changeScale(parseInt(scale * 10)); this.setState({ scale : parseInt(scale * 10) }); } zoomIn = () => { // this.props.changeScale(Math.min(this.props.scale + 1, 30)); this.setState({ scale : Math.min(this.state.scale + 1, 30) }); } zoomOut = () => { // this.props.changeScale(Math.max(this.props.scale - 1, 1)); this.setState({ scale : Math.max(this.state.scale - 1, 1) }); } changeScale = (scale) => { this.setState({ scale : scale }); } importPath = () => { this.props.openPathTemplateDialog(); } setCombine = () => { const { edcPathDesignerStore: store, params } = this.props; this.props.combineSetDialogStore.open({ appid: params.appid }); } changeLayout = (e) => { // const { edcPathDesignerStore: store } = this.props; this.searchedNode = []; // this.props.changeLayout(e.target.value); this.setState({ layout : e.target.value }); } saveNode = () => { this.props.saveNode(); } saveAsTemplate = () => { const { edcPathDesignerStore: store } = this.props; if (this.props.d3Tree) { const { edcPathDesignerStore: store } = this.props; const svg = this.props.d3Tree .baseSvg; const g = this.props.d3Tree .svgGroup; const serializer = new XMLSerializer(); let source = serializer.serializeToString(svg.node()); source = '\r\n' + source; const url = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(source); const canvas = document.createElement("canvas"); const { width, height } = svg.node().getBoundingClientRect(); canvas.width = width; canvas.height = height; const context = canvas.getContext("2d"); const image = new Image; image.src = url; image.onload = () => { context.drawImage(image, 50, 25); const img = canvas.toDataURL("image/png"); this.props.saveAsTemplate(img); } } } addChildren = () => { const { edcPathDesignerStore: store } = this.props; const { nodeForm } = store; this.props.setChildOpreator([]); this.props.allChildOpreator(nodeForm.id).then((childOpreator) => { this.props.setChildOpreator(childOpreator); if (this.browser) { this.browser.openModal(); const selectPerson = (ids, names, objs) => { if (objs.length > 99) { message.warn(getLabel('502645', '下级节点不能超过99个')); this.browser.openModal(); return; } const { edcPathDesignerStore: store } = this.props; const oldids = childOpreator.map(d => d.id); const newids = objs.filter(d => oldids.indexOf(d.id) === -1).map(d => d.id); if (newids.length === 0) { message.warn(getLabel('502646', '请选择需要添加的人员')); return; } this.props.addNodes(nodeForm.id, newids.join(',')); } this.selectPerson = selectPerson; } }); } addNodes = (ids, names, objs) => { this.selectPerson(ids, names, objs); } deleteNode = () => { Modal.confirm({ title: getLabel('505951','删除节点') , content: getLabel('505952','确认要删除选中的节点?') , onOk: () => { const { edcPathDesignerStore: store } = this.props; const { nodeForm } = store; this.props.deleteNode(nodeForm.id); } }); } deleteChildren = () => { Modal.confirm({ title: getLabel('505953','删除节点') , content: getLabel('505954','确认要删除所有下级节点?') , onOk: () => { const { edcPathDesignerStore: store } = this.props; const { nodeForm } = store; this.props.deleteChildren(nodeForm.id); } }); } synchronize = () => { if (this.nodeBrowser) { this.nodeBrowser.openModal(); } } }