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
import { IPSAppDEWFDynaEditView, IPSAppView, IPSDEDRTab, IPSDEDRTabPage, IPSDEForm, IPSDEFormGroupPanel, IPSLanguageRes, IPSUIActionGroupDetail } from '@ibiz/dynamic-model-api';
import { WFDynaEditViewEngine, Util, ModelTool, GetModelService, AppModelService, LogUtil, throttle, WFDynaEditViewInterface } from 'ibiz-core';
import { Subscription } from 'rxjs';
import { AppCenterService, AppViewLogicService } from '../app-service';
import { MainViewBase } from './mainview-base';
/**
* 工作流动态编辑视图基类
*
* @export
* @class WFDynaEditViewBase
* @extends {MainViewBase}
*/
export class WFDynaEditViewBase extends MainViewBase implements WFDynaEditViewInterface {
/**
* 视图引擎
*
* @public
* @type {Engine}
* @memberof WFDynaEditViewBase
*/
public engine: WFDynaEditViewEngine = new WFDynaEditViewEngine();
/**
* 视图实例
*
* @memberof WFDynaEditViewBase
*/
public declare viewInstance: IPSAppDEWFDynaEditView;
/**
* 编辑表单实例
*
* @public
* @type {IBizFormModel}
* @memberof WFDynaEditViewBase
*/
public editFormInstance !: IPSDEForm;
/**
* 第一个且带界面行为组的表单分组
*
* @public
* @type {IBizFormModel}
* @memberof WFDynaEditViewBase
*/
public firstFormGroup !: IPSDEFormGroupPanel;
/**
* 第一个表单分组的界面行为组的运行时模型
*
* @public
* @type {IBizFormModel}
* @memberof WFDynaEditViewBase
*/
public uiActionGroup !: any;
/**
* 数据关系分页部件实例
*
* @public
* @type {IPSDEDRTab}
* @memberof WFDynaEditViewBase
*/
public drtabInstance !: IPSDEDRTab;
/**
* 工具栏模型数据
*
* @memberof WFDynaEditViewBase
*/
public linkModel: Array<any> = [];
/**
* 视图引用数据
*
* @memberof WFDynaEditViewBase
*/
public viewRefData: any = {};
/**
* 关系数据分页部件分页
*
* @type {IPSDEDRTabPage[] | null}
* @memberof WFDynaEditViewBase
*/
public deDRTabPages: IPSDEDRTabPage[] | null = [];
/**
* 是否可编辑
*
* @type {boolean}
* @memberof WFDynaEditViewBase
*/
public isEditable:boolean = true;
/**
* 工作流附加功能类型映射关系对象
*
* @memberof WFDynaEditViewBase
*/
public wfAddiFeatureRef: any = {
"reassign": { featureTag: "REASSIGN", action: "TransFerTask" },
"addstepbefore": { featureTag: "ADDSTEPBEFORE", action: "BeforeSign" },
"sendback": { featureTag: "SENDBACK", action: "SendBack" },
"sendcopy": { featureTag: "SENDCOPY", action: "sendCopy" }
};
/**
* @description 工具栏事件
* @type {(Subscription | undefined)}
* @memberof WFDynaEditViewBase
*/
public toolbarEvent: Subscription | undefined;
/**
* @description 辅助功能事件
* @type {(Subscription | undefined)}
* @memberof WFDynaEditViewBase
*/
public featureEvent: Subscription | undefined;
/**
* 引擎初始化
*
* @public
* @memberof WFDynaEditViewBase
*/
public engineInit(): void {
if (this.Environment && this.Environment.isPreviewMode) {
return;
}
this.engine.init({
view: this,
keyPSDEField: this.appDeCodeName.toLowerCase(),
majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
isLoadDefault: this.viewInstance.loadDefault,
});
}
/**
* 初始化挂载状态集合
*
* @memberof WFDynaEditViewBase
*/
public initUIContainerMountedMap() {
this.mountedMap.set('self', false);
}
/**
* 设置已经绘制完成状态
*
* @memberof WFDynaEditViewBase
*/
public setContainerIsMounted(name: string = 'self') {
super.setContainerIsMounted(name);
if (this.editFormInstance?.name == name) {
this.viewState.next({ tag: this.editFormInstance.name, action: 'autoload', data: { srfkey: this.context[this.appDeCodeName.toLowerCase()] } });
}
}
/**
* 初始化编辑视图实例
*
* @memberof WFDynaEditViewBase
*/
public async viewModelInit() {
await super.viewModelInit();
this.viewRefData = await ModelTool.loadedAppViewRef(this.viewInstance);
this.drtabInstance = ModelTool.findPSControlByName('drtab', this.viewInstance.getPSControls()) as IPSDEDRTab;
this.deDRTabPages = this.drtabInstance?.getPSDEDRTabPages();
}
/**
* 初始化工具栏数据
*
* @memberof WFDynaEditViewBase
*/
public renderToolBar() {
return (
<div slot="toolbar" class="view-toolbar">
<div class='view-toolbar-container'>
{
this.uiActionGroup && this.uiActionGroup?.details?.map((item: any)=>{
return (
<tooltip v-show={item.visabled} transfer={true} max-width={600} >
<app-button
disabled={item.disabled}
caption={item.caption}
loading={this.viewLoadingService.isLoading}
on-onClick={(event: any) => { throttle(this.handleActionClick,[event,item],this) }}>
</app-button>
<div slot='content'>{item.caption}</div>
</tooltip>
)
})
}
{
this.linkModel.map((linkItem: any) => {
return (
<tooltip transfer={true} max-width={600} >
<app-button
caption={linkItem.sequenceFlowName}
loading={this.viewLoadingService.isLoading}
on-onClick={(event: any) => { throttle(this.dynamic_toolbar_click,[linkItem, event],this) }}>
</app-button>
<div slot='content'>{linkItem.sequenceFlowName}</div>
</tooltip>
)
})
}
</div >
</div >
)
}
/**
* 渲染视图主体内容区
*
* @memberof WFDynaEditViewBase
*/
public renderMainContent() {
if (!this.editFormInstance) {
return;
}
if (this.deDRTabPages && this.deDRTabPages.length > 0) {
const tempContext = Util.deepCopy(this.context);
const tabsName = `${this.appDeCodeName?.toLowerCase()}_${this.viewInstance.codeName.toLowerCase()}`;
return (
<tabs animated={false} name={tabsName} class="view-content__body__wfdynaeditviewtabs">
<tab-pane tab={tabsName} label={this.editFormInstance.logicName}>
{this.renderFormContent()}
</tab-pane>
{this.deDRTabPages.map((deDRTabPage: IPSDEDRTabPage) => {
return (
<tab-pane tab={tabsName} label={this.$tl(deDRTabPage.getCapPSLanguageRes()?.lanResTag, deDRTabPage.caption)}>
{ this.$createElement('app-view-shell', {
props: {
staticProps: {
viewDefaultUsage: false,
appDeCodeName: this.appDeCodeName
},
dynamicProps: {
viewdata: JSON.stringify(Object.assign(tempContext, { viewpath: deDRTabPage?.M?.getPSAppView?.path })),
viewparam: JSON.stringify(this.viewparams),
},
}
})}
</tab-pane>
)
})}
</tabs>
)
} else {
return this.renderFormContent();
}
}
/**
* 渲染流程表单内容区
*
* @memberof WFDynaEditViewBase
*/
public renderFormContent() {
if (!this.editFormInstance) {
return;
}
let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.editFormInstance);
Object.assign(targetCtrlParam.staticProps, {
iseditable: this.isEditable
});
return (
this.$createElement(targetCtrlName, { slot: 'default', props: targetCtrlParam, ref: this.editFormInstance.name, on: targetCtrlEvent })
);
}
/**
* 获取动态表单模型
*
* @memberof WFDynaEditViewBase
*/
public getFormModel(): Promise<any> {
return new Promise((resolve: any, reject: any) => {
let datas: any[] = [];
if (Object.keys(this.viewparams).length > 0) {
Object.assign(datas, { 'processDefinitionKey': this.viewparams.processDefinitionKey });
Object.assign(datas, { 'taskDefinitionKey': this.viewparams.taskDefinitionKey });
}
this.appEntityService.getWFStep(JSON.parse(JSON.stringify(this.context)), datas, true).then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
this.isEditable = data.iseditable === 'true';
if (data && data['process-form']) {
this.computeActivedForm(data['process-form']);
} else {
this.computeActivedForm(null);
}
}else{
this.$throw(response,'getFormModel');
}
}).catch((response: any) => {
this.$throw(response,'getFormModel');
});
});
}
/**
* 获取工具栏按钮
*
* @memberof WFDynaEditViewBase
*/
public getWFLinkModel(arg: any): Promise<any> {
return new Promise((resolve: any, reject: any) => {
let datas: any[] = [];
if (Object.keys(this.viewparams).length > 0) {
Object.assign(datas, { 'processDefinitionKey': this.viewparams.processDefinitionKey });
Object.assign(datas, { 'taskDefinitionKey': this.viewparams.taskDefinitionKey });
}
if (arg && Object.keys(arg).length > 0) {
Object.assign(datas, { activedata: arg });
}
this.appEntityService.GetWFLink(JSON.parse(JSON.stringify(this.context)), datas, true).then((response: any) => {
if (response && response.status === 200) {
this.linkModel = response.data;
}else{
this.$throw(response,'getWFLinkModel');
}
}).catch((response: any) => {
this.$throw(response,'getWFLinkModel');
});
})
}
/**
* 计算激活表单
*
* @memberof WFDynaEditViewBase
*/
public computeActivedForm(inputForm: any) {
if (!inputForm) {
this.editFormInstance = ModelTool.findPSControlByName('form', this.viewInstance.getPSControls()) as IPSDEForm;
} else {
this.editFormInstance = ModelTool.findPSControlByName(`wfform_${inputForm.toLowerCase()}`, this.viewInstance.getPSControls()) as IPSDEForm;
}
this.computeFormGroup();
this.mountedMap.set(this.editFormInstance.name, false);
this.$forceUpdate();
}
/**
* @description 计算需要重绘的表单分组
* @memberof WFDynaEditViewBase
*/
public computeFormGroup(){
// 获取表单第一个分组,如果它有界面行为组则赋值
let formGroup = ModelTool.getAllFormDetails(this.editFormInstance)?.find((item: any)=>{
return item.detailType == 'GROUPPANEL';
})
if(formGroup?.getPSUIActionGroup?.()?.getPSUIActionGroupDetails?.()?.length > 0){
this.firstFormGroup = formGroup
}
if(this.firstFormGroup){
var style = document.createElement('style');
style.innerHTML=`#${this.firstFormGroup.codeName} .ivu-card-extra .ui-actions{ display:none; }`;
document.getElementById(this.viewInstance.codeName)?.appendChild(style);
}
}
/**
* 动态工具栏点击
*
* @memberof WFDynaEditViewBase
*/
public dynamic_toolbar_click(linkItem: any, $event: any) {
const _this: any = this
let datas: any[] = [];
let xData: any = (this.$refs[this.editFormInstance.name] as any).ctrl;
if (xData.getDatas && xData.getDatas instanceof Function) {
datas = [...xData.getDatas()];
}
const submit: Function = (submitData: any, linkItem: any) => {
xData.wfsubmit(submitData, linkItem).then((response: any) => {
if (!response || response.status !== 200) {
return;
}
const { data: _data } = response;
if (_this.viewdata) {
_this.$emit('view-event', { viewName: this.viewInstance.name, action: 'viewdataschange', data: [{ ..._data }] });
_this.$emit('view-event', { viewName: this.viewInstance.name, action: 'close', data: null });
} else {
this.closeView([{ ..._data }]);
}
});
}
const submitAction: Function = () => {
if (linkItem && linkItem.sequenceflowview) {
const targetViewRef: any = this.viewRefData.find((item: any) => {
return item.name === `WFACTION@${linkItem.sequenceflowview}`;
})
if (targetViewRef) {
let tempContext: any = Util.deepCopy(_this.context);
Object.assign(tempContext, { [this.appDeCodeName.toLowerCase()]: datas && datas[0].srfkey });
let tempViewParam: any = { actionView: linkItem.sequenceflowview, actionForm: linkItem.sequenceflowform };
Object.assign(tempContext, { viewpath: targetViewRef?.getRefPSAppView?.path });
GetModelService(tempContext).then((modelService: AppModelService) => {
modelService.getPSAppView(targetViewRef?.getRefPSAppView?.path).then((viewResult: IPSAppView) => {
const appmodal = _this.$appmodal.openModal({ viewname: 'app-view-shell', title: this.$tl(viewResult.getTitlePSLanguageRes()?.lanResTag, viewResult.title), height: viewResult.height, width: viewResult.width }, tempContext, tempViewParam);
this.toolbarEvent = appmodal.subscribe((result: any) => {
if (!result || !Object.is(result.ret, 'OK')) {
return;
}
let tempSubmitData: any = Util.deepCopy(datas[0]);
if (result.datas && result.datas[0]) {
const resultData: any = result.datas[0];
if (Object.keys(resultData).length > 0) {
let tempData: any = {};
Object.keys(resultData).forEach((key: any) => {
if (resultData[key] && (key !== "srfuf")) tempData[key] = resultData[key];
})
Object.assign(tempSubmitData, tempData);
}
}
submit([tempSubmitData], linkItem);
});
})
})
}
} else {
submit(datas, linkItem);
}
}
if (linkItem && linkItem.type) {
if (Object.is(linkItem.type, "finish")) {
submitAction();
} else {
this.handleWFAddiFeature(linkItem);
}
} else {
submitAction();
}
}
/**
* 处理工作流辅助功能
*
* @memberof WFDynaEditViewBase
*/
public handleWFAddiFeature(linkItem: any) {
let featureTag: string = this.wfAddiFeatureRef[linkItem?.type]?.featureTag;
if (!featureTag) return;
let targetViewRef: any = this.viewRefData.find((item: any) => {
return item.name === `WFUTILACTION@${featureTag}`;
})
if (!targetViewRef) {
LogUtil.warn(this.$t('app.wizardpanel.nofind'));
return;
}
// 准备参数
let datas: any[] = [];
let xData: any = (this.$refs[this.editFormInstance.name] as any).ctrl;
if (xData.getDatas && xData.getDatas instanceof Function) {
datas = [...xData.getDatas()];
}
let tempContext: any = Util.deepCopy(this.context);
Object.assign(tempContext, { [this.appDeCodeName.toLowerCase()]: datas && datas[0].srfkey });
let tempViewParam: any = { actionView: linkItem.sequenceflowview, actionForm: linkItem.sequenceflowform };
Object.assign(tempContext, { viewpath: targetViewRef?.getRefPSAppView?.path });
GetModelService(tempContext).then((modelService: AppModelService) => {
modelService.getPSAppView(targetViewRef?.getRefPSAppView?.path).then((viewResult: IPSAppView) => {
const appmodal = this.$appmodal.openModal({ viewname: 'app-view-shell', title: this.$tl(viewResult.getTitlePSLanguageRes()?.lanResTag, viewResult.title), height: viewResult.height, width: viewResult.width }, tempContext, tempViewParam);
this.featureEvent = appmodal.subscribe((result: any) => {
if (!result || !Object.is(result.ret, 'OK')) {
return;
}
let tempSubmitData: any = Util.deepCopy(datas[0]);
if (result.datas && result.datas[0]) {
const resultData: any = result.datas[0];
if (Object.keys(resultData).length > 0) {
let tempData: any = {};
Object.keys(resultData).forEach((key: any) => {
if (resultData[key] && (key !== "srfuf")) tempData[key] = resultData[key];
})
Object.assign(tempSubmitData, tempData);
}
this.submitWFAddiFeature(linkItem, tempSubmitData);
}
});
})
})
}
/**
* 提交工作流辅助功能
*
* @memberof WFDynaEditViewBase
*/
public submitWFAddiFeature(linkItem: any, submitData: any) {
let tempSubmitData: any = Object.assign(linkItem, { "activedata": submitData });
let action: string = this.wfAddiFeatureRef[linkItem?.type]?.action;
if (!action) return;
this.appEntityService[action](Util.deepCopy(this.context), tempSubmitData).then((response: any) => {
const { data: data } = response;
if (!response || response.status !== 200) {
this.$throw(response,'submitWFAddiFeature');
return;
}
let _this: any = this;
if (_this.viewdata) {
_this.$emit('view-event', { viewName: this.viewInstance.name, action: 'viewdataschange', data: [{ ...data }] });
_this.$emit('view-event', { viewName: this.viewInstance.name, action: 'close', data: null });
} else {
this.closeView([{ ...data }]);
}
AppCenterService.notifyMessage({ name: this.appDeCodeName, action: 'appRefresh', data: data });
this.$success(data?.message ? data.message : this.$t('app.wizardpanel.success'),'submitWFAddiFeature');
}).catch((error: any) => {
this.$throw(error,'submitWFAddiFeature');
})
}
/**
* 处理操作列点击
*
* @param {*} event 事件对象
* @param {*} item 界面行为的运行时模型对象
* @memberof EditFormControlBase
*/
public handleActionClick(event: any, item: any) {
let actionDetal: any = this.firstFormGroup?.getPSUIActionGroup()?.getPSUIActionGroupDetails()?.find((groupDetail: IPSUIActionGroupDetail)=>{
return item.name == `${this.firstFormGroup.name}_${groupDetail.name}`;
})
if(actionDetal){
let formRef = (this.$refs[this.editFormInstance.name] as any).ctrl;
AppViewLogicService.getInstance().executeViewLogic(`${this.editFormInstance.name}_${this.firstFormGroup.codeName}_${actionDetal.name}_click`, event, formRef, undefined, this.editFormInstance.getPSAppViewLogics() || []);
}
}
/**
* 部件事件机制
*
* @param {string} ctrlName
* @param {string} eventName
* @param {*} args
* @memberof CalendarExpViewEngine
*/
public onCtrlEvent(ctrlName: string, eventName: string, args: any): void {
super.onCtrlEvent(ctrlName, eventName, args);
if (ctrlName == this.editFormInstance?.name && eventName == "load") {
// 处理第一个表单分组的界面行为组
if(this.firstFormGroup){
let formEl = (this.$refs[this.editFormInstance.name] as any).ctrl;
this.uiActionGroup = formEl.detailsModel[this.firstFormGroup.name]?.uiActionGroup;
}
}
}
/**
* @description 视图销毁
* @memberof WFDynaEditViewBase
*/
public viewDestroyed() {
super.viewDestroyed();
if (this.toolbarEvent) {
this.toolbarEvent.unsubscribe();
}
if (this.featureEvent) {
this.featureEvent.unsubscribe();
}
}
}