-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpluginFlowExec.js
61 lines (55 loc) · 1.73 KB
/
pluginFlowExec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { CONNECTORSEPARATESYMBOL } from './const';
export default function flowExec({ instance }) {
/**
* @description 模拟延时效果
* @param {function} fn
* @param {number} time
* @returns
*/
function timeout(fn, time) {
return new Promise((res) => {
setTimeout(() => {
fn();
res(true);
}, time);
});
}
function changeStateByNodeId(nodeId, state) {
const nodeEl = document.getElementById(nodeId);
nodeEl.vNode.$children[0].state = state;
}
function getConnectorByUuids(uuids) {
const edge = uuids.join(CONNECTORSEPARATESYMBOL);
const connectors = instance.getAllConnections();
const connector = connectors.find(c => c.getUuids().join(CONNECTORSEPARATESYMBOL) === edge);
return connector;
}
function blingConnectors(edges) {
const connectors = instance.getAllConnections();
connectors.forEach((c) => {
c.canvas.classList.remove('active');
});
edges.forEach((edge) => {
const c = getConnectorByUuids(edge.split(CONNECTORSEPARATESYMBOL));
c.canvas.classList.add('active');
});
}
this.execModel = () => {
changeStateByNodeId('aaa', 'loading');
return timeout(() => {
changeStateByNodeId('aaa', 'success');
changeStateByNodeId('bbb', 'loading');
blingConnectors(['source1&&target1', 'source2&&target2']);
}, 3000)
.then(() => timeout(() => {
changeStateByNodeId('bbb', 'success');
changeStateByNodeId('ccc', 'loading');
blingConnectors(['source3&&ccc111', 'source3&&ccc222']);
}, 4000))
.then(() => timeout(() => {
changeStateByNodeId('ccc', 'success');
changeStateByNodeId('ddd', 'failed');
blingConnectors([]);
}, 5000));
};
}