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
import { ViewEngine } from './view-engine';
/**
* 实体移动端编辑视图界面引擎
*
* @export
* @class MobEditViewEngine
* @extends {ViewEngine}
*/
export class MobEditViewEngine extends ViewEngine {
/**
* 表单部件
*
* @protected
* @type {*}
* @memberof MobEditViewEngine
*/
protected form: any;
/**
* 初始化编辑视图引擎
*
* @param {*} [options={}]
* @memberof MobEditViewEngine
*/
public init(options: any = {}): void {
this.form = options.form;
super.init(options);
}
/**
* 引擎加载
*
* @param {*} [opts={}]
* @memberof MobEditViewEngine
*/
public load(opts: any = {}): void {
super.load(opts);
if (this.getForm()) {
const tag = this.getForm().name;
let action: string = '';
// 实体主键字段有值时load该记录数据,否则loaddraft加载草稿
if ((this.keyPSDEField && this.view.context[this.keyPSDEField] && !Object.is(this.view.context[this.keyPSDEField], '') && !Object.is(this.view.context[this.keyPSDEField], 'null'))) {
action = 'load';
} else {
action = 'loaddraft';
}
this.setViewState2({ tag: tag, action: action, viewdata: { ...this.view.viewparams } });
}
}
/**
* 部件事件机制
*
* @param {string} ctrlName
* @param {string} eventName
* @param {*} args
* @memberof MobEditViewEngine
*/
public onCtrlEvent(ctrlName: string, eventName: string, args: any): void {
super.onCtrlEvent(ctrlName, eventName, args);
if (Object.is(ctrlName, 'form')) {
this.formEvent(eventName, args);
}
}
/**
* 表单事件
*
* @param {string} eventName
* @param {*} args
* @memberof MobEditViewEngine
*/
public formEvent(eventName: string, args: any): void {
if (Object.is(eventName, 'load')) {
this.onFormLoad(args);
}
if (Object.is(eventName, 'save')) {
this.onFormSave(args);
}
if (Object.is(eventName, 'remove')) {
this.onFormRemove(args);
}
if (Object.is(eventName, 'datachange')) {
this.onFormDataChange(args);
}
}
/**
* 表单数据变更
*
* @param {*} arg
* @memberof MobEditViewEngine
*/
public onFormDataChange(arg: any) {
if (this.view) {
this.view.dataChange = arg;
}
}
/**
* 表单加载完成
*
* @param {*} args
* @memberof MobEditViewEngine
*/
public onFormLoad(arg: any): void {
if (this.view.model) {
this.view.model.dataInfo = Object.is(arg.srfuf, '1')
? this.majorPSDEField
? arg[this.majorPSDEField]
: arg.srfmajortext
: this.view.$t('app.local.new');
this.setNavCaption(Object.is(arg.srfuf, '0'));
}
this.emitViewEvent('load', arg);
this.emitViewEvent('viewdataschange', JSON.stringify({ action: 'load', status: 'success', data: arg }));
const newdata: boolean = !Object.is(arg.srfuf, '1');
this.calcToolbarItemState(newdata);
this.calcToolbarItemAuthState(arg);
}
/**
* 设置导航标题
*
* @memberof EditViewEngine
*/
public setNavCaption(isCreate: boolean): void {
let viewdata: any = this.view.model;
if (viewdata) {
if (!isCreate && this.form) {
this.view.initNavCaption();
}
}
}
/**
* 表单保存完成
*
* @param {*} args
* @memberof MobEditViewEngine
*/
public onFormSave(arg: any): void {
this.emitViewEvent('save', arg);
this.emitViewEvent('viewdataschange', JSON.stringify({ action: 'save', status: 'success', data: arg }));
const newdata: boolean = !Object.is(arg.srfuf, '1');
this.calcToolbarItemState(newdata);
this.calcToolbarItemAuthState(arg);
}
/**
* 表单删除完成
*
* @param {*} args
* @memberof MobEditViewEngine
*/
public onFormRemove(arg: any): void {
this.emitViewEvent('remove', arg);
this.emitViewEvent('viewdataschange', JSON.stringify({ action: 'remove', status: 'success', data: arg }));
}
/**
* 获取表单对象
*
* @returns {*}
* @memberof MobEditViewEngine
*/
public getForm(): any {
return this.form;
}
/**
* 转化数据
*
* @memberof EditViewEngine
*/
public transformData(arg: any) {
if (!this.getForm() || !(this.getForm().transformData instanceof Function)) {
return null;
}
return this.getForm().transformData(arg);
}
}