Showing
6 changed files
with
230 additions
and
4 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-10 13:07:05 | 2 | * @Date: 2025-03-10 13:07:05 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-11 17:23:23 | 4 | + * @LastEditTime: 2025-03-12 23:35:54 |
| 5 | * @FilePath: /logic-flow2/src/main.js | 5 | * @FilePath: /logic-flow2/src/main.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -22,7 +22,7 @@ LogicFlow.use(DndPanel) // 拖拽面板 | ... | @@ -22,7 +22,7 @@ LogicFlow.use(DndPanel) // 拖拽面板 |
| 22 | LogicFlow.use(SelectionSelect) // 选中元素 | 22 | LogicFlow.use(SelectionSelect) // 选中元素 |
| 23 | // LogicFlow.use(Control) // 控制面板 | 23 | // LogicFlow.use(Control) // 控制面板 |
| 24 | LogicFlow.use(InsertNodeInPolyline) // 边上插入节点 | 24 | LogicFlow.use(InsertNodeInPolyline) // 边上插入节点 |
| 25 | -LogicFlow.use(Highlight) // 高亮 | 25 | +// LogicFlow.use(Highlight) // 高亮 |
| 26 | 26 | ||
| 27 | const app = createApp(App) | 27 | const app = createApp(App) |
| 28 | app.use(ElementPlus) | 28 | app.use(ElementPlus) | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-10 13:15:30 | 2 | * @Date: 2025-03-10 13:15:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-12 11:06:26 | 4 | + * @LastEditTime: 2025-03-12 21:27:32 |
| 5 | * @FilePath: /logic-flow2/src/router/index.js | 5 | * @FilePath: /logic-flow2/src/router/index.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -70,6 +70,16 @@ const router = createRouter({ | ... | @@ -70,6 +70,16 @@ const router = createRouter({ |
| 70 | name: 'theme', | 70 | name: 'theme', |
| 71 | component: () => import('../views/theme/index.vue') | 71 | component: () => import('../views/theme/index.vue') |
| 72 | }, | 72 | }, |
| 73 | + { | ||
| 74 | + path: '/adv-node-rule', | ||
| 75 | + name: 'adv-node-rule', | ||
| 76 | + component: () => import('../views/adv-node/rule/index.vue') | ||
| 77 | + }, | ||
| 78 | + { | ||
| 79 | + path: '/adv-node-anchor', | ||
| 80 | + name: 'adv-node-anchor', | ||
| 81 | + component: () => import('../views/adv-node/anchor/index.vue') | ||
| 82 | + }, | ||
| 73 | ] | 83 | ] |
| 74 | }) | 84 | }) |
| 75 | 85 | ... | ... |
src/views/adv-node/rule/connectData.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2025-03-12 18:20:35 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-12 20:37:40 | ||
| 5 | + * @FilePath: /logic-flow2/src/views/adv-node/rule/connectData.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +const data = { | ||
| 9 | + nodes: [ | ||
| 10 | + { | ||
| 11 | + id: '1', | ||
| 12 | + type: 'rect', | ||
| 13 | + x: 300, | ||
| 14 | + y: 100, | ||
| 15 | + }, | ||
| 16 | + { | ||
| 17 | + id: '2', | ||
| 18 | + type: 'circle', | ||
| 19 | + x: 300, | ||
| 20 | + y: 250, | ||
| 21 | + }, | ||
| 22 | + { | ||
| 23 | + id: '3', | ||
| 24 | + type: 'hexagonNode', | ||
| 25 | + x: 100, | ||
| 26 | + y: 100, | ||
| 27 | + text: '只能连接到圆', | ||
| 28 | + properties: { | ||
| 29 | + // isSelected: true, | ||
| 30 | + }, | ||
| 31 | + }, | ||
| 32 | + ], | ||
| 33 | + edges: [], | ||
| 34 | +}; | ||
| 35 | + | ||
| 36 | +export default data; |
src/views/adv-node/rule/customHexagon.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2025-03-12 18:21:07 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-12 20:38:00 | ||
| 5 | + * @FilePath: /logic-flow2/src/views/adv-node/rule/customHexagon.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +import { PolygonNodeModel, PolygonNode } from '@logicflow/core'; | ||
| 9 | + | ||
| 10 | +class CustomHexagonModel extends PolygonNodeModel { | ||
| 11 | + setAttributes() { | ||
| 12 | + const width = 100; | ||
| 13 | + const height = 100; | ||
| 14 | + const x = 50; | ||
| 15 | + const y = 50; | ||
| 16 | + // 计算六边形, 中心点为[50, 50], 宽高均为100 | ||
| 17 | + const pointList= [ | ||
| 18 | + [x - 0.205 * width, y - 0.5 * height], | ||
| 19 | + [x + 0.205 * width, y - 0.5 * height], | ||
| 20 | + [x + 0.5 * width, y], | ||
| 21 | + [x + 0.205 * width, y + 0.5 * height], | ||
| 22 | + [x - 0.205 * width, y + 0.5 * height], | ||
| 23 | + [x - 0.5 * width, y], | ||
| 24 | + ]; | ||
| 25 | + this.points = pointList; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + getConnectedSourceRules() { | ||
| 29 | + const rules = super.getConnectedSourceRules(); | ||
| 30 | + const getWayOnlyAsTarget = { | ||
| 31 | + message: '下一个节点只能是circle', | ||
| 32 | + validate: ( | ||
| 33 | + source, | ||
| 34 | + target, | ||
| 35 | + sourceAnchor, | ||
| 36 | + targetAnchor, | ||
| 37 | + ) => { | ||
| 38 | + console.warn('sourceAnchor, targetAnchor', sourceAnchor, targetAnchor); | ||
| 39 | + const isValid = target.type === 'circle'; | ||
| 40 | + // 根据验证结果设置节点状态 | ||
| 41 | + this.updateValidateState(isValid); | ||
| 42 | + return isValid; | ||
| 43 | + }, | ||
| 44 | + }; | ||
| 45 | + rules.push(getWayOnlyAsTarget); | ||
| 46 | + return rules; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + // 新增方法:更新验证状态 | ||
| 50 | + updateValidateState(isValid) { | ||
| 51 | + this.setProperties({ | ||
| 52 | + validateState: isValid ? 'valid' : 'invalid' | ||
| 53 | + }); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + getNodeStyle() { | ||
| 57 | + const style = super.getNodeStyle(); | ||
| 58 | + if (this.properties.isSelected) { | ||
| 59 | + style.fill = 'red'; | ||
| 60 | + } | ||
| 61 | + if (this.isHovered) { | ||
| 62 | + style.stroke = 'red'; | ||
| 63 | + } | ||
| 64 | + // 根据验证状态设置颜色 | ||
| 65 | + if (this.properties.validateState === 'invalid') { | ||
| 66 | + style.fill = 'red'; | ||
| 67 | + } | ||
| 68 | + if (this.properties.validateState === 'valid') { | ||
| 69 | + style.fill = 'green'; | ||
| 70 | + } | ||
| 71 | + return style; | ||
| 72 | + } | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +export default { | ||
| 76 | + type: 'hexagonNode', | ||
| 77 | + model: CustomHexagonModel, | ||
| 78 | + view: PolygonNode, | ||
| 79 | +}; |
src/views/adv-node/rule/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2025-03-10 16:52:35 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-12 20:18:28 | ||
| 5 | + * @FilePath: /logic-flow2/src/views/adv-node/rule/index.vue | ||
| 6 | + * @Description: 连接规则 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="container"> | ||
| 10 | + <div ref="container" class="flow-container"></div> | ||
| 11 | + </div> | ||
| 12 | +</template> | ||
| 13 | + | ||
| 14 | +<script setup> | ||
| 15 | +import LogicFlow from "@logicflow/core"; | ||
| 16 | +import CustomHexagon from "./customHexagon"; | ||
| 17 | +import data from "./connectData"; | ||
| 18 | + | ||
| 19 | +const SilentConfig = { | ||
| 20 | + stopScrollGraph: true, | ||
| 21 | + stopMoveGraph: true, | ||
| 22 | + stopZoomGraph: true, | ||
| 23 | +}; | ||
| 24 | + | ||
| 25 | +const styleConfig = { | ||
| 26 | + style: { | ||
| 27 | + rect: { | ||
| 28 | + rx: 5, | ||
| 29 | + ry: 5, | ||
| 30 | + strokeWidth: 2, | ||
| 31 | + }, | ||
| 32 | + circle: { | ||
| 33 | + fill: "#f5f5f5", | ||
| 34 | + stroke: "#666", | ||
| 35 | + }, | ||
| 36 | + ellipse: { | ||
| 37 | + fill: "#dae8fc", | ||
| 38 | + stroke: "#6c8ebf", | ||
| 39 | + }, | ||
| 40 | + polygon: { | ||
| 41 | + fill: "#d5e8d4", | ||
| 42 | + stroke: "#82b366", | ||
| 43 | + }, | ||
| 44 | + diamond: { | ||
| 45 | + fill: "#ffe6cc", | ||
| 46 | + stroke: "#d79b00", | ||
| 47 | + }, | ||
| 48 | + text: { | ||
| 49 | + color: "#b85450", | ||
| 50 | + fontSize: 12, | ||
| 51 | + }, | ||
| 52 | + }, | ||
| 53 | +}; | ||
| 54 | + | ||
| 55 | +const container = ref(null); | ||
| 56 | +let lf = null; | ||
| 57 | + | ||
| 58 | +onMounted(() => { | ||
| 59 | + lf = new LogicFlow({ | ||
| 60 | + container: container.value, | ||
| 61 | + grid: true, | ||
| 62 | + ...SilentConfig, | ||
| 63 | + ...styleConfig, | ||
| 64 | + }); | ||
| 65 | + | ||
| 66 | + lf.register(CustomHexagon); | ||
| 67 | + | ||
| 68 | + lf.setTheme({ | ||
| 69 | + nodeText: { | ||
| 70 | + color: "#000000", | ||
| 71 | + overflowMode: "ellipsis", | ||
| 72 | + lineHeight: 1.2, | ||
| 73 | + fontSize: 12, | ||
| 74 | + }, | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + lf.render(data); | ||
| 78 | + lf.translateCenter(); | ||
| 79 | + | ||
| 80 | + lf.on("connection:not-allowed", (msg) => { | ||
| 81 | + console.log(msg); | ||
| 82 | + }); | ||
| 83 | +}); | ||
| 84 | +</script> | ||
| 85 | + | ||
| 86 | +<style scoped> | ||
| 87 | +.container { | ||
| 88 | + width: 100vw; | ||
| 89 | + height: 100vh; | ||
| 90 | + display: flex; | ||
| 91 | + flex-direction: column; | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +.flow-container { | ||
| 95 | + flex: 1; | ||
| 96 | + width: 100%; | ||
| 97 | + height: 100%; | ||
| 98 | +} | ||
| 99 | +</style> |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-03-10 14:37:31 | 2 | * @Date: 2025-03-10 14:37:31 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-12 16:29:56 | 4 | + * @LastEditTime: 2025-03-12 21:27:39 |
| 5 | * @FilePath: /logic-flow2/src/views/home.vue | 5 | * @FilePath: /logic-flow2/src/views/home.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -18,6 +18,8 @@ | ... | @@ -18,6 +18,8 @@ |
| 18 | <el-button type="primary" @click="goTo('edge-text')">edge-text</el-button> | 18 | <el-button type="primary" @click="goTo('edge-text')">edge-text</el-button> |
| 19 | <el-button type="primary" @click="goTo('edge-arrow')">edge-arrow</el-button> | 19 | <el-button type="primary" @click="goTo('edge-arrow')">edge-arrow</el-button> |
| 20 | <el-button type="primary" @click="goTo('theme')">theme</el-button> | 20 | <el-button type="primary" @click="goTo('theme')">theme</el-button> |
| 21 | + <el-button type="primary" @click="goTo('adv-node-rule')">adv-node-rule</el-button> | ||
| 22 | + <el-button type="primary" @click="goTo('adv-node-anchor')">adv-node-anchor</el-button> | ||
| 21 | </template> | 23 | </template> |
| 22 | 24 | ||
| 23 | <script setup> | 25 | <script setup> | ... | ... |
-
Please register or login to post a comment