FlowForm.vue
17.2 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<template>
<div
class="flow-form"
:style="{
'--outHeight': `${outHeight}px`,
}"
>
<!-- //为el-tooltip隐藏后能正常二次点击 -->
<van-field
style="
z-index: -999;
width: 0;
height: 0;
line-height: 0;
position: absolute;
"
@focus.prevent="afocus"
ref="adsaFocus"
/>
<ht-online-form
v-if="formType == 'INNER'"
ref="flowOnlineForm"
class="online-form"
:class="{ 'readonly-form': isView }"
:html="innerHtml"
:data="data"
:permission="permission"
:extend-prop="recordData"
:is-view="isView"
:is-support-mobile="isSupportMobile"
:inst-id="instId"
:def-id="defId"
/>
<iframe
v-else-if="formType == 'FRAME'"
name="flowFrameForm"
:src="frameUrl"
></iframe>
<!-- 设置紧急程度弹窗 -->
<van-popup v-model="showMergencyConfig" position="bottom" round>
<van-picker
v-if="mergencyConfig && mergencyConfig.conf.length > 0"
show-toolbar
:columns="mergencyConfig.conf"
value-key="state"
ref="mergencyPickers"
item-height="48px"
@confirm="onConfirm"
@cancel="showMergencyConfig = false"
>
<template #option="option">
<div :style="{ color: `${option.color}` }">
{{ option.name }}
</div>
</template>
</van-picker>
</van-popup>
</div>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
import { TASK_INFO } from './const.js'
import {
getProcessInfo,
getUrgentStateConf,
getProcessTitle,
getTaskInfo,
getCurNodeProperties,
} from '@/api/process'
export default {
name: 'FlowForm',
props: {
form: {
type: Object,
default: () => {
return {}
},
},
data: {
type: Object,
default: () => {
return null
},
},
permission: {
type: Object,
default: () => {
return null
},
},
frameSaveDataTimeOut: {
type: Number,
default: 10,
},
instId: {
type: String,
default: '',
},
defId: {
type: String,
default: '',
},
isDialogModel: {
type: Boolean,
default: false,
},
recordData: {
type: Object,
default: () => {
return {}
},
},
doneDataVersion: {
type: String,
default: '',
},
nodeOptions: {
type: Array,
default: () => {
return []
},
},
currentSelectNode: {
type: String,
default: '',
},
outHeight: {
type: Number,
default: 112,
},
},
data() {
return {
formType: 'INNER',
innerHtml: null,
frameUrl: null,
frameRoger: null,
frameCancelTimeout: null,
frameSaveDataPromiseResolve: null,
frameSaveDataPromiseReject: null,
processInfo: {},
isShowHelp: false,
mergencyConfig: null,
processName: '',
currentNode: '',
isSupportMobile: false,
taskInfo: TASK_INFO,
selectNode: '',
currentSelectNodeName: '',
flag: 0,
showMergencyConfig: false,
}
},
computed: {
...mapState('process', ['bpmTask']),
...mapGetters('login', ['token']),
instStatus() {
return this.$route.query.instStatus
},
taskId() {
return this.$route.query.taskId || this.$route.params.taskId
},
isShowCurrentNode() {
const { type, taskId } = this.$route.query
return (
['request', 'todo'].includes(type) ||
taskId ||
(type === 'done' && this.isHistory)
)
},
isDone() {
return this.$route.query.type === 'done'
},
isView() {
// 加签 征询 流转时禁止编辑
const statusList = ['TRANSFORMEDINQU', 'USERADDSIGN', 'TRANSFORMED']
const result =
(this.instId && !this.taskId && !this.isDialogModel) ||
statusList.includes(this.bpmTask.status)
return result ? true : false
},
headers() {
return { Authorization: `Bearer ${this.accessToken}` }
},
isShowTop() {
return !this.instId && !this.isShowHelp && !this.mergencyConfig
},
isHistory() {
return this.doneDataVersion === 'history'
},
},
watch: {
form: function (newVal) {
if (newVal) {
this.formType = newVal.type
if (this.formType == 'INNER') {
this.innerHtml = newVal.formHtml
} else if (this.formType == 'FRAME') {
this.frameUrl = newVal.formValue
}
this.$emit('formTypeChange', this.formType)
}
if (newVal.helpFile) {
this.isShowHelp = true
}
},
urgentStateValue(val) {
const urgentStateValue = localStorage.getItem('urgentStateValue')
if (urgentStateValue) {
const savaData = { ...JSON.parse(urgentStateValue), new: val }
localStorage.setItem('urgentStateValue', JSON.stringify(savaData))
}
},
mergencyConfig: {
handler(config) {
const urgentStateValue = localStorage.getItem('urgentStateValue')
if (urgentStateValue) {
const savaData = {
...JSON.parse(urgentStateValue),
new: config.value,
}
localStorage.setItem('urgentStateValue', JSON.stringify(savaData))
}
},
deep: true,
},
'mergencyConfig.value': {
handler(val) {
let index = this.mergencyConfig.conf.findIndex(
(item) => item.state == val
)
this.$emit('urgentStateValueChange', val, index)
},
deep: true,
},
showMergencyConfig: {
handler(newVal) {
let currentIndex = 0
for (let i = 0; i < this.mergencyConfig.conf.length; i++) {
if (
this.mergencyConfig.value == this.mergencyConfig.conf[i].state
) {
currentIndex = i
}
}
// picker打开,默认选中已选择的那一栏
this.$nextTick(() => {
if (
this.mergencyConfig.conf != null &&
this.mergencyConfig.conf.length > 0
) {
this.$refs.mergencyPickers.setColumnIndex(0, currentIndex)
this.showBottomPop = newVal
}
})
},
},
currentSelectNode(val) {
this.selectNode = val
if (this.nodeOptions.length > 0) {
const result =
this.nodeOptions.find((item) => item.taskKey === val) || {}
this.currentSelectNodeName = result.taskName
}
},
},
created() {
window.addEventListener('message', this.handleFrameMessage)
this.instId && this.getProcessInfoByInstId()
this.getEmergencyStatusConf()
this.defId && this.getProcessTitleByDefId()
// 流程初始化时获取流程节点配置信息
this.getFlowConfig()
},
mounted() {
window.addEventListener('scroll', this.scrollBackTop, true) //监听滚动条
},
beforeDestroy() {
window.removeEventListener('message', this.handleFrameMessage)
window.removeEventListener('scroll', this.scrollBackTop)
},
methods: {
afocus() {
this.$refs.adsaFocus.blur()
},
scrollBackTop() {
const myNodeList = document.querySelectorAll('.el-tooltip__popper')
if (myNodeList.length > 0) {
myNodeList.forEach((value) => {
value.style.display = 'none'
value.ariaHidden = true
})
this.$refs.adsaFocus.afocus()
}
},
getFlowConfig() {
if (this.defId) {
getCurNodeProperties({
defId: this.defId,
instId: '',
taskId: '',
}).then((res) => {
if (
res &&
res.localProperties &&
res.localProperties.initFillData
) {
this.recordData.initFillData = true
}
})
}
},
getData(verify) {
if (this.formType == 'INNER') {
return this.$refs.flowOnlineForm.getData(verify)
} else if (this.formType == 'FRAME') {
const frm = this.getFrameFormElement()
// 发送保存数据的消息
frm.contentWindow.postMessage('saveData', '*')
this.frameRoger = false
this.frameCancelTimeout = false
// 1.未收到roger消息,认为url表单未引入hotent.helper.js文件
const rogerJudge = new Promise((resolve, reject) => {
setTimeout(() => {
if (this.frameRoger === false) {
this.$message.error(
`当前URL表单没有回复保存数据的消息,可能没有引入hotent.helper.js文件。`
)
reject()
}
}, 200)
})
// 2.超时未返回saveData消息
var timeoutHandler
const timeoutJudge = new Promise((resolve, reject) => {
timeoutHandler = setTimeout(() => {
if (this.frameCancelTimeout === false) {
this.$message.error(
`当前URL表单保存数据超时,超时时间为:${this.frameSaveDataTimeOut}秒。`
)
reject()
}
}, this.frameSaveDataTimeOut * 1000)
})
// 3.接受到保存完数据的消息后resolve
const receiveData = new Promise((resolve, reject) => {
this.frameSaveDataPromiseResolve = resolve
this.frameSaveDataPromiseReject = reject
})
return Promise.race([rogerJudge, timeoutJudge, receiveData]).finally(
() => {
this.frameRoger = null
this.frameCancelTimeout = null
this.frameSaveDataPromiseResolve = null
this.frameSaveDataPromiseReject = null
if (timeoutHandler) {
clearTimeout(timeoutHandler)
}
}
)
} else {
throw `不识别的表单类型${this.formType}`
}
},
getFrameFormElement() {
const frm = document.querySelectorAll("[name='flowFrameForm']")[0]
const frmControl = document.querySelectorAll("[name='iframeControl']")
if (!frm && !frmControl) {
this.$message.error('当前URL表单加载不正确。')
}
return frm
},
// 处理iframe表单发送过来的消息
handleFrameMessage(e) {
if (
!e ||
!e.data ||
!e.data.type ||
e.data.type.startsWith?.('webpack')
) {
return
}
const frm = this.getFrameFormElement()
switch (e.data.type) {
//调整iframe的高度
case 'height': {
frm.style.visibility = 'hidden'
// 提前还原高度
frm.setAttribute('height', 'auto')
setTimeout(function () {
frm.setAttribute('height', e.data.height)
frm.style.visibility = 'visible'
frm.dispatchEvent(new Event('mouseover'))
}, 0)
break
}
//获取到frame表单传过来的流程变量数据
case 'saveData': {
if (e.data.state && this.frameSaveDataPromiseResolve) {
const iframeData = {
businessKey: e.data.businessKey,
sysCode: e.data.sysCode,
}
if (e.data.vars) {
iframeData.vars = e.data.vars
}
this.$emit('update:data', iframeData)
this.frameSaveDataPromiseResolve()
} else if (!e.data.state && this.frameSaveDataPromiseReject) {
this.frameSaveDataPromiseReject()
this.$message.error('业务表单数据保存失败')
}
break
}
//表示frame表单收到了保存表单数据的消息
case 'roger':
this.frameRoger = true
break
//frame表单取消超时判断
case 'cancelTimeout':
this.frameCancelTimeout = true
break
}
},
getProcessInfoByInstId() {
getProcessInfo(this.instId).then((res) => {
this.processInfo = res
this.isSupportMobile = res.supportMobile === 1 ? true : false
this.$emit('get-process-sponsor', res.createAccount)
this.$emit('getInstStatus', res.status)
this.$emit('updateHeaderData', {
...this.processInfo,
currentNode: this.currentNode,
})
this.getCurrentNode(res.status)
})
},
getCurrentStatusColorOrText(type) {
const currentStatus = this.processInfo.status || this.instStatus
return STATUS_COLOR[currentStatus]?.[type]
},
preview() {
const files = this.form?.helpFile ? JSON.parse(this.form.helpFile) : []
window.open(
`${this.$file.previewUrl}?fileId=${files[0]?.id}&token=${this.accessToken}`
)
},
getEmergencyStatusConf() {
const params = {
defId: this.defId,
instId: this.instId,
taskId: this.taskId,
}
getUrgentStateConf(params).then((data) => {
if (data.conf) {
try {
data.conf = JSON.parse(data.conf)
} catch (error) {
data.conf = eval('(' + data.conf + ')')
}
localStorage.setItem(
'urgentStateValue',
JSON.stringify({ old: data.value })
)
if (!data.value) {
data.conf?.map?.((item) => {
if (item.default) {
data.value = item.state
}
})
}
this.mergencyConfig = data
} else {
localStorage.removeItem('urgentStateValue')
}
this.$emit('urgentStateList', this.mergencyConfig)
})
},
getProcessTitleByDefId() {
getProcessTitle(this.defId).then((res) => {
if (res.state) {
this.processName = res.value.name
this.$store.commit('process/setprocessName', res.value.name)
}
})
},
getCurrentNode(status) {
getTaskInfo([this.instId]).then((res) => {
if (!res.state) return this.$message.error(res.message)
const currentNodeList = res.value?.[this.instId]
if (currentNodeList?.length > 0) {
let nodeMap = {}
currentNodeList.forEach((item) => {
const { nodeId, name } = item
nodeMap[nodeId] = name
})
if (this.$route.query.type === 'request') {
if (currentNodeList.length === 1) {
this.currentNode = currentNodeList[0].name
} else {
this.currentNode = '请查看流程图'
}
this.isSupportMobile = currentNodeList[0].supportMobile === 1
} else {
const currentTask = currentNodeList.find(
(item) => item.id === this.taskId
)
this.currentNode = currentTask && currentTask.name
if (currentTask && currentTask.supportMobile) {
this.isSupportMobile = currentTask.supportMobile === 1
}
}
// 更新当前节点
this.$emit('updateHeaderData', {
...this.processInfo,
currentNode: this.currentNode,
nodeId: currentNodeList[0].nodeId,
})
}
})
},
handleNodeChange(taskKey) {
this.$emit('node-change', taskKey)
},
onConfirm(value) {
this.mergencyConfig.value = value.state
this.showMergencyConfig = false
},
},
}
</script>
<style lang="scss" scoped>
.flow-form {
background: #fff;
height: calc(#{$vh} - var(--outHeight));
::v-deep {
.el-form-item__label {
line-height: 48px;
text-align: left;
span {
margin-left: 0 !important;
display: inline-block;
line-height: 24px;
padding: 12px 0;
}
}
.el-form-item__content {
line-height: 48px;
.van-cell__right-icon {
font-size: 18px;
margin-right: -5px;
line-height: 24px;
}
}
.ht-form-item-top-label {
.el-form-item__content {
line-height: 24px;
.field-tail {
text-align: left;
display: inline-block;
line-height: 24px;
}
}
}
}
.online-form {
overflow-y: auto;
overflow-x: hidden;
padding-bottom: 24px;
height: calc(#{$vh} - var(--outHeight) - 24px);
}
::v-deep {
.van-stepper__minus,
.van-stepper__plus {
background: #409eff;
}
iframe[name='flowFrameForm'] {
min-height: 300px;
width: 100%;
border: none;
}
}
}
</style>