870 lines
29 KiB
HTML
870 lines
29 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 mb-1 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)">
|
|
<v-card-text class="pa-4">
|
|
<span>{{nodeItem.properties.label}}</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}" >
|
|
<!-- <div>{{constantObj.displayModes[displayModeIndex].text}}</div> -->
|
|
<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>
|
|
|
|
</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组件 -->
|
|
|
|
<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
|
|
},
|
|
},
|
|
data: () => {
|
|
return {
|
|
constantObj: {
|
|
displayModes: [
|
|
{
|
|
text: '简易模式',
|
|
value: 'simple'
|
|
},
|
|
{
|
|
text: '复杂模式',
|
|
value: 'complex'
|
|
},
|
|
],
|
|
nodeColor: {
|
|
'start':'#88939F',
|
|
'userTask':'#FCAD22',
|
|
'approvalTask':'#FCAD22',
|
|
'noticeTask':'#3CB4B2',
|
|
'conditionTask':'#88939F',
|
|
'approvalTask':'#88939F',
|
|
}
|
|
},
|
|
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,
|
|
};
|
|
},
|
|
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;
|
|
default:
|
|
console.error("[doUiAction] uiActionId not find", {uiActionId});
|
|
break;
|
|
}
|
|
},
|
|
|
|
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 = initLinebySimple(prevNode, node)
|
|
var nextLine = 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 - 130,
|
|
"y": prevNode.y + 40,
|
|
"value": type == 'approvalTask' ? '审批节点' : '抄送节点',
|
|
}
|
|
}
|
|
return node
|
|
}
|
|
|
|
function initLinebySimple(prevNode, nextNode){
|
|
if(!prevNode || !nextNode) throw new Error("[initNodebySimple] 无前置或后置节点!");
|
|
var Id = _this.getUUID(type)
|
|
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
|
|
}
|
|
},
|
|
|
|
// 切换展示模式
|
|
changeDisplayMode(displayMode){
|
|
var changeAble = true
|
|
var changeText = ""
|
|
var lineList = this.workflowConfig.lineList
|
|
var nodeList = this.workflowConfig.nodeList
|
|
|
|
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);
|
|
}
|
|
}
|
|
],
|
|
edgeMenu: [
|
|
{
|
|
text: '删除连线',
|
|
callback(edge) {
|
|
logicFlow.deleteEdge(edge.id);
|
|
this.getBusinessData()
|
|
}
|
|
}
|
|
]
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 绑定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);
|
|
});
|
|
// 双击节点 TODO:删除后更新数据
|
|
logicFlow.on("node:dbclick", (e) => {
|
|
const {id} = e.data;
|
|
logicFlow.deleteNode(id);
|
|
|
|
});
|
|
|
|
// 双击边 TODO:删除后更新数据
|
|
logicFlow.on("edge:dbclick", (e) => {
|
|
const {id} = e.data;
|
|
logicFlow.deleteEdge(id);
|
|
});
|
|
// // 历史变化
|
|
// 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)
|
|
// nodeList: logicFlowData.nodes.map(node => ({
|
|
// ...node.properties,
|
|
// origin: node
|
|
// })),
|
|
// lineList: logicFlowData.edges.map(line => ({
|
|
// ...line.properties,
|
|
// origin: 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.map(node => node).filter(node => node != null),
|
|
edges: this.workflowConfig.lineList.map(line => line).filter(line => line != 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;
|
|
}
|
|
/* .v-list-item:hover{
|
|
background-color: red;
|
|
|
|
} */
|
|
</style>
|