import React, { useEffect, useMemo, useState } from "react"; import { Button, Input, Dropdown, Tooltip, MenuProps, Divider } from "antd"; import { LeftOutlined, MenuOutlined } from "@ant-design/icons"; import logo from "@/assets/logo.png"; import { useModel, Icon } from "umi"; import { addTopic } from "../../mindMap"; import { TopicType } from "@/enum"; import { selectTopic, addBorder, addSummary } from "@/utils/mindmapHander"; import { createNew } from "@/utils"; export default function index() { const { mindProjectInfo, setMindProjectInfo, canRedo, canUndo, onRedo, onUndo, enableFormatBrush, toggleFormatBrush, graph, selectedCell, setCorrelationEdgeInfo, } = useModel("mindMapModel"); const currentNode = useMemo(() => { return selectedCell.filter(cell => cell.isNode()); }, [selectedCell]); const [title, setTitle] = useState(mindProjectInfo?.name || ""); useEffect(() => { setTitle(mindProjectInfo?.name || ""); }, [mindProjectInfo?.name]) const handleChangeTitle = () => { mindProjectInfo && setMindProjectInfo({ ...mindProjectInfo, name: title, }) } // 预览 todo const handlePreview = () => {}; // 保存 todo const handleSave = () => {}; // 克隆 todo const handleClone = () => {}; // 历史记录 todo const handleHistory = () => {}; // 查找替换 const handleReplace = () => {}; // 增加子主题 const handleAddSubTopic = () => { if(!currentNode.length) return; const topic = addTopic( currentNode[0].data.type === TopicType.main ? TopicType.branch : TopicType.sub, setMindProjectInfo, currentNode[0] ); graph && selectTopic(graph, topic); }; // 添加边框 const handleAddBorder = () => { addBorder(currentNode.filter(item => item.data.parentId)); } // 添加概要 const handleAddSummary = () => { addSummary(currentNode.filter(item => item.data.parentId)) } // 添加关联线 const handleAddCorrelation = () => { if(!currentNode.length) return; setCorrelationEdgeInfo(currentNode[0]); }; const menuData: MenuProps["items"] = [ { key: "1", label: "新建", icon: , children: [ { key: "1-1-1", label: "流程图", icon: , onClick: () => { createNew("flow"); }, }, { key: "1-1-2", label: "思维导图", icon: , onClick: () => { createNew("mindmap"); }, }, { key: "1-1-3", label: "UML", icon: , onClick: () => { createNew("uml"); }, }, { key: "1-1-4", label: "网络拓扑图", icon: , onClick: () => { createNew("net"); }, }, { key: "1-1-5", label: "组织结构图", icon: , onClick: () => { createNew("org"); }, }, { key: "1-1-6", label: "BPMN", icon: , onClick: () => { createNew("bpmn"); }, }, ], }, // { // key: "2", // label: "预览", // icon: , // onClick: handlePreview, // }, { key: "3", label: (
保存 Ctrl+S
), icon: , onClick: handleSave, }, { key: "4", label: "克隆", icon: , onClick: handleClone, }, { key: "5", label: "查找替换", icon: , onClick: handleReplace, }, { key: "6", label: "历史记录", icon: , onClick: handleHistory, }, // { // key: "1-8", // type: "divider", // }, ]; const noParent = useMemo(() => { const nodes = selectedCell?.filter(cell => cell.isNode()); return !!(nodes.length && !nodes.find(node => !node.data?.parentId)); }, [selectedCell]); return (
{mindProjectInfo && ( setTitle(e.target.value) } onBlur={handleChangeTitle} onPressEnter={handleChangeTitle} /> )}
); }