BpmnEdit.vue
4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div v-if="show">
<vue-bpmn @save="btnSave" :defKey="defKey" :modelData="modelData" :processStatus="processStatus" :operateType="operateType"
:key="new Date().getTime()" />
</div>
</template>
<script>
import { Message } from 'element-ui'
import VueBpmn from '@/components/VueBpmn'
export default {
name: 'FlowableModelEdit',
components: {VueBpmn},
props: {
defId: String,
defKey: String,
operateType:String,
processStatus: String,
designPattern: String,
flowData: Object
},
data() {
return {
id: '',
modelData: {
id: '',
defId: '',
bpmnXml: '',
defKey: '',
key: '',
name: '',
typeId: '',
typeName: '',
desc: '',
designer: 'BPMNJS',
designPattern: 'normal',
},
show: false,
designPattern: this.designPattern,
}
},
created() {
this.getModelData()
},
methods: {
getModelData() {
if (this.defId) {
this.$http
.get('${bpmModel}/flow/def/v1/webDefDesign?defId=' + this.defId)
.then(({data}) => {
this.modelData = data
this.modelData.id = data.defId
this.modelData.defId = data.defId
this.modelData.designer = 'BPMNJS'
this.modelData.bpmnXml = this.replace2BpmnDefinitions(data.bpmnXml)
this.modelData.key = data.defKey
this.modelData.category = data.typeId
this.modelData.designPattern = data.designPattern || 'normal'
this.show = true
})
} else {
if (this.flowData) {
this.modelData.typeId = this.flowData.categoryId
this.modelData.typeName = this.flowData.categoryName
this.modelData.name = this.flowData.name
this.modelData.desc = this.flowData.desc
this.modelData.defKey = this.flowData.alias
this.modelData.key = this.flowData.alias
}
this.show = true
}
},
replace2BpmnDefinitions(xml) {
var reg = new RegExp(/ext:definitions/, 'g')
xml = xml.replace(reg, 'bpmn:definitions')
return xml
},
btnSave(params,cb) {
const xmlStr = params.defaultBpmDefinition.bpmnXml
const myregexp = /\s{1}id="(.*?)"\s{1}/g
let result = [],
match = null
// 通过正则提取流程xml中的id
while ((match = myregexp.exec(xmlStr))) {
if (match[1]) {
result.push(match[1])
}
}
result = result.sort()
const errorIdAry = []
for (var i = 0; i < result.length; i++) {
// 判断id是否重复
if (result[i] == result[i + 1]) {
errorIdAry.push(result[i])
}
}
if (errorIdAry.length > 0) {
this.$message({
message: `以下节点ID:【${errorIdAry.join(
','
)}】重复(流程key和节点ID也不能重复),无法发布该流程。`,
type: 'error',
})
return
}
//保存时,删除defaultBpmDefinition中的多余的key属性
if(params.defaultBpmDefinition.hasOwnProperty('key')){
this.$delete(params.defaultBpmDefinition,'key')
}
let dataParam = _.cloneDeep(params)
delete dataParam.defaultBpmDefinition.modelId
this.$http
.post('${bpmModel}/flow/def/v1/webDefSave', dataParam)
.then((msg, data) => {
if (msg.data.state) {
Message.success(params.isdeploy ? '发布成功' : '保存成功')
cb()
this.modelData.defId = msg.data.value
setTimeout(() => {
this.receiveMsg(params.isdeploy)
}, 2000)
}
})
},
receiveMsg(param) {
let type = ''
if (['true',true].includes(param)) {
type = 'flowDesignPublishSuccess'
}
if (['false',false].includes(param)) {
type = 'flowDesignSaveSuccess'
}
switch (type) {
case 'flowDesignFullscreen':
this.toggle()
break
case 'flowDesignPublishSuccess':
this.$emit('def-deploy-success', this.modelData.defId)
break
case 'flowDesignSaveSuccess':
this.$emit('switch-config-refresh')
break
}
},
toggle() {
if (!screenfull.isEnabled) {
this.$message({
message: '不支持全屏',
type: 'warning',
})
return false
}
screenfull.toggle(this.$el)
this.fullscreen = !this.fullscreen
},
}
}
</script>