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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<template>
<layout class="app-wizard">
<el-steps class="wizard-steps" v-if="isShowStepBar" :active="wizardForms.indexOf(activeForm)" finish-status="success" align-center>
<el-step title="查看图书"></el-step>
<el-step title="借阅图书"></el-step>
<el-step title="归还图书"></el-step>
</el-steps>
<i-content class="app-wizard-content">
<view_wizardpanel_form_FirstForm
v-show="activeForm == 'wizardpanel_form_FirstForm'"
:key="'wizardpanel_form_FirstForm'"
:viewState='wizardState'
:context="context"
:viewtag="viewtag"
:viewparams="viewparams"
updateAction="Update"
removeAction=""
loadAction="Get"
@save="wizardpanel_form_FirstForm_save"
@load="wizardpanel_form_FirstForm_load"
name='wizardpanel_form_FirstForm'
ref='wizardpanel_form_FirstForm'>
</view_wizardpanel_form_FirstForm>
<view_wizardpanel_form_SecondForm
v-show="activeForm == 'wizardpanel_form_SecondForm'"
:key="'wizardpanel_form_SecondForm'"
:viewState='wizardState'
:context="context"
:viewtag="viewtag"
:viewparams="viewparams"
updateAction="Update"
removeAction=""
loadAction="Get"
@save="wizardpanel_form_SecondForm_save"
@load="wizardpanel_form_SecondForm_load"
name='wizardpanel_form_SecondForm'
ref='wizardpanel_form_SecondForm'>
</view_wizardpanel_form_SecondForm>
<view_wizardpanel_form_ThirdForm
v-show="activeForm == 'wizardpanel_form_ThirdForm'"
:key="'wizardpanel_form_ThirdForm'"
:viewState='wizardState'
:context="context"
:viewtag="viewtag"
:viewparams="viewparams"
updateAction="Update"
removeAction=""
loadAction="Get"
@save="wizardpanel_form_ThirdForm_save"
@load="wizardpanel_form_ThirdForm_load"
name='wizardpanel_form_ThirdForm'
ref='wizardpanel_form_ThirdForm'>
</view_wizardpanel_form_ThirdForm>
</i-content>
<footer class="app-wizard-footer">
<i-button v-show="!isHidden('PREV')" @click="onClickPrev()" type="primary">{{$t('app.wizardPanel.back')}}</i-button>
<i-button v-show="!isHidden('NEXT')" @click="onClickNext()" type="primary">{{$t('app.wizardPanel.next')}}</i-button>
<i-button v-show="!isHidden('FINISH')" @click="onClickFinish()" type="primary">{{$t('app.wizardPanel.complete')}}</i-button>
</footer>
</layout>
</template>
<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util,ViewTool } from '@/utils';
import NavDataService from '@/service/app/navdata-service';
import AppCenterService from "@service/app/app-center-service";
import IBIZBOOKEntityService from '@/service/ibizbook/ibizbook-service';
import GuideService from './guide-wizardpanel-service';
import IBIZBOOKUIService from '@/uiservice/ibizbook/ibizbook-ui-service';
@Component({
components: {
}
})
export default class GuideBase extends Vue implements ControlInterface {
/**
* 名称
*
* @type {string}
* @memberof GuideBase
*/
@Prop() public name?: string;
/**
* 视图通讯对象
*
* @type {Subject<ViewState>}
* @memberof GuideBase
*/
@Prop() public viewState!: Subject<ViewState>;
/**
* 应用上下文
*
* @type {*}
* @memberof GuideBase
*/
@Prop() public context!: any;
/**
* 视图参数
*
* @type {*}
* @memberof GuideBase
*/
@Prop() public viewparams!: any;
/**
* 视图状态事件
*
* @public
* @type {(Subscription | undefined)}
* @memberof GuideBase
*/
public viewStateEvent: Subscription | undefined;
/**
* 获取部件类型
*
* @returns {string}
* @memberof GuideBase
*/
public getControlType(): string {
return 'WIZARDPANEL'
}
/**
* 计数器服务对象集合
*
* @type {Array<*>}
* @memberof GuideBase
*/
public counterServiceArray:Array<any> = [];
/**
* 建构部件服务对象
*
* @type {GuideService}
* @memberof GuideBase
*/
public service: GuideService = new GuideService({ $store: this.$store });
/**
* 实体服务对象
*
* @type {IBIZBOOKService}
* @memberof GuideBase
*/
public appEntityService: IBIZBOOKEntityService = new IBIZBOOKEntityService({ $store: this.$store });
/**
* wizardpanel_form_FirstForm 部件 save 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_FirstForm_save($event: any, $event2?: any) {
this.wizardpanel_formsave($event, 'wizardpanel_form_FirstForm', $event2);
}
/**
* wizardpanel_form_FirstForm 部件 load 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_FirstForm_load($event: any, $event2?: any) {
this.wizardpanel_formload($event, 'wizardpanel_form_FirstForm', $event2);
}
/**
* wizardpanel_form_SecondForm 部件 save 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_SecondForm_save($event: any, $event2?: any) {
this.wizardpanel_formsave($event, 'wizardpanel_form_SecondForm', $event2);
}
/**
* wizardpanel_form_SecondForm 部件 load 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_SecondForm_load($event: any, $event2?: any) {
this.wizardpanel_formload($event, 'wizardpanel_form_SecondForm', $event2);
}
/**
* wizardpanel_form_ThirdForm 部件 save 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_ThirdForm_save($event: any, $event2?: any) {
this.wizardpanel_formsave($event, 'wizardpanel_form_ThirdForm', $event2);
}
/**
* wizardpanel_form_ThirdForm 部件 load 事件
*
* @param {*} [args={}]
* @param {*} $event
* @memberof GuideBase
*/
public wizardpanel_form_ThirdForm_load($event: any, $event2?: any) {
this.wizardpanel_formload($event, 'wizardpanel_form_ThirdForm', $event2);
}
/**
* 转化数据
*
* @param {any} args
* @memberof GuideBase
*/
public transformData(args: any) {
let _this: any = this;
if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
return _this.service.handleRequestData('transform',_this.context,args)['data'];
}
}
/**
* 关闭视图
*
* @param {any} args
* @memberof GuideBase
*/
public closeView(args: any): void {
let _this: any = this;
_this.$emit('closeview', [args]);
}
/**
* 计数器刷新
*
* @memberof GuideBase
*/
public counterRefresh(){
const _this:any =this;
if(_this.counterServiceArray && _this.counterServiceArray.length >0){
_this.counterServiceArray.forEach((item:any) =>{
if(item.refreshData && item.refreshData instanceof Function){
item.refreshData();
}
})
}
}
/**
* 部件行为--init
*
* @type {string}
* @memberof GuideBase
*/
@Prop() public initAction!: string;
/**
* 部件行为--finish
*
* @type {string}
* @memberof GuideBase
*/
@Prop() public finishAction!: string;
/**
* 显示处理提示
*
* @type {boolean}
* @memberof GuideBase
*/
@Prop({ default: true }) public showBusyIndicator?: boolean;
/**
* 视图标识
*
* @type {string}
* @memberof GuideBase
*/
@Prop() public viewtag!: string;
/**
* 状态属性
*
* @type {string}
* @memberof GuideBase
*/
public stateField: string = '';
/**
* 步骤标识集合
*
* @type {*}
* @memberof GuideBase
*/
public stepTags: any = {};
/**
* 显示步骤栏
*
* @type {Boolean}
* @memberof GuideBase
*/
public isShowStepBar: Boolean = true ;
/**
* 获取多项数据
*
* @returns {any[]}
* @memberof GuideBase
*/
public getDatas(): any[] {
return [this.formParam];
}
/**
* 获取单项数据
*
* @returns {*}
* @memberof GuideBase
*/
public getData(): any {
return this.formParam;
}
/**
* 视图状态订阅对象
*
* @public
* @type {Subject<{action: string, data: any}>}
* @memberof GuideBase
*/
public wizardState: Subject<ViewState> = new Subject();
/**
* 当前激活表单
*
* @type {string}
* @memberof GuideBase
*/
public activeForm: string = 'wizardpanel_form_FirstForm';
/**
* 向导表单参数
*
* @type {*}
* @memberof GuideBase
*/
public formParam: any = {};
/**
* 执行过的表单
*
* @public
* @type {Array<string>}
* @memberof GuideBase
*/
public historyForms: Array<string> = [];
/**
* 步骤行为集合
*
* @type {*}
* @memberof GuideBase
*/
public stepActions: any = {};
/**
* 向导表单集合
*
* @type {Array<any>}
* @memberof GuideBase
*/
public wizardForms: Array<any> = [];
/**
* 当前状态
*
* @memberof GuideBase
*/
public curState = '';
/**
* Vue声明周期(处理组件的输入属性)
*
* @memberof GuideBase
*/
public created(): void {
this.regFormActions();
if(this.activeForm && !this.stateField) {
this.historyForms.push(this.activeForm);
}
if (this.viewState) {
this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
if (Object.is(tag, this.name)) {
if (Object.is('load', action)) {
this.doInit(data);
}
}
});
}
}
/**
* vue 生命周期
*
* @memberof GuideBase
*/
public destroyed() {
if (this.viewStateEvent) {
this.viewStateEvent.unsubscribe();
}
}
/**
* 注册表单步骤行为
*
* @memberof GuideBase
*/
public regFormActions() {
this.regFormAction('wizardpanel_form_FirstForm',{loadAction:"Get",saveAction:'Update',actions:['NEXT']},'viewbook');
this.regFormAction('wizardpanel_form_SecondForm',{loadAction:"Get",saveAction:'Update',actions:['PREV','NEXT']},'borrow');
this.regFormAction('wizardpanel_form_ThirdForm',{loadAction:"Get",saveAction:'Update',actions:['PREV','FINISH']},'return');
}
/**
* 注册表单步骤行为
*
* @memberof GuideBase
*/
public regFormAction(name: string, actionParams: any,stepTag:any) {
this.stepActions[name] = actionParams;
this.stepTags[name] = stepTag;
this.wizardForms.push(name);
}
/**
* 初始化行为
*
* @memberof GuideBase
*/
public doInit(opt: any = {}) {
const arg: any = { ...opt };
Object.assign(arg,{viewparams:this.viewparams});
const post: Promise<any> = this.service.init(this.initAction, JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
post.then((response: any) => {
if (response && response.status === 200) {
this.formParam = response.data;
if(response.data.ibizbook){
Object.assign(this.context,{ibizbook:response.data.ibizbook})
}
this.formLoad(this.formParam);
}
}).catch((response: any) => {
if (response && response.status === 401) {
return;
}
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
});
}
/**
* 表单加载
*
* @memberof GuideBase
*/
public formLoad(data:any) {
if(this.stateField) this.computedActiveForm(data);
if(this.activeForm) {
this.wizardState.next({ tag: this.activeForm, action:'panelaction',data: {action:this.stepActions[this.activeForm].loadAction,emitAction:'load',data:this.formParam} });
}
}
/**
* 根据状态获取当前激活表单
*
* @memberof GuideBase
*/
public computedActiveForm(data:any){
if(data && data[this.stateField]){
if(Object.keys(this.stepTags).length >0){
Object.keys(this.stepTags).forEach((name:string) =>{
if(this.stepTags[name] === data[this.stateField]){
this.activeForm = name;
return;
}
})
}
}
}
/**
* 完成行为
*
* @memberof GuideBase
*/
public doFinish() {
let arg: any = {};
Object.assign(arg, this.formParam);
Object.assign(arg,{viewparams:this.viewparams});
const post: Promise<any> = this.service.finish(this.finishAction, JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
this.$Notice.success({ title: this.$t('app.commonWords.success') as string, desc: this.$t('app.commonWords.startsuccess') as string });
this.$emit("finish", data);
AppCenterService.notifyMessage({name:"IBIZBOOK",action:'appRefresh',data:data});
}
}).catch((response: any) => {
if (response && response.status === 401) {
return;
}
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
});
}
/**
* 向导表单加载完成
*
* @param {*} args
* @param {string} name
* @memberof GuideBase
*/
public wizardpanel_formload(args: any, name: string, $event2?: any) {
if(args) {
Object.assign(this.formParam, args);
if (Object.is(this.curState, 'NEXT') || Object.is(this.curState, 'PREV')) {
this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: true });
}
}
}
/**
* 向导表单保存完成
*
* @param {*} args
* @param {string} name
* @memberof GuideBase
*/
public wizardpanel_formsave(args: any, name: string, $event2?: any) {
Object.assign(this.formParam, args);
if(Object.is(this.curState, 'NEXT')) {
this.historyForms.push(name);
if(!this.stateField){
if (this.getNextForm()) {
this.activeForm = this.getNextForm();
setTimeout(() => {
this.formLoad(this.formParam);
}, 1);
} else {
this.doFinish();
}
}else{
setTimeout(() => {
this.formLoad(this.formParam);
}, 1);
}
}else if(Object.is(this.curState, 'PREV')) {
if(this.stateField){
setTimeout(() => {
this.formLoad(this.formParam);
}, 1);
}
}else if(Object.is(this.curState, 'FINISH')) {
this.doFinish();
}
}
/**
* 获取下一步向导表单
*
* @memberof GuideBase
*/
public getNextForm() {
let index = this.wizardForms.indexOf(this.activeForm);
if(index >= 0) {
if(this.wizardForms[index + 1]) {
return this.wizardForms[index + 1];
}
}
return undefined;
}
/**
* 上一步
*
* @memberof GuideBase
*/
public onClickPrev() {
if(!this.stateField){
const length = this.historyForms.length;
if(length > 1) {
this.curState = 'PREV';
this.activeForm = this.historyForms[length - 1];
setTimeout(() => {
this.formLoad(this.formParam);
}, 1);
this.historyForms.splice(length - 1, 1);
}
}else{
if(this.activeForm) {
if(this.$refs && this.$refs[this.activeForm]){
let form: any = this.$refs[this.activeForm];
this.curState = 'PREV';
if(!this.stepActions[this.activeForm].preAction){
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc:this.$t('app.wizardPanel.preactionmessage') as string });
return;
}
this.wizardState.next({ tag: this.activeForm, action:'panelaction',data: {action:this.stepActions[this.activeForm].preAction,emitAction:'save',data:this.formParam} });
}
}
}
}
/**
* 下一步
*
* @memberof GuideBase
*/
public onClickNext() {
if(this.activeForm) {
if(this.$refs && this.$refs[this.activeForm]){
let form: any = this.$refs[this.activeForm];
if(form.formValidateStatus()) {
this.curState = 'NEXT';
this.wizardState.next({ tag: this.activeForm, action:'panelaction',data: {action:this.stepActions[this.activeForm].saveAction,emitAction:'save',data:this.formParam} });
} else {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.rulesException') as string) });
}
}
}
}
/**
* 完成
*
* @memberof GuideBase
*/
public onClickFinish() {
if(this.activeForm) {
if(this.$refs && this.$refs[this.activeForm]){
let form: any = this.$refs[this.activeForm];
if(form.formValidateStatus()) {
this.curState = 'FINISH';
this.wizardState.next({ tag: this.activeForm, action:'panelaction',data: {action:this.stepActions[this.activeForm].saveAction,emitAction:'save',data:this.formParam} });
} else {
this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.rulesException') as string) });
}
}
}
}
/**
* 是否隐藏
*
* @param {string} type
* @memberof GuideBase
*/
public isHidden(type: string) {
const actions: Array<string> = this.stepActions[this.activeForm].actions;
if(actions && actions.indexOf(type) < 0) {
return true;
}
return false;
}
}
</script>
<style lang='less'>
@import './guide-wizardpanel.less';
</style>