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
/**
* 界面行为工具类
*/
export class UIActionTool {
/**
* 处理应用上下文参数
*
* @param actionTarget 数据目标
* @param args 传入数据对象
* @param parentContext 父上下文
* @param parentParams 父参数
* @param param 传入应用上下数据参数
*/
public static handleContextParam(actionTarget: any, args: any,parentContext:any,parentParams:any, context: any) {
return this.formatData(actionTarget, args,parentContext,parentParams,context);
}
/**
* 处理界面行为参数
*
* @param actionTarget 数据目标
* @param args 传入数据对象
* @param parentContext 父上下文
* @param parentParams 父参数
* @param param 传入界面行为附加参数
*/
public static handleActionParam(actionTarget: any, args: any,parentContext:any,parentParams:any, params: any) {
return this.formatData(actionTarget, args,parentContext,parentParams,params);
}
/**
* 格式化数据
*
* @private
* @static
* @param {*} actionTarget
* @param {*} args
* @param parentContext
* @param parentParams
* @param {*} _params
* @returns {*}
* @memberof UIActionTool
*/
private static formatData(actionTarget: any, args: any,parentContext:any,parentParams:any, _params: any): any {
let _data: any = {};
if (Object.is(actionTarget, 'SINGLEKEY') || Object.is(actionTarget, 'NONE')) {
let [arg] = args;
Object.keys(_params).forEach((name: string) => {
let hasProperty = true;
if (!name) {
return;
}
let value: string | null = _params[name];
if (value && typeof(value) === 'string' && value.startsWith('%') && value.endsWith('%')) {
const key = value.substring(1, value.length - 1);
if (arg && arg.hasOwnProperty(key) && Object.is(actionTarget, 'SINGLEKEY')) {
value = (arg[key] !== null && arg[key] !== undefined) ? arg[key] : null;
} else if(parentContext && parentContext.hasOwnProperty(key)){
value = (parentContext[key] !== null && parentContext[key] !== undefined) ? parentContext[key] : null;
}else if(parentParams && parentParams.hasOwnProperty(key)){
value = (parentParams[key] !== null && parentParams[key] !== undefined) ? parentParams[key] : null;
}else {
hasProperty = false;
}
}
if(hasProperty){
Object.assign(_data, { [name.toLowerCase()]: value });
}
});
} else if (Object.is(actionTarget, 'MULTIKEY')) {
Object.keys(_params).forEach((name: string) => {
let noPropertyNum = 0;
if (!name) {
return;
}
let value: string | null = _params[name];
let values: any[] = [];
if (value && typeof(value) === 'string' && value.startsWith('%') && value.endsWith('%')) {
const key = value.substring(1, value.length - 1);
args.forEach((arg: any) => {
if (arg && arg.hasOwnProperty(key)) {
value = (arg[key] !== null && arg[key] !== undefined) ? arg[key] : null;
}else if(parentContext && parentContext.hasOwnProperty(key)){
value = (parentContext[key] !== null && parentContext[key] !== undefined) ? parentContext[key] : null;
}else if(parentParams && parentParams.hasOwnProperty(key)){
value = (parentParams[key] !== null && parentParams[key] !== undefined) ? parentParams[key] : null;
}else {
value = null;
noPropertyNum++;
}
values.push(value);
});
}
if(values.length !== noPropertyNum){
Object.assign(_data, { [name.toLowerCase()]: values.length > 0 ? values.join(',') : value });
}
});
}
return _data;
}
}