|
@@ -7,22 +7,84 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { ref, onMounted } from 'vue';
|
|
|
-import logicFlows from '@/utils/logicFlow';
|
|
|
+import { ref, onMounted, watch } from 'vue';
|
|
|
import LogicFlow from "@logicflow/core";
|
|
|
-import { DndPanel, SelectionSelect, Group, Menu, MiniMap, regeister } from "@logicflow/extension";
|
|
|
+import { DndPanel, SelectionSelect, Group, Menu, MiniMap, regeister, Snapshot } from "@logicflow/extension";
|
|
|
import "@logicflow/core/dist/style/index.css";
|
|
|
import "@logicflow/extension/lib/style/index.css";
|
|
|
export default {
|
|
|
- setup() {
|
|
|
+ props: {
|
|
|
+ lineMenuColor: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setup(props, { emit }) {
|
|
|
const container = ref();
|
|
|
const lf = ref();
|
|
|
+ let needColor = props.lineMenuColor
|
|
|
+ let lineColor = ref('#255CE7')
|
|
|
+ let copyColor = ref('')
|
|
|
+ let delId = ref('')
|
|
|
+ let nodeId = ref('')
|
|
|
+ watch(() => props.lineMenuColor, (newVal) => {
|
|
|
+ copyColor.value = newVal
|
|
|
+ })
|
|
|
+ function blue() {
|
|
|
+ lf.value.setTheme({
|
|
|
+ baseEdge: {
|
|
|
+ stroke: '#255CE7',
|
|
|
+ strokeWidth: 2,
|
|
|
+ },
|
|
|
+ });//设置连接线为蓝色
|
|
|
+ }
|
|
|
+ function orange() {
|
|
|
+ lf.value.setTheme({
|
|
|
+ baseEdge: {
|
|
|
+ stroke: 'orange',
|
|
|
+ strokeWidth: 2,
|
|
|
+ },
|
|
|
+ });//设置连接线为橙色
|
|
|
+ }
|
|
|
+ function delLine() {
|
|
|
+ if (delId.value) {
|
|
|
+ lf.value.deleteEdge(delId.value)//删除选择的连接线
|
|
|
+ }
|
|
|
+ if (nodeId.value) {
|
|
|
+ lf.value.deleteNode(nodeId.value)//删除节点
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function saveLine() {
|
|
|
+ lf.value.getSnapshot()//保存为图片
|
|
|
+ }
|
|
|
+ function cleanMap() {
|
|
|
+ lf.value.clearData()
|
|
|
+ }
|
|
|
+ function textColor() {
|
|
|
+ if (lineColor.value == "#255CE7") {
|
|
|
+ lf.value.setTheme({
|
|
|
+ baseEdge: {
|
|
|
+ stroke: "orange",
|
|
|
+ strokeWidth: 2,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ lineColor.value = 'orange'
|
|
|
+ } else {
|
|
|
+ lf.value.setTheme({
|
|
|
+ baseEdge: {
|
|
|
+ stroke: "#255CE7",
|
|
|
+ strokeWidth: 2,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ lineColor.value = '#255CE7'
|
|
|
+ }
|
|
|
+ }
|
|
|
onMounted(() => {
|
|
|
lf.value = new LogicFlow({
|
|
|
// 通过选项指定了渲染的容器和需要显示网格
|
|
|
container: container.value,
|
|
|
- grid: true,
|
|
|
- plugins: [DndPanel, SelectionSelect, Group, Menu, MiniMap],
|
|
|
+ grid: false,
|
|
|
+ plugins: [DndPanel, SelectionSelect, Group, Menu, MiniMap, Snapshot],
|
|
|
keyboard: {
|
|
|
enabled: true
|
|
|
},
|
|
@@ -95,13 +157,12 @@ export default {
|
|
|
icon: "",
|
|
|
}
|
|
|
]
|
|
|
- var lineColor = '#255CE7'
|
|
|
lf.value.setTheme({
|
|
|
rect: {
|
|
|
fill: "#FFFFFF",
|
|
|
stroke: "#255CE7",
|
|
|
strokeWidth: 2,
|
|
|
- },
|
|
|
+ },//放置的元素
|
|
|
snapline: {
|
|
|
stroke: '#1E90FF', // 对齐线颜色
|
|
|
strokeWidth: 1, // 对齐线宽度
|
|
@@ -109,11 +170,11 @@ export default {
|
|
|
edgeText: {
|
|
|
textWidth: 100,
|
|
|
overflowMode: "default",
|
|
|
- fontSize: 16,
|
|
|
+ fontSize: 18,
|
|
|
background: {
|
|
|
fill: "#FFFFFF",
|
|
|
},
|
|
|
- },
|
|
|
+ },//连接线w文字样式
|
|
|
outline: {
|
|
|
fill: "transparent",
|
|
|
stroke: "#949494",
|
|
@@ -132,27 +193,31 @@ export default {
|
|
|
stroke: "#949494",
|
|
|
r: 10,
|
|
|
},
|
|
|
- },
|
|
|
+ },//锚点样式
|
|
|
+ baseEdge: {
|
|
|
+ stroke: "#255CE7",
|
|
|
+ strokeWidth: 2,
|
|
|
+ },//连接线颜色
|
|
|
+ nodeText: {
|
|
|
+ color: "#255CE7",
|
|
|
+ overflowMode: "autoWrap",
|
|
|
+ lineHeight: 1.2,
|
|
|
+ fontSize: 12,
|
|
|
+ },//节点内文字样式
|
|
|
});
|
|
|
lf.value.on("edge:click", function (data, e, position) {
|
|
|
- if (lineColor == "#255CE7") {
|
|
|
- lf.value.setTheme({
|
|
|
- baseEdge: {
|
|
|
- stroke: "orange",
|
|
|
- strokeWidth: 2,
|
|
|
- },
|
|
|
- });
|
|
|
- lineColor = 'orange'
|
|
|
- } else {
|
|
|
- lf.value.setTheme({
|
|
|
- baseEdge: {
|
|
|
- stroke: "#255CE7",
|
|
|
- strokeWidth: 2,
|
|
|
- },
|
|
|
- });
|
|
|
- lineColor = '#255CE7'
|
|
|
+ delId.value = data.data.id
|
|
|
+ })
|
|
|
+ lf.value.on('node:click', function (data, e, position) {
|
|
|
+ nodeId.value = data.data.id
|
|
|
+ })
|
|
|
+ lf.value.on('edge:click', function (data, e, position) {//解决点击连接线问题
|
|
|
+ if (copyColor.value == '#255CE7') {
|
|
|
+ blue()
|
|
|
+ }
|
|
|
+ if (copyColor.value == 'orange') {
|
|
|
+ orange()
|
|
|
}
|
|
|
-
|
|
|
})
|
|
|
// lf.value.register(logicFlows)
|
|
|
lf.value.extension.dndPanel.setPatternItems(patternItems);
|
|
@@ -161,6 +226,15 @@ export default {
|
|
|
return {
|
|
|
container,
|
|
|
lf,
|
|
|
+ textColor,
|
|
|
+ lineColor,
|
|
|
+ blue,
|
|
|
+ orange,
|
|
|
+ delLine,
|
|
|
+ saveLine,
|
|
|
+ cleanMap,
|
|
|
+ nodeId,
|
|
|
+ copyColor,
|
|
|
}
|
|
|
},
|
|
|
}
|