Showing
5 changed files
with
161 additions
and
1 deletions
| ... | @@ -65,6 +65,11 @@ const router = createRouter({ | ... | @@ -65,6 +65,11 @@ const router = createRouter({ |
| 65 | name: 'edge-arrow', | 65 | name: 'edge-arrow', |
| 66 | component: () => import('../views/edge/arrow.vue') | 66 | component: () => import('../views/edge/arrow.vue') |
| 67 | }, | 67 | }, |
| 68 | + { | ||
| 69 | + path: '/theme', | ||
| 70 | + name: 'theme', | ||
| 71 | + component: () => import('../views/theme/index.vue') | ||
| 72 | + }, | ||
| 68 | ] | 73 | ] |
| 69 | }) | 74 | }) |
| 70 | 75 | ... | ... |
| 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 15:31:05 | 4 | + * @LastEditTime: 2025-03-12 16:29:56 |
| 5 | * @FilePath: /logic-flow2/src/views/home.vue | 5 | * @FilePath: /logic-flow2/src/views/home.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | <el-button type="primary" @click="goTo('edge-custom')">edge-custom</el-button> | 17 | <el-button type="primary" @click="goTo('edge-custom')">edge-custom</el-button> |
| 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 | </template> | 21 | </template> |
| 21 | 22 | ||
| 22 | <script setup> | 23 | <script setup> | ... | ... |
src/views/theme/ButtonNode.js
0 → 100644
File mode changed
src/views/theme/customEdge.js
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2025-03-12 17:05:09 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-12 17:06:34 | ||
| 5 | + * @FilePath: /logic-flow2/src/views/theme/customEdge.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +import { PolylineEdge, PolylineEdgeModel } from '@logicflow/core'; | ||
| 9 | + | ||
| 10 | +class CustomEdgeModel extends PolylineEdgeModel { | ||
| 11 | + // 始终显示锚点 | ||
| 12 | + getEdgeStyle() { | ||
| 13 | + const style = super.getEdgeStyle(); | ||
| 14 | + return { | ||
| 15 | + ...style, | ||
| 16 | + hideAnchor: false // 强制显示锚点 | ||
| 17 | + }; | ||
| 18 | + } | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +class CustomEdge extends PolylineEdge { | ||
| 22 | + // 可选:自定义锚点渲染方式 | ||
| 23 | + getEndArrow() { | ||
| 24 | + // 保持原有箭头逻辑 | ||
| 25 | + return super.getEndArrow(); | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +export default { | ||
| 30 | + type: 'custom-edge', | ||
| 31 | + model: CustomEdgeModel, | ||
| 32 | + view: CustomEdge, | ||
| 33 | +} |
src/views/theme/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2025-03-10 16:52:35 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2025-03-12 18:00:09 | ||
| 5 | + * @FilePath: /logic-flow2/src/views/theme/index.vue | ||
| 6 | + * @Description: 主题 Theme | ||
| 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 CustomEdge from "./CustomEdge"; | ||
| 17 | + | ||
| 18 | +const container = ref(null); | ||
| 19 | +let lf = null; | ||
| 20 | + | ||
| 21 | +onMounted(() => { | ||
| 22 | + // 方法1:new LogicFlow时作为配置传入 | ||
| 23 | + const config = { | ||
| 24 | + domId: "app", | ||
| 25 | + width: 1000, | ||
| 26 | + height: 800, | ||
| 27 | + style: { | ||
| 28 | + // 设置默认主题样式 | ||
| 29 | + // rect: { ... }, // 矩形样式 | ||
| 30 | + // circle: { ... }, // 圆形样式 | ||
| 31 | + // nodeText: { ... }, // 节点文本样式 | ||
| 32 | + // edgeText: { ... }, // 边文本样式 | ||
| 33 | + // anchor: { ... }, // 锚点样式 | ||
| 34 | + // ..., | ||
| 35 | + }, | ||
| 36 | + }; | ||
| 37 | + | ||
| 38 | + // 方法2: 调用LogicFlow的setTheme方法 | ||
| 39 | + // lf.setTheme({ // 设置默认主题样式 | ||
| 40 | + // rect: {...}, // 矩形样式 | ||
| 41 | + // circle: {...}, // 圆形样式 | ||
| 42 | + // nodeText: {...}, // 节点文本样式 | ||
| 43 | + // edgeText: {...}, // 边文本样式 | ||
| 44 | + // anchor: {...}, // 锚点样式 | ||
| 45 | + // ... | ||
| 46 | + // }) | ||
| 47 | + | ||
| 48 | + lf = new LogicFlow({ | ||
| 49 | + container: container.value, | ||
| 50 | + grid: true, | ||
| 51 | + }); | ||
| 52 | + | ||
| 53 | + lf.setTheme({ | ||
| 54 | + rect: { | ||
| 55 | + fill: "#FFFFFF", | ||
| 56 | + stroke: "rgba(68, 83, 130, 0.25)", | ||
| 57 | + strokeWidth: 1, | ||
| 58 | + anchorShow: true, // 强制显示锚点 | ||
| 59 | + anchorHoverShow: true, // 保持 hover 效果 | ||
| 60 | + }, | ||
| 61 | + circle: { | ||
| 62 | + // 新增圆形节点配置 | ||
| 63 | + anchorShow: true, // 强制显示锚点 | ||
| 64 | + anchorHoverShow: true, | ||
| 65 | + }, | ||
| 66 | + anchor: { | ||
| 67 | + stroke: "#4d53e8", | ||
| 68 | + fill: "#4d53e8", | ||
| 69 | + r: 3, | ||
| 70 | + show: true, // 新增:全局显示锚点 | ||
| 71 | + hover: { | ||
| 72 | + fill: "#949494", | ||
| 73 | + fillOpacity: 0.5, | ||
| 74 | + stroke: "#949494", | ||
| 75 | + r: 10, | ||
| 76 | + }, | ||
| 77 | + }, | ||
| 78 | + }); | ||
| 79 | + | ||
| 80 | + lf.register(CustomEdge); | ||
| 81 | + | ||
| 82 | + // 使用自定义连线类型 | ||
| 83 | + lf.setDefaultEdgeType("custom-edge"); | ||
| 84 | + | ||
| 85 | + lf.render({ | ||
| 86 | + nodes: [ | ||
| 87 | + { id: "node1", type: "rect", x: 200, y: 100 }, | ||
| 88 | + { id: "node2", type: "circle", x: 400, y: 100 }, | ||
| 89 | + { id: '7', type: 'html', x: 600, y: 320 }, | ||
| 90 | + ], | ||
| 91 | + edges: [ | ||
| 92 | + { id: "edge1", sourceNodeId: "node1", targetNodeId: "node2", type: "custom-edge" }, | ||
| 93 | + ], | ||
| 94 | + }); | ||
| 95 | + | ||
| 96 | + lf.on("node:render", (node) => { | ||
| 97 | + const { nodeConfig } = node; | ||
| 98 | + // 设定锚点 | ||
| 99 | + nodeConfig.anchors = [ | ||
| 100 | + { x: 0.5, y: 0 }, // 上部中间 | ||
| 101 | + { x: 0.5, y: 1 }, // 下部中间 | ||
| 102 | + ]; | ||
| 103 | + // 也可以设置其他锚点 | ||
| 104 | + }); | ||
| 105 | +}); | ||
| 106 | +</script> | ||
| 107 | + | ||
| 108 | +<style scoped> | ||
| 109 | +.container { | ||
| 110 | + width: 100vw; | ||
| 111 | + height: 100vh; | ||
| 112 | + display: flex; | ||
| 113 | + flex-direction: column; | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +.flow-container { | ||
| 117 | + flex: 1; | ||
| 118 | + width: 100%; | ||
| 119 | + height: 100%; | ||
| 120 | +} | ||
| 121 | +</style> |
-
Please register or login to post a comment