hookehuyr

复制节点功能完善

......@@ -2,6 +2,7 @@
<div class="app" style="height: 100vh">
<vue-flow-editor
ref="editor"
menuWidth="180px"
modelWidth="300px"
:data="state.data"
:grid="showGrid"
......@@ -653,6 +654,7 @@ export default {
/********** 流程图功能函数 **********/
let editor: {
clearStates(arg0: any): () => void
openModel: () => void
closeModel: () => void
addNode: (arg0: any) => void
......@@ -1010,11 +1012,16 @@ export default {
const copyData = () => { // 复制节点回调
if (state.detailModel.control !== 'start' && state.detailModel.control !== 'end') {
editor.clearStates(state.detailModel.id); // 清除选中节点的状态
const timestamp = Date.now();
const random = timestamp + '';
state.detailModel.id = random; // ID需要重新生成
state.detailModel.y = state.detailModel.y + 50
editor.addNode(state.detailModel);
editor.closeModel();
// 保存流程图数据
state.data.nodes = editor.editorState.graph.save().nodes
state.data.edges = editor.editorState.graph.save().edges
} else {
ElNotification.error('开始或者结束节点不可以复制')
}
......
......@@ -109,6 +109,10 @@ export default {
} else {
console.warn('graph is not initialized')
}
},
clearStates: (id) => {
let item = editorState.graph.findById(id)
item.clearStates('selected')
}
}
provide(VueFlowEditorProvider, provideContext)
......