@byteluck-fe/model-driven-upgrade 4.41.0-lx0 → 5.3.1-1-zt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ import { loop, CONTROL_TYPE } from '@byteluck-fe/model-driven-shared';
2
+ var dataCleaner = function(schemaItems, payload) {
3
+ var isArray = Array.isArray(schemaItems);
4
+ var schemaArray = isArray ? schemaItems : [
5
+ schemaItems
6
+ ];
7
+ var new_schema = loop(schemaArray, function(item) {
8
+ return conversion(item, payload);
9
+ });
10
+ // 将footers的数据转入headers中
11
+ conversionFootersToHeaders(new_schema);
12
+ conversionRowStyle(new_schema);
13
+ return isArray ? new_schema : new_schema[0];
14
+ };
15
+ function conversion(schema, payload) {
16
+ if (schema.type === CONTROL_TYPE.SIMPLE_SEARCH) {
17
+ schema.children.forEach(function(item) {
18
+ if (item.type === CONTROL_TYPE.SELECT || item.type === CONTROL_TYPE.SELECT_MULTIPLE) {
19
+ var selectInstance = item;
20
+ if (selectInstance.props.option_config === 'datasource') {
21
+ selectInstance.props.default_show_options = false;
22
+ }
23
+ }
24
+ });
25
+ }
26
+ return schema;
27
+ }
28
+ // 行背景色格式转换成单元格背景色格式
29
+ function conversionRowStyle(schema) {
30
+ if (schema[0].type === CONTROL_TYPE.LIST_VIEW) {
31
+ var props = schema[0].props;
32
+ var _props_row_style_type, _props_row_style_bg_color;
33
+ var rowStyle = {
34
+ "type": (_props_row_style_type = props.row_style_type) !== null && _props_row_style_type !== void 0 ? _props_row_style_type : "none",
35
+ "interval": {
36
+ "color": (_props_row_style_bg_color = props.row_style_bg_color) !== null && _props_row_style_bg_color !== void 0 ? _props_row_style_bg_color : ''
37
+ },
38
+ "rules": []
39
+ };
40
+ if (props.row_style_rules) {
41
+ props.row_style_rules.forEach(function(rule) {
42
+ var id = rule.id;
43
+ var setting = {
44
+ "color": rule.color,
45
+ "type": "background",
46
+ "scope": "row",
47
+ "fieldCodes": [
48
+ "_row_"
49
+ ]
50
+ };
51
+ var script;
52
+ if (props.row_style_rules_script) {
53
+ var scriptItem = props.row_style_rules_script.find(function(scriptItem) {
54
+ return scriptItem.id === id;
55
+ });
56
+ if (scriptItem) {
57
+ script = parseScript(rule.filters, scriptItem.script);
58
+ }
59
+ }
60
+ rule.settings = [
61
+ setting
62
+ ];
63
+ rule.script = script;
64
+ delete rule.color;
65
+ });
66
+ rowStyle.rules = props.row_style_rules;
67
+ }
68
+ props.row_style = rowStyle;
69
+ delete props.row_style_type;
70
+ delete props.row_style_bg_color;
71
+ delete props.row_style_rules;
72
+ delete props.row_style_rules_script;
73
+ }
74
+ }
75
+ function getRuleLeftValuesOfNeedSpecialMatch(filters, leftValues) {
76
+ if (!leftValues) {
77
+ leftValues = {};
78
+ }
79
+ filters.forEach(function(filter) {
80
+ if (filter.children) {
81
+ getRuleLeftValuesOfNeedSpecialMatch(filter.children, leftValues);
82
+ } else {
83
+ var left = filter.left_variable_bo;
84
+ switch(left.type){
85
+ case 'people':
86
+ case 'department':
87
+ case 'array':
88
+ case 'timestamp':
89
+ var field = left.value;
90
+ leftValues[field] = left;
91
+ break;
92
+ }
93
+ }
94
+ });
95
+ return leftValues;
96
+ }
97
+ function getScriptList(script) {
98
+ script = script.replace(/\(|\)/g, '').replace(/(\|\|)|(&&)/g, '__split__');
99
+ var list = script.split('__split__').map(function(str) {
100
+ return str.replace(/^\s+|\s+$/gm, '');
101
+ });
102
+ return list;
103
+ }
104
+ function getScriptOperateAndValue(script) {
105
+ var operate = '';
106
+ var value = '';
107
+ if (script[0] === '!') {
108
+ operate = 'is_empty';
109
+ } else {
110
+ var match = script.match(/(===|!=|>|>=|<|<=)/);
111
+ if (match) {
112
+ var oldOperate = match[0];
113
+ switch(oldOperate){
114
+ case '===':
115
+ operate = 'op_equal';
116
+ break;
117
+ case '!=':
118
+ operate = 'op_no_equal';
119
+ break;
120
+ case '>':
121
+ operate = 'op_greater';
122
+ break;
123
+ case '>=':
124
+ operate = 'op_greater_equal';
125
+ break;
126
+ case '<':
127
+ operate = 'op_less';
128
+ break;
129
+ case '<=':
130
+ operate = 'op_less_equal';
131
+ break;
132
+ default:
133
+ operate = 'is_not_empty';
134
+ break;
135
+ }
136
+ value = script.split(oldOperate)[1] || '';
137
+ } else {
138
+ operate = 'is_not_empty';
139
+ }
140
+ }
141
+ return {
142
+ operate: operate,
143
+ value: value
144
+ };
145
+ }
146
+ function parseScript(filters, script) {
147
+ var leftValues = getRuleLeftValuesOfNeedSpecialMatch(filters);
148
+ var scriptList = getScriptList(script);
149
+ scriptList.forEach(function(scriptItem) {
150
+ Object.keys(leftValues).forEach(function(field) {
151
+ var index = scriptItem.indexOf("params.data.data_value_map['".concat(field, "']"));
152
+ if (index > -1) {
153
+ var left = leftValues[field];
154
+ var type = left.type;
155
+ var _getScriptOperateAndValue = getScriptOperateAndValue(scriptItem), operate = _getScriptOperateAndValue.operate, value = _getScriptOperateAndValue.value;
156
+ var newScriptItem = "SpecialMatch(data, sys, '".concat(field, "', '").concat(type, "', '").concat(operate, "', ").concat(value ? value : "''", ")");
157
+ script = script.replace(scriptItem, newScriptItem);
158
+ }
159
+ });
160
+ });
161
+ script = script.replace(/params.data.data_value_map/g, 'data');
162
+ return script;
163
+ }
164
+ function conversionFootersToHeaders(schema) {
165
+ if (schema[0].type === CONTROL_TYPE.LIST_VIEW) {
166
+ var tableSchema = schema[0].children.find(function(item) {
167
+ return item.type === CONTROL_TYPE.GRID_TABLE;
168
+ });
169
+ if (tableSchema) {
170
+ var headers = tableSchema.props.headers;
171
+ var footers = tableSchema.props.footers;
172
+ var footersObj = {};
173
+ if (footers && footers.length > 0) {
174
+ footers.forEach(function(item) {
175
+ var id = item.id.replace('foot_', '');
176
+ var children = item.children;
177
+ if (children && children.length > 0) {
178
+ if (item.children[0].type !== CONTROL_TYPE.BUTTON) {
179
+ item.children[0].field_type = item.field_type || 'varchar';
180
+ }
181
+ }
182
+ footersObj[id] = item;
183
+ });
184
+ }
185
+ headers.forEach(function(header) {
186
+ var footer = footersObj[header.id];
187
+ if (footer) {
188
+ var footerChildren = footer.children;
189
+ if (!footerChildren || footerChildren.length === 0) {
190
+ return;
191
+ }
192
+ var headerChildren = header.children || [];
193
+ header.children = [].concat(headerChildren, footerChildren);
194
+ }
195
+ });
196
+ tableSchema.props.footers = [];
197
+ }
198
+ }
199
+ return schema;
200
+ }
201
+ export { dataCleaner };