使用logicflow重构流程图

This commit is contained in:
Jam committed 2022-11-27 01:05:41 +08:00
1 parent 134acc057e
commit 8ff82208ad
6 files changed
+342 -770

No files matched your search

+13 -7
View File
@@ -64,6 +64,12 @@
template: '#edit-line', template: '#edit-line',
vuetify: new Vuetify(), vuetify: new Vuetify(),
name: 'editLine', name: 'editLine',
props: {
lf: {
type: Object,
default: null
}
},
data() { data() {
return { return {
line: { label: '' }, line: { label: '' },
@@ -74,10 +80,10 @@
}, },
watch: { watch: {
line: { line: {
handler(val) { handler: function (line) {
if (this.isUpdate) { this.lf.updateText(line.id, `${line.type}-${line.label}`);
this.$emit('line-save', this.line); this.lf.setProperties(line.id, line);
} console.log(this.lf.getEdgeModelById(line.id));
}, },
deep: true deep: true
} }
@@ -88,11 +94,11 @@
}, },
}, },
methods: { methods: {
init(item, lineTypeList) { init(line, lineTypeList) {
this.isUpdate = false; this.isUpdate = false;
this.line = item; this.line = line.properties;
this.lineTypeList = lineTypeList; this.lineTypeList = lineTypeList;
this.$nextTick(function () { this.$nextTick(() => {
this.isUpdate = true; this.isUpdate = true;
}); });
}, },
+13 -2
View File
@@ -117,6 +117,10 @@
vuetify: new Vuetify(), vuetify: new Vuetify(),
name: 'editNode', name: 'editNode',
props: { props: {
lf: {
type: Object,
default: null
},
user: { user: {
type: Array, type: Array,
default: () => { default: () => {
@@ -152,6 +156,13 @@
} }
}, },
watch: { watch: {
node: {
handler: function (node) {
this.lf.updateText(node.id, node.label);
this.lf.setProperties(node.id, node);
},
deep: true
}
}, },
computed: { computed: {
isMobile() { isMobile() {
@@ -177,8 +188,8 @@
} }
}, },
methods: { methods: {
init(data, node) { init(node) {
this.node = node; this.node = node.properties;
}, },
getOptionList() { getOptionList() {
if (!this.node.assignType) { if (!this.node.assignType) {
-159
View File
@@ -1,159 +0,0 @@
<template id="flow-node">
<div class="node-item"
:class="{'node-item-active': current === node.id}"
ref="node"
:style="flowNodeContainer"
@mouseenter="showDelete"
@mouseleave="hideDelete"
@mouseup="changeNodeSite"
@click.stop="editNode">
<!-- <div class="node-titel">
<div class="node-icon" v-show="mouseEnter">
<i class="el-icon-delete" @@click.stop="deleteNode"></i>
</div>
</div> -->
<div class="node-con"><i :class="iconClass" class="type-icon"></i><span>{{node.label}}</span></div>
<div class="node-del" v-show="mouseEnter && !readonly" @click.stop="deleteNode">
×
</div>
<!--连线用--//触发连线的区域-->
<div class="flow-node-drag" v-show="isconnect"></div>
</div>
</template>
<script>
Vue.component("flow-node", {
template: '#flow-node',
vuetify: new Vuetify(),
name: 'flow-node',
props: {
node: Object,
isconnect: Boolean,
current: String,
readonly: Boolean
},
data() {
return {
mouseEnter: false
}
},
computed: {
isMobile() {
return window.innerWidth < 600;
},
// 节点容器样式
flowNodeContainer: {
get() {
return {
position: 'absolute',
minWidth: '80px',
top: this.node.top,
left: this.node.left,
boxShadow: this.mouseEnter ? '#66a6e0 0px 0px 12px 0px' : '',
}
}
},
iconClass() {
const type = this.node.type;
if (type == 'start') {
return 'el-icon-help';
} else if (type == 'end') {
return 'el-icon-s-help';
} else if (type == 'userTask') {
return 'el-icon-user';
} else if (type == 'receiveTask') {
return 'el-icon-s-tools';
}
}
},
created() {},
methods: {
// 删除节点
deleteNode() {
this.$emit('delete-node', this.node.id)
},
// 编辑节点
editNode() {
this.$emit('edit-node', this.node)
},
// 鼠标进入
showDelete() {
this.mouseEnter = true
},
// 鼠标离开
hideDelete() {
this.mouseEnter = false
},
// 鼠标移动后抬起
changeNodeSite() {
this.$emit('change-node-site', {
nodeId: this.node.id,
left: this.$refs.node.style.left,
top: this.$refs.node.style.top,
})
}
}
})
</script>
<style>
.node-item {
border-radius: 4px;
box-shadow: 0 0 2px #696969;
cursor: move;
overflow: initial;
background: #fbf4dc;
padding: 0 10px;
}
.node-titel {
height: 20px;
background: #ffc400;
}
.node-icon {
position: absolute;
top: 0px;
right: 0px;
line-height: 20px
}
.node-icon i {
cursor: pointer;
}
.node-con {
text-align: center;
line-height: 30px;
}
.node-del {
position: absolute;
color: white;
background-color: red;
width: 15px;
height: 15px;
border-radius: 100%;
text-align: center;
line-height: 15px;
font-size: 20px;
cursor: pointer;
top: -5px;
right: -5px;
}
.flow-node-drag {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: crosshair;
}
.node-item-active {
background-color: #4caf50;
color: white;
}
</style>
+311 -597
View File
@@ -1,47 +1,13 @@
<template id="process-flow"> <template id="process-flow">
<div class="process-flow-container"> <div class="process-flow-container">
<v-card v-if="!readonly" class="flow-menu pa-4 mr-4" width="140px"> <v-card v-if="!readonly" class="flow-menu pa-4 mr-4" width="140px">
<div class="menu-item mb-3" v-for="item in menuList" draggable="true" @dragstart="drag(item)"> <div class="menu-item mb-3" v-for="item in menuList" @mousedown.stop.prevent="startDrag(item)">
<i :class="item.icon"></i> <i :class="item.icon"></i>
<div>{{item.name}}</div> <div>{{item.name}}</div>
</div> </div>
<v-divider></v-divider>
<v-btn block class="menu-item mt-3" :color="isConnect ? 'success' : 'gray'" @click="isConnect=true">
<i class="el-icon-bottom-right"></i>
<div>连线</div>
</v-btn>
<v-btn block class="menu-item" :color="!isConnect ? 'success' : 'gray'" @click="isConnect=false">
<i class="el-icon-rank"></i>
<div>选择</div>
</v-btn>
</v-card> </v-card>
<v-card class="flow-detail pa-0"> <v-card class="flow-detail pa-0">
<div id="flowContent" ref="flowContent" @drop="drop($event)" @dragover="allowDrop($event)" @dblclick="isConnect=false"> <div id="flowContent" ref="flowContent"></div>
<div id="flow">
<div
v-show="auxiliaryLine.isShowXLine"
class="auxiliary-line-x"
:style="{
width: auxiliaryLinePos.width,
top: auxiliaryLinePos.y + 'px',
left: auxiliaryLinePos.offsetX + 'px'
}"
></div>
<div
v-show="auxiliaryLine.isShowYLine"
class="auxiliary-line-y"
:style="{
height: auxiliaryLinePos.height,
left: auxiliaryLinePos.x + 'px',
top: auxiliaryLinePos.offsetY + 'px'
}"
></div>
<flow-node v-for="node in data.nodeList" :current="currentNodeId" :key="node.id" :node="node" :id="node.id" :readonly="readonly" :isconnect="isConnect"
@delete-node="deleteNode" @change-node-site="changeNodeSite" @edit-node="editNode">
</flow-node>
</div>
</div>
</v-card> </v-card>
<v-card v-show="!readonly" class="flow-edit pa-4 ml-4"> <v-card v-show="!readonly" class="flow-edit pa-4 ml-4">
<template v-if="editType == 'node' || editType == 'line'"> <template v-if="editType == 'node' || editType == 'line'">
@@ -50,8 +16,8 @@
<span style="transform: translateY(2px); display: inline-block; ">{{editType == 'node' ? '节点' : '连线'}}属性</span> <span style="transform: translateY(2px); display: inline-block; ">{{editType == 'node' ? '节点' : '连线'}}属性</span>
</div> </div>
<div class="flow-edit-content"> <div class="flow-edit-content">
<edit-node ref="nodeForm" v-if="editType == 'node'" :user="user" :group="group" :tpl="tpl"></edit-node> <edit-node ref="nodeForm" v-if="editType == 'node'" :lf="lf" :user="user" :group="group" :tpl="tpl"></edit-node>
<edit-line ref="lineForm" v-if="editType == 'line'" @line-save="lineLabelSave"></edit-line> <edit-line ref="lineForm" v-if="editType == 'line'" :lf="lf"></edit-line>
</div> </div>
</template> </template>
<template v-else> <template v-else>
@@ -68,12 +34,14 @@
</div> </div>
</template> </template>
<link href="/<$ ctx.app.config.appId $>/public/jsplumb/jsplumbtoolkit-defaults.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/style/index.css" />
<script src="/<$ ctx.app.config.appId $>/public/jsplumb/jsplumb.min.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/style/index.css" />
<script src="/<$ ctx.app.config.appId $>/public/panzoom/panzoom.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@logicflow/core/dist/logic-flow.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/MiniMap.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/Menu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@logicflow/extension/lib/SelectionSelect.js"></script>
<script type="module"> <script type="module">
Vue.component("process-flow", { Vue.component("process-flow", {
template: '#process-flow', template: '#process-flow',
vuetify: new Vuetify(), vuetify: new Vuetify(),
@@ -116,486 +84,231 @@
}, },
}, },
data: () => { data: () => {
const connectorPaintStyle = {
lineWidth: 4,
strokeStyle: "#61B7CF",
joinstyle: "round",
outlineColor: "white",
outlineWidth: 2
};
// 鼠标悬浮在连接线上的样式
const connectorHoverStyle = {
lineWidth: 4,
strokeStyle: "#216477",
outlineWidth: 2,
outlineColor: "white"
};
return { return {
menuList: [{ menuList: [
type: 'start', { name: '起点', type: 'start', icon: 'el-icon-help' },
name: '起点', { name: '终点', type: 'end', icon: 'el-icon-s-help' },
icon: 'el-icon-help' { name: '审批节点', type: 'userTask', icon: 'el-icon-user' },
}, { name: '处理节点', type: 'receiveTask', icon: 'el-icon-s-tools' },
{
name: '终点',
type: 'end',
icon: 'el-icon-s-help'
},
{
name: '审批节点',
type: 'userTask',
icon: 'el-icon-user'
},
{
name: '处理节点',
type: 'receiveTask',
icon: 'el-icon-s-tools'
},
], ],
auxiliaryLine: { isShowXLine: false, isShowYLine: false }, //对齐辅助线是否显示 lf: null, // logicflow实例
auxiliaryLinePos: {
width: "100%",
height: "100%",
offsetX: 0,
offsetY: 0,
x: 20,
y: 20
},
jsPlumb: null, // jsPlumb 实例
index: 1,
// 默认设置参数
jsplumbSetting: {
// 动态锚点、位置自适应
Anchors: ['Top', 'TopCenter', 'TopRight', 'TopLeft', 'Right', 'RightMiddle', 'Bottom', 'BottomCenter',
'BottomRight', 'BottomLeft', 'Left', 'LeftMiddle'
],
Container: 'flow',
// 连线的样式 StateMachine、Flowchart,有四种默认类型:Bezier(贝塞尔曲线),Straight(直线),Flowchart(流程图),State machine(状态机)
Connector: 'Straight',
//这个是鼠标拉出来的线的属性
ConnectionOverlays: [
["Label", {
label: "同意-连线文本",
id: "label-1",
cssClass: "csslabel"
}]
],
// 鼠标不能拖动删除线
ConnectionsDetachable: false,
// 删除线的时候节点不删除
DeleteEndpointsOnDetach: false,
// 连线的端点
// Endpoint: ["Dot", {radius: 5}],
Endpoint: ["Rectangle", {
height: 10,
width: 10
}],
// 线端点的样式
EndpointStyle: {
fill: 'rgba(255,255,255,0)',
outlineWidth: 1
},
LogEnabled: true, //是否打开jsPlumb的内部日志记录
// 绘制线
PaintStyle: {
stroke: '#409eff',
strokeWidth: 2
},
// 绘制箭头
Overlays: [
['Arrow', {
width: 8,
length: 8,
location: 1
}],
],
RenderMode: "svg"
},
// jsplumb连接参数
jsplumbConnectOptions: {
isSource: true,
isTarget: true,
// 动态锚点、提供了4个方向 Continuous、AutoDefault
anchor: "Continuous",
},
jsplumbSourceOptions: {
filter: ".flow-node-drag", //触发连线的区域
/*"span"表示标签,".className"表示类,"#id"表示元素id*/
filterExclude: false,
anchor: "Continuous",
allowLoopback: false
},
jsplumbTargetOptions: {
filter: ".flow-node-drag",
/*"span"表示标签,".className"表示类,"#id"表示元素id*/
filterExclude: false,
anchor: "Continuous",
allowLoopback: false
},
// 是否加载完毕 // 是否加载完毕
loadEasyFlowFinish: false, loadEasyFlowFinish: false,
// 数据 // 数据
currentItem: '', //临时存添加的元素
isConnect: false, //判断是否连接
timer: null, //定时器,判断单双击,
currentConnect: '', //当前的连接线
currentLine: '', //当前连接线数据
editType: 'flow', //编辑的类型 editType: 'flow', //编辑的类型
connectorPaintStyle,
// 鼠标悬浮在连接线上的样式
connectorHoverStyle,
hollowCircle: {
endpoint: ["Dot", { radius: 8 }], //端点的形状
connectorStyle: connectorPaintStyle,//连接线的颜色,大小样式
connectorHoverStyle: connectorHoverStyle,
paintStyle: {
strokeStyle: "#1e8151",
fillStyle: "transparent",
radius: 2,
lineWidth: 2
}, //端点的颜色样式
//anchor: "AutoDefault",
isSource: true, //是否可以拖动(作为连线起点)
connector: ["Flowchart", { stub: [40, 60], gap: 10, cornerRadius: 5, alwaysRespectStubs: true }], //连接线的样式种类有[Bezier],[Flowchart],[StateMachine ],[Straight ]
isTarget: true, //是否可以放置(连线终点)
maxConnections: -1, // 设置连接点最多可以连接几条线
connectorOverlays: [["Arrow", { width: 10, length: 10, location: 1 }]]
},
lineTypeList: [ lineTypeList: [
{text: '同意', value: 'agree'}, {text: '同意', value: 'agree'},
{text: '拒绝', value: 'deny'}, {text: '拒绝', value: 'deny'},
] ]
}; };
}, },
watch: {
data: {
// 每个属性值发生变化就会调用这个函数
handler(newVal, oldVal) {
this.saveData(newVal)
},
// 深度监听 属性的变化
deep: true
}
},
created() { },
mounted() { mounted() {
this.jsPlumb = jsPlumb.getInstance(); this.init();
this.$nextTick(() => {
this.init();
});
}, },
methods: { methods: {
init() { init() {
const _this = this this.initLFInstance();
if (this.jsPlumb) { this.initLFCustomType();
_this.jsPlumb.setSuspendDrawing(false, true); this.initLFMenu();
} this.initLFEvent();
this.jsPlumb.ready(function () { this.initLFData();
// 导入默认配置 },
_this.jsPlumb.importDefaults(_this.jsplumbSetting)
// 会使整个jsPlumb立即重绘。
_this.jsPlumb.setSuspendDrawing(false, true);
// 初始化节点 /**
_this.loadEasyFlow() * 初始化logicFlow实例
*/
// 单点连接线(编辑label), initLFInstance() {
_this.jsPlumb.bind('click', function (conn, originalEvent) { this.lf = new LogicFlow({
if (_this.readonly) { container: document.querySelector('#flowContent'),
// 只读模式禁止切换 grid: true,
return style: {
rect: {
fill: "#fbf4dc",
stroke: "#cecece",
className: "node-item"
},
nodeText: {
},
polyline: {
stroke: '#409eff'
},
edgeText: {
background: {
fill: "white"
},
color: '#409eff'
} }
//clearTimeout(this.timer); },
//this.timer = setTimeout(function () { // 这里采用执行自定义事件的方式 textEdit: false,
// console.log("click", conn); // edgeTextDraggable: true,
// _this.editLine(conn); stopScrollGraph: true,
//}, 300); // 延迟300ms执行单击事件,区分双击事件 edgeType: 'polyline',
// console.log("click", conn); plugins: [MiniMap, Menu, SelectionSelect],
_this.editLine(conn); isSilentMode: this.readonly
// console.log(conn.getOverlay("label-1"));
//conn.getOverlay("label-1").setLabel('大肥肚'); //初始化label
})
// 双击连接线(删除),
_this.jsPlumb.bind('dblclick', function (conn, originalEvent) {
if (_this.readonly) {
// 只读模式禁止删除
return
}
clearTimeout(this.timer);
console.log("dblclick", conn)
_this.jsPlumb.deleteConnection(conn)
})
// 连线
_this.jsPlumb.bind("connection", function (evt) {
console.log('connection', evt)
let from = evt.source.id
let to = evt.target.id
if (_this.loadEasyFlowFinish) {
_this.data.lineList.push({
from: from,
to: to,
label: '连线名称',
type: 'agree',
id: _this.getUUID('line'),
Remark: '',
endpoint: 'Dot' // 线的类型
})
};
setTimeout(function () {
_this.editLine(evt.connection, true);
}, 100);
})
// 删除连线
_this.jsPlumb.bind("connectionDetached", function (evt) {
console.log('connectionDetached', evt)
_this.deleteLine(evt.sourceId, evt.targetId)
})
// 改变线的连接节点
_this.jsPlumb.bind("connectionMoved", function (evt) {
console.log('connectionMoved', evt)
_this.changeLine(evt.originalSourceId, evt.originalTargetId)
})
// 单击endpoint
// jsPlumb.bind("endpointClick", function (evt) {
// console.log('endpointClick', evt)
// })
//
// // 双击endpoint
// jsPlumb.bind("endpointDblClick", function (evt) {
// console.log('endpointDblClick', evt)
// })
// contextmenu 右键
_this.jsPlumb.bind("contextmenu", function (evt) {
console.log('contextmenu', evt)
})
// beforeDrop
_this.jsPlumb.bind("beforeDrop", function (evt) {
console.log('beforeDrop', evt)
let from = evt.sourceId
let to = evt.targetId
if (from === to) {
window.vtoast.fail('不能连接自己');
return false
}
if (_this.hasLine(from, to)) {
window.vtoast.fail({ message: '不能重复连线' });
return false
}
// if (_this.hashOppositeLine(from, to)) {
// window.vtoast.fail('不能回环哦');
// return false
// }
return true
})
// beforeDetach
_this.jsPlumb.bind("beforeDetach", function (evt) {
console.log('beforeDetach', evt)
})
})
this.initPanZoom();
},
// 加载流程图
loadEasyFlow() {
// 初始化节点
for (var i = 0; i < this.data.nodeList.length; i++) {
let node = this.data.nodeList[i]
// 设置源点,可以拖出线连接其他节点
this.jsPlumb.makeSource(node.id, this.jsplumbSourceOptions)
// // 设置目标点,其他源点拖出的线可以连接该节点
this.jsPlumb.makeTarget(node.id, this.jsplumbTargetOptions)
// 设置可拖拽
// jsPlumb.draggable(node.id, {
// containment: 'parent',
// grid: [10, 10]
// })
this.jsPlumb.draggable(node.id, {
containment: 'parent'
})
// jsPlumb.draggable(node.id)
}
// 初始化连线
for (var i = 0; i < this.data.lineList.length; i++) {
let line = this.data.lineList[i]
let connection = this.jsPlumb.connect({
source: line.from,
target: line.to,
endpoint: 'Dot' // 线的类型
}, this.jsplumbConnectOptions);
if (connection && connection.getOverlay("label-1")) {
connection.getOverlay("label-1").setLabel((line.operationByUser? `${line.operationByUser}-`: '') + line.type + '-' +line.label); //初始化label
}
}
this.$nextTick(function () {
this.loadEasyFlowFinish = true
})
},
// 添加新的节点
addNode(temp) {
console.log('添加节点', temp)
this.data.nodeList.push(temp);
this.$nextTick(function () {
this.jsPlumb.makeSource(temp.id, this.jsplumbSourceOptions)
this.jsPlumb.makeTarget(temp.id, this.jsplumbTargetOptions)
this.jsPlumb.draggable(temp.id, {
containment: 'parent'
})
})
},
// 删除线
deleteLine(from, to) {
this.data.lineList = this.data.lineList.filter(function (line) {
return line.from !== from && line.to !== to
})
},
// 改变连线
changeLine(oldFrom, oldTo) {
this.deleteLine(oldFrom, oldTo)
},
// 改变节点的位置
changeNodeSite(data) {
for (var i = 0; i < this.data.nodeList.length; i++) {
let node = this.data.nodeList[i]
if (node.id === data.nodeId) {
this.data.nodeList[i].left = data.left
this.data.nodeList[i].top = data.top
}
}
},
//删除节点
async deleteNode(nodeId) {
// this.data.nodeList = this.data.nodeList.filter(function(node) {
// if (node.id === nodeId) {
// node.show = false
// }
// return true
// })
this.data.nodeList.forEach((item, index) => {
if (item.id === nodeId) {
this.data.nodeList.splice(index, 1);
}
})
this.$nextTick(function () {
console.log('删除' + nodeId)
this.jsPlumb.removeAllEndpoints(nodeId);
})
return true
},
//编辑节点
editNode(node) {
if (this.readonly) {
// 只读模式、禁止切换节点
return
}
//console.log('编辑节点', nodeId)
this.editType = 'node';
this.currentNodeId = node.id
this.changeLineState("");
this.$nextTick(function () {
this.$refs.nodeForm.init(this.data, node)
})
},
editLine(conn, add = false) {
const _this = this;
this.currentNodeId = ''
_this.currentConnect = conn;
_this.data.lineList.forEach(function (item, index) {
if (item.from == conn.sourceId && item.to == conn.targetId) {
// 获取上一个节点
const preNode = _this.data.nodeList.find(e => e.id === item.from);
const lineTypeList = preNode.lineTypeList ? preNode.lineTypeList.split(',') : []
// 如果不是开始节点 并且类型不在允许的操作内
if (!lineTypeList.includes(item.type) ) {
// 1 - 删除画布连线 | 2 - 清空line的操作属性
// _this.jsPlumb.deleteConnection(conn)
// 默认修改类型为第一个
if (!preNode.id.includes('start-')) {
if (add) {
item.type = lineTypeList[0] || '';
} else {
item.type = '';
}
} else {
item.type = lineTypeList[0] || '';
}
// item.type = lineTypeList[0] || '';
}
_this.currentLine = item;
_this.editType = 'line';
_this.changeLineState("line", item);
_this.$nextTick(function () {
_this.$refs.lineForm.init(item, lineTypeList)
})
return;
}
}); });
}, },
//更改连线状态
changeLineState(nodeId, val) { /**
let lines = this.jsPlumb.getAllConnections(); * 注册自定义节点
if (!nodeId) { */
lines.forEach((line) => { initLFCustomType() {
line.canvas.classList.remove("active"); let _this = this
}); class CustomNodeView extends RectNode {}
return; class CustomNodeModel extends RectNodeModel {
} else if (nodeId === "line") { initNodeData(data) {
lines.forEach((line) => { super.initNodeData(data);
if (line.targetId === val.to && line.sourceId === val.from) { this.width = 100;
line.canvas.classList.add("active"); this.height = 40;
} else { this.radius = 5;
line.canvas.classList.remove("active"); }
getNodeStyle() {
const style = super.getNodeStyle();
const properties = this.properties;
if (_this.currentNodeId === this.id) {
style.fill = "#4caf50";
} }
}); return style;
}
getTextStyle() {
const style = super.getTextStyle();
const properties = this.properties;
if (_this.currentNodeId === this.id) {
style.color = "white";
}
return style;
}
} }
}, let CustomNode = {
//删除线 type: "CustomNode",
delLine(conn) { view: CustomNodeView,
this.jsPlumb.deleteConnection(conn) model: CustomNodeModel
},
// 是否具有该线
hasLine(from, to) {
return !!this.data.lineList.find(line => line.from === from && line.to === to)
},
// 是否含有相反的线
hashOppositeLine(from, to) {
return this.hasLine(to, from)
},
lineLabelSave(line) {
this.currentConnect.getOverlay("label-1").setLabel(line.type + '-' +line.label);
//this.$set(this.currentLine, 'label', line.label);
},
drag(item) {
this.currentItem = item;
},
drop(event) {
//event.preventDefault();
var _obj = this.$refs.flowContent;
var temp = {
id: this.getUUID(this.currentItem.type),
label: this.currentItem.name,
top: event.offsetY + 'px',
left: event.offsetX + 'px',
type: this.currentItem.type,
assignType: 'person',
assignValue: ['<$ ctx.userInfo.userId $>'],
lineTypeList: this.currentItem.type === 'start' ? '同意' : this.currentItem.type === 'end' ? '' : '同意,拒绝',
} }
this.addNode(temp); this.lf.register(CustomNode);
this.editNode(temp);
}, },
allowDrop(event) {
event.preventDefault() /**
* 初始化LogicFlow菜单
*/
initLFMenu() {
let lf = this.lf;
if(this.readonly) {
lf.extension.menu.setMenuConfig({
nodeMenu: false,
edgeMenu: false
})
return
}
lf.extension.menu.setMenuConfig({
nodeMenu: [
{
text: '删除节点',
callback(node) {
lf.deleteNode(node.id);
}
}
],
edgeMenu: [
{
text: '删除连线',
callback(edge) {
lf.deleteEdge(edge.id);
}
}
]
});
}, },
/**
* 绑定logicFlow事件
*/
initLFEvent() {
if(this.readonly) {
return
}
let lf = this.lf;
// 添加节点
lf.on('node:add', (e) => {
const { data } = e;
this.data.nodeList.push(data);
this.addNode(data);
this.editNode(data);
});
// 选中节点
lf.on("node:click", (e) => {
const { data } = e;
this.editNode(data);
});
// 添加边
lf.on("edge:add", (e) => {
const { data } = e;
const { id, sourceNodeId, targetNodeId, properties } = data;
let line = {
from: sourceNodeId,
to: targetNodeId,
label: '连线文本',
type: '同意',
id: this.getUUID('line'),
Remark: '',
endpoint: 'Dot' // 线的类型
}
this.data.lineList.push(line);
lf.updateText(id, line.label);
lf.setProperties(id, line);
this.editLine(lf.getEdgeDataById(id));
lf.changeEdgeId(id, line.id);
});
// 选中边
lf.on("edge:click", (e) => {
const { data } = e;
if (this.readonly) {
// 只读模式禁止切换
return
}
this.editLine(data);
});
// 双击节点
lf.on("node:dbclick", (e) => {
const { id } = e.data;
lf.deleteNode(id);
});
// 双击边
lf.on("edge:dbclick", (e) => {
const { id } = e.data;
lf.deleteEdge(id);
});
// // 历史变化
// lf.on("history:change", (e) => {
// console.log("history:change", e);
// });
// // 进入边
// lf.on("edge:mouseenter", (e) => {
// const { id } = e.data;
// lf.openEdgeAnimation(id)
// });
// // 离开边
// lf.on("edge:mouseleave", (e) => {
// const { id } = e.data;
// lf.closeEdgeAnimation(id)
// });
},
/**
* 初始化LogicFlow数据
*/
initLFData() {
// this.lf.render({ "nodes":[], "edges":[] })
// this.lf.render({"nodes":[{"id":"3","type":"CustomNode","x":380,"y":140,"properties":{},"text":{"x":380,"y":140,"value":"开始"}},{"id":"1","type":"CustomNode","x":380,"y":280,"properties":{},"text":{"x":380,"y":280,"value":"经理"}},{"id":"2","type":"CustomNode","x":380,"y":420,"properties":{},"text":{"x":380,"y":420,"value":"结束"}}],"edges":[{"id":"a2ed12a0-7548-4725-a8e6-290d565d66da","type":"polyline","sourceNodeId":"3","targetNodeId":"1","startPoint":{"x":380,"y":160},"endPoint":{"x":380,"y":260},"properties":{},"text":{"x":380,"y":190,"value":"开始"},"pointsList":[{"x":380,"y":160},{"x":380,"y":260}]},{"id":"135f3e3a-d8c5-4329-83d6-833512175ea4","type":"polyline","sourceNodeId":"2","targetNodeId":"1","startPoint":{"x":330,"y":420},"endPoint":{"x":330,"y":280},"properties":{},"text":{"x":265,"y":350,"value":"经理审核拒绝"},"pointsList":[{"x":330,"y":420},{"x":265,"y":420},{"x":265,"y":280},{"x":330,"y":280}]},{"id":"c4dbefa6-1ce0-4cef-babe-444329affea7","type":"polyline","sourceNodeId":"1","targetNodeId":"2","startPoint":{"x":430,"y":280},"endPoint":{"x":430,"y":420},"properties":{},"text":{"x":495,"y":350,"value":"经理审核通过"},"pointsList":[{"x":430,"y":280},{"x":495,"y":280},{"x":495,"y":420},{"x":430,"y":420}]},{"id":"6fb6a3b1-a8fc-4d22-b9f0-5692208118d5","type":"polyline","sourceNodeId":"1","targetNodeId":"2","startPoint":{"x":348,"y":300},"endPoint":{"x":348,"y":400},"properties":{},"text":{"x":348,"y":350,"value":"同意-连线文本"},"pointsList":[{"x":348,"y":300},{"x":348,"y":400}]}]})
// this.lf.render({"nodes":[{"id":"start-c31f75a55c48","type":"CustomNode","x":100,"y":80,"properties":{"id":"start-c31f75a55c48","label":"起点","type":"start","assignType":"person","assignValue":["admin"],"lineTypeList":"同意"},"text":{"x":100,"y":80,"value":"起点"}},{"id":"end-72e945407d48","type":"CustomNode","x":540,"y":80,"properties":{"id":"end-72e945407d48","label":"终点","type":"end","assignType":"person","assignValue":["admin"],"lineTypeList":""},"text":{"x":540,"y":80,"value":"终点"}},{"id":"userTask-fa96d9f1f548","type":"CustomNode","x":320,"y":80,"properties":{"id":"userTask-fa96d9f1f548","label":"审批节点","type":"userTask","assignType":"person","assignValue":["admin"],"lineTypeList":"同意,拒绝"},"text":{"x":320,"y":80,"value":"审批节点"}}],"edges":[{"id":"line-8c746156fb48","type":"polyline","sourceNodeId":"start-c31f75a55c48","targetNodeId":"userTask-fa96d9f1f548","startPoint":{"x":150,"y":80},"endPoint":{"x":270,"y":80},"properties":{"from":"start-c31f75a55c48","to":"userTask-fa96d9f1f548","label":"同意-连线文本3","type":"同意","id":"line-8c746156fb48","Remark":"","endpoint":"Dot"},"text":{"x":210,"y":80,"value":"同意-连线文本3"},"pointsList":[{"x":150,"y":80},{"x":270,"y":80}]},{"id":"line-088a246e9248","type":"polyline","sourceNodeId":"userTask-fa96d9f1f548","targetNodeId":"end-72e945407d48","startPoint":{"x":370,"y":80},"endPoint":{"x":490,"y":80},"properties":{"from":"userTask-fa96d9f1f548","to":"end-72e945407d48","label":"同意-连线文本","type":"同意","id":"line-088a246e9248","Remark":"","endpoint":"Dot"},"text":{"x":430,"y":80,"value":"同意-连线文本"},"pointsList":[{"x":370,"y":80},{"x":490,"y":80}]}]});
this.lf.render(this.parseBusinessDataToLfData(this.data));
},
/**
* 获取UUID
* @returns {string}
*/
getUUID(prefix) { getUUID(prefix) {
var s = []; var s = [];
var hexDigits = "0123456789abcdef"; var hexDigits = "0123456789abcdef";
@@ -607,66 +320,103 @@
var uuid = s.join(""); var uuid = s.join("");
return prefix + '-' + uuid; return prefix + '-' + uuid;
}, },
saveData() {
//console.log(this.jsPlumb)
//console.log(this.jsPlumb.Defaults)
//console.log('线', this.jsPlumb.getConnections())
console.log(this.data);
this.$emit('change-structure', this.data)
},
initPanZoom() {
const mainContainer = this.jsPlumb.getContainer();
const mainContainerWrap = mainContainer.parentNode;
const pan = panzoom(mainContainer, {
smoothScroll: false,
bounds: true,
// autocenter: true,
zoomDoubleClickSpeed: 1,
minZoom: 0.5,
maxZoom: 2,
//设置滚动缩放的组合键,默认不需要组合键
beforeWheel: (e) => {
// console.log(e);
// let shouldIgnore = !e.ctrlKey
// return shouldIgnore
},
beforeMouseDown: function (e) {
// allow mouse-down panning only if altKey is down. Otherwise - ignore
var shouldIgnore = e.ctrlKey;
return shouldIgnore;
}
});
this.jsPlumb.mainContainerWrap = mainContainerWrap;
this.jsPlumb.pan = pan;
// 缩放时设置jsPlumb的缩放比率
pan.on("zoom", (e) => {
const { x, y, scale } = e.getTransform();
this.jsPlumb.setZoom(scale);
//根据缩放比例,缩放对齐辅助线长度和位置
this.auxiliaryLinePos.width = (1 / scale) * 100 + "%";
this.auxiliaryLinePos.height = (1 / scale) * 100 + "%";
this.auxiliaryLinePos.offsetX = -(x / scale);
this.auxiliaryLinePos.offsetY = -(y / scale);
});
pan.on("panend", (e) => {
const { x, y, scale } = e.getTransform();
this.auxiliaryLinePos.width = (1 / scale) * 100 + "%";
this.auxiliaryLinePos.height = (1 / scale) * 100 + "%";
this.auxiliaryLinePos.offsetX = -(x / scale);
this.auxiliaryLinePos.offsetY = -(y / scale);
});
// 平移时设置鼠标样式 /**
mainContainerWrap.style.cursor = "grab"; * 拖拽生成节点
mainContainerWrap.addEventListener("mousedown", function wrapMousedown() { * @param 拖拽项
this.style.cursor = "grabbing"; */
mainContainerWrap.addEventListener("mouseout", function wrapMouseout() { startDrag(item) {
this.style.cursor = "grab"; let id = this.getUUID(item.type);
}); let node = {
}); type: 'CustomNode',
mainContainerWrap.addEventListener("mouseup", function wrapMouseup() { id,
this.style.cursor = "grab"; text: item.name,
}); properties: {
id,
label: item.name,
type: item.type,
assignType: 'person',
assignValue: ['<$ ctx.userInfo.userId $>'],
lineTypeList: item.type === 'start' ? '同意' : item.type === 'end' ? '' : '同意,拒绝',
}
}
this.lf.dnd.startDrag(node);
},
/**
* 添加新的节点
* @param node
*/
addNode(node) {
this.data.nodeList.push(node);
},
/**
* 编辑节点
* @param node
*/
editNode(node) {
if (this.readonly) {
return
}
this.editType = 'node';
// this.currentNodeId = node.id;
this.$nextTick(function () {
this.$refs.nodeForm.init(node);
})
},
/**
* 编辑连线
* @param line
*/
editLine(line) {
if (this.readonly) {
return
}
const { id, properties } = line;
let fromNodeData = this.lf.getNodeDataById(line.sourceNodeId).properties;
const lineTypeList = fromNodeData.lineTypeList? fromNodeData.lineTypeList.split(','): [];
this.editType = 'line';
this.currentLineId = line.id;
this.$nextTick(function () {
this.$refs.lineForm.init(line, lineTypeList);
})
},
/**
* 获取流程图数据(组件外使用)
* @returns {{nodeList: Array, lineList: Array}}
*/
getData() {
return this.parseLFDataToBusinessData();
},
/**
* 将流程设计器数据转换为业务数据
*/
parseLFDataToBusinessData() {
const lfData = this.lf.getGraphData();
return {
nodeList: lfData.nodes.map(node => ({
...node.properties,
origin: node
})),
lineList: lfData.edges.map(line => ({
...line.properties,
origin: line
}))
}
},
/**
* 将业务数据转换为流程设计器数据
*/
parseBusinessDataToLfData() {
return {
nodes: this.data.nodeList.map(node => node.origin).filter(node => node != null),
edges: this.data.lineList.map(line => line.origin).filter(line => line != null)
}
} }
} }
}) })
@@ -676,8 +426,13 @@
.process-flow-container { .process-flow-container {
display: flex; display: flex;
width: 100%; width: 100%;
height: calc(100vh - 260px); /* height: calc(100vh - 260px); */
height: 500px;
color: #606266; color: #606266;
margin-bottom: 20px;
}
.lf-element-text {
cursor: move;
} }
.flow-detail { .flow-detail {
@@ -699,21 +454,6 @@
overflow: hidden; overflow: hidden;
cursor: grab; cursor: grab;
} }
#flowContent #flow {
position: relative;
width: 100%;
height: 100%;
}
#flowContent #flow .auxiliary-line-x {
position: absolute;
border: 0.5px dashed #2ab1e8;
z-index: 9999;
}
#flowContent #flow .auxiliary-line-y {
position: absolute;
border: 0.5px dashed #2ab1e8;
z-index: 9999;
}
.item { .item {
position: absolute; position: absolute;
@@ -768,30 +508,4 @@
border-radius: 4px; border-radius: 4px;
} }
.csslabel {
color: #434343;
font-weight: 400;
z-index: 10;
font-size: 12px;
color: #409eff;
background: #fff;
}
.csslabel .label-text {
background-color: white;
}
.jtk-connector.active {
z-index: 9999;
}
.jtk-connector.active path {
stroke: #150042;
stroke-width: 1.5;
animation: ring;
animation-duration: 3s;
animation-timing-function: linear;
animation-iteration-count: infinite;
stroke-dasharray: 5;
}
</style> </style>
+2 -2
View File
@@ -143,7 +143,6 @@
{% block vue_body %} {% block vue_body %}
{% include 'component/flow/processFlow.html' %} {% include 'component/flow/processFlow.html' %}
{% include 'component/flow/flowNode.html' %}
{% include 'component/flow/editFlow.html' %} {% include 'component/flow/editFlow.html' %}
{% include 'component/flow/editLine.html' %} {% include 'component/flow/editLine.html' %}
{% include 'component/flow/editNode.html' %} {% include 'component/flow/editNode.html' %}
@@ -238,7 +237,8 @@ new Vue({
this.nextLineList = _.uniqBy(nextLineList, 'type') ; this.nextLineList = _.uniqBy(nextLineList, 'type') ;
// 更新操作人到连线 // 更新操作人到连线
taskHistoryConfigList.lineList.map(line => { taskHistoryConfigList.lineList.map(line => {
line.operationByUser = (taskHistoryList.find(taskHistory => taskHistory.taskConfigId == line.from && taskHistory.taskLineTo == line.to) || {}).operationByUser; let operationByUser = (taskHistoryList.find(taskHistory => taskHistory.taskConfigId == line.from && taskHistory.taskLineTo == line.to) || {}).operationByUser;
line.origin.text.value = `${operationByUser}-${line.label}`;
}); });
this.taskHistoryConfigList = taskHistoryConfigList; this.taskHistoryConfigList = taskHistoryConfigList;
this.isTableLoading = false; this.isTableLoading = false;
+3 -3
View File
@@ -35,7 +35,7 @@
</tpl-form-design> </tpl-form-design>
<div class="pt-8 pb-4" style="font-size: 18px; font-weight: bold">流程设置</div> <div class="pt-8 pb-4" style="font-size: 18px; font-weight: bold">流程设置</div>
<process-flow v-if="!loading" :data="editItem.workflowConfig" :user="constantCollection.userList" <process-flow v-if="!loading" ref="processFlow" :data="editItem.workflowConfig" :user="constantCollection.userList"
:group="constantCollection.groupList" :tpl="constantCollection.workflowFormList"> :group="constantCollection.groupList" :tpl="constantCollection.workflowFormList">
</process-flow> </process-flow>
@@ -55,7 +55,6 @@
{% include 'component/flow/editFlow.html' %} {% include 'component/flow/editFlow.html' %}
{% include 'component/flow/editLine.html' %} {% include 'component/flow/editLine.html' %}
{% include 'component/flow/editNode.html' %} {% include 'component/flow/editNode.html' %}
{% include 'component/flow/flowNode.html' %}
{% include 'component/tpl/tplFormDesign.html' %} {% include 'component/tpl/tplFormDesign.html' %}
{% include 'component/tpl/formItemListGenerator.html' %} {% include 'component/tpl/formItemListGenerator.html' %}
{% include 'component/tpl/formItemListRender.html' %} {% include 'component/tpl/formItemListRender.html' %}
@@ -124,7 +123,8 @@ new Vue({
}, },
buildEditItem() { buildEditItem() {
const { id, workflowId, workflowName, workflowRemark, workflowCategory, workflowConfig, workflowForm } = this.editItem; const { id, workflowId, workflowName, workflowRemark, workflowCategory, workflowForm } = this.editItem;
const workflowConfig = this.$refs.processFlow.getData();
let item = { let item = {
workflowName, workflowName,
workflowRemark, workflowRemark,