Files
workflow/app/view/component/flow/processFlow.html
T
2024-05-08 17:22:01 +08:00

1090 lines
38 KiB
HTML

<template id="process-flow">
<v-card class="process-flow-container">
<template v-if="displayMode == 'simple'">
<!-- 简单左侧 >>>>>>>>>>>>> -->
<div style="width: 100%;">
<v-card class="d-flex py-2 overflow-y-auto " height="700" outlined>
<div class="d-flex flex-column flex-fill align-center">
<template v-for="(nodeItem, nodeIndex) in workflowConfig.nodeList" :key="index">
<v-card elevation="2" width="240" @click="editNode(nodeItem)">
<!-- :style="`backgroundColor: ${constantObj.nodeColorClass[nodeItem.properties.type]}`;" -->
<v-card-title class="pa-2 " :class="constantObj.nodeColorClass[nodeItem.properties.type]">
<div class="text-truncate" style="width: 80%; font-size: medium;">{{nodeItem.properties.label}}</div>
<v-spacer></v-spacer>
<v-icon color="grey" v-if="!['start','end'].includes(nodeItem.properties.type)" @click.stop="doUiAction('deleteNodeBySimple', nodeItem)">mdi-close</v-icon>
</v-card-title>
<v-card-text class="pa-4" v-if="!['start','end'].includes(nodeItem.properties.type) ">
<span>{{ nodeItem.properties.approverType || nodeItem.properties.noticerType }}</span>
</v-card-text>
</v-card>
<template v-if="!nodeItem.id.startsWith('end-')">
<div class="d-flex justify-center" style="position: relative;width: 240px;">
<div class="mr-2">
<div class="divider-vertical"></div>
<div class="arrow"></div>
</div>
<v-menu
:value="menuShown(event, nodeIndex)"
:data-menu-Index="nodeIndex"
:close-on-content-click="false"
offset-x
>
<template v-slot:activator="{ on, attrs }">
<div class="add-btn-box" v-bind="attrs" v-on="on" :data-menu-Index="nodeIndex" @click="showMenuShown"></div>
</template>
<v-list class="d-flex">
<v-list-item :data-from="nodeItem.id" :data-to="workflowConfig.nodeList[nodeIndex + 1].id" @click="addNodeBySimple({type: 'approvalTask', prevIndex: nodeIndex})">
<div class="d-flex flex-column align-center add-node-box">
<v-icon class="mb-1" color="#FCAD22">mdi-stamper</v-icon>
<span>审批节点</span>
</div>
</v-list-item>
<v-list-item :data-from="nodeItem.id" :data-to="workflowConfig.nodeList[nodeIndex + 1].id" @click="addNodeBySimple({type: 'noticeTask', prevIndex: nodeIndex})">
<div class="d-flex flex-column align-center add-node-box">
<v-icon class="mb-1" color="#3CB4B2">mdi-send</v-icon>
<span>抄送节点</span>
</div>
</v-list-item>
</v-list>
</v-menu>
</div>
</template>
</template>
</div>
</v-card>
</div>
<!-- <<<<<<<<<<<<< 简单左侧 -->
</template>
<template v-if="displayMode == 'complex'">
<!-- 复杂左侧 >>>>>>>>>>>>> -->
<div style="width: 100%;">
<!-- <<<<<<<<<<<<< 左上 节点选择列表 -->
<v-card v-if="!readonly" class="d-flex mb-1" outlined>
<div class="menu-item ma-1" v-for="item in menuList" @mousedown.stop.prevent="startDrag(item)">
<v-icon small class="mr-1">{{ item.icon }}</v-icon>
<span>{{item.name}}</span>
</div>
</v-card>
<!-- <<<<<<<<<<<<< 左上 节点选择列表 -->
<!-- 左下 主内容编辑区 >>>>>>>>>>>>> -->
<v-card class="flow-detail pa-2" outlined>
<div id="flowContent" ref="flowContent"></div>
</v-card>
<!-- <<<<<<<<<<<<< 左下 主内容编辑区 -->
</div>
<!-- <<<<<<<<<<<<< 复杂左侧 -->
</template>
<template>
<!-- 复杂右侧 >>>>>>>>>>>>> -->
<div :style="{'width': isMobile ? 'auto' : '350px'}">
<!-- 右上 模式切换区 >>>>>>>>>>>>> -->
<v-card class="mb-1 d-flex align-center" :class="{'ml-2': !isMobile}" >
<v-btn v-for="(displayMode, index) in constantObj.displayModes" v-if="index != displayModeIndex" class="ml-1 my-2" style="flex: 1;" color="primary"
small outlined @click="doUiAction('changeDisplayMode', displayMode.value)">
<span>切换展示模式</span>
</v-btn>
</v-card>
<!-- <<<<<<<<<<<<< 右上 模式切换区 -->
<!-- 右下 属性编辑区 >>>>>>>>>>>>> -->
<v-card v-show="!readonly" class="pa-2" :class="{'ml-2': !isMobile}" style="height: 100%;" outlined>
<div class="font-weight-medium text-subtitle-2 text-subtitle-2 mb-3">
<v-icon size="18" class="mr-1">mdi-application-cog-outline</v-icon>
<span style="transform: translateY(2px); display: inline-block;">{{editType == 'node' ? '节点属性' : editType == 'line' ? '连线属性' : '属性面板'}}</span>
</div>
<div v-if="editType == 'node' || editType == 'line'" class="flow-edit-content">
<edit-node ref="nodeForm" v-if="editType == 'node'" :lf="logicFlow" :user="user" :group="group" :label="label" :workflow-form="workflowForm" :workflow-config="workflowConfig"
:display-mode="displayMode" @reflesh-workflow="setBusinessData"></edit-node>
<edit-line ref="lineForm" v-if="editType == 'line'" :lf="logicFlow" @reflesh-workflow="setBusinessData"></edit-line>
</div>
<div v-else class="text-center mt-8">
请选择节点或连接线~
</div>
</v-card>
<!-- <<<<<<<<<<<<< 右下 属性编辑区 -->
</div>
<!-- <<<<<<<<<<<<< 复杂右侧 -->
</template>
<template>
<v-snackbar v-model="isSnackerShown" top timeout="5000">
<span>{{disPassValidateText}}</span>
<template v-slot:action="{ attrs }">
<v-btn
color="red"
text
v-bind="attrs"
@click="isSnackerShown = false"
>
关闭
</v-btn>
</template>
</v-snackbar>
</template>
</v-card>
</template>
<!-- 加载logicflow组件 >>>>>>>>>>>>> -->
<link rel="stylesheet" href="/<$ ctx.app.config.appId $>/public/logicflow/core/dist/style/index.css" />
<link rel="stylesheet" href="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/style/index.css" />
<script src="/<$ ctx.app.config.appId $>/public/logicflow/core/dist/logic-flow.js"></script>
<script src="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/MiniMap.js"></script>
<script src="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/Menu.js"></script>
<script src="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/SelectionSelect.js"></script>
<script src="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/Control.js"></script>
<script src="/<$ ctx.app.config.appId $>/public/logicflow/extension/lib/Popup.js"></script>
<!-- <<<<<<<<<<<<< 加载logicflow组件 -->
{% include 'component/flow/editLine.html' %}
{% include 'component/flow/editNode.html' %}
<script type="module">
Vue.component("process-flow", {
template: '#process-flow',
vuetify: new Vuetify(),
name: 'process-flow',
props: {
workflowConfig: {
type: Object,
default: () => {
return {
nodeList: [],
lineList: []
}
}
},
user: {
type: Array,
default: () => {
return []
}
},
group: {
type: Array,
default: () => {
return []
}
},
label: {
type: Array,
default: () => {
return []
}
},
workflowForm: {
type: Array,
default: () => {
return []
}
},
currentNodeId: {
type: String,
default: ''
},
readonly: {
type: Boolean,
default: false
},
isDrawerShown: {
type: Boolean,
default: false
},
},
data: () => {
return {
constantObj: {
displayModes: [
{
text: '简易模式',
value: 'simple'
},
{
text: '复杂模式',
value: 'complex'
},
],
nodeColorClass: {
'start':'start-background',
'approvalTask':'approvalTask-background',
'noticeTask':'noticeTask-background',
'conditionTask':'conditionTask-background',
'end':'end-background',
},
},
menuList: [
{name: '起点', type: 'start', icon: 'mdi-ray-start'},
{name: '终点', type: 'end', icon: 'mdi-ray-end'},
{name: '审批节点', type: 'approvalTask', icon: 'mdi-account-check-outline'},
{name: '抄送节点', type: 'noticeTask', icon: 'mdi-account-check-outline'},
{name: '条件节点', type: 'conditionTask', icon: 'mdi-account-check-outline'},
],
logicFlow: null, // logicflow实例
// 是否加载完毕
loadEasyFlowFinish: false,
// 数据
editType: 'flow', //编辑的类型
displayModeIndex: 1, // 'complex'、'simple'
displayMode: 'complex', // 'complex'、'simple'
isAddNodeMenuShown: false,
activeMenuIndex: -1,
isSnackerShown: false,
disPassValidateText:"",
isPassValidate: true
};
},
watch: {
workflowConfig: {
handler: async function (val) {
// 初始化起点和终点
if(!val.nodeList.length && !val.lineList.length){
let startId = this.getUUID('start')
let endId = this.getUUID('end')
let lineId = this.getUUID('line')
this.workflowConfig = {
"nodeList":[
{"id":startId,"type":"CustomNode","x":400,"y":160,"properties":{"id":startId,"label":"起点","type":"start"},"text":{"x":400,"y":160,"value":"起点"}},
{"id":endId,"type":"CustomNode","x":400,"y":320,"properties":{"id":endId,"label":"终点","type":"end"},"text":{"x":400,"y":320,"value":"终点"}}
],
"lineList":[
{"id":lineId,"type":"polyline","sourceNodeId":startId,"targetNodeId":endId,
"startPoint":{"x":400,"y":180},"endPoint":{"x":400,"y":300},
"properties":{"from":startId,"to":endId,"label":"连线文本","type":"同意","id":lineId,"Remark":"","endpoint":"Dot"},
"text":{"x":400,"y":225,"value":"同意-连线文本"},"pointsList":[{"x":400,"y":180},{"x":400,"y":300}]}
]
}
}
},
deep: true
},
},
computed: {
isMobile() {
return window.innerWidth < 600;
},
},
created(){
},
mounted() {
},
methods: {
async doUiAction(uiActionId, uiActionData) {
switch (uiActionId) {
case 'complexModeInit':
await this.initLogicFlowInstance();
await this.initLogicFlowCustomType();
await this.initLogicFlowControl();
await this.initLogicFlowMenu();
await this.initLogicFlowEvent();
await this.initLogicFlowData();
break;
case 'changeDisplayMode':
await this.changeDisplayMode(uiActionData);
break;
case 'deleteNodeBySimple':
await this.deleteNodeBySimple(uiActionData);
break;
case 'dataValidate':
await this.dataValidate();
break;
case 'closeEditNode':
await this.closeEditNode();
break;
default:
console.error("[doUiAction] uiActionId not find", {uiActionId});
break;
}
},
setDisplayMode(index){
this.displayModeIndex = index
this.displayMode = this.constantObj.displayModes[index].value
},
showMenuShown(event){
this.activeMenuIndex = event?.target.dataset.menuIndex
},
menuShown(index){
return event?.target.dataset.itemIndex == this.activeMenuIndex || false
},
async addNodeBySimple({type, prevIndex = -1}){
if(prevIndex == -1) throw new Error("[addNodeBySimple] 出错!");
// 加一个节点和两条线
var _this = this
var prevNode = _this.workflowConfig.nodeList[prevIndex]
var nextNode = _this.workflowConfig.nodeList[prevIndex + 1]
var node = await initNodebySimple(type, prevNode)
var prevLine = this.initLinebySimple(prevNode, node)
var nextLine = this.initLinebySimple(node, nextNode)
_this.workflowConfig.nodeList.splice(prevIndex + 1, 0 ,node)
_this.workflowConfig.lineList.push(prevLine, nextLine)
// 去掉原有的连线
_this.workflowConfig.lineList = _this.workflowConfig.lineList.filter(line => !(line.sourceNodeId == prevNode.id && line.targetNodeId == nextNode.id))
this.$emit('reflesh-workflow-config', this.workflowConfig)
// 两种模式统一数据,待优化
this.initLogicFlowData()
function initNodebySimple(type = 'approvalTask', prevNode){
if(!prevNode) throw new Error("[initNodebySimple] 无前置节点!");
var Id = _this.getUUID(type)
var node = {
"id": Id,
"type": "CustomNode",
"x": prevNode.x - 150,
"y": prevNode.y + 40,
"properties": {
"id": Id,
"label": type == 'approvalTask' ? '审批节点' : '抄送节点',
"type": type
},
"text": {
"x": prevNode.x - 150,
"y": prevNode.y + 40,
"value": type == 'approvalTask' ? '审批节点' : '抄送节点',
}
}
return node
}
},
initLinebySimple(prevNode, nextNode){
if(!prevNode || !nextNode) throw new Error("[initNodebySimple] 无前置或后置节点!");
var Id = this.getUUID('line')
var line = {
"id": Id,
"type": "polyline",
"sourceNodeId": prevNode.id,
"targetNodeId": nextNode.id,
"startPoint": {
"x": prevNode.x + 10,
"y": prevNode.y + 20,
},
"endPoint": {
"x": nextNode.x + 10,
"y": nextNode.y - 20,
},
"properties": {
"from": prevNode.id,
"to": nextNode.id,
"label": "连线文本",
"type": "同意",
"id": Id,
"endpoint": "Dot",
},
"text": {
"x": (prevNode.x + nextNode.x) / 2,
"y": (prevNode.y + nextNode.y) / 2,
"value": "同意-连线文本"
}
}
return line
},
async deleteNodeBySimple(node){
if(!node) throw new Error("[deleteNodeBySimple] node不存在!");
var _this = this
var nodeId = node.id
var preLine = _this.workflowConfig.lineList.find(line => line.targetNodeId == nodeId)
var nextLine = _this.workflowConfig.lineList.find(line => line.sourceNodeId == nodeId)
var preNode = _this.workflowConfig.nodeList.find(node => node.id == preLine.sourceNodeId)
var nextNode = _this.workflowConfig.nodeList.find(node => node.id == nextLine.targetNodeId)
// 创建节点连线
var newLine = _this.initLinebySimple(preNode, nextNode)
// 删除与该节点相连的线
_this.workflowConfig.lineList = _this.workflowConfig.lineList.filter(line => line.sourceNodeId != nodeId && line.targetNodeId != nodeId)
// 删除该节点
_this.workflowConfig.nodeList = _this.workflowConfig.nodeList.filter(node => node.id != nodeId)
// 插入新连线
_this.workflowConfig.lineList.push(newLine)
await this.$emit('reflesh-workflow-config', _this.workflowConfig)
// 两种模式统一数据,待优化
this.initLogicFlowData()
},
// 切换展示模式
changeDisplayMode(displayMode){
var changeAble = true,
changeText = "";
const {lineList, nodeList} = this.workflowConfig;
if(displayMode == 'simple'){
// 检查是否有多个开始节点或结束节点
if(nodeList.filter(n=>n.properties.type == 'start').length != 1 || nodeList.filter(n=>n.properties.type == 'end').length != 1){
changeAble = false
changeText = "只允许存在1个开始节点或结束节点"
}
// 检查是否有条件节点
if(changeAble && nodeList.filter(n=>n.properties.type == 'conditionTask').length){
changeAble = false
changeText = "存在条件节点"
}
// 检查是否有多线程:有两条线的sourceNodeId/targetNodeId一样
var hasSerial = _.some(lineList, (item, index) => {
return _.some(lineList.slice(0, index), prevItem => {
return prevItem.sourceNodeId === item.sourceNodeId || prevItem.targetNodeId === item.targetNodeId
})
})
if(changeAble && hasSerial){
changeAble = false
changeText = "存在多线程"
}
// 检查是否存在节点未连接
if(changeAble && lineList.length != nodeList.length - 1){
changeAble = false
changeText = "存在节点未连接"
}
}
if(changeAble){
this.displayMode = displayMode
this.displayModeIndex = this.constantObj.displayModes.findIndex(m=>m.value == displayMode)
this.editType = null
if(this.displayMode == 'complex'){
this.$nextTick(()=>{
this.doUiAction('complexModeInit')
})
}
}else{
window.vtoast.fail("当前结构不能切换到简易模式:" + changeText + "!");
}
},
/**
* 初始化logicFlow实例
*/
initLogicFlowInstance() {
this.logicFlow = new LogicFlow({
container: document.querySelector('#flowContent'),
grid: true,
style: {
rect: {
fill: "#fbf4dc",
stroke: "#cecece",
className: "node-item"
},
nodeText: {},
polyline: {
stroke: '#409eff'
},
edgeText: {
background: {
fill: "white"
},
color: '#409eff'
}
},
textEdit: false,
// edgeTextDraggable: true,
stopScrollGraph: true,
edgeType: 'polyline',
plugins: [MiniMap, Menu, SelectionSelect, Control, Popup],
isSilentMode: this.readonly,
width: 1100,
height: 700
});
},
/**
* 注册自定义节点
*/
initLogicFlowCustomType() {
let _this = this
class CustomNodeView extends RectNode {
}
class CustomNodeModel extends RectNodeModel {
initNodeData(data) {
super.initNodeData(data);
this.width = 100;
this.height = 40;
this.radius = 5;
}
getNodeStyle() {
const style = super.getNodeStyle();
const properties = this.properties;
if (_this.currentNodeId === this.id) {
style.fill = "#4caf50";
} else {
const rawNode = _this.workflowConfig.nodeList.find(o => o.id === this.id)
if (rawNode && rawNode.inPath) {
style.fill = "#d4ffd6";
}
}
return style;
}
getTextStyle() {
const style = super.getTextStyle();
if (_this.currentNodeId === this.id) {
style.color = "white";
}
return style;
}
}
let CustomNode = {
type: "CustomNode",
view: CustomNodeView,
model: CustomNodeModel
}
this.logicFlow.register(CustomNode);
},
/**
* 初始化LogicFlow控制台
*/
initLogicFlowControl() {
// 删除上一步
this.logicFlow.extension.control.removeItem('undo');
// 删除下一步
this.logicFlow.extension.control.removeItem('redo');
},
/**
* 初始化LogicFlow菜单
*/
initLogicFlowMenu() {
let logicFlow = this.logicFlow;
if (this.readonly) {
logicFlow.extension.menu.setMenuConfig({
nodeMenu: false,
edgeMenu: false
})
return
}
// logicFlow.extension.menu.setMenuConfig({
// nodeMenu: [
// {
// text: '删除节点',
// callback(node) {
// logicFlow.deleteNode(node.id);
// this.setBusinessData()
// }
// }
// ],
// edgeMenu: [
// {
// text: '删除连线',
// callback(edge) {
// logicFlow.deleteEdge(edge.id);
// this.setBusinessData()
// }
// }
// ]
// });
},
/**
* 绑定logicFlow事件
*/
initLogicFlowEvent() {
if (this.readonly) {
return
}
let logicFlow = this.logicFlow;
// 添加节点
logicFlow.on('node:add', (e) => {
const {data} = e;
this.workflowConfig.nodeList.push(data);
this.addNode(data);
this.editNode(data);
});
// 选中节点
logicFlow.on("node:click", (e) => {
const {data} = e;
this.editNode(data);
});
// 添加边
logicFlow.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.workflowConfig.lineList.push(line);
logicFlow.updateText(id, line.label);
logicFlow.setProperties(id, line);
this.editLine(logicFlow.getEdgeDataById(id));
logicFlow.changeEdgeId(id, line.id);
});
// 选中边
logicFlow.on("edge:click", (e) => {
const {data} = e;
if (this.readonly) {
// 只读模式禁止切换
return
}
this.editLine(data);
});
// 双击节点
logicFlow.on("node:dbclick", (e) => {
const {id} = e.data;
logicFlow.deleteNode(id);
this.setBusinessData()
});
// 双击边
logicFlow.on("edge:dbclick", (e) => {
const {id} = e.data;
logicFlow.deleteEdge(id);
this.setBusinessData()
});
// // 历史变化
// logicFlow.on("history:change", (e) => {
// console.log("history:change", e);
// });
// // 进入边
// logicFlow.on("edge:mouseenter", (e) => {
// const { id } = e.data;
// logicFlow.openEdgeAnimation(id)
// });
// // 离开边
// logicFlow.on("edge:mouseleave", (e) => {
// const { id } = e.data;
// logicFlow.closeEdgeAnimation(id)
// });
},
/**
* 初始化LogicFlow数据
*/
initLogicFlowData() {
// this.logicFlow.render({ "nodes":[], "edges":[] })
// this.logicFlow.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.logicFlow.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.logicFlow.render(this.parseBusinessDataTologicFlowData(this.workflowConfig));
},
/**
* 获取UUID
* @returns {string}
*/
getUUID(prefix) {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 10; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
var uuid = s.join("");
return prefix + '-' + uuid;
},
/**
* 拖拽生成节点
* @param 拖拽项
*/
startDrag(funObj) {
let id = this.getUUID(funObj.type);
let node = {
type: 'CustomNode',
id,
text: funObj.name,
properties: {
id,
label: funObj.name,
type: funObj.type,
}
}
this.logicFlow.dnd.startDrag(node);
},
/**
* 添加新的节点
* @param node
*/
addNode(node) {
this.workflowConfig.nodeList.push(node);
},
/**
* 编辑节点
* @param node
*/
editNode(node) {
if (this.readonly) {
return
}
this.editType = 'node';
// this.currentNodeId = node.id;
this.$nextTick(function () {
this.$refs.nodeForm.doUiAction('init', node);
})
},
/**
* 编辑连线
* @param line
*/
editLine(line) {
if (this.readonly) {
return
}
let fromNodeData = this.logicFlow.getNodeDataById(line.sourceNodeId).properties;
this.editType = 'line';
// this.currentLineId = line.id;
this.$nextTick(function () {
this.$refs.lineForm.init(line);
})
},
/**
* 获取流程图业务数据(组件外使用)
* @returns {{nodeList: Array, lineList: Array}}
*/
getBusinessData() {
return this.parseLogicFlowDataToBusinessData();
},
/**
* 设置流程图业务数据(组件外使用)
*/
setBusinessData(){
this.workflowConfig = this.parseLogicFlowDataToBusinessData();
},
/**
* 将流程设计器数据转换为业务数据
*/
parseLogicFlowDataToBusinessData() {
const logicFlowData = this.getOrderedGraphData();
return {
nodeList: logicFlowData.nodes.map(node => node),
lineList: logicFlowData.edges.map(line => line)
}
},
/**
* 获取排序后的GraphData
* @param nodeList
*/
getOrderedGraphData() {
const graphData = this.logicFlow.getGraphData();
const orderedNodes = graphData.edges.reduce((nodeList, edge) => {
const sourceNode = graphData.nodes.find(node => node.id === edge.sourceNodeId);
const targetNode = graphData.nodes.find(node => node.id === edge.targetNodeId);
if (sourceNode && targetNode) {
const sourceIndex = nodeList.findIndex(node => node.id === sourceNode.id);
const targetIndex = nodeList.findIndex(node => node.id === targetNode.id);
if (sourceIndex > targetIndex) {
nodeList.splice(targetIndex, 0, sourceNode);
nodeList.splice(sourceIndex + 1, 1);
}
}
return nodeList;
}, graphData.nodes);
return {
nodes: orderedNodes,
edges: graphData.edges
}
},
/**
* 将业务数据转换为流程设计器数据
*/
parseBusinessDataTologicFlowData() {
return {
nodes: this.workflowConfig.nodeList.filter(node => node != null),
edges: this.workflowConfig.lineList.filter(line => line != null)
}
},
/**
* 检验数据
*/
async dataValidate(){
this.disPassValidateText = ""
this.isPassValidate = true
const { lineList, nodeList } = this.workflowConfig;
// 不允许多个开始节点或结束节点
if(nodeList.filter(n=>n.properties.type == 'start').length != 1 || nodeList.filter(n=>n.properties.type == 'end').length != 1){
this.isPassValidate = false
this.disPassValidateText += "只允许存在1个开始节点或结束节点!\n"
}
// 不允许孤立节点 => 除了开始节点和结束节点外,每个节点都有入线和出线
var lineBySourceNodeId = _.groupBy(lineList, 'sourceNodeId'),
lineByTargetNodeId = _.groupBy(lineList, 'targetNodeId'),
mergeTemp = _.mergeWith(_.cloneDeep(lineBySourceNodeId), lineByTargetNodeId, (objValue, srcValue)=>{
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
});
if(Object.keys(mergeTemp).length < nodeList.length){
this.isPassValidate = false
this.disPassValidateText += '不允许存在孤立节点!\n'
}else{
// 判断开始节点是否只含有出线sourceNodeId
if(_.some(Object.keys(lineByTargetNodeId), (i) => i.startsWith('start-'))){
this.isPassValidate = false
this.disPassValidateText += "连线终点不能为开始节点!"
}
// 结束节点是否是含有入线targetNodeId
if(_.some(Object.keys(lineBySourceNodeId), (i) => i.startsWith('end-'))){
this.isPassValidate = false
this.disPassValidateText += "连线起点不能为结束节点!"
}
// 其他的节点必须至少有一个入线和出线
for (const key in mergeTemp) {
if (Object.hasOwnProperty.call(mergeTemp, key)) {
if(!(key.startsWith('start-') || key.startsWith('end-'))){
const element = mergeTemp[key];
if(!_.some(element, i => i.sourceNodeId == key) || !_.some(element, i => i.targetNodeId == key)){
this.isPassValidate = false
this.disPassValidateText += "不允许存在除了开始和结束节点以外的节点没有入线或出线!"
break
}
}
}
}
}
// 不允许条件节点和审批/通知节点存在同一层级 以及 不允许无条件层级,多个审批/抄送节点同时存在
for (const key in lineBySourceNodeId) {
if (Object.hasOwnProperty.call(lineBySourceNodeId, key)) {
const element = lineBySourceNodeId[key];
// 拿到同一层的节点
var node = element.map(l => nodeList.find(n => n.id === l.targetNodeId))
if(_.some(node, i => i.properties.type == "conditionTask")){
if(_.some(node, i => i.properties.type != "conditionTask")){
this.isPassValidate = false
this.disPassValidateText += "不允许条件节点和审批/通知节点存在同一层级!"
}
}else{
if(node.length > 1){
this.isPassValidate = false
this.disPassValidateText += "不允许同一层级多个审批/抄送节点同时存在!"
}
}
}
}
// 不允许有条件节点的优先级没有默认优先级节点, 允许存在多个默认节点,读取顺序按放置时间的先后顺序
var conditionNodeLineBySourceNodeId = _.groupBy(lineList.filter(i => i.targetNodeId.startsWith('conditionTask-')), 'sourceNodeId');
for (const key in conditionNodeLineBySourceNodeId) {
if (Object.hasOwnProperty.call(conditionNodeLineBySourceNodeId, key)) {
const element = conditionNodeLineBySourceNodeId[key];
// 拿到同一层的条件节点
var conditionNode = element.map(l => nodeList.find(n => n.id === l.targetNodeId))
if(!_.some(conditionNode, i => i.properties.priority == -1)){
this.isPassValidate = false
this.disPassValidateText += "不允许存在某层条件节点没有默认条件优先级!"
}
}
}
// 检查条件节点是否选了条件 检查审核/抄送节点是否选了类型
for (var index = 0; index < nodeList.length; index++) {
const element = nodeList[index];
if(['conditionTask'].includes(element.properties.type)){
if(!element.properties.priority){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有设置优先级!`
}else{
if(element.properties.priority != -1 && element.properties.conditionList.length <= 0){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有设置条件组!`
}
}
}else if(['approvalTask'].includes(element.properties.type)){
if(!element.properties.approvalType || !element.properties.approverType){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有完善信息!`
}else if(element.properties.approverType != '申请人自选'){
if(!(element.properties.user && element.properties.user?.length > 0)){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有完善信息!`
}
}
}else if(['noticeTask'].includes(element.properties.type)){
if(!element.properties.noticerType){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有完善信息!`
}else if(element.properties.noticerType != '申请人自选'){
if(!(element.properties.user && element.properties.user?.length > 0)){
this.isPassValidate = false
this.disPassValidateText += `${element.properties.label}节点没有完善信息!`
}
}
}
}
if(!this.isPassValidate){
// await window.vtoast.fail(this.disPassValidateText);
this.isSnackerShown = true
throw new Error(this.disPassValidateText)
}
},
closeEditNode(){
this.editType = null
}
}
})
</script>
<style>
.process-flow-container {
display: flex;
width: 100%;
/* height: calc(100vh - 260px); */
height: 700px;
margin-bottom: 10px;
}
.lf-element-text {
cursor: move;
}
.flow-detail {
flex: 1;
word-break: break-all;
position: relative;
}
#flowContent {
/* width: 100%; */
height: 650px;
position: relative;
background-image: url("/<$ ctx.app.config.appId $>/public/images/point.png");
background-repeat: repeat;
overflow: hidden;
cursor: grab;
}
.menu-item {
padding: 8px 10px;
background: #f5f8fa;
font-size: 12px;
cursor: move;
border: 1px dashed #f5f8fa;
border-radius: 3px;
white-space: nowrap;
}
.menu-item:hover {
border: 1px dashed #4caf50;
background: #f5f8fa;
color: #4caf50;
}
.menu-item:hover .v-icon {
color: #4caf50;
}
.flow-edit-content {
max-height: 95%;
overflow-y: auto;
}
.lf-control-item i {
width: 10px;
height: 10px;
}
.divider-vertical{
display: flex;
justify-content: center;
}
.divider-vertical::before{
content: '';
display: block;
width: 2px;
height: 60px;
background: #dbdbdb;
}
.arrow{
width: 0px;
height: 6px;
border: 6px solid;
border-color: #dbdbdb transparent transparent transparent;
justify-self: center;
}
.add-btn-box{
position: absolute;
width: 22px;
height: 22px;
background-color: #A0B5C8;
border-radius: 50%;
align-self: center;
margin-bottom: 10px;
margin-right: 7px;
}
.add-btn-box::before{
content: '';
position: absolute;
display: inline-block;
width: 2px;
height: 15px;
left: 10px;
top: 4px;
background-color: #fff;
}
.add-btn-box::after{
content: '';
position: absolute;
display: inline-block;
height: 2px;
width: 14px;
top: 10px;
left: 4px;
background-color: #fff;
}
.add-node-box{
width: 60px;
height: 40px;
}
.start-background,
.end-background{
background-color: #EEF4FB;
color: #88939F;
}
.noticeTask-background{
background-color: #E6F8F8;
color: #3CB4B2;
}
.approvalTask-background{
background-color: #FFF9EE;
color: #FCAD22;
}
.conditionTask-background{
background-color: #E0F2FD;
color:#3EA9F0;
}
.omit{
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;
}
</style>