|
@@ -10,13 +10,14 @@ import {
|
|
|
import { Button, Divider, Dropdown, Tooltip, Popover } from "antd";
|
|
|
import NodeMenu from "@/components/NodeMenu";
|
|
|
import type { MenuProps } from "antd/lib";
|
|
|
-import { useRef, useEffect } from "react";
|
|
|
+import { useRef, useEffect, useState } from "react";
|
|
|
import { MiniMap } from "@antv/x6-plugin-minimap";
|
|
|
import { useModel } from "umi";
|
|
|
|
|
|
export default function index() {
|
|
|
const minimapRef = useRef<HTMLDivElement>(null);
|
|
|
const { graph } = useModel("flowModel");
|
|
|
+ const [scale, setScale] = useState(100);
|
|
|
|
|
|
const zoomItems: MenuProps["items"] = [
|
|
|
{ key: "1", label: "25%" },
|
|
@@ -47,35 +48,65 @@ export default function index() {
|
|
|
}
|
|
|
}, [graph, minimapRef.current]);
|
|
|
|
|
|
+ // 添加备注
|
|
|
const handleAddNotice = () => {
|
|
|
const { width = 100, height = 100 } = graph?.getGraphArea() || {};
|
|
|
- graph?.addNode({
|
|
|
- shape: 'notice-node',
|
|
|
+ graph?.addNode({
|
|
|
+ shape: "notice-node",
|
|
|
zIndex: -1,
|
|
|
position: {
|
|
|
x: width / 2 - 150,
|
|
|
y: height / 2 - 100,
|
|
|
},
|
|
|
data: {
|
|
|
- name: '',
|
|
|
- text: ''
|
|
|
- }
|
|
|
+ name: "",
|
|
|
+ text: "",
|
|
|
+ },
|
|
|
});
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ graph?.on("scale", (scaleInfo) => {
|
|
|
+ setScale(parseInt(scaleInfo.sx * 100 + ""));
|
|
|
+ });
|
|
|
+ }, [graph]);
|
|
|
+
|
|
|
+ const handleZoom = (value: number) => {
|
|
|
+ graph?.zoomTo(value / 100);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleZoomFit = () => {
|
|
|
+ graph?.zoomToFit({});
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOnChange = (value: number) => {
|
|
|
+ setScale(Math.round(value));
|
|
|
+ handleZoom(value);
|
|
|
+ };
|
|
|
|
|
|
return (
|
|
|
<div className="absolute left-32px bottom-32px z-2 flex gap-12px">
|
|
|
<div className="w-120px h-40px rounded-12px bg-#fff box-shadow-sm flex items-center justify-between px-12px">
|
|
|
- <Button type="text" icon={<ZoomInOutlined />} />
|
|
|
+ <Button
|
|
|
+ type="text"
|
|
|
+ icon={<ZoomOutOutlined />}
|
|
|
+ disabled={scale <= 50}
|
|
|
+ onClick={() => handleOnChange(scale - 10)}
|
|
|
+ />
|
|
|
<Dropdown
|
|
|
menu={{
|
|
|
items: zoomItems,
|
|
|
style: { width: "160px", transform: "translate(-65px, -10px)" },
|
|
|
}}
|
|
|
>
|
|
|
- <span>100%</span>
|
|
|
+ <span>{scale}%</span>
|
|
|
</Dropdown>
|
|
|
- <Button type="text" icon={<ZoomOutOutlined />} />
|
|
|
+ <Button
|
|
|
+ type="text"
|
|
|
+ icon={<ZoomInOutlined />}
|
|
|
+ disabled={scale >= 200}
|
|
|
+ onClick={() => handleOnChange(scale + 10)}
|
|
|
+ />
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
@@ -84,7 +115,11 @@ export default function index() {
|
|
|
></div>
|
|
|
|
|
|
<div className="w-60px h-40px rounded-12px bg-#fff box-shadow-sm flex items-center justify-between px-12px">
|
|
|
- <Button type="text" icon={<i className="iconfont icon-undo" />} disabled={true} />
|
|
|
+ <Button
|
|
|
+ type="text"
|
|
|
+ icon={<i className="iconfont icon-undo" />}
|
|
|
+ disabled={true}
|
|
|
+ />
|
|
|
<Button type="text" icon={<i className="iconfont icon-redo" />} />
|
|
|
</div>
|
|
|
|
|
@@ -100,7 +135,11 @@ export default function index() {
|
|
|
</Button>
|
|
|
</Popover>
|
|
|
<Tooltip title="添加文本">
|
|
|
- <Button type="text" icon={<FileAddOutlined />} onClick={handleAddNotice} />
|
|
|
+ <Button
|
|
|
+ type="text"
|
|
|
+ icon={<FileAddOutlined />}
|
|
|
+ onClick={handleAddNotice}
|
|
|
+ />
|
|
|
</Tooltip>
|
|
|
<Divider type="vertical" />
|
|
|
<Tooltip title="指针模式">
|