guozhaolong / wfd-vue

flowable workflow designer for Vue base on @antv/g6
https://guozhaolong.github.io/wfd-vue/
995 stars 261 forks source link

远程请求来的数据不能拖动到右边画布(刷新页面之后不可以,代码热更新是可以的) #61

Open bingyuea opened 3 years ago

bingyuea commented 3 years ago

`刚开始以为是左边图表没有加载好,然后加载完毕之后还是不能拖动(刷新之后),但是更改代码让代码热更新之后是可以拖动到右边的。 不太清楚是哪里出了问题 注册左边图形代码 image

async getDevices() { getDevice().then(async res => { await registerShape(G6,res.data); registerBehavior(G6); setTimeout(function() { this.devices = _.groupBy(res.data,'typeId') }.bind(this),500) }) },

initPlugin(graph) { // 确保图片加载完毕 let timer = setInterval(function() { const parentNode = this.get('container'); const ghost = createDom('<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"' + ' style="opacity:0"/>'); const children = parentNode.querySelectorAll('.itemPanel img[data-item]') if (children.length) { if (Array.from(children).every(img => img.height > 0)) { setTimeout(function() { each(children,(child,i) => { const addModel = (new Function("return " + child.getAttribute('data-item')))(); child.addEventListener('dragstart',e => { console.log(addModel,'点击!') e.dataTransfer.setDragImage(ghost,0,0); graph.set('addNodeDragging',true); graph.set('addModel',addModel); }); child.addEventListener('dragend',e => { graph.emit('canvas:mouseup',e); graph.set('addNodeDragging',false); graph.set('addModel',null); }); }) }.bind(this),500) clearInterval(timer) } } }.bind(this),1000) }

bingyuea commented 3 years ago

`` image image

这个是两个graph 对象,第一个是正常的,第二张是所说的问题。

AmySay commented 3 years ago

registerShape(G6) registerBehavior(G6) 这两个方法 重新注册下试试

bingyuea commented 3 years ago

registerShape(G6) registerBehavior(G6) 这两个方法 重新注册下试试

好像可以了

wiserliu commented 3 years ago

你好,我也遇到了同样的问题,请问怎么解决的

bingyuea commented 3 years ago

你好,我也遇到了同样的问题,请问怎么解决的

加载顺序问题,按照上面的办法试试