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
import {
getPSUIActionByModelObject,
IPSAppDataEntity,
IPSAppDEField,
IPSAppDEMethod,
IPSAppView
} from '@ibiz/dynamic-model-api';
import { ModelTool, UIActionTool, Util } from 'ibiz-core';
import { DataServiceHelp } from 'ibiz-core';
import { AppGlobalService, ViewOpenService } from '../app-service';
import { NoticeHandler } from '../utils';
import { AppDEUIAction } from './app-ui-action';
import { UIActionResult } from './appuilogic';
export class AppBackEndAction extends AppDEUIAction {
/**
* 是否合并参数
*
* @memberof AppBackEndAction
*/
public isMergeParam: boolean = false;
/**
* 视图打开服务
*
* @type {ViewOpenService}
* @memberof AppBackEndAction
*/
public openService: ViewOpenService = ViewOpenService.getInstance();
/**
* 初始化AppBackEndAction
*
* @memberof AppBackEndAction
*/
constructor(opts: any, context?: any) {
super(opts, context);
const method: IPSAppDEMethod = this.actionModel.getPSAppDEMethod() as IPSAppDEMethod;
if (method?.M && (method.M.customCode || !method.M.getPSDEServiceAPIMethod)) {
this.isMergeParam = true;
}
}
/**
* 执行界面行为
*
* @param args
* @param context
* @param params
* @param $event
* @param xData
* @param actionContext
* @param srfParentDeName
*
* @memberof AppBackEndAction
*/
public async execute(
args: any[],
context: any = {},
params: any = {},
$event?: any,
xData?: any,
actionContext?: any,
srfParentDeName?: string,
deUIService?: any,
) {
if (Object.is(this.actionModel?.uILogicAttachMode, 'REPLACE')) {
return this.executeDEUILogic(args, context, params, $event, xData, actionContext, srfParentDeName);
}
const actionTarget: string | null = this.actionModel.actionTarget;
if (this.actionModel.enableConfirm && this.actionModel.confirmMsg) {
let confirmResult: boolean = await new Promise((resolve: any, reject: any) => {
actionContext.$Modal.confirm({
title: actionContext.$t('app.commonWords.warning'),
content: `${this.actionModel.confirmMsg}`,
onOk: () => {
resolve(true);
},
onCancel: () => {
resolve(false);
},
});
});
if (!confirmResult) {
return;
}
}
if (Object.is(actionTarget, 'MULTIDATA')) {
actionContext.$Notice(actionContext.$t('app.commonWords.nosupportmultile'));
} else {
let data: any = {};
let tempData: any = {};
let tempContext: any = {};
let tempViewParam: any = {};
const _this: any = actionContext;
if (this.actionModel.saveTargetFirst && xData) {
const result: any = await xData.save(args, false);
if (Object.is(actionTarget, 'SINGLEDATA')) {
Object.assign(args[0], result.data);
} else {
args = [result.data];
}
}
if (Object.is(actionTarget, 'SINGLEKEY') || Object.is(actionTarget, 'MULTIKEY')) {
// todo 后台调用获取主键及主信息属性的name
const entityName = this.actionModel.getPSAppDataEntity()?.codeName.toLowerCase();
const key = (ModelTool.getAppEntityKeyField(
this.actionModel.getPSAppDataEntity(),
) as IPSAppDEField)?.name.toLowerCase();
const majorKey = (ModelTool.getAppEntityMajorField(
this.actionModel.getPSAppDataEntity(),
) as IPSAppDEField)?.name.toLowerCase();
if (args[0]?.[key]) {
Object.assign(tempContext, { [entityName!]: `%${key}%` });
} else {
Object.assign(tempContext, { [entityName!]: `%${entityName}%` });
}
Object.assign(tempViewParam, { [key!]: `%${key}%` });
Object.assign(tempViewParam, { [majorKey]: `%${majorKey}%` });
} else if (Object.is(actionTarget, 'SINGLEDATA')) {
data = args[0] ? args[0] : {};
}
// 自定义导航参数优先级大于预置导航参数
const navigateContexts = this.actionModel.getPSNavigateContexts();
if (navigateContexts && navigateContexts.length > 0) {
const localContext = Util.formatNavParam(navigateContexts);
Object.assign(tempContext, localContext);
}
const navigateParams = this.actionModel.getPSNavigateParams();
if (navigateParams && navigateParams.length > 0) {
const localParam = Util.formatNavParam(navigateParams);
Object.assign(tempViewParam, localParam);
}
tempContext = UIActionTool.handleContextParam(actionTarget, args, context, params, tempContext);
if (Object.is(actionTarget, 'SINGLEDATA')) {
tempData = UIActionTool.handleActionParam(actionTarget, args, context, params, tempViewParam);
Object.assign(data, tempData);
} else {
data = UIActionTool.handleActionParam(actionTarget, args, context, params, tempViewParam);
}
// 多项数据主键转换数据
if (Object.is(actionTarget, 'MULTIKEY')) {
let tempDataArray: Array<any> = [];
if (args.length > 1 && Object.keys(data).length > 0) {
for (let i = 0; i < args.length; i++) {
let tempObject: any = {};
Object.keys(data).forEach((key: string) => {
Object.assign(tempObject, { [key]: data[key].split(',')[i] });
});
tempDataArray.push(tempObject);
}
} else {
tempDataArray.push(data);
}
data = tempDataArray;
}
Object.assign(context, tempContext);
// 构建srfparentdename和srfparentkey
let parentObj: any = {
srfparentdename: srfParentDeName ? srfParentDeName : null,
srfparentkey: srfParentDeName ? context[srfParentDeName.toLowerCase()] : null,
};
if (!Object.is(actionTarget, 'MULTIKEY')) {
Object.assign(data, parentObj);
}
Object.assign(context, parentObj);
if (context && context.srfsessionid) {
context.srfsessionkey = context.srfsessionid;
delete context.srfsessionid;
}
const backend = async () => {
if (xData && xData.formValidateStatus instanceof Function) {
if (!await xData.formValidateStatus()) {
actionContext.$Notice(actionContext.$t('app.searchform.globalerrortip') as string);
return;
}
}
if (this.actionModel.getPSAppDataEntity() && this.actionModel.getPSAppDEMethod()) {
DataServiceHelp.getInstance()
.getService((this.actionModel.getPSAppDataEntity() as IPSAppDataEntity),context)
.then(async (curService: any) => {
const method: IPSAppDEMethod = this.actionModel.getPSAppDEMethod() as IPSAppDEMethod;
const methodCodeName = method?.codeName;
let viewLoadingService = actionContext.viewLoadingService ? actionContext.viewLoadingService : {};
viewLoadingService.isLoading = true;
let promises: any;
if (Object.is(actionTarget, 'MULTIKEY')) {
if (curService && curService[`${methodCodeName}Batch`]) {
promises = curService[`${methodCodeName}Batch`](
context,
data,
this.actionModel.showBusyIndicator
)
} else {
let promiseArr: any = [];
if (data && data.length > 0) {
const key = this.actionModel.getPSAppDataEntity?.()?.codeName?.toLowerCase() as string;
const srfkeys = context[key]?.split(',');
data.forEach((ele: any, index: number) => {
const tempContext = Util.deepCopy(context);
Object.assign(tempContext, { [key]: srfkeys[index] });
promiseArr.push(curService[methodCodeName](tempContext, ele, this.actionModel.showBusyIndicator));
})
}
promises = Promise.all(promiseArr);
}
} else {
promises = curService[methodCodeName](
context,
data,
this.actionModel.showBusyIndicator
)
}
promises.then(async (response: any) => {
if (Object.is(actionTarget, 'SINGLEDATA')) {
Util.clearAdditionalData(tempData, args[0]);
}
if ((!response || response.status !== 200) && !Array.isArray(response)) {
actionContext.$Notice(response?.message as string);
return;
}
let { data } = response;
if(response && Array.isArray(response) && response.length >0){
data = [];
response.forEach((item:any) =>{
data.push(item?.data);
})
}
if (this.isMergeParam && args && args.length > 0 && Object.prototype.toString.call(data) === '[Object Object]') {
Object.assign(args[0], data);
actionContext.$forceUpdate();
}
viewLoadingService.isLoading = false;
if (this.actionModel.showBusyIndicator) {
if (this.actionModel.successMsg) {
NoticeHandler.message(response,() =>{
actionContext.$success(this.actionModel.successMsg, 'AppBackEndAction');
});
}
}
if (
this.actionModel.reloadData &&
xData &&
xData.refresh &&
xData.refresh instanceof Function
) {
xData.refresh(args);
}
if (this.actionModel.closeEditView) {
actionContext.closeView(null);
}
// 后续界面行为
if (this.actionModel.M?.getNextPSUIAction) {
const { data: result } = response;
let _args: any[] = [];
if (Object.is(actionContext.$util.typeOf(result), 'array')) {
_args = [...result];
} else if (Object.is(actionContext.$util.typeOf(result), 'object')) {
_args = [{ ...result }];
} else {
_args = [...args];
}
getPSUIActionByModelObject(this.actionModel).then((nextUIaction: any) => {
if (nextUIaction.getPSAppDataEntity()) {
let [tag, appDeName] = nextUIaction.id.split('@');
if (deUIService) {
return deUIService.excuteAction(
tag,
_args,
context,
params,
$event,
xData,
actionContext,
undefined,
deUIService,
);
}
} else {
return (AppGlobalService.getInstance() as any).executeGlobalAction(
nextUIaction.id,
_args,
context,
params,
$event,
xData,
actionContext,
undefined,
);
}
});
} else {
if (Object.is(this.actionModel?.uILogicAttachMode, 'AFTER')) {
return this.executeDEUILogic(args, context, params, $event, xData, actionContext, context?.srfparentdename);
} else {
return new UIActionResult({ ok: true, result: args });
}
}
})
.catch((response: any) => {
viewLoadingService.isLoading = false;
if (response) {
actionContext.$Notice(response.message);
}
});
});
}
};
if (this.actionModel.getFrontPSAppView()) {
const frontPSAppView: IPSAppView | null = this.actionModel.getFrontPSAppView();
await frontPSAppView?.fill(true);
if (!frontPSAppView) {
return;
}
const view: any = {
viewname: 'app-view-shell',
height: frontPSAppView.height,
width: frontPSAppView.width,
title: actionContext.$tl(frontPSAppView.getCapPSLanguageRes()?.lanResTag, frontPSAppView.caption),
};
if (frontPSAppView && frontPSAppView.modelPath) {
Object.assign(context, { viewpath: frontPSAppView.modelPath });
}
if (frontPSAppView.openMode?.indexOf('DRAWER') !== -1) {
const result = await this.openService.openDrawer(view, context, data);
if (result && Object.is(result.ret, 'OK')) {
Object.assign(data, { srfactionparam: result.datas });
backend();
}
} else if (Object.is(frontPSAppView.openMode, 'POPOVER')) {
const result = await this.openService.openPopOver(view, context, data);
if (result && Object.is(result.ret, 'OK')) {
Object.assign(data, { srfactionparam: result.datas });
backend();
}
} else {
const result: any = await this.openService.openModal(view, context, data);
if (result && Object.is(result.ret, 'OK')) {
Object.assign(data, { srfactionparam: result.datas });
backend();
}
}
} else {
backend();
}
}
}
}