index.vue
2.42 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!--
* @Date: 2025-03-11 17:20:37
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-11 18:15:05
* @FilePath: /logic-flow2/src/views/node-vue/index.vue
* @Description: 文件描述
-->
<template>
<div class="container">
<div ref="containerRef" id="graph" class="flow-container"></div>
</div>
<TeleportContainer :flow-id="flowId" />
</template>
<script setup>
import { forEach, map, has } from "lodash-es";
import LogicFlow, { ElementState, LogicFlowUtil } from "@logicflow/core";
import { register, getTeleport } from "@logicflow/vue-node-registry";
import ProgressNode from "./ProgressNode.vue";
const containerRef = ref(null);
const TeleportContainer = getTeleport();
const flowId = ref("");
onMounted(() => {
if (containerRef.value) {
const lf = new LogicFlow({
container: containerRef.value,
grid: true,
});
// 注册自定义 vue 节点
register(
{
type: "custom-vue-node",
component: ProgressNode,
},
lf
);
lf.on("graph:rendered", ({ graphModel }) => {
flowId.value = graphModel?.flowId || "";
});
// 注册事件
lf.render({});
const node1 = lf.addNode({
id: "vue-node-1",
type: "custom-vue-node",
x: 80,
y: 80,
properties: {
progress: 60,
width: 80,
height: 80,
},
});
console.log("node1 --->>>", node1);
const node2 = lf.addNode({
id: "vue-node-2",
type: "custom-vue-node",
x: 360,
y: 80,
properties: {
progress: 60,
width: 80,
height: 80,
},
});
// setInterval(() => {
// const { properties } = node2.getData();
// console.log("properties.progress --->>>", properties?.progress);
// if (has(properties, "progress")) {
// const progress = properties?.progress;
// node2.setProperty("progress", (progress + 10) % 100);
// }
// }, 2000);
setTimeout(() => {
const { properties } = node2.getData();
console.log("properties.progress --->>>", properties?.progress);
if (has(properties, "progress")) {
const progress = properties?.progress;
node2.setProperty("progress", (progress + 10) % 100);
}
}, 2000);
}
});
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.flow-container {
flex: 1;
width: 100%;
height: 100%;
}
</style>