sasp-flow-render 1.1.22 → 1.1.24-decoupling

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2222 @@
1
+ // utils/workflow.js
2
+
3
+ import {AjaxUtil} from "sasp-base";
4
+
5
+ /**
6
+ * 工作流引擎类
7
+ * 支持多步骤、异步操作、自定义弹窗内容、错误处理
8
+ */
9
+ class WorkflowEngine {
10
+ initParams(component,flowAttrs = {}){
11
+ this.$this = component; // required
12
+ if(!this.$this){
13
+ console.error("初始化失败,component不能为空");
14
+ return;
15
+ }
16
+ this.flowId = flowAttrs.flowId; // required
17
+ this.tableviewId = flowAttrs.tableviewId; // 外部调用时初始化必须
18
+ this.formGloabalInfo = (this.$this.formGloabalInfo || {});
19
+ this.flowParams = {};
20
+ this.formComponent = this.formGloabalInfo.formComponent;
21
+ this.dataId = "";
22
+ this.formId = "";
23
+ this.currentInst = {};
24
+ this.installListObj = this.$this.EVENT_PLUGIN['installEventObj']||{}; //已经安装的流程事件
25
+ this.loginUser = this.$this.FLOW_CACHE_GLOBAL.getLoginUser();
26
+ this.skipAutoInit = false;
27
+ if(flowAttrs.skipAutoInit){
28
+ this.skipAutoInit = flowAttrs.skipAutoInit;
29
+ }
30
+ this.formInfo = {
31
+ dataId: this.dataId,
32
+ opt: "view",
33
+ }
34
+ this.$flowDialog = this.$this.$flowDialog;
35
+ this.flowDefine = {};
36
+
37
+ // 初始化插入部分方法
38
+ let methods = flowAttrs["methods"] || {};
39
+ this.initTabNum = methods["initTabNum"];
40
+ this.tabCrudSearch = methods["tabCrudSearch"];
41
+ this.batchTabRemove = methods["batchTabRemove"];
42
+ this.setFlowTabInfo = methods["setFlowTabInfo"];
43
+ this.getFlowBatchDialog = methods["getFlowBatchDialog"];
44
+ this.closeFlowBatchDialog = methods["closeFlowBatchDialog"];
45
+ this.initFormInfo = methods["initFormInfo"];
46
+ this.saveFormInfo = methods["saveFormInfo"];
47
+ this.getFormInfo = methods["getFormInfo"];
48
+ this.flowNextOperation = methods["flowNextOperation"];
49
+ this.forceUpdateComponent = methods["forceUpdateComponent"];
50
+ this.nextStepAfterSave = methods["nextStepAfterSave"];
51
+ this.setParams = methods["setParams"];
52
+
53
+ if(!this.initFormInfo){
54
+ this.initFormInfo = this.$flowDialog.initFormInfo;
55
+ }
56
+
57
+ if(!this.saveFormInfo){
58
+ this.saveFormInfo = this.$flowDialog.saveFormInfo;
59
+ }
60
+
61
+ if(!this.getFormInfo){
62
+ this.getFormInfo = this.$flowDialog.getFormInfo;
63
+ }
64
+
65
+ // 流程的参数
66
+ this.flowInstDataDialog = false;
67
+ this.nextSteptUserDialog = false;
68
+ this.doMainDatasObj = {};
69
+ this.userMap = {};
70
+ this.userArr = [];
71
+ this.tabActive = "draft";
72
+ this.flowDefineByFlowId = {};
73
+ this.startNodeKey = "";
74
+ this.startNodeKeyObj = {};
75
+ this.allNodeInfo = {};
76
+ this.flowNodeIdToInfo = {};
77
+ this.flowNodeNameObj = {};
78
+ this.nodeListButtonObj = {};
79
+ this.listButtonObj = { // 列表按钮
80
+ add: "新增",
81
+ delete: "删除",
82
+ update: "修改",
83
+ view: "查看",
84
+ deal: "处理",
85
+ flowRecord: "流转记录",
86
+ flowChart: "流程图",
87
+ };
88
+ this.diyButtonsObj= {};
89
+ this.optColumnWidth = 336;
90
+ this.nodeFormButtonObj = {};
91
+ this.nodeFormBtnObj = {};
92
+ this.startNodeKeyObjByFlowId = {};
93
+ this.flowVersionNodeObj = {}; //版本号对应的节点对象
94
+ this.flowVersionNodeObjByFlowId = {};
95
+ this.flowEventScriptByFlowId = {};
96
+ this.operateType= {};
97
+
98
+ this.nextNode = {};
99
+ this.description = "";
100
+ this.saveInstId = "";
101
+ this.nowNode = {};
102
+ this.isProceedNext = false;
103
+ this.nextNodeName = "";
104
+ this.choosePosUserIds = "";
105
+ this.choosePosUserIdsObj = {};
106
+ this.chooseNextUserIdObj = {};
107
+ this.chooseNextUserNameObj = {};
108
+ this.chooseNextUserId = "";
109
+ this.chooseNextUserName = "";
110
+ this.nextSteptUserArr = [];
111
+
112
+ this.newEventObj = {};
113
+ this.resourceTabOpts = ['draft','pending','processed','rescinded','finished','discontinue','flowQuery'];
114
+ //表单按钮
115
+ this.formButtonObj = {
116
+ saveDraft: "存草稿",
117
+ completeSign: "加签",
118
+ turnSign: "转签",
119
+ nextStep: "下一步",
120
+ back: "退回",
121
+ getBack: "取回",
122
+ cancel: "撤销",
123
+ stopped: "中止",
124
+ close: "关闭",
125
+ export: "导出",
126
+ retSpecified: "退回指定节点"
127
+ }
128
+
129
+ this.flowParams = {};
130
+ this.isDisabled = {
131
+ update: true,
132
+ deal: true,
133
+ flowRecord: true,
134
+ flowChart: true,
135
+ view: true,
136
+ saveDraft: true,
137
+ completeSign: true,
138
+ turnSign: true,
139
+ nextStep: true,
140
+ back: true,
141
+ cancel: true,
142
+ stopped: true,
143
+ close: true,
144
+ export: true,
145
+ retSpecified: true,
146
+ getBack: true,
147
+ record: true,
148
+ restore: true,
149
+ };
150
+
151
+ this.formBtnObjDefault = {
152
+ saveDraft: {
153
+ text: "存草稿",
154
+ type: "success",
155
+ icon: "el-icon-check",
156
+ disabled: false,
157
+ show: true,
158
+ method: () => {
159
+ this.saveDraft();
160
+ }
161
+ },
162
+
163
+ nextStep: {
164
+ text: "下一步",
165
+ type: "primary",
166
+ icon: "el-icon-d-arrow-right",
167
+ disabled: false,
168
+ show: true,
169
+ method: () => {
170
+ this.nextStep();
171
+ // this.isDisabled1 = true;
172
+ this.$flowDialog.fillFlowDialogParams({
173
+ isDisabled1: true
174
+ });
175
+ }
176
+ },
177
+
178
+ completeSign: {
179
+ text: "加签",
180
+ type: "primary",
181
+ icon: "saspiconfont pl-icon-jiaqian",
182
+ disabled: false,
183
+ show: false,
184
+ method: () => {
185
+ // this.completeSignDialog = true; // todo加签
186
+ this.$flowDialog.operateDialog('completeSignDialog',true);
187
+ }
188
+ },
189
+
190
+ turnSign: {
191
+ text: "转签",
192
+ type: "primary",
193
+ icon: "saspiconfont pl-icon-zhuanqian-icon",
194
+ disabled: false,
195
+ show: false,
196
+ method: () => {
197
+ // this.turnSignDialog = true; // todo转签
198
+ this.$flowDialog.operateDialog('turnSignDialog',true);
199
+ }
200
+ },
201
+
202
+ back: {
203
+ text: "退回",
204
+ type: "danger",
205
+ icon: "el-icon-d-arrow-left",
206
+ disabled: false,
207
+ show: false,
208
+ method: () => {
209
+ this.backToPrevious(this.currentInst);
210
+ }
211
+ },
212
+
213
+ retSpecified: {
214
+ text: "退回指定节点",
215
+ type: "danger",
216
+ icon: "el-icon-refresh-left",
217
+ disabled: false,
218
+ show: false,
219
+ method: () => {
220
+ this.retSpecified(this.currentInst); //退回指定节点
221
+ }
222
+ },
223
+
224
+ stopped: {
225
+ text: "中止",
226
+ type: "danger",
227
+ icon: "saspiconfont pl-icon-yizhongzhi",
228
+ disabled: false,
229
+ show: false,
230
+ method: () => {
231
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.stopFlow, {
232
+ instId: this.currentInst.flowInstId, type: "0",
233
+ procInstId: this.currentInst.linkProcId,
234
+ taskId: this.currentInst.taskId
235
+ }).then(res => {
236
+ if (res && res.data) {
237
+ if (res.data.operateSuccess) {
238
+ this.$this.$message({type: "success", message: "中止成功!"});
239
+ if (this.getFlowBatchDialog && this.getFlowBatchDialog()) {
240
+ this.batchTabRemove(this.currentInst.dataId);
241
+ } else {
242
+ this.tabCrudSearch && this.tabCrudSearch();
243
+ this.flowInstDataDialog = false;
244
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
245
+ }
246
+ this.initTabNum && this.initTabNum();
247
+
248
+ let remindParam = {
249
+ instId:this.currentInst.flowInstId,
250
+ flowId:this.flowDefine.id,
251
+ flowName:this.flowDefine.flowName,
252
+ // formId:this.formInfo.formId,
253
+ // listViewId:this.formInfo.listViewId,
254
+ dataId:this.formInfo.dataId,
255
+ instType:"stopped"
256
+ };
257
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.saveRemind,remindParam);
258
+
259
+ //执行事件规则
260
+ let currentNodeObj = this.flowNodeIdToInfo[this.currentInst.currentNode] ||{};
261
+ if(currentNodeObj.openEvent == '1'){
262
+ this.exeNewFlowEvent("suspend",currentNodeObj.nodeLinkId||'');
263
+ }
264
+ } else {
265
+ this.$this.$message({type: "error", message: res.data.operateMessage});
266
+ }
267
+ }
268
+ });
269
+ }
270
+ },
271
+
272
+ cancel: {
273
+ text: "撤销",
274
+ type: "danger",
275
+ icon: "saspiconfont pl-icon-chexiao",
276
+ disabled: false,
277
+ show: false,
278
+ isView: true,
279
+ method: () => {
280
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.revokeFlow, {
281
+ instId: this.currentInst.flowInstId,
282
+ taskId: this.currentInst.taskId
283
+ }).then(res => {
284
+ if (res && res.data) {
285
+ if (res.data.operateSuccess) {
286
+ this.$this.$message({type: "success", message: "撤销成功!"});
287
+ this.tabCrudSearch && this.tabCrudSearch();
288
+ this.flowInstDataDialog = false;
289
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
290
+ this.initTabNum && this.initTabNum();
291
+
292
+ let remindParam = {
293
+ instId:this.currentInst.flowInstId,
294
+ flowId:this.flowDefine.id,
295
+ flowName:this.flowDefine.flowName,
296
+ // formId:this.formInfo.formId,
297
+ // listViewId:this.formInfo.listViewId,
298
+ dataId:this.formInfo.dataId,
299
+ instType:"cancel"
300
+ };
301
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.saveRemind,remindParam);
302
+
303
+
304
+ } else {
305
+ this.$this.$message({type: "error", message: res.data.operateMessage});
306
+ }
307
+ }
308
+ });
309
+ }
310
+ },
311
+
312
+ getBack: {
313
+ text: "取回",
314
+ type: "danger",
315
+ icon: "el-icon-refresh-left",
316
+ disabled: false,
317
+ show: false,
318
+ isView: true,
319
+ method: () => {
320
+ this.getBackPrevious();
321
+ }
322
+ },
323
+
324
+ restore: {
325
+ text: "恢复",
326
+ type: "success",
327
+ icon: "saspiconfont pl-icon-chexiao",
328
+ disabled: false,
329
+ show: false,
330
+ isView: true,
331
+ method: () => {
332
+ this.restoreFlow();
333
+ }
334
+ },
335
+ record: {
336
+ text: "流转记录",
337
+ type: "warning",
338
+ icon: "saspiconfont pl-icon-liuchengtu",
339
+ disabled: false,
340
+ show: true,
341
+ isView: true,
342
+ method: () => {
343
+ this.openFlowRecord(this.currentInst);
344
+ }
345
+ },
346
+ close: {
347
+ text: "关闭",
348
+ type: "",
349
+ icon: "el-icon-close",
350
+ disabled: false,
351
+ show: true,
352
+ isView: true,
353
+ method: () => {
354
+ this.flowInstDataDialog = false;
355
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
356
+ this.closeFlowBatchDialog && this.closeFlowBatchDialog();
357
+ }
358
+ },
359
+ }
360
+ this.loadSuccess = false;
361
+ }
362
+
363
+ constructor(component,flowAttrs = {}) {
364
+ // 工作流配置
365
+ this.initParams(component,flowAttrs);
366
+ }
367
+
368
+ init(){
369
+ return new Promise(resolve => {
370
+ if(!this.skipAutoInit && !this.loadSuccess){
371
+ this.$this.saspFlowAxios.all([
372
+ this.initFlowInfo(),
373
+ this.initFlowFormInfo()
374
+ ]).then(this.$this.saspFlowAxios.spread((resFlow, resForm) => {
375
+ this.loadSuccess = true;
376
+ resolve();
377
+ }));
378
+ }else{
379
+ resolve();
380
+ }
381
+ this.initUserData();
382
+ this.initDialogProps();
383
+ })
384
+ }
385
+
386
+ initFlowFormInfo(){
387
+ return new Promise(resolve => {
388
+ if(!this.$this.FORM_GLOBAL){
389
+ this.$this.$message.error("未安装表单组件,请使用自定义表单开发");
390
+ return;
391
+ }
392
+ this.$this.FORM_GLOBAL.getTableViews(this.tableviewId).then(tableviewsData => {
393
+ if(!tableviewsData || !tableviewsData.id){
394
+ this.$message.error("表单资源不存在!");
395
+ return;
396
+ }
397
+ this.formId = tableviewsData.formId;
398
+ this.$flowDialog.fillFlowDialogParams({
399
+ formId: this.formId,
400
+ tableviewId: this.tableviewId,
401
+ dataId: this.dataId
402
+ });
403
+ resolve();
404
+ });
405
+ });
406
+ }
407
+
408
+ initDialogProps() {
409
+ let dialogProps = {
410
+ flowNextOperation: this.flowNextOperation,
411
+ workFlowUtil: this
412
+ }
413
+ this.$flowDialog.initDialogProps(dialogProps);
414
+ }
415
+
416
+ // 初始化流程相关信息
417
+ initFlowInfo() {
418
+ return new Promise(resolve => {
419
+ if (this.flowId.includes(",")) {
420
+ this.getMultiFlowInfo().then(() => {
421
+ resolve();
422
+ })
423
+ } else {
424
+ this.getFlowInfo().then(() => {
425
+ resolve();
426
+ });
427
+ }
428
+ });
429
+ }
430
+
431
+ /**
432
+ * 多流程初始化
433
+ */
434
+ getMultiFlowInfo() {
435
+ return new Promise(resolve => {
436
+ let flowIdArr = this.flowId.split(",").filter(item => item);
437
+ flowIdArr.forEach(flowId => {
438
+ this.$this.FLOW_GLOBAL.getFlowDefineById(flowId).then(flowDefine => {
439
+ this.flowDefineByFlowId[flowId] = flowDefine;
440
+ });
441
+ });
442
+
443
+ const initFlowNodeFunc = flowIdArr.map(flowId => (() => this.$this.FLOW_GLOBAL.getFlowNodesByFlowId(flowId)));
444
+ Promise.all(initFlowNodeFunc.map(func => func())).then(allFlowNodeArr => {
445
+ //工作流节点
446
+ this.startNodeKey = "Activity_draft"; // todo 确定startNodeKey的位置
447
+ for (const allFlowNode of allFlowNodeArr) {
448
+ this.startNodeKeyObj = {};
449
+ this.flowVersionNodeObj = {};
450
+ let flowId = allFlowNode[0].flowId;
451
+ this.flowDefine = this.flowDefineByFlowId[flowId];
452
+ (allFlowNode || []).forEach(item => {
453
+ if (item.nodeLinkId.indexOf("Activity_draft") > -1) {
454
+ this.startNodeKey = item.nodeLinkId;
455
+ this.startNodeKeyObj[item.version] = item.nodeLinkId; //开始节点对应版本号
456
+ }
457
+ if (!this.flowVersionNodeObj[item.version]) {
458
+ this.$this.$set(this.flowVersionNodeObj, item.version, {});
459
+ }
460
+ this.$this.$set(this.flowVersionNodeObj[item.version], item.nodeLinkId, item); //版本节点对象
461
+
462
+ this.allNodeInfo[item.id] = item;
463
+ this.flowNodeIdToInfo[item.id] = item;
464
+ let nodeArr = ['StartEvent', 'ParallelGateway', 'SequenceFlow', 'ExclusiveGateway', 'InclusiveGateway'];
465
+ if (item.nodeType && nodeArr.indexOf(item.nodeType) === -1) {
466
+ if (!this.flowNodeNameObj[item.nodeLinkId]) {
467
+ let nodeName = item.nodeName;
468
+ if (this.flowId.includes(",")) {
469
+ nodeName = this.flowDefine.flowName + "-" + item.nodeName;
470
+ }
471
+ this.$this.$set(this.flowNodeNameObj, item.nodeLinkId, nodeName);
472
+ } else {
473
+ if (this.flowNodeNameObj[item.nodeLinkId] !== item.nodeName) {
474
+ this.flowNodeNameObj[item.nodeLinkId] = this.flowNodeNameObj[item.nodeLinkId] + "," + item.nodeName;
475
+ }
476
+ }
477
+ }
478
+ if (item.nodeType === "UserTask" && (item.nodeLinkId || "").indexOf("Activity_draft") > -1) {
479
+ this.draftNodeId = item.id; // 草稿节点id
480
+ }
481
+ // 行按钮
482
+ let listButton = JSON.parse(item.listButton || "[]") || [];
483
+ listButton.forEach(button => {
484
+ button.showName = button.showName ? button.showName : this.listButtonObj[button.type];
485
+ });
486
+ this.nodeListButtonObj[item.id] = listButton;
487
+
488
+ // 表单按钮
489
+ let formButton = JSON.parse(item.formButton || "[]") || [];
490
+ formButton.forEach(button => {
491
+ button.showName = button.showName ? button.showName : this.formButtonObj[button.type];
492
+ });
493
+
494
+ this.nodeFormButtonObj[item.id] = this.sortButtonArr(formButton);
495
+ this.nodeFormBtnObj[item.id] = this.formatterFormButton(formButton);
496
+ });
497
+ this.$this.$set(this.startNodeKeyObjByFlowId, flowId, this.startNodeKeyObj);
498
+ this.$this.$set(this.flowVersionNodeObjByFlowId, flowId, this.flowVersionNodeObj);
499
+ // this.initFlowScript().then(() => {
500
+ // resolve(true);
501
+ // });
502
+ }
503
+ const initFlowScriptFunc = flowIdArr.map(flowId => () => this.initFlowScript(flowId));
504
+ Promise.all(initFlowScriptFunc.map(func => func())).then(scriptArr => {
505
+ (scriptArr || []).forEach(scriptEventObj => {
506
+ Object.keys(scriptEventObj).forEach(key => {
507
+ if (key) {
508
+ this.flowEventScriptByFlowId[key] = scriptEventObj[key];
509
+ }
510
+ });
511
+ });
512
+ }).catch(reason => {
513
+ console.log('流程脚本加载出错了', reason);
514
+ });
515
+ let result = {
516
+ flowDefineByFlowId : this.flowDefineByFlowId,
517
+ startNodeKeyObj : this.startNodeKeyObj,
518
+ flowDefine : this.flowDefineByFlowId[this.flowId],
519
+ startNodeKey : this.startNodeKey,
520
+ allNodeInfo : this.allNodeInfo,
521
+ flowNodeIdToInfo : this.flowNodeIdToInfo,
522
+ flowNodeNameObj : this.flowNodeNameObj,
523
+ draftNodeId : this.draftNodeId,
524
+ nodeListButtonObj : this.nodeListButtonObj,
525
+ nodeFormButtonObj : this.nodeFormButtonObj,
526
+ nodeFormBtnObj : this.nodeFormBtnObj,
527
+ startNodeKeyObjByFlowId : this.startNodeKeyObjByFlowId,
528
+ flowVersionNodeObjByFlowId : this.flowVersionNodeObjByFlowId,
529
+ flowEventScriptByFlowId : this.flowEventScriptByFlowId
530
+ };
531
+ resolve(result);
532
+ });
533
+ });
534
+ }
535
+
536
+ /**
537
+ * 初始化流程信息
538
+ */
539
+ getFlowInfo(){
540
+ this.flowDefine.id = this.flowId;
541
+ return new Promise(resolve => {
542
+ this.$this.FLOW_GLOBAL.getFlowDefineById(this.flowId).then(flowobj => {
543
+ this.flowDefine = flowobj;
544
+ this.$flowDialog.fillFlowDialogParams({
545
+ flowDefine: this.flowDefine
546
+ });
547
+ let tabSetting = JSON.parse(this.flowDefine.tabSetting,"[]");
548
+ (tabSetting || []).forEach(item => {
549
+ if(item.isUse == '1'){
550
+ this.operateType[item.type] = true;
551
+ }
552
+ })
553
+ let activeArr = [];
554
+ Object.keys(this.operateType).forEach(key => {
555
+ if(this.operateType[key] && this.resourceTabOpts.indexOf(key) > -1){
556
+ activeArr.push(key);
557
+ }
558
+ })
559
+ if(activeArr.length > 0 && activeArr.indexOf("pending") == -1){
560
+ this.tabActive = activeArr[0]; // todo 返回tabActive
561
+ }
562
+ // this.showModel = flowobj.showModel;
563
+ // this.showInfo = flowobj.showInfo;
564
+ // let formType = flowobj.formType;
565
+ //工作流节点
566
+ this.startNodeKey = "Activity_draft";
567
+ this.startNodeKeyObj = {};
568
+ // let flowVersion = this.flowDefine.flowVersion || '1.0';
569
+ this.$this.FLOW_GLOBAL.getFlowNodesByFlowId(this.flowId).then(nodeDatas => {
570
+ if (nodeDatas) {
571
+ nodeDatas.forEach(item => {
572
+ if (item.nodeLinkId.indexOf("Activity_draft") > -1) {
573
+ this.startNodeKey = item.nodeLinkId;
574
+ this.startNodeKeyObj[item.version] = item.nodeLinkId; //开始节点对应版本号
575
+ }
576
+ if(!this.flowVersionNodeObj[item.version]){
577
+ this.$this.$set(this.flowVersionNodeObj,item.version,{});
578
+ }
579
+ this.$this.$set(this.flowVersionNodeObj[item.version],item.nodeLinkId,item); //版本节点对象
580
+ // if(item.version == this.flowDefine.releaseVersion){ //节点信息只取最新版本
581
+ this.flowNodeIdToInfo[item.id] = item;
582
+ if(item.nodeType&&['StartEvent','ParallelGateway','SequenceFlow','ExclusiveGateway','InclusiveGateway'].indexOf(item.nodeType) == -1){
583
+ if(!this.flowNodeNameObj[item.nodeLinkId]){
584
+ this.$this.$set(this.flowNodeNameObj,item.nodeLinkId,item.nodeName);
585
+ }else {
586
+ if(this.flowNodeNameObj[item.nodeLinkId] != item.nodeName){
587
+ this.flowNodeNameObj[item.nodeLinkId] = this.flowNodeNameObj[item.nodeLinkId] + "," + item.nodeName;
588
+ }
589
+ }
590
+ }
591
+ if(item.nodeType == "UserTask" && (item.nodeLinkId || "").indexOf("Activity_draft") > -1){
592
+ this.draftNodeId = item.id; // 草稿节点id
593
+ }
594
+ // }
595
+ this.allNodeInfo[item.id] = item;
596
+ // 行按钮
597
+ let listButton = JSON.parse(item.listButton || "[]") || [];
598
+ listButton = listButton.filter(item => !item.buttonId);
599
+ listButton.forEach(button => {
600
+ button.showName = button.showName ? button.showName : this.listButtonObj[button.type];
601
+ });
602
+ this.nodeListButtonObj[item.id] = listButton;
603
+
604
+ // 表单按钮
605
+ let formButton = JSON.parse(item.formButton || "[]") || [];
606
+ formButton = formButton.filter(item => !item.buttonId);
607
+ formButton.forEach(button => {
608
+ button.showName = button.showName ? button.showName : this.formButtonObj[button.type];
609
+ });
610
+
611
+ this.nodeFormButtonObj[item.id] = this.sortButtonArr(formButton);
612
+ this.nodeFormBtnObj[item.id] = this.formatterFormButton(formButton);
613
+
614
+ // 自定义按钮
615
+ if(item.plFlowButtons) {
616
+ (item.plFlowButtons || []).forEach(button => {
617
+ this.diyButtonsObj[button.id] = button;
618
+ })
619
+ }
620
+
621
+ let width = 0;
622
+ (this.nodeListButtonObj[item.id] || []).forEach(item => {
623
+ let nameLength = item.showName.length;
624
+ if (nameLength > 2) {
625
+ width += 100 + (nameLength - 2) * 12;
626
+ } else {
627
+ width += 100;
628
+ }
629
+ });
630
+ if (this.optColumnWidth < width) {
631
+ this.optColumnWidth = width;
632
+ }
633
+ });
634
+
635
+ // 显示
636
+ // this.isShowAgentSet = true;
637
+ // this.$forceUpdate();
638
+ }
639
+ // 加载工作流脚本与工作流事件规则
640
+ this.initFlowScript().then(() => {
641
+ let result = {
642
+ operateType : this.operateType,
643
+ tabActive : this.tabActive,
644
+ flowDefine : this.flowDefine,
645
+ startNodeKey : this.startNodeKey,
646
+ startNodeKeyObj : this.startNodeKeyObj,
647
+ flowVersionNodeObj : this.flowVersionNodeObj,
648
+ allNodeInfo : this.allNodeInfo,
649
+ flowNodeNameObj : this.flowNodeNameObj,
650
+ flowNodeIdToInfo : this.flowNodeIdToInfo,
651
+ nodeListButtonObj : this.nodeListButtonObj,
652
+ nodeFormButtonObj : this.nodeFormButtonObj,
653
+ nodeFormBtnObj : this.nodeFormBtnObj,
654
+ optColumnWidth : this.optColumnWidth,
655
+ diyButtonsObj : this.diyButtonsObj,
656
+ };
657
+ this.initFlowObj();
658
+ resolve(result);
659
+ })
660
+ });
661
+ });
662
+ });
663
+ }
664
+
665
+ initFlowObj() {//处理流程定义对象
666
+ this.isRefreshGetNextUsers = [];
667
+ let gatewayFields = this.flowDefine.gatewayFields || "";
668
+ this.isRefreshGetNextUsers = gatewayFields.split(",");
669
+ Object.keys(this.allNodeInfo).forEach(key => {
670
+ let obj = this.allNodeInfo[key];
671
+ if (obj.nodeType === "UserTask" && (!obj.nodeLinkId || obj.nodeLinkId.indexOf('Activity_draft') === -1)) {
672
+ if (obj.dealerType === "form" && obj.formField) {
673
+ this.isRefreshGetNextUsers.push(obj.formField);
674
+ }
675
+ if (obj.dealerType === "variable" && obj.variable) {
676
+ this.isRefreshGetNextUsers.push(obj.variable);
677
+ }
678
+ if (obj.dealerType === "interface" && obj.dealerUrlParam) {
679
+ let dealerUrlParam = JSON.parse(obj.dealerUrlParam || "[]");
680
+ dealerUrlParam.forEach(param => {
681
+ if (param.paramType === "variable") {
682
+ this.isRefreshGetNextUsers.push(param.paramVal);
683
+ }
684
+ })
685
+ }
686
+ }
687
+ });
688
+ let tabTypeObj= {};
689
+ if (!this.flowId.includes(",")) {
690
+ let tabSetting = JSON.parse(this.flowDefine.tabSetting);
691
+ tabSetting.forEach(data => {
692
+ this.$this.$set(tabTypeObj, data.type, data);
693
+ });
694
+ Object.keys(tabTypeObj).forEach(key => {
695
+ let objTemp = tabTypeObj[key];
696
+ objTemp.tabName = objTemp["showName"] || objTemp["name"];
697
+ });
698
+ let tabTitleType = this.flowDefine.tabTitleType;
699
+ if (tabTitleType === "1") {
700
+ tabTypeObj["showtTabText"] = true;
701
+ tabTypeObj["showTabIcon"] = true;
702
+ } else if (tabTitleType === "2") {
703
+ tabTypeObj["showtTabText"] = true;
704
+ } else if (tabTitleType === "3") {
705
+ tabTypeObj["showTabIcon"] = true;
706
+ }
707
+ }
708
+
709
+ let result = {
710
+ isRefreshGetNextUsers : this.isRefreshGetNextUsers,
711
+ tabTypeObj: tabTypeObj
712
+ }
713
+ this.setFlowTabInfo && this.setFlowTabInfo(result);
714
+ }
715
+
716
+ // 初始化流程信息end
717
+
718
+ /**
719
+ * 下一步,保存数据以及获取处理人
720
+ */
721
+ nextStep() {
722
+ let afterClickResult;
723
+ let result;
724
+ let currentNodeObj = this.flowNodeIdToInfo[this.currentInst.currentNode || this.draftNodeId] ||{};
725
+ afterClickResult=this.exeFlowEvent("nextStep","afterClick", this.currentInst.currentNode || this.draftNodeId);
726
+
727
+ if(typeof afterClickResult == "boolean" && afterClickResult === false){
728
+ return;
729
+ }
730
+
731
+ if(currentNodeObj.openEvent === '1'){
732
+ afterClickResult = this.exeNewFlowEvent("nextClick",currentNodeObj.nodeLinkId);
733
+ }
734
+
735
+ if(typeof afterClickResult == "boolean" && afterClickResult === false){
736
+ return;
737
+ }
738
+
739
+ // let afterValidateResult;
740
+ // let currentNodeObj = this.flowNodeIdToInfo[this.currentInst.currentNode || this.draftNodeId] ||{};
741
+ result = this.exeFlowEvent("nextStep","afterValidate", this.currentInst.currentNode || this.draftNodeId);
742
+ if(typeof result == "boolean" && result === false){
743
+ return;
744
+ }
745
+ if(currentNodeObj.openEvent === '1'){
746
+ result = this.exeNewFlowEvent("nextCheck",currentNodeObj.nodeLinkId);
747
+ if(typeof result == "boolean" && result === false){
748
+ return;
749
+ }
750
+ }
751
+
752
+ this.isDisabled['nextStep'] = false;
753
+ this.$flowDialog.fillFlowDialogParams({
754
+ flowParams: this.flowParams,
755
+ isDisabled: this.isDisabled
756
+ });
757
+ this.saveDataFunc('nextStep').then(flowParams => {
758
+ this.flowParams = JSON.parse(JSON.stringify(flowParams));
759
+ this.setParams && this.setParams({
760
+ flowParams:this.flowParams
761
+ });
762
+ let instId = flowParams.flowInstId;
763
+ this.$this.$set(this.formInfo,"opt","update");
764
+ this.currentInst.id = instId;
765
+ this.description = "";
766
+ this.saveInstId = instId;
767
+ this.nowNode = this.allNodeInfo[currentNodeObj.id] || {};
768
+ this.nextStepAfterSaveFunc().then(resultEvt => {
769
+ if(!resultEvt){
770
+ this.isDisabled['nextStep'] = true;
771
+ this.$flowDialog.fillFlowDialogParams({
772
+ isDisabled: this.isDisabled
773
+ });
774
+ return;
775
+ }
776
+ this.isProceedNext = true;
777
+ //获取处理人
778
+ let obj = {instId: instId, taskId: this.currentInst.taskId,};
779
+ if(this.nowNode && this.nowNode.dealType && this.nowNode.dealType == 'multi'){
780
+ this.$this.$set(obj,'passCondition',this.nowNode.passCondition)
781
+ }
782
+ let params = {"SASP_FLOW_USE_VARIABLES":"yes"};
783
+ // Object.assign(params,flowParams || {},obj);
784
+ Object.assign(params,obj);
785
+ let allParamKeys = Object.keys(flowParams || {});
786
+ allParamKeys.forEach(templateKey => {
787
+ if(this.isRefreshGetNextUsers.indexOf(templateKey) > -1){
788
+ params[templateKey] = flowParams[templateKey];
789
+ if(allParamKeys.indexOf(templateKey + "_SASP_SYS_DATA") > -1){
790
+ params[templateKey + "_SASP_SYS_DATA"] = flowParams[templateKey + "_SASP_SYS_DATA"];
791
+ }
792
+ if(allParamKeys.indexOf(templateKey + "_SASP_SYS_DATA_ID") > -1){
793
+ params[templateKey + "_SASP_SYS_DATA_ID"] = flowParams[templateKey + "_SASP_SYS_DATA_ID"];
794
+ }
795
+ }
796
+ });
797
+ this.$flowDialog.fillFlowDialogParams({
798
+ flowParams: this.flowParams,
799
+ formInfo: this.formInfo,
800
+ currentInst: this.currentInst,
801
+ description: this.description,
802
+ saveInstId: this.saveInstId,
803
+ nowNode: this.nowNode,
804
+ isProceedNext: this.isProceedNext,
805
+ });
806
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.getNextUsers, params).then(res => {
807
+ if(!res.data.operateSuccess){
808
+ this.isDisabled['nextStep'] = true;
809
+ if(res.data.resultObject === 'requestException'){
810
+ this.$this.$message.error(res.data.errorInfo);
811
+ }else{
812
+ this.$this.$message.error("未获取到处理人");
813
+ }
814
+ return;
815
+ }
816
+ let obj = {};
817
+ if (res && res.data) {
818
+ obj = res.data.operateObj || {};
819
+ if(res.data.operateMap && res.data.operateMap.isPassCondition == 0){
820
+ this.isProceedNext = false;
821
+ this.$flowDialog.fillFlowDialogParams({
822
+ isProceedNext: this.isProceedNext,
823
+ });
824
+ }
825
+ }
826
+ this.nextNodeName = "";
827
+ this.choosePosUserIds = "";
828
+ this.choosePosUserIdsObj = {};
829
+ this.nextNode = obj;
830
+ this.chooseNextUserIdObj = {};
831
+ this.chooseNextUserNameObj = {};
832
+ this.chooseNextUserId = "";
833
+ this.chooseNextUserName = "";
834
+ let paramKeyArr = ["nextNodeName","choosePosUserIds","choosePosUserIdsObj","nextNode",
835
+ "chooseNextUserIdObj","chooseNextUserNameObj","chooseNextUserId","chooseNextUserName",
836
+ "nextSteptUserArr","nextSteptUserType"];
837
+ let params = {};
838
+ paramKeyArr.forEach(key => {
839
+ params[key] = this[key];
840
+ })
841
+ this.$flowDialog.fillFlowDialogParams(params);
842
+ if (obj.nextType == "inclusiveGateway") {
843
+ let autoChooseUser = false;
844
+ (obj.result || []).forEach(item => {
845
+ //获取下一个节点信息
846
+ let nextNodeTmp = this.flowNodeIdToInfo[item.nextNodeId] || {};
847
+ if (nextNodeTmp.nodeType == "UserTask") {
848
+ item.mulitiChooseUser = nextNodeTmp.dealType != "single";
849
+ autoChooseUser = nextNodeTmp.autoChooseUser == "1";
850
+ if (item.mulitiChooseUser) {
851
+ this.$this.$set(this.chooseNextUserIdObj, item.nodeKey, []);
852
+ } else {
853
+ this.$this.$set(this.chooseNextUserIdObj, item.nodeKey, "");
854
+ }
855
+ } else if (this.nextNode.nodeType == "EndEvent") {
856
+ return;
857
+ }
858
+ let userArr = item.userArr || [];
859
+ //自动执行时的自动执行人
860
+ if (autoChooseUser) {
861
+ if (item.type == "user" && userArr.length == 0) {
862
+ // this.$this.$message({type:"error",message:"没有处理人!"});
863
+ return;
864
+ } else {
865
+ let userIds = "";
866
+ let userNames = "";
867
+ userArr.forEach(userInfo => {
868
+ userIds += "," + userInfo.id;
869
+ userNames += "," + userInfo.userName;
870
+ });
871
+ this.chooseNextUserIdObj[item.nodeKey] = userIds.substring(1);
872
+ this.chooseNextUserId = userIds.substring(1);
873
+ this.chooseNextUserName = userNames.substring(1);
874
+ this.$flowDialog.fillFlowDialogParams({
875
+ chooseNextUserId: this.chooseNextUserId,
876
+ chooseNextUserName: this.chooseNextUserName,
877
+ chooseNextUserIdObj: this.chooseNextUserIdObj
878
+ });
879
+ this.$flowDialog.saveNextStept();
880
+ }
881
+ }
882
+ item.nextSteptUserType = obj.type;
883
+ if (item.type == "user" || item.type== 'all') {
884
+ item.nextSteptUserArr = userArr;
885
+ }
886
+ });
887
+ if(!autoChooseUser){
888
+ this.nextSteptUserDialog = true;
889
+ this.$flowDialog.operateDialog('nextSteptUserDialog',true);
890
+ }
891
+ } else {
892
+ //获取下一个节点信息
893
+ this.nextNode = this.allNodeInfo[obj.nextNodeId] || {};
894
+ this.nextNodeName = obj.nextNodeName || "";
895
+ let autoChooseUser = false;
896
+ this.$flowDialog.fillFlowDialogParams({
897
+ nextNode: this.nextNode,
898
+ nextNodeName: this.nextNodeName
899
+ });
900
+ if (this.nextNode.nodeType == "UserTask") {
901
+ this.mulitiChooseUser = this.nextNode.dealType != "single";
902
+ autoChooseUser = this.nextNode.autoChooseUser == "1";
903
+ this.chooseNextUserId = "";
904
+ this.chooseNextUserName = "";
905
+ this.$flowDialog.fillFlowDialogParams({
906
+ chooseNextUserId: this.chooseNextUserId,
907
+ chooseNextUserName: this.chooseNextUserName
908
+ });
909
+ } else if (this.nextNode.nodeType == "EndEvent") {
910
+ this.nextSteptUserDialog = true;
911
+ this.$flowDialog.operateDialog('nextSteptUserDialog',true);
912
+ return;
913
+ }
914
+ let userArr = obj.userArr || [];
915
+ //自动执行时的自动执行人
916
+ if (autoChooseUser) {
917
+ if (obj.type == "user" && userArr.length == 0) {
918
+ this.$this.$message({type: "error", message: "没有处理人!"});
919
+ return;
920
+ } else {
921
+ let userIds = "";
922
+ let userNames = "";
923
+ userArr.forEach(userInfo => {
924
+ userIds += "," + userInfo.id;
925
+ userNames += "," + userInfo.userName;
926
+ });
927
+ if (userIds) {
928
+ this.chooseNextUserId = userIds.substring(1);
929
+ this.chooseNextUserName = userNames.substring(1);
930
+ }
931
+ this.$flowDialog.fillFlowDialogParams({
932
+ chooseNextUserId: this.chooseNextUserId,
933
+ chooseNextUserName: this.chooseNextUserName
934
+ });
935
+ this.$flowDialog.saveNextStept();
936
+ }
937
+ }
938
+ this.nextSteptUserType = obj.type;
939
+ if (obj.type == "user" || obj.type == 'all') {
940
+ this.nextSteptUserArr = userArr;
941
+ }
942
+ this.$flowDialog.fillFlowDialogParams({
943
+ nextSteptUserType: this.nextSteptUserType,
944
+ nextSteptUserArr: this.nextSteptUserArr
945
+ });
946
+ if(!autoChooseUser){
947
+ this.nextSteptUserDialog = true;
948
+ this.$flowDialog.operateDialog('nextSteptUserDialog',true);
949
+ }
950
+ }
951
+ if(this.nextNode.nextType == 'inclusiveGateway'){
952
+ (this.nextNode.result || []).forEach(item => {
953
+ this.chooseNextUserIdObj[item.nodeKey] = (item.userArr || {}).id;
954
+ });
955
+ this.$flowDialog.fillFlowDialogParams({
956
+ chooseNextUserIdObj: this.chooseNextUserIdObj,
957
+ });
958
+ }else{
959
+ let userInfo = this.nextSteptUserArr[0] || {};
960
+ if(this.nextNode.dealType=="single"){
961
+ this.chooseNextUserId = userInfo.id;
962
+ this.chooseNextUserName = userInfo.userName;
963
+ this.$flowDialog.fillFlowDialogParams({
964
+ chooseNextUserId: this.chooseNextUserId,
965
+ chooseNextUserName: this.chooseNextUserName
966
+ });
967
+ }
968
+ if(this.nextNode.dealType === "multi" && this.nextSteptUserArr.length === 1){
969
+ this.chooseNextUserId = [userInfo.id];
970
+ this.$flowDialog.fillFlowDialogParams({
971
+ chooseNextUserId: this.chooseNextUserId
972
+ });
973
+ }
974
+ }
975
+ });
976
+ })
977
+ });
978
+ }
979
+
980
+ nextStepAfterSaveFunc(){
981
+ return new Promise(resolve => {
982
+ if(this.nextStepAfterSave){
983
+ let result = this.nextStepAfterSave(this.$this,this);
984
+ if(result && result.then){
985
+ result.then(res => {
986
+ resolve(res);
987
+ })
988
+ }else{
989
+ resolve(result);
990
+ }
991
+ }else{
992
+ resolve(true);
993
+ }
994
+ })
995
+ }
996
+
997
+ saveDataFunc(type){ // 保存完成后返回流程的相关变量,通过变量传递到后台驱动流程运转
998
+ // 保存草稿、下一步保存
999
+ return new Promise(resolve => {
1000
+ if(this.saveFormInfo){
1001
+ let result = this.saveFormInfo(type);
1002
+ if(result && result.then){
1003
+ result.then(res => {
1004
+ if(!res){
1005
+ this.isDisabled['nextStep'] = true;
1006
+ return;
1007
+ }
1008
+ if(typeof res !== 'object'){
1009
+ res = {};
1010
+ }
1011
+ this.saveFlowData(res).then(flowInstData => {
1012
+ res['flowInstId'] = flowInstData.id;
1013
+ resolve(res);
1014
+ })
1015
+ })
1016
+ }else{
1017
+ if(!result){
1018
+ return;
1019
+ }
1020
+ if(typeof result !== 'object'){
1021
+ result = {};
1022
+ }
1023
+ this.saveFlowData(result).then(flowInstData => {
1024
+ result['flowInstId'] = flowInstData.id;
1025
+ resolve(result);
1026
+ })
1027
+ }
1028
+ }else{
1029
+ this.saveFlowData().then(flowInstData => {
1030
+ let obj = {};
1031
+ obj['flowInstId'] = flowInstData.id;
1032
+ resolve(obj);
1033
+ })
1034
+ }
1035
+ })
1036
+ }
1037
+
1038
+ saveFlowData(flowParams){
1039
+ return new Promise(resolve => {
1040
+ flowParams = flowParams || {};
1041
+ let flowSummary = this.getFlowSummary(flowParams);
1042
+ let flowInst = {};
1043
+ let dataId = (flowParams || {}).flowDataId || "";
1044
+ this.dataId = dataId;
1045
+ if(this.currentInst && this.currentInst.id){
1046
+ this.$this.$set(this.formInfo,"opt","update");
1047
+ flowInst = {
1048
+ "id": this.currentInst.id,
1049
+ "flowSummary": flowSummary,
1050
+ "updated": this.loginUser.id,
1051
+ };
1052
+ if(this.formInfo.opt == 'add' || !this.currentInst.linkProcId){ //版本号也要随之更新
1053
+ flowInst = Object.assign(flowInst,{"version":this.flowDefine.releaseVersion,"isRelease":this.flowDefine.isRelease})
1054
+ }
1055
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.url + "/" + this.formInfo.opt, flowInst).then(instRes => {
1056
+ this.runFlowEvt();
1057
+ resolve(instRes.data.operateObj);
1058
+ });
1059
+ }else{
1060
+ let startNodeKey = this.startNodeKeyObj[this.flowDefine.releaseVersion];
1061
+ if (this.formInfo.opt == "add") {
1062
+ flowInst = {
1063
+ flowId: this.flowDefine.id,
1064
+ flowSummary: flowSummary,
1065
+ dataId: dataId,
1066
+ version:this.flowDefine.releaseVersion, //版本号
1067
+ startTime: this.$this.DATE_UTIL.getCurrentDateTime(), flowStatus: "0",
1068
+ created: this.loginUser.id,
1069
+ currentNode: this.flowVersionNodeObj[this.flowDefine.releaseVersion][startNodeKey].id,
1070
+ isRelease:this.flowDefine.isRelease
1071
+ };
1072
+ } else {
1073
+ flowInst = {
1074
+ id: this.currentInst.id,
1075
+ flowSummary: flowSummary,
1076
+ version:this.flowDefine.releaseVersion, //版本号也要随之更新
1077
+ updated: this.loginUser.id,
1078
+ };
1079
+ }
1080
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.url + "/" + this.formInfo.opt, flowInst).then(instRes => {
1081
+ this.runFlowEvt();
1082
+ resolve(instRes.data.operateObj);
1083
+ this.currentInst=instRes.data.operateObj;
1084
+ });
1085
+ }
1086
+ })
1087
+ }
1088
+
1089
+ /**
1090
+ * 获取流程概要
1091
+ */
1092
+ getFlowSummary(dataObj, summaryTemplate) {
1093
+ let flowSummary = "";
1094
+ let summarySet = summaryTemplate || this.flowDefine.flowSummary;
1095
+ if (!this.currentInst.linkProcId) { // 草稿数据
1096
+ flowSummary = this.$this.platStringUtil.replaceAll(summarySet, "${startUserName*}", this.loginUser.userName);
1097
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${createTime*}", this.$this.DATE_UTIL.getCurrentDateTime());
1098
+ } else {
1099
+ flowSummary = this.$this.platStringUtil.replaceAll(summarySet, "${startUserName*}", this.currentStartUser);
1100
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${createTime*}", this.currentStartTime);
1101
+ }
1102
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${flowName*}", this.flowDefine.flowName);
1103
+ if (this.flowDefine.summaryNameId) {
1104
+ // flowSummary = flowSummary.toUpperCase();
1105
+ let summaryNameId = JSON.parse(this.flowDefine.summaryNameId);
1106
+ Object.keys(summaryNameId).forEach(fieldName => {
1107
+ let fieldId = summaryNameId[fieldName];
1108
+ if (fieldName && dataObj.hasOwnProperty(fieldId)) {
1109
+ let replaceVal = dataObj[fieldId];
1110
+ if(dataObj[fieldId + "_SASP_SYS_DATA"]){
1111
+ replaceVal = dataObj[fieldId+ "_SASP_SYS_DATA"];
1112
+ }
1113
+ if(dataObj[fieldId + "_sequence"]){ // 自增序列
1114
+ replaceVal = dataObj[fieldId + "_sequence"];
1115
+ }
1116
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${" + fieldName + "}", replaceVal);
1117
+ }else if(fieldName && dataObj.hasOwnProperty(fieldName)){
1118
+ let replaceVal = dataObj[fieldName];
1119
+ if(dataObj[fieldName + "_SASP_SYS_DATA"]){
1120
+ replaceVal = dataObj[fieldName+ "_SASP_SYS_DATA"];
1121
+ }
1122
+ if(dataObj[fieldName + "_sequence"]){ // 自增序列
1123
+ replaceVal = dataObj[fieldName + "_sequence"];
1124
+ }
1125
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${" + fieldName + "}", replaceVal);
1126
+ }else{
1127
+ flowSummary = this.$this.platStringUtil.replaceAll(flowSummary, "${" + fieldName + "}", "");
1128
+ }
1129
+ });
1130
+ }
1131
+ return flowSummary;
1132
+ }
1133
+
1134
+
1135
+ /**
1136
+ * 加载工作流脚本与工作流事件规则
1137
+ */
1138
+ initFlowScript(flowId){
1139
+ if (flowId) {
1140
+ this.flowDefine = this.flowDefineByFlowId[flowId] || {};
1141
+ }
1142
+ return new Promise(resolve => {
1143
+ this.$this.saspFlowAxios.all([
1144
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowScript.find,{"flowId": this.flowDefine.id}),
1145
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowEventDetail.findByFlowAndLeadFunc,{"flowId": this.flowDefine.id,"version":this.flowDefine.flowVersion || "1.0"})
1146
+ ]).then(this.$this.saspFlowAxios.spread((resScript, resEvent) => {
1147
+ // 流程脚本
1148
+ if(resScript){
1149
+ let scriptDatas = resScript.data || [];
1150
+ // 脚本order排序
1151
+ scriptDatas = scriptDatas.sort(sortScript);
1152
+ function sortScript(a,b){
1153
+ return Number(a.scriptOrder) - Number(b.scriptOrder);
1154
+ }
1155
+ // 根据节点区分
1156
+ let scriptObj = {};
1157
+ let arr = ['vm','axios','CTX','formData','LOGINUSER','Ajax','nextNode','resolve'];
1158
+ scriptDatas.forEach(item => {
1159
+ // 添加修改是单独区分开,没有节点概念
1160
+ if(item.executePosition == "add" || item.executePosition == "update"){
1161
+ if(!scriptObj[item.executePosition]){
1162
+ scriptObj[item.executePosition] = {};
1163
+ }
1164
+ if(!scriptObj[item.executePosition][item.executeTime]){
1165
+ scriptObj[item.executePosition][item.executeTime] = [];
1166
+ }
1167
+ try{
1168
+ if(item.content){
1169
+ let value = item.content;
1170
+ value = this.replaceUrl(value);
1171
+ item.content = value;
1172
+ }
1173
+ scriptObj[item.executePosition][item.executeTime].push(new Function(...arr,item.content));
1174
+ }catch (e) {
1175
+ console.log(item.content);
1176
+ console.log("脚本编译失败!");
1177
+ }
1178
+ }else{
1179
+ if(!scriptObj[item.nodeId]){
1180
+ scriptObj[item.nodeId] = {};
1181
+ }
1182
+ let nodeObj = scriptObj[item.nodeId]; // 节点的所有内容
1183
+ if(!nodeObj[item.executePosition]){
1184
+ nodeObj[item.executePosition] = {};
1185
+ }
1186
+ let positionObj = nodeObj[item.executePosition]; // 脚本的执行位置,add,update,deal,等
1187
+ if(!positionObj[item.executeTime]){
1188
+ positionObj[item.executeTime] = [];
1189
+ }
1190
+ let executeTimeArr = positionObj[item.executeTime]; // 在该时间对应的脚本内容数组
1191
+ try{
1192
+ if(item.content){
1193
+ let value = item.content;
1194
+ value = this.replaceUrl(value);
1195
+ item.content = value;
1196
+ }
1197
+ executeTimeArr.push(new Function(...arr,item.content));
1198
+ }catch (e) {
1199
+ console.log(item.content);
1200
+ console.log("脚本编译失败!");
1201
+ }
1202
+ }
1203
+ })
1204
+ this.scriptObj = scriptObj;
1205
+ }
1206
+ // 流程事件规则
1207
+ if(resEvent){
1208
+ let eventDataArr = resEvent.data || [];
1209
+ let scriptObj = {};
1210
+ let eventObj = {};
1211
+ let arr = ['vm','axios','CTX','formData','LOGINUSER','Ajax','nextNode','resolve'];
1212
+ eventDataArr.forEach(item =>{
1213
+ let executeTypeArr = (item.executeType || '').split(",");
1214
+ executeTypeArr.forEach(executeType =>{
1215
+ if (item.source == 'diy'){
1216
+ //自定义
1217
+ // 添加是单独区分开,没有节点概念
1218
+ if(executeType == "addAfter"){
1219
+ if(!scriptObj[executeType]){
1220
+ scriptObj[executeType] = [];
1221
+ }
1222
+ try{
1223
+ if(item.funcBody){ //方法体
1224
+ let value = item.funcBody;
1225
+ value = this.replaceUrl(value);
1226
+ item.funcBody = value;
1227
+ }
1228
+ scriptObj[executeType].push(new Function(...arr,item.funcBody));
1229
+ }catch (e) {
1230
+ console.log(item.funcBody);
1231
+ console.log("脚本编译失败!");
1232
+ }
1233
+ }else{
1234
+ if(!scriptObj[item.nodeKey]){
1235
+ scriptObj[item.nodeKey] = {};
1236
+ }
1237
+ let nodeObj = scriptObj[item.nodeKey]; // 节点的所有内容
1238
+ if(!nodeObj[executeType]){
1239
+ nodeObj[executeType] = [];
1240
+ }
1241
+ let positionArr = nodeObj[executeType]; // 脚本的执行位置,add,update,deal,等
1242
+ try{
1243
+ if(item.funcBody){
1244
+ let value = item.funcBody;
1245
+ value = this.replaceUrl(value);
1246
+ item.funcBody = value;
1247
+ }
1248
+ positionArr.push(new Function(...arr,item.funcBody));
1249
+ }catch (e) {
1250
+ console.log(item.funcBody);
1251
+ console.log("脚本编译失败!");
1252
+ }
1253
+ }
1254
+ this.newScriptObj = scriptObj;
1255
+ }else if(item.source == 'event'){ //事件规则
1256
+ //获取响应配置
1257
+ // 添加单独区分开,没有节点概念
1258
+ if(executeType == "addAfter"){
1259
+ if(!eventObj[executeType]){
1260
+ eventObj[executeType] = {};
1261
+ }
1262
+ try{
1263
+ if(item.resConfigurateion){ //响应配置
1264
+ let resConfigurateionObj = JSON.parse(item.resConfigurateion || "{}");
1265
+ let eventKey = resConfigurateionObj.eventKey;
1266
+ if(!eventObj[executeType][eventKey]){
1267
+ eventObj[executeType][eventKey] = [];
1268
+ }
1269
+ eventObj[executeType][eventKey].push(resConfigurateionObj); //复制响应配置
1270
+ }
1271
+ }catch (e) {
1272
+ console.log(item.funcBody);
1273
+ console.log("脚本编译失败!");
1274
+ }
1275
+ }else{
1276
+ if(!eventObj[item.nodeKey]){
1277
+ eventObj[item.nodeKey] = {};
1278
+ }
1279
+ let nodeObj = eventObj[item.nodeKey]; // 节点的所有内容
1280
+ if(!nodeObj[executeType]){
1281
+ nodeObj[executeType] = {};
1282
+ }
1283
+ let positionObj = nodeObj[executeType]; // 脚本的执行位置,add,update,deal,等
1284
+ try{
1285
+ if(item.resConfigurateion){//响应配置
1286
+ let resConfigurateionObj = JSON.parse(item.resConfigurateion || "{}");
1287
+ let eventKey = resConfigurateionObj.eventKey;
1288
+ if(!positionObj[eventKey]){
1289
+ positionObj[eventKey] = [];
1290
+ }
1291
+ positionObj[eventKey].push(resConfigurateionObj); //复制响应配\
1292
+ }
1293
+ }catch (e) {
1294
+ console.log(item.funcBody);
1295
+ console.log("脚本编译失败!");
1296
+ }
1297
+ }
1298
+ this.newEventObj = eventObj;
1299
+ }
1300
+ });
1301
+ });
1302
+ }
1303
+ // 结束
1304
+ let obj = {"scriptObj": this.scriptObj, "newScriptObj": this.newScriptObj, "newEventObj": this.newEventObj};
1305
+ resolve({[flowId]: obj});
1306
+ }));
1307
+ })
1308
+ }
1309
+
1310
+ /**
1311
+ * 执行下一步
1312
+ * @returns {Promise<boolean>} 是否继续流程
1313
+ */
1314
+ async executeNextStep() {
1315
+
1316
+ }
1317
+
1318
+ /**
1319
+ * 取消当前流程
1320
+ */
1321
+ cancel() {
1322
+
1323
+ }
1324
+
1325
+ // 脚本执行区
1326
+
1327
+ setFlowScript(flowId) {
1328
+ if (flowId) {
1329
+ let scriptObj = this.flowEventScriptByFlowId[flowId] || {};
1330
+ this.scriptObj = scriptObj.scriptObj || {};
1331
+ this.newScriptObj = scriptObj.newScriptObj || {};
1332
+ this.newEventObj = scriptObj.newEventObj || {};
1333
+ }
1334
+ }
1335
+
1336
+ runFlowEvt(){
1337
+ // let afterClickResult;
1338
+ let currentNodeObj = this.flowNodeIdToInfo[this.currentInst.currentNode || this.draftNodeId] ||{};
1339
+ if(currentNodeObj.openEvent == '1'){
1340
+ this.exeNewFlowEvent("saveAfter", currentNodeObj.nodeLinkId);
1341
+ }
1342
+ }
1343
+
1344
+ /**
1345
+ * 执行工作流脚本,为兼容1.0版本定制
1346
+ */
1347
+ exeFlowEvent(executePosition,executeTime,nodeId){
1348
+ // executePosition(为方便1.0转换,与1.0保持相同):add/update/handle/nextStep/view/columnFormatter
1349
+ // executePosition:add:['afterClick'],update:['afterClick'],handle:['afterClick'],
1350
+ // nextStep:['afterClick','afterValidate','submitSuccess'],view:['afterClick'],
1351
+ // (columnFormatter:['finished','end']?暂时不用)
1352
+ let formData = {};
1353
+ if(this.getFormInfo){
1354
+ formData = this.getFormInfo();
1355
+ }
1356
+ let CTX = "";
1357
+ let paramValues = [this,this.$this.saspFlowAxios,CTX,formData,this.loginUser,AjaxUtil,this.nextNode,null]; // 入参
1358
+ if(executePosition == "add" || executePosition == "update"){
1359
+ ((this.scriptObj[executePosition] || {})[executeTime] || []).forEach(event => {
1360
+ event && event(...paramValues); // 执行事件
1361
+ });
1362
+ return;
1363
+ }
1364
+ let eventArr = ((this.scriptObj[nodeId] || {})[executePosition] || {})[executeTime] || [];
1365
+ let result=true;
1366
+ try{
1367
+ eventArr.forEach(event => {
1368
+ let eventResult=event && event(...paramValues); // 执行事件
1369
+ if(eventResult ==false){
1370
+ throw new Error("ending");//报错,就跳出循环
1371
+ }
1372
+ })
1373
+ }catch (e) {
1374
+ console.log(e);
1375
+ result=false;
1376
+ }
1377
+ return result;
1378
+ }
1379
+
1380
+ /**
1381
+ * 执行工作流新版本事件规则
1382
+ */
1383
+ exeNewFlowEvent(executeType,nodeKey){
1384
+ let formData = {};
1385
+ if(this.getFormInfo){
1386
+ formData = this.getFormInfo();
1387
+ }
1388
+ //执行自定义脚本
1389
+ // let CTX = window.JAVA_URL;
1390
+ let CTX = "";
1391
+ let paramValues = [this,this.$this.saspFlowAxios,CTX,formData,this.loginUser,AjaxUtil,this.nextNode]; // 入参
1392
+ if(executeType == "addAfter"){ //新增或后
1393
+ (this.newScriptObj[executeType] || []).forEach(event => {
1394
+ event && event(...paramValues); // 执行事件
1395
+ });
1396
+
1397
+ //执行事件规则脚本
1398
+ Object.keys(this.newEventObj[executeType] || {}).forEach(eventKey =>{
1399
+ if(this.installListObj[eventKey]
1400
+ && this.installListObj[eventKey]["config"]
1401
+ && this.installListObj[eventKey]["config"].methods.renderFlowConfig){
1402
+ let affectContentArr = this.newEventObj[executeType][eventKey] || [];
1403
+ affectContentArr.forEach(affectContent =>{
1404
+ this.installListObj[eventKey]["config"].methods.renderFlowConfig(this.$this,this.$this.CTX,this.$this.saspFlowAxios,this.nextNode,formData,affectContent);
1405
+ });
1406
+ }
1407
+ });
1408
+ return;
1409
+ }
1410
+ let eventArr = (this.newScriptObj[nodeKey] || {})[executeType] || [];
1411
+ let result=true;
1412
+ try{
1413
+ eventArr.forEach(event => {
1414
+ let eventResult=event && event(...paramValues); // 执行事件
1415
+ if(eventResult ==false){
1416
+ throw new Error("ending");//报错,就跳出循环
1417
+ }
1418
+ });
1419
+
1420
+ let eventObj = (this.newEventObj[nodeKey] || {})[executeType] || {};
1421
+ Object.keys(eventObj).forEach(eventKey =>{
1422
+ if(this.installListObj[eventKey]
1423
+ && this.installListObj[eventKey]["config"]
1424
+ && this.installListObj[eventKey]["config"].methods.renderFlowConfig){
1425
+ let affectContentArr = eventObj[eventKey] || [];
1426
+ affectContentArr.forEach(affectContent =>{
1427
+ this.installListObj[eventKey]["config"].methods.renderFlowConfig(this.$this,this.$this.CTX,this.$this.saspFlowAxios,this.nextNode,formData,affectContent,executeType);
1428
+ });
1429
+ }
1430
+ });
1431
+ }catch (e) {
1432
+ console.log(e);
1433
+ result=false;
1434
+ }
1435
+
1436
+ return result;
1437
+
1438
+ }
1439
+ // end脚本执行结束
1440
+
1441
+
1442
+ // buttonMethod,按钮方法
1443
+
1444
+ // 打开前方法
1445
+ /**
1446
+ * 打开[添加]窗口
1447
+ */
1448
+ openAddFlowForm() {
1449
+ return new Promise(resolve => {
1450
+ this.init().then(() => {
1451
+ let nowVersion = this.flowDefine.releaseVersion; //只要已发布最小版本为1.0
1452
+ this.currentRowData = {};
1453
+ this.initFieldStatus(this.startNodeKeyObj[nowVersion],nowVersion).then(()=>{
1454
+ this.flowInstDataDialog = true;
1455
+ this.$flowDialog.operateDialog('flowInstDataDialog',true);
1456
+ this.$this.$nextTick(() => {
1457
+ this.initFormInfoFunc('add').then(() => {
1458
+ this.formBtnArr = this.getAddAndUpdateFormBtn({});
1459
+ Object.assign(this.formInfo, {
1460
+ dataId: "",
1461
+ opt: "add"
1462
+ });
1463
+ this.currentInst = {};
1464
+ this.$this.$nextTick(() => {
1465
+ this.exeFlowEvent("add","afterClick");
1466
+ let startNodeKey = this.startNodeKeyObj[nowVersion];
1467
+ let startNodeObj = this.flowVersionNodeObj[nowVersion][startNodeKey] || {};
1468
+ if(startNodeObj.openEvent == '1'){
1469
+ this.exeNewFlowEvent("addAfter");//新事件规则
1470
+ }
1471
+ })
1472
+ let result = {
1473
+ currentRowData: this.currentRowData,
1474
+ formBtnArr: this.formBtnArr,
1475
+ currentInst: this.currentInst,
1476
+ formInfo: this.formInfo
1477
+ };
1478
+ this.$flowDialog.fillFlowDialogParams(result);
1479
+ resolve(result);
1480
+ })
1481
+ });
1482
+ });
1483
+ })
1484
+ });
1485
+ }
1486
+
1487
+ initFormInfoFunc(type,rowData){
1488
+ if(!rowData){
1489
+ rowData = {};
1490
+ }
1491
+ let dataId = rowData.dataId || "";
1492
+ let nodeObjs = this.flowVersionNodeObj[this.flowDefine.releaseVersion];
1493
+ let startNodeKey = this.startNodeKeyObj[rowData.version];
1494
+ let nodeKey = rowData.nodeKey;
1495
+ let currentNode = nodeObjs[nodeKey || startNodeKey];
1496
+ if(type === 'add'){
1497
+ let version = this.flowDefine.releaseVersion;
1498
+ currentNode = this.flowVersionNodeObj[version][this.startNodeKeyObj[version]];
1499
+ }
1500
+ return new Promise(resolve => {
1501
+ if(this.initFormInfo){
1502
+ let promise = this.initFormInfo(type,dataId,JSON.parse(currentNode.fieldOperate || "{}"),rowData);
1503
+ this.forceUpdateComponent && this.forceUpdateComponent();
1504
+ if(promise.then){
1505
+ promise.then(() => {
1506
+ resolve();
1507
+ })
1508
+ }else{
1509
+ resolve();
1510
+ }
1511
+ } else{
1512
+ resolve();
1513
+ }
1514
+ })
1515
+ }
1516
+ /**
1517
+ * 打开[修改和处理]窗口
1518
+ */
1519
+ initUpdateFlowForm(row, type) {
1520
+ this.currentRowData = row;
1521
+ this.currNodeName = 'noEnd';
1522
+ if (this.flowId.includes(',')) {
1523
+ this.flowDefine = this.flowDefineByFlowId[row.flowId];
1524
+ this.startNodeKeyObj = this.startNodeKeyObjByFlowId[row.flowId];
1525
+ this.flowVersionNodeObj = this.flowVersionNodeObjByFlowId[row.flowId];
1526
+ this.initFlowObj();
1527
+ // 加载工作流脚本与工作流事件规则
1528
+ // this.initFlowScript();
1529
+ // Object.assign(this.formInfo, this.formInfoByFlowId[row.flowId]);
1530
+ }
1531
+
1532
+ return new Promise(resolve => {
1533
+ let startNodeKey = this.startNodeKeyObj[row.version];
1534
+ this.initFieldStatus(row.nodeKey || startNodeKey,row.version).then(()=>{
1535
+ this.initFormInfoFunc(type,row).then(() => {
1536
+ this.currentStartUser = this.userMap[row.startUserId] || "";
1537
+ this.currentStartTime = row.startTime;
1538
+ this.currentInst = row;
1539
+
1540
+ Object.assign(this.formInfo, {
1541
+ dataId: row.dataId,
1542
+ opt: "update"
1543
+ });
1544
+ this.formBtnArr = this.getAddAndUpdateFormBtn(row);
1545
+ let result = {
1546
+ currentRowData: this.currentRowData,
1547
+ currNodeName : this.currNodeName,
1548
+ flowDefine: this.flowDefine,
1549
+ startNodeKeyObj: this.startNodeKeyObj,
1550
+ flowVersionNodeObj: this.flowVersionNodeObj,
1551
+ currentStartUser : this.currentStartUser,
1552
+ currentStartTime : this.currentStartTime,
1553
+ currentInst : this.currentInst,
1554
+ formInfo : this.formInfo,
1555
+ formBtnArr : this.formBtnArr,
1556
+ dataId : row.dataId
1557
+ }
1558
+ resolve(result);
1559
+ });
1560
+ })
1561
+ })
1562
+ }
1563
+
1564
+ /**
1565
+ * 打开[修改和处理]窗口
1566
+ */
1567
+ openUpdateFlowForm(row,executePosition) {
1568
+ return new Promise(resolve => {
1569
+ this.init().then(() => {
1570
+ if (this.flowId.includes(",")) {
1571
+ this.setFlowScript(row.flowId);
1572
+ }
1573
+ this.currentRowData = row;
1574
+ this.currNodeName = 'noEnd';
1575
+ let currentNodeObj1 = this.flowNodeIdToInfo[row.currentNode] ||{};
1576
+ let result = this.exeNewFlowEvent("editBefore",currentNodeObj1.nodeLinkId ||'');//新事件规则
1577
+ if(result === false && typeof result == "boolean"){
1578
+ return;
1579
+ }
1580
+ this.flowInstDataDialog = true;
1581
+ this.$flowDialog.fillFlowDialogParams({
1582
+ flowDefine: this.flowDefine,
1583
+ formInfo: this.formInfo
1584
+ });
1585
+ this.$flowDialog.operateDialog('flowInstDataDialog',true);
1586
+ this.initUpdateFlowForm(row, 'update').then(() =>{
1587
+ this.$this.$nextTick(() => {
1588
+ this.exeFlowEvent(executePosition,"afterClick",row.currentNode);
1589
+ let currentNodeObj = this.flowNodeIdToInfo[row.currentNode] ||{};
1590
+ if(currentNodeObj.openEvent === '1'){ //开启事件
1591
+ this.exeNewFlowEvent("editAfter",currentNodeObj.nodeLinkId ||'');//新事件规则
1592
+ }
1593
+ let result = {
1594
+ currentRowData: this.currentRowData,
1595
+ currNodeName : this.currNodeName,
1596
+ flowDefine: this.flowDefine,
1597
+ startNodeKeyObj: this.startNodeKeyObj,
1598
+ flowVersionNodeObj: this.flowVersionNodeObj,
1599
+ currentStartUser : this.currentStartUser,
1600
+ currentStartTime : this.currentStartTime,
1601
+ currentInst : this.currentInst,
1602
+ formInfo : this.formInfo,
1603
+ formBtnArr : this.formBtnArr
1604
+ }
1605
+ this.$flowDialog.fillFlowDialogParams(result);
1606
+ resolve(result);
1607
+ })
1608
+ });
1609
+ });
1610
+ });
1611
+ }
1612
+
1613
+ /**
1614
+ * 打开[查看]窗口
1615
+ */
1616
+ openViewFlowForm(row) {
1617
+ return new Promise(resolve => {
1618
+ this.init().then(() => {
1619
+ this.currentRowData = row;
1620
+ let startNodeKey = this.startNodeKeyObj[row.version];
1621
+ if (row.currentNodeName === "结束"){
1622
+ this.currNodeName = "end";
1623
+ }
1624
+ this.initFieldStatus(row.nodeKey || startNodeKey,row.version,row.flowStatus).then(() =>{
1625
+ this.$flowDialog.fillFlowDialogParams({
1626
+ flowDefine: this.flowDefine,
1627
+ formInfo: this.formInfo
1628
+ });
1629
+ this.flowInstDataDialog = true;
1630
+ this.$flowDialog.operateDialog('flowInstDataDialog',true);
1631
+ this.$this.$nextTick(() => {
1632
+ this.initFormInfoFunc('view',row).then(() => {
1633
+ this.currentStartUser = this.userMap[row.startUserId] || "";
1634
+ this.currentStartTime = row.startTime;
1635
+ this.currentInst = row;
1636
+
1637
+ Object.assign(this.formInfo, {
1638
+ dataId: row.dataId,
1639
+ opt: "view",
1640
+ });
1641
+ this.formBtnArr = this.getViewFormBtn(row);
1642
+ let result = {
1643
+ currentRowData: this.currentRowData,
1644
+ currNodeName : this.currNodeName,
1645
+ currentStartUser : this.currentStartUser,
1646
+ currentStartTime : this.currentStartTime,
1647
+ currentInst : this.currentInst,
1648
+ formInfo : this.formInfo,
1649
+ formBtnArr : this.formBtnArr,
1650
+ }
1651
+ this.$flowDialog.fillFlowDialogParams(result);
1652
+ resolve(result);
1653
+ });
1654
+ });
1655
+ });
1656
+ });
1657
+ })
1658
+ }
1659
+
1660
+ // 打开前方法end
1661
+
1662
+
1663
+
1664
+ /**
1665
+ * 存草稿
1666
+ */
1667
+ saveDraft() {
1668
+ // let loading = this.$this.$loading({
1669
+ // lock: true,
1670
+ // spinner: 'el-icon-loading',
1671
+ // background: 'rgba(0, 0, 0, 0.7)'
1672
+ // })
1673
+
1674
+ this.saveDataFunc('draft').then(resData => {
1675
+ this.tabCrudSearch && this.tabCrudSearch(); // todo 回调刷新方法,初始化置入即可
1676
+
1677
+ this.flowInstDataDialog = false;
1678
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
1679
+ if (resData.flowInstId) {
1680
+ this.$this.$message({type: "success", message: "保存成功!"});
1681
+ if (this.getFlowBatchDialog && this.getFlowBatchDialog()) {//批量处理 需处理tab页
1682
+ this.batchSaveDraft();
1683
+ }
1684
+ } else {
1685
+ this.$this.$message({type: "error", message: "保存失败!"});
1686
+ }
1687
+ // loading && loading.close();
1688
+ this.currentInst={};
1689
+ });
1690
+ }
1691
+
1692
+ /**
1693
+ * 批量处理存草稿
1694
+ */
1695
+ batchSaveDraft() {
1696
+ this.batchTabRemove(this.currentInst.dataId);
1697
+ }
1698
+
1699
+ /**
1700
+ * 回退到上一步
1701
+ */
1702
+ backToPrevious() {
1703
+ let loading = this.$this.$loading({
1704
+ lock: true,
1705
+ text: '正在退回,请稍后....',
1706
+ spinner: 'el-icon-loading',
1707
+ background: 'rgba(0, 0, 0, 0.7)'
1708
+ })
1709
+ let currentInst = this.currentInst;
1710
+ this.$this.$prompt('退回备注', '确定要退回至上一个节点吗?', {
1711
+ confirmButtonText: '确定',
1712
+ cancelButtonText: '取消',
1713
+ inputType: 'textarea',
1714
+ }).then(({ value }) => {
1715
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.backRewrite,
1716
+ {
1717
+ taskId:currentInst.taskId,
1718
+ remarks: value
1719
+ }).then(res => {
1720
+ if (res && res.data && res.data.operateSuccess) {
1721
+ this.$this.$message({type: "success", message: "退回成功!"});
1722
+ this.initTabNum && this.initTabNum();
1723
+ if (this.getFlowBatchDialog && this.getFlowBatchDialog()) {
1724
+ this.batchTabRemove(this.currentInst.dataId);
1725
+ } else {
1726
+ this.tabCrudSearch && this.tabCrudSearch();
1727
+ }
1728
+ } else {
1729
+ this.$this.$message({type: "error", message: res.data.operateMessage});
1730
+ }
1731
+ loading && loading.close();
1732
+ this.flowInstDataDialog = false;
1733
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
1734
+ })
1735
+ }).catch(() => {
1736
+ loading && loading.close();
1737
+ });
1738
+ }
1739
+
1740
+
1741
+ /**
1742
+ * 取回
1743
+ */
1744
+ getBackPrevious() {
1745
+ let loading = this.$this.$loading({
1746
+ lock: true,
1747
+ text: '正在取回,请稍后....',
1748
+ spinner: 'el-icon-loading',
1749
+ background: 'rgba(0, 0, 0, 0.7)'
1750
+ })
1751
+ let currentInst = this.currentInst;
1752
+ this.$this.$confirm('确定要取回吗?', '警告', {
1753
+ confirmButtonText: '确定',
1754
+ cancelButtonText: '取消',
1755
+ }).then(() => {
1756
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.getBackRewrite,
1757
+ {
1758
+ flowInstId: currentInst.flowInstId,
1759
+ }).then(res => {
1760
+ if (res && res.data && res.data.operateSuccess) {
1761
+ this.$this.$message({type: "success", message: "取回成功!"});
1762
+ this.initTabNum && this.initTabNum();
1763
+ if (this.getFlowBatchDialog && this.getFlowBatchDialog()) {
1764
+ this.batchTabRemove(this.currentInst.dataId);
1765
+ } else {
1766
+ this.tabCrudSearch && this.tabCrudSearch();
1767
+ }
1768
+ } else {
1769
+ this.$this.$message({type: "error", message: res.data.operateMessage});
1770
+ }
1771
+ loading && loading.close();
1772
+ this.flowInstDataDialog = false;
1773
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
1774
+ })
1775
+ }).catch(() => {
1776
+ loading && loading.close();
1777
+ });
1778
+ }
1779
+
1780
+ /**
1781
+ * 打开退回节点窗口
1782
+ */
1783
+ retSpecified(currentInst){
1784
+ let flowInstId = currentInst.flowInstId;
1785
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.getBackData,{"flowInstId":flowInstId}).then(res => {
1786
+ this.backNodeArr = [];
1787
+ if(res.data.operateSuccess){
1788
+ let result = res.data.resultObject || [];
1789
+ if(result.length == 0){
1790
+ this.$this.$message.warning("没有可以退回的节点!");
1791
+ return;
1792
+ }
1793
+ let arr = [];
1794
+ result.forEach((item,index) =>{
1795
+ // if(index != res.data.resultObject.length -1){
1796
+ // this.backNodeArr.push(item);
1797
+ // }
1798
+ if(item["endTimeNull"]){
1799
+ arr.push(item);
1800
+ }else{
1801
+ this.backNodeArr.push(item);
1802
+ }
1803
+ });
1804
+ this.backNodeArr = this.backNodeArr.concat(arr);
1805
+ this.backNodeArr.splice(this.backNodeArr.length - 1,1);
1806
+ this.isDisabled2 = true;
1807
+ this.backMsg = "";
1808
+ this.backNodeId = "";
1809
+ this.backDialogVisible = true;
1810
+ this.$flowDialog.operateDialog('backDialogVisible',true);
1811
+ }
1812
+ })
1813
+ }
1814
+
1815
+ /**
1816
+ * 恢复方法
1817
+ */
1818
+ restoreFlow() {
1819
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.stopFlow, {
1820
+ instId: this.currentInst.flowInstId, type: "1",
1821
+ procInstId: this.currentInst.linkProcId,
1822
+ taskId: this.currentInst.taskId
1823
+ }).then(res => {
1824
+ if (res && res.data) {
1825
+ if (res.data.operateSuccess) {
1826
+ this.$this.$message({type: "success", message: "恢复成功!"});
1827
+ this.flowInstDataDialog = false;
1828
+ this.$flowDialog.operateDialog('flowInstDataDialog',false);
1829
+ if (this.getFlowBatchDialog && this.getFlowBatchDialog()) {
1830
+ this.batchTabRemove(this.currentInst.dataId);
1831
+ } else {
1832
+ this.tabCrudSearch && this.tabCrudSearch();
1833
+ }
1834
+ this.initTabNum && this.initTabNum();
1835
+ } else {
1836
+ this.$this.$message({type: "error", message: res.data.operateMessage});
1837
+ }
1838
+ }
1839
+ })
1840
+ }
1841
+
1842
+ /**
1843
+ * 打开流转记录窗口
1844
+ * @param row 流程行数据
1845
+ */
1846
+ openFlowRecord(row) {
1847
+ let arr = ["2", "3", "4"]; // 旧版本的已办结已撤销以及已中止数据通过旧版接口查询流转记录
1848
+ if (arr.indexOf(row.flowStatus) > -1 && row.isOldData === "1") {
1849
+ this.flowRecordObj = {instId: row.flowInstId || "", oldDialogVisible: true};
1850
+ } else {
1851
+ this.flowRecordObj = {instId: row.flowInstId || "", dialogVisible: true};
1852
+ }
1853
+ this.$flowDialog.fillFlowDialogParams({
1854
+ flowRecordObj: this.flowRecordObj
1855
+ });
1856
+ }
1857
+
1858
+ // end of button methods 按钮方法结束
1859
+
1860
+ // 功能区域,用于作为一些方法处理数据
1861
+
1862
+ // 自定义按钮窗口回调函数
1863
+ openDiyButtonEvent(type,row, button) {
1864
+ let formData = {};
1865
+ if(this.getFormInfo){
1866
+ formData = this.getFormInfo();
1867
+ }
1868
+ if(type === 'list') {
1869
+ this.execDiyBtnScripts(type,row,button.funcBody);
1870
+ }else {
1871
+ this.execDiyBtnScripts(type,formData,button.funcBody);
1872
+ }
1873
+ }
1874
+
1875
+ judeDiyButton(tabActive,button) {
1876
+ if(tabActive === 'pending') {
1877
+ return button.position === 'table' && button.nodeId === this.currentInst.currentNode;
1878
+ }
1879
+ return button.position === 'table' && button.buttonSign.indexOf(tabActive) > -1;
1880
+ }
1881
+
1882
+ execDiyBtnScripts(type,data,fnBody) {
1883
+ try {
1884
+ fnBody = this.replaceUrl(fnBody);
1885
+ fnBody = fnBody.replace(/\\'/g, "'").replace(/&quot;/g, "\"");
1886
+ if(type === 'list') {
1887
+ new Function('vm,rowData,Ajax', fnBody)(this.$this,data,AjaxUtil);
1888
+ }else {
1889
+ new Function('vm,formData,Ajax', fnBody)(this.$this,data,AjaxUtil);
1890
+ }
1891
+ } catch (e) {
1892
+ console.log("自定义按钮事件执行错误!", e);
1893
+ }
1894
+ }
1895
+
1896
+ /**
1897
+ * 获取[添加、修改和处理]的操作按钮
1898
+ */
1899
+ getAddAndUpdateFormBtn(row) {
1900
+ //走版本
1901
+ let arrNodeFormBtns = [];
1902
+ if(row.version){
1903
+ arrNodeFormBtns = this.nodeFormBtnObj[(this.flowVersionNodeObj[row.version][row.nodeKey || this.startNodeKeyObj[row.version]] || {}).id];
1904
+ }else {
1905
+ arrNodeFormBtns = this.nodeFormBtnObj[this.flowVersionNodeObj[this.flowDefine.releaseVersion][this.startNodeKeyObj[this.flowDefine.releaseVersion]].id];
1906
+ }
1907
+ let hideBtnTypes = new Set(["getBack","stopped"]);
1908
+ if (this.tabActive == "draft") {
1909
+ hideBtnTypes.add("flowRecord");
1910
+ hideBtnTypes.add("record");
1911
+ }else if(this.tabActive == "pending"){//待处理
1912
+ hideBtnTypes.add("cancel");
1913
+ if(row.operateStatus=='1'||row.operateStatus=='3'){//如果是加签转签 不需要部分按钮
1914
+ hideBtnTypes.add("retSpecified");
1915
+ hideBtnTypes.add("back");
1916
+ hideBtnTypes.add("completeSign");
1917
+ hideBtnTypes.add("turnSign");
1918
+ }
1919
+ }
1920
+
1921
+ return this.formatterFormBtnByHideBtnTypes(arrNodeFormBtns, hideBtnTypes);
1922
+ }
1923
+
1924
+ /**
1925
+ * 根据隐藏按钮类型格式化按钮信息
1926
+ */
1927
+ formatterFormBtnByHideBtnTypes(arrFormBtns, hideBtnTypes) {
1928
+ let arrResults = [];
1929
+ arrFormBtns.forEach(data => {
1930
+ let objTmp = Object.assign({}, data);
1931
+ hideBtnTypes.has(data.btnType) && (objTmp.show = false);
1932
+ if(this.tabActive == "discontinue" && data.btnType == "restore" && !hideBtnTypes.has(data.btnType)){
1933
+ objTmp.show = true;
1934
+ }
1935
+ if(this.tabActive == "processed" && data.btnType == "getBack" && !hideBtnTypes.has(data.btnType)){
1936
+ objTmp.show = true;
1937
+ }
1938
+ if(this.tabActive == "processed" && data.btnType == "cancel" && !hideBtnTypes.has(data.btnType)){
1939
+ objTmp.show = true;
1940
+ }
1941
+ arrResults.push(objTmp);
1942
+ });
1943
+ return arrResults;
1944
+ }
1945
+
1946
+ /**
1947
+ * 获取[查看]的操作按钮
1948
+ */
1949
+ getViewFormBtn(row) {
1950
+ //走版本
1951
+ let arrNodeFormBtns = [];
1952
+ if(row.version){
1953
+ arrNodeFormBtns = this.nodeFormBtnObj[(this.flowVersionNodeObj[row.version][row.nodeKey || this.startNodeKeyObj[row.version]] || {}).id];
1954
+ }else {
1955
+ arrNodeFormBtns = this.nodeFormBtnObj[this.flowVersionNodeObj[this.flowDefine.releaseVersion][this.startNodeKeyObj[this.flowDefine.releaseVersion]].id];
1956
+ }
1957
+ let hideBtnTypes = new Set(["getBack", "cancel", "restore"]);
1958
+ if (this.tabActive == "processed") { // 已处理
1959
+
1960
+ // 上个节点的处理可以取回(已开启按钮的情况下)
1961
+ if ((row.beforeDealer || "").split(",").indexOf(this.loginUser.id) > -1) {
1962
+ hideBtnTypes.delete("getBack");
1963
+ }
1964
+
1965
+ // 流程的发起人可以撤销(已开启按钮的情况下)
1966
+ if (row.startUserId == this.loginUser.id) {
1967
+ // hideBtnTypes.delete("cancel");
1968
+ }
1969
+ //被挂起数据只有查看按钮
1970
+ if(row.hangUp == '1'){
1971
+ hideBtnTypes.add("getBack");
1972
+ hideBtnTypes.add("cancel");
1973
+ hideBtnTypes.add("restore");
1974
+ }
1975
+ } else if (this.tabActive == "discontinue" && row.discontinueUserId == this.loginUser.id) { // 已中止
1976
+ // 当前登陆用户是中止人才显示恢复按钮(已开启按钮的情况下)
1977
+ hideBtnTypes.delete("restore");
1978
+ }
1979
+
1980
+ return this.formatterFormBtnByHideBtnTypes(arrNodeFormBtns, hideBtnTypes);
1981
+ }
1982
+
1983
+ initFieldStatus(nodeKey,version,flowStatus) {
1984
+ return new Promise(resolve => {
1985
+ resolve();
1986
+ });
1987
+ }
1988
+
1989
+ replaceUrl(value){
1990
+ if(window.ADMIN_URL && (value.indexOf("/admin/") > -1 || value.indexOf("/oaadmin/") > -1)){
1991
+ if(value.indexOf("/admin/") > -1){
1992
+ value = this.$this.platStringUtil.replaceAll(value,"/admin/", window.ADMIN_URL + "/");
1993
+ }else{
1994
+ value = this.$this.platStringUtil.replaceAll(value,"/oaadmin/",window.ADMIN_URL + "/");
1995
+ }
1996
+ }
1997
+ if(window.FLOW_URL && (value.indexOf("/flow/") > -1 || value.indexOf("/oaflow/") > -1)){
1998
+ if(value.indexOf("/flow/") > -1){
1999
+ value = this.$this.platStringUtil.replaceAll(value,"/flow/", window.FLOW_URL + "/");
2000
+ }else{
2001
+ value = this.$this.platStringUtil.replaceAll(value,"/oaflow/",window.FLOW_URL + "/");
2002
+ }
2003
+ }
2004
+ if(window.FORM_RENDER_URL && (value.indexOf("/form/") > -1|| value.indexOf("/oaform/") > -1)){
2005
+ if(value.indexOf("/form/") > -1){
2006
+ value = this.$this.platStringUtil.replaceAll(value,"/form/", window.FORM_RENDER_URL + "/");
2007
+ }else{
2008
+ value = this.$this.platStringUtil.replaceAll(value,"/oaform/",window.FORM_RENDER_URL + "/");
2009
+ }
2010
+ }
2011
+ if(window.OA_URL && (value.indexOf("/project/") > -1 || value.indexOf("/oaproject/") > -1)){
2012
+ if(value.indexOf("/project/") > -1){
2013
+ value = this.$this.platStringUtil.replaceAll(value,"/project/", window.OA_URL + "/");
2014
+ }else{
2015
+ value = this.$this.platStringUtil.replaceAll(value,"/oaproject/",window.OA_URL + "/");
2016
+ }
2017
+ }
2018
+ value = this.$this.platStringUtil.replaceAll(value,"window.JAVA_URL","''");
2019
+ value = this.$this.platStringUtil.replaceAll(value,"JAVA_URL","''");
2020
+ value = this.$this.platStringUtil.replaceAll(value,"window.baseUrl","''");
2021
+ value = this.$this.platStringUtil.replaceAll(value,"baseUrl","''");
2022
+ return value;
2023
+ }
2024
+
2025
+ /**
2026
+ * 格式化表单操作按钮
2027
+ */
2028
+ formatterFormButton(formButton) {
2029
+
2030
+ let formBtnObj = {};
2031
+ let formBtnArr = [];
2032
+
2033
+ for (let [key, data] of Object.entries(this.formBtnObjDefault)) {
2034
+ formBtnObj[key] = Object.assign({btnType: key}, data);
2035
+ }
2036
+
2037
+ let objTmp;
2038
+ (formButton || []).forEach(data => {
2039
+ if (formBtnObj[data.type]) {
2040
+ objTmp = formBtnObj[data.type];
2041
+ objTmp.show = (data.isUse != '0');
2042
+ objTmp.text = data.showName || objTmp.text;
2043
+ }
2044
+ });
2045
+
2046
+ for (let [key, data] of Object.entries(formBtnObj)) {
2047
+ formBtnArr.push(data);
2048
+ }
2049
+ return formBtnArr;
2050
+ }
2051
+
2052
+ sortButtonArr(formButton) {
2053
+ let objBtnOrder = {
2054
+ "saveDraft": 1,
2055
+ "nextStep": 2,
2056
+ "completeSign": 3,
2057
+ "turnSign": 4,
2058
+ "retSpecified": 5,
2059
+ "back": 6,
2060
+ "stopped": 7,
2061
+ "close": 8
2062
+ };
2063
+ (formButton || []).forEach(data => {
2064
+ data.order = objBtnOrder[data.type] || data.order;
2065
+ });
2066
+ return formButton;
2067
+ }
2068
+
2069
+ // 获取流程用户数据
2070
+ initUserData(){
2071
+ // 先载入系统接口数据
2072
+ let userArr = this.$this.INTER_CACHE.getUserArr();
2073
+ if(userArr && userArr.length > 0){
2074
+ this.userMap = this.$this.INTER_CACHE.getUserMap();
2075
+ this.userArr = userArr;
2076
+ }else{
2077
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInterface.find,{sysInterName:'userData',interType:'sys',interStatus:'1'}).then(res => {
2078
+ if((res.data || []).length === 0){
2079
+ return;
2080
+ }
2081
+ let dataInter = res.data[0];
2082
+ this.loadUserData(dataInter);
2083
+ })
2084
+ }
2085
+ }
2086
+ loadUserData(dataInter){
2087
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowDomain.findRealUrl,{status:'1'}).then(res => {
2088
+ (res.data || []).forEach(item => {
2089
+ this.doMainDatasObj[item.id] = item.domainUrl;
2090
+ })
2091
+ // 解析用户数据
2092
+ this.analyseRequest(dataInter).then(data => {
2093
+ let arr = [];
2094
+ let userIdArr = [];
2095
+ data.forEach(item => {
2096
+ item.dataUserId = item[dataInter["idCode"] || "userId"];
2097
+ item.dataKey = item.dataUserId;
2098
+ item.flowDataType = "user";
2099
+ item.dataLabel = item[dataInter["showCode"] || "userName"];
2100
+ item.dataOrgId = item[dataInter["orgCode"] || "orgId"];
2101
+ item.dataPosId = item[dataInter["posCode"] || "posId"];
2102
+ if(item.dataOrgId){
2103
+ item.dataParentId = item.orgId;
2104
+ }
2105
+ if(item.dataPosId){
2106
+ item.dataParentId = item.posId;
2107
+ }
2108
+ if(userIdArr.indexOf(item.dataKey) === -1){
2109
+ arr.push({
2110
+ id:item.dataKey,
2111
+ userName:item.dataLabel
2112
+ })
2113
+ userIdArr.push(item.dataKey);
2114
+ }
2115
+ })
2116
+ this.userArr = arr;
2117
+ this.$this.INTER_CACHE.setUserArr(arr);
2118
+ this.$this.userMap = this.$this.INTER_CACHE.getUserMap();
2119
+ })
2120
+ })
2121
+ }
2122
+ analyseRequest(dataInter){
2123
+ return new Promise(resolve => {
2124
+ let domainUrl = this.doMainDatasObj[dataInter.domainId] || "";
2125
+ let url = domainUrl + dataInter.requestUrl;
2126
+ let requestParam = JSON.parse(dataInter.requestParam || "[]");
2127
+ let obj = {};
2128
+ requestParam.forEach(item => {
2129
+ if(!item.key){
2130
+ return;
2131
+ }
2132
+ obj[item.key] = item.value || ""; // 注意这里要replace ${userCode}
2133
+ })
2134
+ if(dataInter.requestType === 'post'){
2135
+ this.$this.saspFlowAxios.post(url,obj).then(res => {
2136
+ this.$this.INTER_CACHE.setCacheInfo(dataInter.sysInterName,res.data);
2137
+ resolve(res.data || []);
2138
+ })
2139
+ }else{
2140
+ let params = "";
2141
+ let arr = []
2142
+ Object.keys(obj).forEach(key => {
2143
+ arr.push(key + "=" + obj[key]);
2144
+ })
2145
+ params = arr.join("&");
2146
+ if(params){
2147
+ if(url.indexOf("?") > -1){
2148
+ url += "&" + params;
2149
+ }else{
2150
+ url += "?" + params;
2151
+ }
2152
+ }
2153
+ this.$this.saspFlowAxios(url).then(res => {
2154
+ this.$this.INTER_CACHE.setCacheInfo(dataInter.sysInterName,res.data);
2155
+ resolve(res.data || []);
2156
+ })
2157
+ }
2158
+ })
2159
+ }
2160
+
2161
+ open(dataId,type,callback){
2162
+ if(!this.tableviewId){
2163
+ this.$this.$message.error("请先设置tableviewId");
2164
+ return;
2165
+ }
2166
+ this.init().then(() => {
2167
+ this.formInfo["dataId"] = dataId;
2168
+ this.$flowDialog.fillFlowDialogParams({
2169
+ formId: this.formId,
2170
+ tableviewId: this.tableviewId,
2171
+ dataId: dataId || "",
2172
+ formInfo: this.formInfo
2173
+ });
2174
+ if(dataId){
2175
+ this.$this.saspFlowAxios.post(this.$this.api.plFlowInst.getFlowInstByFlowDataId,{flowId:this.flowId,dataId:dataId}).then(res => {
2176
+ if(!res.data){
2177
+ this.$this.$message.error("未获取到此流程数据!");
2178
+ return;
2179
+ }
2180
+ let rowData = res.data || {};
2181
+ if(type !== "view" && rowData.operateAuth === "0"){
2182
+ console.log("当前登录用户无此流程数据操作权限,已自动切换为查看!");
2183
+ type = "view";
2184
+ }
2185
+ if(rowData.linkProcId){
2186
+ this.tabActive = "pending";
2187
+ }else{
2188
+ this.tabActive = "draft";
2189
+ }
2190
+ this.currentInst = rowData;
2191
+ if(type === "view"){
2192
+ this.openViewFlowForm(rowData).then(() => {
2193
+ callback && callback(this,this.$this);
2194
+ })
2195
+ }else{
2196
+ let executePosition = "update";
2197
+ if(rowData.linkProcId){
2198
+ executePosition = "handle";
2199
+ }
2200
+ this.openUpdateFlowForm(rowData,executePosition).then(() => {
2201
+ callback && callback(this,this.$this);
2202
+ })
2203
+ }
2204
+ });
2205
+ }else{
2206
+ this.currentInst = {};
2207
+ this.tabActive = "draft";
2208
+ this.openAddFlowForm().then(() => {
2209
+ callback && callback(this,this.$this);
2210
+ })
2211
+ }
2212
+ })
2213
+ }
2214
+
2215
+ openFlowDialog(args){
2216
+ this.$flowDialog.openFlowDialog(args);
2217
+ }
2218
+ }
2219
+
2220
+ export default {
2221
+ workflow: WorkflowEngine
2222
+ }