antv-X6-Vue3总结03-Vue节点配置

部分源代码:https://gitee.com/eadela/x6-example.git

channelReferral.vue 节点组件

<template>
  <!-- 多波次 -->
  <div class="node-box">
    <Icon type="cancel-questionnaire" class="icon" />
    <p> 渠道转介 </p>

    <div class="child">
      <Button type="text" @click="edit">
        编辑
      </Button>
      <Button type="text" @click="del" class="m-l-1">
        删除
      </Button>
    </div>
  </div>
</template>

<script lang="ts" setup>
/*eslint-disable */
import { Icon, Button } from '@bairong/uxd-ui'
import { defineProps } from 'vue'

const props = defineProps({
  icon: {
    type: String
    // required: true
  },
  text: {
    type: String
    // required: true
  }
})

defineExpose({
  ...props
})

const edit = () => {
  console.log(123123)
}
const del = () => {
  console.log(456456)
}

/*eslint-disable */
</script>

<style scoped lang="less">
.child {
  width: 150px;
  min-height: 100px;
  background: #fff;
  position: absolute;
  left: 60px;
  top: 0;
  display: none;
}
.node-box {
  width: 64px;
  height: 64px;
  border: 1px solid #136fff;
  border-radius: 5px;
  background: #fff;
  text-align: center;
  padding-top: 6px;
  position: relative;
  &:hover {
    background: #136fff;
    color: #fff;
    .child {
      // display: block;
      color: #000;
    }
    .icon {
      color: #fff;
    }
  }
  .icon {
    font-size: 22px;
    color: #136fff;
  }
}
</style>

常量

// 所有节点组
export const ShapeComs = {
  HEEL_NODE: 'HeelNode', // 客群筛选
  SEC_SCREENING: 'SecScreening', // 二次筛选
  SEC_CREATE: 'SecCreate', // 二次筛选裂变产生 -- 特殊节点
  AB_TEST: 'AbTest', // AB测试
  AB_CREATE: 'AbCreate', // AB测试裂变产生  -- 特殊节点
  EXTERNAL_DATA: 'ExternalData', // 外部数据
  FINANCIAL_MANAGER: 'FinancialManager', // 理财经理
  MANUAL_OUTBOUND_CALL: 'ManualOutboundCall', // 人工外呼
  SHORT_MESSAGE: 'ShortMessage', // 短信
  PHONE_
### 安装与配置 为了使用 `@antv/x6-vue-shape`,需要先通过包管理工具安装必要的依赖: ```bash pnpm install @antv/x6 @antv/x6-vue-shape ``` 此命令会下载并安装 AntV X6 及其 Vue 组件支持库[^1]。 ### 创建自定义形状组件 在项目中创建一个新的 Vue 单文件组件来表示图形中的节点。这个组件可以利用 Element Plus 或其他任何 UI 库构建复杂的界面逻辑。 例如,在 `src/components/CustomNode.vue` 中定义如下结构: ```vue <template> <div class="custom-node"> <!-- 节点内部的内容 --> {{ nodeData.label }} </div> </template> <script setup lang="ts"> import { defineProps } from &#39;vue&#39;; defineProps<{ nodeData: any; }>(); </script> <style scoped> .custom-node { width: 100%; height: 100%; } </style> ``` ### 注册自定义形状到AntV X6 为了让 AntV X6 认识新创建的 Vue 组件作为合法的绘图元素之一,需调用 `registerVueComponent()` 方法完成注册过程。 ```javascript import { registerVueComponent } from &#39;@antv/x6-vue-shape&#39;; import CustomNode from &#39;@/components/CustomNode.vue&#39;; // 将 Vue 组件注册为 AntV X6 形状 registerVueComponent(&#39;custom-node&#39;, CustomNode); ``` ### 构建画布实例 初始化一个 Graph 实例,并设置容器和其他选项如网格线显示等特性。 ```typescript import { Graph } from &#39;@antv/x6&#39;; const graph = new Graph({ container: document.getElementById(&#39;container&#39;), grid: true, }); ``` ### 添加带有上下文菜单功能的节点 最后一步是在图表上添加具有交互特性的节点,比如这里展示的是如何集成右键点击弹出菜单的功能。 ```typescript graph.addNode({ shape: &#39;custom-node&#39;, x: 100, y: 150, id: &#39;node-id&#39;, tools:[ { name: &#39;contextmenu&#39;, args: { menu: [ { key: &#39;input&#39;, label: &#39;输入内容&#39;, click(view) { console.log(view); }}, { key: &#39;flow&#39;, label: &#39;查看流水&#39;} ] } }, ], data: { label: "这是一个测试标签" } }); ``` 上述代码片段展示了如何结合 AntV X6Vue 来制作可定制化的流程图编辑器的一部分——即带有一个简单上下文菜单的自定义节点[^2]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

eadela

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值