|
@@ -7,9 +7,11 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import {getCurrentInstance, inject, onMounted, reactive, ref, watch} from "vue";
|
|
|
|
-import { Graph } from '@antv/x6'
|
|
|
|
|
|
+import {createVNode, getCurrentInstance, inject, onMounted, reactive, ref, render, watch} from "vue";
|
|
|
|
+import {Graph, Shape} from '@antv/x6'
|
|
import {WorkflowFunc} from "@/views/workflow/types";
|
|
import {WorkflowFunc} from "@/views/workflow/types";
|
|
|
|
+import {lineStyle} from "@/views/workflow/config";
|
|
|
|
+import {ElTooltip} from "element-plus";
|
|
|
|
|
|
const emits = defineEmits([])
|
|
const emits = defineEmits([])
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
@@ -43,14 +45,78 @@ const initChart = () => {
|
|
],
|
|
],
|
|
},
|
|
},
|
|
connecting: {
|
|
connecting: {
|
|
- anchor: {
|
|
|
|
- name: 'topLeft',
|
|
|
|
|
|
+ snap: { // 连线过程中自动吸附
|
|
|
|
+ radius: 20,
|
|
|
|
+ },
|
|
|
|
+ allowBlank: false, // 是否允许连接到画布空白位置的点
|
|
|
|
+ allowLoop: false, // 是否允许创建循环连线,即边的起始节点和终止节点为同一节点
|
|
|
|
+ allowNode: false, // 是否允许边连接到节点
|
|
|
|
+ allowEdge: false, // 是否允许边链接到另一个边
|
|
|
|
+ allowPort: ({sourcePort, targetPort}: any) => { // 是否允许边链接到连接桩
|
|
|
|
+ return !sourcePort?.includes('start') && targetPort?.includes('start')
|
|
|
|
+ },
|
|
|
|
+ allowMulti: 'withPort', // 当设置为 'withPort' 时,在起始和终止节点的相同连接桩之间只允许创建一条边(即,起始和终止节点之间可以创建多条边,但必须要要链接在不同的连接桩上)
|
|
|
|
+ highlight: true,
|
|
|
|
+ router: {
|
|
|
|
+ name: 'manhattan',
|
|
|
|
+ args: {
|
|
|
|
+ startDirections: ['right'],
|
|
|
|
+ endDirections: ['left'],
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ connector: {
|
|
|
|
+ name: 'rounded',
|
|
args: {
|
|
args: {
|
|
- dx: 0,
|
|
|
|
- dy: 25
|
|
|
|
|
|
+ radius: 20,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
+ createEdge: () => new Shape.Edge({
|
|
|
|
+ attrs: lineStyle
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
+ onPortRendered: (args: any) => {
|
|
|
|
+ const selectors = args.contentSelectors;
|
|
|
|
+ const container = selectors && selectors.foContent;
|
|
|
|
+ if (container) {
|
|
|
|
+ const portName = '<div><div><span style="font-weight: bold">点击</span>添加节点</div><div><span style="font-weight: bold">拖拽</span>连接节点</div></div>'
|
|
|
|
+ const dom = createVNode(
|
|
|
|
+ ElTooltip,
|
|
|
|
+ {
|
|
|
|
+ effect: "light",
|
|
|
|
+ content: portName,
|
|
|
|
+ placement: "top",
|
|
|
|
+ rawContent: true
|
|
|
|
+ },
|
|
|
|
+ [
|
|
|
|
+ createVNode("div", {
|
|
|
|
+ class: "createVNode",
|
|
|
|
+ style: {
|
|
|
|
+ border: '1px solid #8f8f8f',
|
|
|
|
+ backgroundColor: '#ffffff',
|
|
|
|
+ height: '100%',
|
|
|
|
+ width: '100%',
|
|
|
|
+ borderRadius: '50%',
|
|
|
|
+ }
|
|
|
|
+ }),
|
|
|
|
+ ]
|
|
|
|
+ );
|
|
|
|
+ render(dom, container);
|
|
|
|
+ }
|
|
|
|
+ // container.addEventListener('mouseenter', (e: MouseEvent) => {
|
|
|
|
+ // const tooltip = document.querySelector('.x6-tooltip') as HTMLElement
|
|
|
|
+ // const content = tooltip?.querySelector('.ant-tooltip-inner') as HTMLElement
|
|
|
|
+ // if (content) {
|
|
|
|
+ // content.innerText = text
|
|
|
|
+ // tooltip.style.left = `${e.clientX - content.offsetWidth / 2}px`
|
|
|
|
+ // tooltip.style.top = `${e.clientY - 50}px`
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // container.addEventListener('mouseleave', () => {
|
|
|
|
+ // const tooltip = document.querySelector('.x6-tooltip') as HTMLElement
|
|
|
|
+ // tooltip.style.left = '-1000px'
|
|
|
|
+ // tooltip.style.top = '-1000px'
|
|
|
|
+ // })
|
|
|
|
+ }
|
|
})
|
|
})
|
|
graph.fromJSON(props.data)
|
|
graph.fromJSON(props.data)
|
|
graph.zoomToFit({ maxScale: 1 })
|
|
graph.zoomToFit({ maxScale: 1 })
|