[Feature][UI] Added logic to drag and drop nodes to DAG canvas. (#12598)
* [Feature][UI] Added logic to drag and drop nodes to DAG canvas. * [Feature][UI] Added logic to drag and drop nodes to DAG canvas.
This commit is contained in:
parent
207b4e77d3
commit
f39e5853f3
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { DagStore } from './types'
|
||||||
|
|
||||||
|
export const useDagStore = defineStore({
|
||||||
|
id: 'dag-store',
|
||||||
|
state: (): DagStore => ({
|
||||||
|
tasks: []
|
||||||
|
}),
|
||||||
|
persist: true,
|
||||||
|
getters: {
|
||||||
|
getDagTasks(): Array<any> {
|
||||||
|
return this.tasks
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setDagTasks(tasks: Array<any>): void {
|
||||||
|
this.tasks = tasks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface DagStore {
|
||||||
|
tasks: Array<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DagStore }
|
||||||
|
|
@ -21,6 +21,7 @@ import { useDagResize } from './use-dag-resize'
|
||||||
import { useDagGraph } from './use-dag-graph'
|
import { useDagGraph } from './use-dag-graph'
|
||||||
import { useDagNode } from './use-dag-node'
|
import { useDagNode } from './use-dag-node'
|
||||||
import { useDagEdge } from './use-dag-edge'
|
import { useDagEdge } from './use-dag-edge'
|
||||||
|
//import { useAddDagShape } from './use-add-dag-shape'
|
||||||
import { DagNodeName, DagEdgeName } from './dag-setting'
|
import { DagNodeName, DagEdgeName } from './dag-setting'
|
||||||
import styles from './dag-canvas.module.scss'
|
import styles from './dag-canvas.module.scss'
|
||||||
|
|
||||||
|
|
@ -67,6 +68,7 @@ const DagCanvas = defineComponent({
|
||||||
initGraph()
|
initGraph()
|
||||||
registerNode()
|
registerNode()
|
||||||
registerEdge()
|
registerEdge()
|
||||||
|
//useAddDagShape((graph.value as Graph))
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ import styles from './dag-sidebar.module.scss'
|
||||||
|
|
||||||
const DagSidebar = defineComponent({
|
const DagSidebar = defineComponent({
|
||||||
name: 'DagSidebar',
|
name: 'DagSidebar',
|
||||||
emits: ['Dragend'],
|
emits: ['Dragstart'],
|
||||||
setup(props, context) {
|
setup(props, context) {
|
||||||
const { variables, getTaskList } = useSidebar()
|
const { variables, getTaskList } = useSidebar()
|
||||||
|
|
||||||
const handleDragend = (e: DragEvent, task: any) => {
|
const handleDragstart = (e: DragEvent, task: string) => {
|
||||||
context.emit('Dragend', e, task)
|
context.emit('Dragstart', e, task)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|
@ -35,7 +35,7 @@ const DagSidebar = defineComponent({
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(variables),
|
...toRefs(variables),
|
||||||
handleDragend
|
handleDragstart
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
|
@ -44,7 +44,7 @@ const DagSidebar = defineComponent({
|
||||||
{
|
{
|
||||||
this.taskList.map(task => {
|
this.taskList.map(task => {
|
||||||
return (
|
return (
|
||||||
<div class={styles['task-item']} draggable='true' onDragend={(e: DragEvent) => this.handleDragend(e, task)}>
|
<div class={styles['task-item']} draggable='true' onDragstart={(e: DragEvent) => this.handleDragstart(e, task)}>
|
||||||
{task}
|
{task}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -15,36 +15,50 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent, reactive } from 'vue'
|
||||||
import { DagSidebar } from './dag-sidebar'
|
import { DagSidebar } from './dag-sidebar'
|
||||||
import { DagCanvas } from './dag-canvas'
|
import { DagCanvas } from './dag-canvas'
|
||||||
|
import { useDagStore } from '@/store/project/dynamic/dag'
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
|
|
||||||
const DynamicDag = defineComponent({
|
const DynamicDag = defineComponent({
|
||||||
name: 'DynamicDag',
|
name: 'DynamicDag',
|
||||||
setup() {
|
setup() {
|
||||||
const handelDragend = () => {
|
const dragged = reactive({
|
||||||
//console.log(e, task)
|
x: 0,
|
||||||
//if (readonly.value) {
|
y: 0,
|
||||||
// e.preventDefault()
|
task: ''
|
||||||
// return
|
})
|
||||||
//}
|
|
||||||
//dragged.value = {
|
const handelDragstart = (e: DragEvent, task: string) => {
|
||||||
// x: e.offsetX,
|
dragged.x = e.offsetX
|
||||||
// y: e.offsetY,
|
dragged.y = e.offsetY
|
||||||
// type: task
|
dragged.task = task
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
const handelDrop = (e: DragEvent) => {
|
||||||
|
if (!dragged.task) return
|
||||||
|
|
||||||
|
dragged.x = e.offsetX
|
||||||
|
dragged.y = e.offsetY
|
||||||
|
|
||||||
|
const shapes = useDagStore().getDagTasks
|
||||||
|
if (shapes) {
|
||||||
|
shapes.push(dragged)
|
||||||
|
}
|
||||||
|
useDagStore().setDagTasks(shapes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handelDragend
|
handelDragstart,
|
||||||
|
handelDrop
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class={styles['workflow-dag']}>
|
<div class={styles['workflow-dag']}>
|
||||||
<DagSidebar onDragend={this.handelDragend} />
|
<DagSidebar onDragstart={this.handelDragstart} />
|
||||||
<DagCanvas />
|
<DagCanvas onDrop={this.handelDrop} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Graph, Cell } from '@antv/x6'
|
||||||
|
import { useDagStore } from '@/store/project/dynamic/dag'
|
||||||
|
|
||||||
|
export function useAddDagShape(graph: Graph) {
|
||||||
|
const cells: Array<Cell> = useDagStore().getDagTasks
|
||||||
|
|
||||||
|
cells.forEach(item => {
|
||||||
|
if (item.shape === 'dag-edge') {
|
||||||
|
cells.push((graph as Graph).addEdge(item))
|
||||||
|
} else {
|
||||||
|
cells.push((graph as Graph).addNode(item as any))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
;(graph as Graph).resetCells(cells)
|
||||||
|
}
|
||||||
|
|
@ -15,8 +15,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { createVNode } from 'vue'
|
||||||
|
import { DagNode } from './dag-node'
|
||||||
|
import '@antv/x6-vue-shape'
|
||||||
|
|
||||||
export function useDagNode() {
|
export function useDagNode() {
|
||||||
return {
|
return {
|
||||||
inherit: 'rect'
|
inherit: 'vue-shape',
|
||||||
|
component: {
|
||||||
|
render: () => {
|
||||||
|
return createVNode(DagNode)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,9 @@ export default defineConfig({
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, 'src'),
|
'@': path.resolve(__dirname, 'src'),
|
||||||
// resolve vue-i18n warning: You are running the esm-bundler build of vue-i18n.
|
// resolve vue-i18n warning: You are running the esm-bundler build of vue-i18n.
|
||||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||||
|
'@antv/x6': '@antv/x6/dist/x6.js',
|
||||||
|
'@antv/x6-vue-shape': '@antv/x6-vue-shape/lib'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue