vue3使用@imengyu/vue3-context-menu完成antv/x6右键菜单

1、下载插件:

npm i @imengyu/vue3-context-menu@1.3.6

 2、在页面中引入并使用插件:

<script setup>
import ContextMenu from "@imengyu/vue3-context-menu";

graph.on("node:contextmenu", ({ e, x, y, cell, view }) => {
  handleContextmenu(e);
});

// 右键菜单
const handleContextmenu = (e) => {
  const cells = graph.getSelectedCells();
  ContextMenu.showContextMenu({
    x: e.pageX,
    y: e.pageY,
    items: [
      {
        label: "复制(Ctrl+c&Ctrl+z)",
        disabled: cells.length === 0 ? true : false,
        onClick: () => {
          if (cells.length) {
            graph.copy(cells);
            if (!graph.isClipboardEmpty()) {
              const cells = graph.paste({ offset: 32 });
              // 解决复制的节点修改失效问题
              cells.forEach((item) => {
                let node = item.store.data;
                node.shape !== "data-processing-curve" &&
                  (node.data.id = node.id);
              });
              graph.cleanSelection();
              graph.select(cells);
            }
          }
        },
      },
      {
        label: "删除(Backspace)",
        disabled: cells.length === 0 ? true : false,
        onClick: () => {
          if (cells.length) {
            graph.removeCells(cells);
          }
        },
      },
    ],
  });
};
</script>

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-27 11:08:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-27 11:08:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-27 11:08:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-27 11:08:03       18 阅读

热门阅读

  1. TiDB中Table映射到KV

    2024-01-27 11:08:03       31 阅读
  2. nginx做盗链与防盗链配置

    2024-01-27 11:08:03       26 阅读
  3. 常用的gpt-4 prompt words收集8

    2024-01-27 11:08:03       25 阅读
  4. php 源码加密保护 bease方案

    2024-01-27 11:08:03       26 阅读
  5. android studio开发的一些问题

    2024-01-27 11:08:03       35 阅读
  6. CentOS 7.9 OS Kernel Update 3.10 to 4.19

    2024-01-27 11:08:03       29 阅读
  7. 出现次数超过一半的数(c++题解)

    2024-01-27 11:08:03       31 阅读
  8. day32_CSS

    day32_CSS

    2024-01-27 11:08:03      31 阅读