MappingDialog.vue
7.89 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<template>
<div>
<el-button @click="beginMappingSetting" size="small"
>{{ recovery ? '回收映射' : '分发映射' }}配置</el-button
>
<el-dialog
:title="recovery ? '回收映射' : '分发映射'"
width="800px"
append-to-body
class="mapping-dialog"
destroy-on-close
:visible.sync="dialogVisible"
:before-close="handleClose"
>
<mapping-panel
ref="mappingPanel"
:trigger-type="triggerType"
:creator-follow-data-key="creatorFollowDataKey"
/>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="handleClose">取 消</el-button>
<el-button type="primary" size="small" @click="handleDialogSure">
确 定
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import req from '@/request.js'
import MappingPanel from './MappingPanel.vue'
const Base64 = require('js-base64').Base64
export default {
name: 'MappingDialog',
components: {MappingPanel},
props: {
value: {
type: String
},
// 是否是回收映射
recovery: {
type: Boolean,
default: false
},
defId: {
type: String,
required: true
},
nodeId: {
type: String,
required: true
},
triggerType: {
type: String,
required: true
},
creatorFollowDataKey: String
},
data() {
return {
dialogVisible: false,
varTree: null,
subflowVarTree: null
}
},
watch: {
dialogVisible: function(newVal, oldVal) {
if (newVal !== oldVal && newVal) {
this.loadVarTree()
this.loadSubFlowVarTree()
}
}
},
methods: {
loadVarTree() {
this.varTree = null
this.getVarTreeWithDefId(this.defId)
.then(data => {
this.varTree = data
this.extractNodesFromVarTree()
})
.catch(err => {
this.$message.error(
'未获取到主流程绑定的业务模型,无法进行属性映射配置。'
)
throw err
})
},
loadSubFlowVarTree() {
this.subflowVarTree = null
// 通过当前节点获取绑定的子流程defId
req
.get(
`${window.context.bpmModel}/flow/def/v1/subFlowDetail?defId=${this.defId}&nodeId=${this.nodeId}`
)
.then(response => {
const {data} = response
return data.defId
})
.then(subflowDefId => {
// 通过子流程defId获取表单业务对象
return this.getVarTreeWithDefId(subflowDefId)
})
.then(data => {
this.subflowVarTree = data
this.extractNodesFromVarTree()
})
.catch(err => {
this.$message.error(
'未获取到子流程绑定的业务模型,无法进行属性映射配置。'
)
throw err
})
},
// 通过defId获取varTree
getVarTreeWithDefId(defId) {
return new Promise((resolve, reject) => {
req
.post(`${window.context.bpmModel}/flow/node/v1/varTree`, {
defId,
includeBpmConstants: false,
removeSub: false,
bpmForm: true
})
.then(resp => {
let result = null
const {data} = resp
if (data && data.length > 0) {
data.forEach(d => {
if (d.id === '0') {
result = d
}
})
}
if (result) {
resolve(result)
} else {
reject()
}
})
})
},
extractNodesFromVarTree() {
if (this.varTree && this.subflowVarTree) {
let originNodes = []
// 构建来源节点数组(回收映射时以子流程业务对象为来源)
this.buildNode(
originNodes,
this.varTree.children,
this.recovery ? 'RS' : 'Origin',
'main'
)
originNodes = this.filterNodesByTriggerType(
originNodes,
this.recovery ? 'RS' : 'Origin'
)
// 根据每个节点中列的数量计算top值
this.calcTopValueOfNodes(originNodes)
let rsNodes = []
// 构建目标节点数组(回收映射时以主流程业务对象为目标)
this.buildNode(
rsNodes,
this.subflowVarTree.children,
this.recovery ? 'Origin' : 'RS',
'sub'
)
rsNodes = this.filterNodesByTriggerType(
rsNodes,
this.recovery ? 'Origin' : 'RS'
)
// 根据每个节点中列的数量计算top值
this.calcTopValueOfNodes(rsNodes)
const nodes = originNodes.concat(rsNodes)
let edges = null
try {
if (this.value) {
edges = JSON.parse(Base64.decode(this.value))
}
} catch (err) {}
this.$refs.mappingPanel.renderWithJson({nodes, edges})
}
},
// 根据子流程触发类型进行过滤
// 触发类型为:多人发起不同数据/一人发起不同数据,主流程只显示子表实体,子流程只显示主表实体
filterNodesByTriggerType(nodes, type) {
if (!this.recovery && this.triggerType != 'multiSameData') {
const filterType = type == 'RS' ? 'main' : 'sub'
return nodes.filter(n => n.nodeType == filterType)
}
return nodes
},
// 同一种类型的节点 之间设置不同的top,避免图形叠合在一起
calcTopValueOfNodes(nodes) {
nodes.forEach((n, index) => {
const colCount = this.getColumnCountByType(
nodes.slice(index + 1, nodes.length)
)
n.top = 35 * (colCount + 1)
})
},
// 获取节点数组中columns的数量
getColumnCountByType(nodes) {
return nodes.reduce((pre, n) => {
return (pre += n.columns.length)
}, 0)
},
// 构建节点
buildNode(nodes, list, type, flowType) {
list.forEach(obj => {
const {name, comment, children, nodeType} = obj
const node = {
id: `${type}_${name}`,
name,
comment,
type,
nodeType,
flowType,
top: 20,
left: type == 'RS' ? 310 : 10
}
if (children && children.length > 0) {
node.columns = this.buildColumn(
nodes,
children,
type,
nodeType,
flowType
)
}
nodes.push(node)
})
return nodes
},
// 构建节点中的列
buildColumn(nodes, children, type, parentNodeType, flowType) {
const columns = []
children.forEach(obj => {
const {name, comment, nodeType} = obj
if (nodeType == 'field') {
const colum = {
name,
comment
}
columns.push(colum)
} else if (parentNodeType == 'main' && nodeType == 'sub') {
this.buildNode(nodes, [obj], type, flowType)
}
})
return columns
},
beginMappingSetting() {
this.dialogVisible = true
},
handleDialogSure() {
const edgeData = this.$refs.mappingPanel.getEdgeData()
let mappingData = null
if (edgeData && edgeData.length > 0) {
mappingData = JSON.stringify(edgeData)
mappingData = Base64.encode(mappingData)
}
const creatorFollowDataKeyResult = this.$refs.mappingPanel.buildCreatorFollowDataKey()
if (creatorFollowDataKeyResult) {
this.$emit('update:creatorFollowDataKey', creatorFollowDataKeyResult)
}
this.$emit('input', mappingData)
this.dialogVisible = false
},
handleClose() {
this.dialogVisible = false
}
}
}
</script>
<style lang="scss" scoped>
.mapping-dialog {
::v-deep {
.el-dialog__header {
padding: 10px;
border-bottom: 1px solid #ededed;
button {
top: 14px;
}
}
.el-dialog__body {
padding: 10px 20px;
}
}
}
</style>