MappingPanel.vue
6.18 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
<template>
<div class="mapping-panel__container">
<div class="mapping-tool__bar">
<el-button type="text" icon="el-icon-refresh-left" @click="reset"
>重置</el-button
>
<el-divider direction="vertical"></el-divider>
<el-button type="text" icon="el-icon-delete" @click="clear"
>清空</el-button
>
<el-divider direction="vertical"></el-divider>
<el-button
:disabled="!currentConnect"
type="text"
icon="el-icon-close"
@click="handleDeleteKeyUp"
>删除</el-button
>
<el-divider
v-if="triggerType == 'multiDiffData'"
direction="vertical"
></el-divider>
<el-button
v-if="triggerType == 'multiDiffData'"
:disabled="!currentNode || !currentColumn"
type="text"
icon="el-icon-user-solid"
v-tooltip.after="{
content:
'在子流程业务对象中选中一个字段,将所选字段作为子流程发起人字段(注意:只能选择用户账号字段)。'
}"
@click="setCreatorFollowData"
>设置为发起人</el-button
>
</div>
<div
id="flowWrap"
ref="flowWrap"
class="flowWrap"
@keyup.delete="handleDeleteKeyUp"
>
<div id="flow" v-if="json !== null">
<mapping-node-item
v-for="item in json.nodes"
:key="item.id"
:id="item.id"
:node="item"
:current-node="currentNode"
:current-column="currentColumn"
:creator-follow-column="creatorFollowData[item.id]"
@column-click="handleColumnClick"
/>
</div>
</div>
</div>
</template>
<script>
import {jsPlumb} from 'jsplumb'
import jsPlumbSetting from './jsplumbConfig.js'
import core from './coreMethods.js'
import MappingNodeItem from './MappingNodeItem.vue'
import {tbType} from './tbType.js'
export default {
name: 'MappingPanel',
components: {
MappingNodeItem
},
props: {
triggerType: {
type: String,
required: true
},
creatorFollowDataKey: String
},
data() {
return {
jsPlumb: null,
json: null,
jsPlumbSetting: jsPlumbSetting,
commonGrid: [5, 5], //节点移动最小距离
minus: '-', //表名和列名的分割符号
currentConnect: null, //当前选中的连线
creatorFollowData: {}, //用作发起人的字段(以node中id为key,所选列为value)
currentNode: null, //当前选中列所在node
currentColumn: null //当前选中列
}
},
mounted() {
this.jsPlumb = jsPlumb.getInstance()
},
watch: {
currentConnect: function(newVal, oldVal) {
if (newVal !== oldVal) {
if (newVal && newVal.target) {
newVal.setPaintStyle({
stroke: tbType['RS'].color
})
}
if (oldVal && oldVal.target) {
oldVal.setPaintStyle({
stroke: tbType['Union'].color
})
}
}
}
},
methods: {
...core,
handleDeleteKeyUp() {
if (this.currentConnect) {
this.jsPlumb.deleteConnection(this.currentConnect)
}
},
renderWithJson(json) {
if (json) {
this.json = json
if (!this.json.edges) {
this.$set(this.json, 'edges', [])
}
this.parseCreatorFollowDataKey(this.json.nodes)
this.fixNodesPosition()
this.$nextTick(() => this.init())
}
},
// 从发起人字段中解析为 creatorFollowData 对象
parseCreatorFollowDataKey(nodes) {
if (this.triggerType == 'multiDiffData' && this.creatorFollowDataKey) {
const keyAry = this.creatorFollowDataKey.split('.')
if (!keyAry || keyAry.length != 2) {
this.$message.warn('子流程发起人字段格式错误,需要重新设置.')
return
}
const [nodeName, columnName] = keyAry
const node = nodes.find(n => n.name == nodeName)
if (node && node.columns && node.columns.length > 0) {
const column = node.columns.find(c => c.name == columnName)
if (column) {
this.$set(this.creatorFollowData, node.id, column)
}
}
}
},
// 将 creatorFollowData 对象构建为
buildCreatorFollowDataKey() {
let result = null
if (this.triggerType == 'multiDiffData' && this.creatorFollowData) {
const keys = Object.keys(this.creatorFollowData)
if (keys && keys.length > 0) {
const key = keys[0]
const node = this.json.nodes.find(n => n.id == key)
const column = this.creatorFollowData[key]
result = `${node.name}.${column.name}`
}
}
return result
},
reset() {
this.clear()
this.renderWithJson(this.json)
},
clear() {
this.jsPlumb.deleteEveryConnection()
},
setCreatorFollowData() {
if (this.currentNode && this.currentColumn) {
this.$set(
this.creatorFollowData,
this.currentNode.id,
this.currentColumn
)
}
},
handleColumnClick(node, column) {
if (this.currentNode == node && this.currentColumn == column) {
this.$set(this, 'currentNode', null)
this.$set(this, 'currentColumn', null)
} else {
this.$set(this, 'currentNode', node)
this.$set(this, 'currentColumn', column)
}
}
}
}
</script>
<style lang="scss" scoped>
.mapping-panel__container {
.mapping-tool__bar {
background-color: #f8f8f8;
border-radius: 5px;
height: 40px;
margin-bottom: 10px;
padding: 0 20px;
display: flex;
align-items: center;
::v-deep {
svg.el-tooltip.fa-icon {
vertical-align: -3px;
}
}
}
.flowWrap {
border: 1px solid #ccc;
height: 500px;
position: relative;
overflow: hidden;
outline: none !important;
flex-grow: 1;
background-image: url('../../assets/img/point.png');
#flow {
position: relative;
width: 100%;
height: 100%;
}
}
}
</style>
<style lang="scss">
.jtk-connector.jtk-hover {
z-index: 10001;
path {
cursor: pointer !important;
}
}
.jtk-endpoint.endpoint-rect {
z-index: 10000;
cursor: crosshair;
svg {
visibility: hidden;
}
}
</style>