@steedos/filters 2.2.54-beta.3 → 2.2.54-beta.4
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.
- package/dist/assets.json +11 -0
- package/dist/steedos-filters.umd.js +1286 -0
- package/dist/steedos-filters.umd.min.js +7 -0
- package/package.json +7 -5
|
@@ -0,0 +1,1286 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash'), require('moment')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash', 'moment'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SteedosFilters = {}, global._, global.moment));
|
|
5
|
+
})(this, (function (exports, lodash, moment) {
|
|
6
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
9
|
+
|
|
10
|
+
function leftPad(text, length) {
|
|
11
|
+
while(text.length < length) {
|
|
12
|
+
text = "0" + text;
|
|
13
|
+
}
|
|
14
|
+
return text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var FORMAT_TYPES = {
|
|
18
|
+
"3": "abbreviated",
|
|
19
|
+
"4": "wide",
|
|
20
|
+
"5": "narrow"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var LDML_FORMATTERS = {
|
|
24
|
+
y: function(date, count, useUtc) {
|
|
25
|
+
var year = date[useUtc ? "getUTCFullYear" : "getFullYear"]();
|
|
26
|
+
if(count === 2) {
|
|
27
|
+
year = year % 100;
|
|
28
|
+
}
|
|
29
|
+
return leftPad(year.toString(), count);
|
|
30
|
+
},
|
|
31
|
+
M: function(date, count, useUtc, dateParts) {
|
|
32
|
+
var month = date[useUtc ? "getUTCMonth" : "getMonth"]();
|
|
33
|
+
var formatType = FORMAT_TYPES[count];
|
|
34
|
+
if(formatType) {
|
|
35
|
+
return dateParts.getMonthNames(formatType, "format")[month];
|
|
36
|
+
}
|
|
37
|
+
return leftPad((month + 1).toString(), Math.min(count, 2));
|
|
38
|
+
},
|
|
39
|
+
L: function(date, count, useUtc, dateParts) {
|
|
40
|
+
var month = date[useUtc ? "getUTCMonth" : "getMonth"]();
|
|
41
|
+
var formatType = FORMAT_TYPES[count];
|
|
42
|
+
if(formatType) {
|
|
43
|
+
return dateParts.getMonthNames(formatType, "standalone")[month];
|
|
44
|
+
}
|
|
45
|
+
return leftPad((month + 1).toString(), Math.min(count, 2));
|
|
46
|
+
},
|
|
47
|
+
Q: function(date, count, useUtc, dateParts) {
|
|
48
|
+
var month = date[useUtc ? "getUTCMonth" : "getMonth"]();
|
|
49
|
+
var quarter = Math.floor(month / 3);
|
|
50
|
+
var formatType = FORMAT_TYPES[count];
|
|
51
|
+
if(formatType) {
|
|
52
|
+
return dateParts.getQuarterNames(formatType)[quarter];
|
|
53
|
+
}
|
|
54
|
+
return leftPad((quarter + 1).toString(), Math.min(count, 2));
|
|
55
|
+
},
|
|
56
|
+
E: function(date, count, useUtc, dateParts) {
|
|
57
|
+
var day = date[useUtc ? "getUTCDay" : "getDay"]();
|
|
58
|
+
var formatType = FORMAT_TYPES[count < 3 ? 3 : count];
|
|
59
|
+
return dateParts.getDayNames(formatType)[day];
|
|
60
|
+
},
|
|
61
|
+
a: function(date, count, useUtc, dateParts) {
|
|
62
|
+
var hours = date[useUtc ? "getUTCHours" : "getHours"](),
|
|
63
|
+
period = hours < 12 ? 0 : 1,
|
|
64
|
+
formatType = FORMAT_TYPES[count];
|
|
65
|
+
return dateParts.getPeriodNames(formatType)[period];
|
|
66
|
+
},
|
|
67
|
+
d: function(date, count, useUtc) {
|
|
68
|
+
return leftPad(date[useUtc ? "getUTCDate" : "getDate"]().toString(), Math.min(count, 2));
|
|
69
|
+
},
|
|
70
|
+
H: function(date, count, useUtc) {
|
|
71
|
+
return leftPad(date[useUtc ? "getUTCHours" : "getHours"]().toString(), Math.min(count, 2));
|
|
72
|
+
},
|
|
73
|
+
h: function(date, count, useUtc) {
|
|
74
|
+
var hours = date[useUtc ? "getUTCHours" : "getHours"]();
|
|
75
|
+
return leftPad((hours % 12 || 12).toString(), Math.min(count, 2));
|
|
76
|
+
},
|
|
77
|
+
m: function(date, count, useUtc) {
|
|
78
|
+
return leftPad(date[useUtc ? "getUTCMinutes" : "getMinutes"]().toString(), Math.min(count, 2));
|
|
79
|
+
},
|
|
80
|
+
s: function(date, count, useUtc) {
|
|
81
|
+
return leftPad(date[useUtc ? "getUTCSeconds" : "getSeconds"]().toString(), Math.min(count, 2));
|
|
82
|
+
},
|
|
83
|
+
S: function(date, count, useUtc) {
|
|
84
|
+
return leftPad(date[useUtc ? "getUTCMilliseconds" : "getMilliseconds"]().toString(), 3).substr(0, count);
|
|
85
|
+
},
|
|
86
|
+
x: function(date, count, useUtc) {
|
|
87
|
+
var timezoneOffset = useUtc ? 0 : date.getTimezoneOffset(),
|
|
88
|
+
signPart = timezoneOffset > 0 ? "-" : "+",
|
|
89
|
+
timezoneOffsetAbs = Math.abs(timezoneOffset),
|
|
90
|
+
hours = Math.floor(timezoneOffsetAbs / 60),
|
|
91
|
+
minutes = timezoneOffsetAbs % 60,
|
|
92
|
+
hoursPart = leftPad(hours.toString(), 2),
|
|
93
|
+
minutesPart = leftPad(minutes.toString(), 2);
|
|
94
|
+
|
|
95
|
+
return signPart + hoursPart + (count >= 3 ? ":" : "") + (count > 1 || minutes ? minutesPart : "");
|
|
96
|
+
},
|
|
97
|
+
X: function(date, count, useUtc) {
|
|
98
|
+
if(useUtc || !date.getTimezoneOffset()) {
|
|
99
|
+
return "Z";
|
|
100
|
+
}
|
|
101
|
+
return LDML_FORMATTERS.x(date, count, useUtc);
|
|
102
|
+
},
|
|
103
|
+
Z: function(date, count, useUtc) {
|
|
104
|
+
return LDML_FORMATTERS.X(date, count >= 5 ? 3 : 2, useUtc);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
var getFormatter = function(format, dateParts) {
|
|
109
|
+
return function(date) {
|
|
110
|
+
var charIndex,
|
|
111
|
+
formatter,
|
|
112
|
+
char,
|
|
113
|
+
charCount = 0,
|
|
114
|
+
separator = "'",
|
|
115
|
+
isEscaping = false,
|
|
116
|
+
isCurrentCharEqualsNext,
|
|
117
|
+
result = "";
|
|
118
|
+
|
|
119
|
+
if(!date) return null;
|
|
120
|
+
|
|
121
|
+
if(!format) return date;
|
|
122
|
+
|
|
123
|
+
var useUtc = format[format.length - 1] === "Z" || format.slice(-3) === "'Z'";
|
|
124
|
+
|
|
125
|
+
for(charIndex = 0; charIndex < format.length; charIndex++) {
|
|
126
|
+
char = format[charIndex];
|
|
127
|
+
formatter = LDML_FORMATTERS[char];
|
|
128
|
+
isCurrentCharEqualsNext = char === format[charIndex + 1];
|
|
129
|
+
charCount++;
|
|
130
|
+
|
|
131
|
+
if(!isCurrentCharEqualsNext) {
|
|
132
|
+
if(formatter && !isEscaping) {
|
|
133
|
+
result += formatter(date, charCount, useUtc, dateParts);
|
|
134
|
+
}
|
|
135
|
+
charCount = 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if(char === separator && !isCurrentCharEqualsNext) {
|
|
139
|
+
isEscaping = !isEscaping;
|
|
140
|
+
} else if(isEscaping || !formatter) {
|
|
141
|
+
result += char;
|
|
142
|
+
}
|
|
143
|
+
if(char === separator && isCurrentCharEqualsNext) {
|
|
144
|
+
charIndex++;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const _getFormatter = getFormatter;
|
|
152
|
+
|
|
153
|
+
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
|
154
|
+
DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
155
|
+
PERIODS = ["AM", "PM"],
|
|
156
|
+
QUARTERS = ["Q1", "Q2", "Q3", "Q4"];
|
|
157
|
+
|
|
158
|
+
var cutCaptions = function(captions, format) {
|
|
159
|
+
var lengthByFormat = {
|
|
160
|
+
abbreviated: 3,
|
|
161
|
+
short: 2,
|
|
162
|
+
narrow: 1
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return captions.map(function (caption) {
|
|
166
|
+
return caption.substr(0, lengthByFormat[format]);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
function getMonthNames(format) {
|
|
171
|
+
return cutCaptions(MONTHS, format);
|
|
172
|
+
}
|
|
173
|
+
function getDayNames(format) {
|
|
174
|
+
return cutCaptions(DAYS, format);
|
|
175
|
+
}
|
|
176
|
+
function getQuarterNames(format) {
|
|
177
|
+
return QUARTERS;
|
|
178
|
+
}
|
|
179
|
+
function getPeriodNames(format) {
|
|
180
|
+
return PERIODS;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var defaultDateNames = {
|
|
184
|
+
getMonthNames,
|
|
185
|
+
getDayNames,
|
|
186
|
+
getQuarterNames,
|
|
187
|
+
getPeriodNames
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// const DevExpress = require("devextreme/bundles/modules/core");
|
|
191
|
+
// const Guid = require("devextreme/core/guid");
|
|
192
|
+
// const EdmLiteral = require("devextreme/data/odata/utils").EdmLiteral;
|
|
193
|
+
|
|
194
|
+
const DevExpressData = {
|
|
195
|
+
utils: {
|
|
196
|
+
isConjunctiveOperator: function (condition) {
|
|
197
|
+
return /^(and|&&|&)$/i.test(condition);
|
|
198
|
+
},
|
|
199
|
+
normalizeBinaryCriterion: function (crit) {
|
|
200
|
+
return [
|
|
201
|
+
crit[0],
|
|
202
|
+
crit.length < 3 ? "=" : String(crit[1]).toLowerCase(),
|
|
203
|
+
crit.length < 2 ? true : crit[crit.length - 1]
|
|
204
|
+
];
|
|
205
|
+
},
|
|
206
|
+
isUnaryOperation: function (crit) {
|
|
207
|
+
return crit[0] === "!" && Array.isArray(crit[1]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const DevExpressOData = {
|
|
213
|
+
pad(text, length, right) {
|
|
214
|
+
text = String(text);
|
|
215
|
+
while (text.length < length) {
|
|
216
|
+
text = right ? (text + "0") : ("0" + text);
|
|
217
|
+
}
|
|
218
|
+
return text;
|
|
219
|
+
},
|
|
220
|
+
padLeft2(text) {
|
|
221
|
+
return this.pad(text, 2);
|
|
222
|
+
},
|
|
223
|
+
serializePropName(propName) {
|
|
224
|
+
return propName.replace(/\./g, "/");
|
|
225
|
+
},
|
|
226
|
+
serializeValue(value, protocolVersion) {
|
|
227
|
+
if(value === undefined){
|
|
228
|
+
// 解决value为undefined的时候解析异常,需要返回null值
|
|
229
|
+
// 有可能serializeValueV4函数中if (value instanceof Guid)逻辑被注释掉造成的,放开应该就会自动返回null
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
switch (protocolVersion) {
|
|
233
|
+
case 2:
|
|
234
|
+
return this.serializeValueV2(value);
|
|
235
|
+
case 3:
|
|
236
|
+
return this.serializeValueV2(value);
|
|
237
|
+
case 4:
|
|
238
|
+
return this.serializeValueV4(value);
|
|
239
|
+
default:
|
|
240
|
+
return this.serializeValueV4(value);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
serializeValueV2(value) {
|
|
244
|
+
if (value instanceof Date) {
|
|
245
|
+
return this.serializeDate(value);
|
|
246
|
+
}
|
|
247
|
+
// if (value instanceof Guid) {
|
|
248
|
+
// return "guid'" + value + "'";
|
|
249
|
+
// }
|
|
250
|
+
// if (value instanceof EdmLiteral) {
|
|
251
|
+
// return value.valueOf();
|
|
252
|
+
// }
|
|
253
|
+
if (typeof value === "string") {
|
|
254
|
+
return this.serializeString(value);
|
|
255
|
+
}
|
|
256
|
+
return String(value);
|
|
257
|
+
},
|
|
258
|
+
serializeValueV4(value) {
|
|
259
|
+
if (value instanceof Date) {
|
|
260
|
+
return this.formatISO8601(value, false, false);
|
|
261
|
+
}
|
|
262
|
+
// if (value instanceof Guid) {
|
|
263
|
+
// return value.valueOf();
|
|
264
|
+
// }
|
|
265
|
+
if (Array.isArray(value)) {
|
|
266
|
+
return "[" + value.map((item)=>{
|
|
267
|
+
return this.serializeValueV4(item);
|
|
268
|
+
}).join(",") + "]";
|
|
269
|
+
}
|
|
270
|
+
return this.serializeValueV2(value);
|
|
271
|
+
},
|
|
272
|
+
serializeString(value) {
|
|
273
|
+
return "'" + value.replace(/'/g, "''") + "'";
|
|
274
|
+
},
|
|
275
|
+
serializeDate(value, serializationFormat) {
|
|
276
|
+
if (!serializationFormat) {
|
|
277
|
+
return value;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (!(value instanceof Date)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (serializationFormat === "number") {
|
|
285
|
+
return value && value.valueOf ? value.valueOf() : null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return _getFormatter(serializationFormat, defaultDateNames)(value);
|
|
289
|
+
},
|
|
290
|
+
formatISO8601(date, skipZeroTime, skipTimezone) {
|
|
291
|
+
var bag = [];
|
|
292
|
+
|
|
293
|
+
var isZeroTime = function () {
|
|
294
|
+
return date.getUTCHours() + date.getUTCMinutes() + date.getUTCSeconds() + date.getUTCMilliseconds() < 1;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
bag.push(date.getUTCFullYear());
|
|
298
|
+
bag.push("-");
|
|
299
|
+
bag.push(this.padLeft2(date.getUTCMonth() + 1));
|
|
300
|
+
bag.push("-");
|
|
301
|
+
bag.push(this.padLeft2(date.getUTCDate()));
|
|
302
|
+
|
|
303
|
+
if (!(skipZeroTime && isZeroTime())) {
|
|
304
|
+
bag.push("T");
|
|
305
|
+
bag.push(this.padLeft2(date.getUTCHours()));
|
|
306
|
+
bag.push(":");
|
|
307
|
+
bag.push(this.padLeft2(date.getUTCMinutes()));
|
|
308
|
+
bag.push(":");
|
|
309
|
+
bag.push(this.padLeft2(date.getUTCSeconds()));
|
|
310
|
+
|
|
311
|
+
if (date.getUTCMilliseconds()) {
|
|
312
|
+
bag.push(".");
|
|
313
|
+
bag.push(this.pad(date.getUTCMilliseconds(), 3));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (!skipTimezone) {
|
|
317
|
+
bag.push("Z");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return bag.join("");
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class SteedosFilter {
|
|
327
|
+
|
|
328
|
+
constructor(filters, odataProtocolVersion = 4, forceLowerCase = true){
|
|
329
|
+
this.filters = filters || [];
|
|
330
|
+
this.protocolVersion = odataProtocolVersion;
|
|
331
|
+
this.forceLowerCase = forceLowerCase;
|
|
332
|
+
this.formatters = {
|
|
333
|
+
"=": this.createBinaryOperationFormatter("eq"),
|
|
334
|
+
"<>": this.createBinaryOperationFormatter("ne"),
|
|
335
|
+
">": this.createBinaryOperationFormatter("gt"),
|
|
336
|
+
">=": this.createBinaryOperationFormatter("ge"),
|
|
337
|
+
"<": this.createBinaryOperationFormatter("lt"),
|
|
338
|
+
"<=": this.createBinaryOperationFormatter("le"),
|
|
339
|
+
"startswith": this.createStringFuncFormatter("startswith"),
|
|
340
|
+
"endswith": this.createStringFuncFormatter("endswith")
|
|
341
|
+
};
|
|
342
|
+
this.formattersV2 = {...this.formatters, ...{
|
|
343
|
+
"contains": this.createStringFuncFormatter("substringof", true),
|
|
344
|
+
"notcontains": this.createStringFuncFormatter("not substringof", true)
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
this.formattersV4 = {
|
|
348
|
+
...this.formatters, ...{
|
|
349
|
+
"contains": this.createStringFuncFormatter("contains"),
|
|
350
|
+
"notcontains": this.createStringFuncFormatter("not contains"),
|
|
351
|
+
"notstartswith": this.createStringFuncFormatter("not startswith"),
|
|
352
|
+
"notendswith": this.createStringFuncFormatter("not endswith"),
|
|
353
|
+
"in": this.createBinaryOperationFormatter("in"),
|
|
354
|
+
"notin": this.createBinaryOperationFormatter("notin")
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
createBinaryOperationFormatter(op) {
|
|
360
|
+
return (prop, val)=> {
|
|
361
|
+
return prop + " " + op + " " + val;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
createStringFuncFormatter(op, reverse) {
|
|
366
|
+
return (prop, val)=> {
|
|
367
|
+
var bag = [op, "("];
|
|
368
|
+
|
|
369
|
+
if (this.forceLowerCase) {
|
|
370
|
+
// prop = prop.indexOf("tolower(") === -1 ? "tolower(" + prop + ")" : prop;
|
|
371
|
+
// forceLowerCase时不需要在prop外面增加tolower(..),因为odata-v4-mongodb等包不支持
|
|
372
|
+
val = val.toLowerCase();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (reverse) {
|
|
376
|
+
bag.push(val, ",", prop);
|
|
377
|
+
} else {
|
|
378
|
+
bag.push(prop, ",", val);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
bag.push(")");
|
|
382
|
+
return bag.join("");
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
compileUnary(criteria) {
|
|
387
|
+
var op = criteria[0],
|
|
388
|
+
crit = this.compileCore(criteria[1]);
|
|
389
|
+
|
|
390
|
+
if (op === "!") {
|
|
391
|
+
return "not (" + crit + ")";
|
|
392
|
+
}
|
|
393
|
+
throw new Error("E4003");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
compileGroup(criteria) {
|
|
397
|
+
var bag = [],
|
|
398
|
+
groupOperator,
|
|
399
|
+
nextGroupOperator;
|
|
400
|
+
|
|
401
|
+
criteria.forEach((criterion) => {
|
|
402
|
+
if (Array.isArray(criterion)) {
|
|
403
|
+
|
|
404
|
+
if (bag.length > 1 && groupOperator !== nextGroupOperator) {
|
|
405
|
+
throw new Error("E4019");
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
bag.push("(" + this.compileCore(criterion) + ")");
|
|
409
|
+
|
|
410
|
+
groupOperator = nextGroupOperator;
|
|
411
|
+
nextGroupOperator = "and";
|
|
412
|
+
} else {
|
|
413
|
+
nextGroupOperator = DevExpressData.utils.isConjunctiveOperator(criterion) ? "and" : "or";
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
return bag.join(" " + groupOperator + " ");
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
compileBinary(criteria){
|
|
421
|
+
criteria = DevExpressData.utils.normalizeBinaryCriterion(criteria);
|
|
422
|
+
|
|
423
|
+
var op = criteria[1],
|
|
424
|
+
formatters = this.protocolVersion === 4
|
|
425
|
+
? this.formattersV4
|
|
426
|
+
: this.formattersV2,
|
|
427
|
+
formatter = formatters[op.toLowerCase()];
|
|
428
|
+
|
|
429
|
+
if (!formatter) {
|
|
430
|
+
throw new Error("E4003");
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
var fieldName = criteria[0],
|
|
434
|
+
value = criteria[2];
|
|
435
|
+
|
|
436
|
+
return formatter(
|
|
437
|
+
DevExpressOData.serializePropName(fieldName),
|
|
438
|
+
(op === 'in' || op === 'notin') ? value : DevExpressOData.serializeValue(value, this.protocolVersion)
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
compileCore(criteria) {
|
|
443
|
+
if (!criteria || criteria.length === 0){
|
|
444
|
+
return "";
|
|
445
|
+
}
|
|
446
|
+
if (Array.isArray(criteria[0])) {
|
|
447
|
+
return this.compileGroup(criteria);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (DevExpressData.utils.isUnaryOperation(criteria)) {
|
|
451
|
+
return this.compileUnary(criteria);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return this.compileBinary(criteria);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
formatFiltersToODataQuery() {
|
|
458
|
+
// 转换filters为odata串
|
|
459
|
+
let filters = this.filters;
|
|
460
|
+
let query = this.compileCore(filters);
|
|
461
|
+
return query;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var filter = /*#__PURE__*/Object.freeze({
|
|
466
|
+
__proto__: null,
|
|
467
|
+
'default': SteedosFilter
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
let t = (key) => {
|
|
471
|
+
return key;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
let getMonthDays = (year, month) => {
|
|
475
|
+
var days, endDate, millisecond, startDate;
|
|
476
|
+
if (month === 11) {
|
|
477
|
+
return 31;
|
|
478
|
+
}
|
|
479
|
+
millisecond = 1000 * 60 * 60 * 24;
|
|
480
|
+
startDate = new Date(year, month, 1);
|
|
481
|
+
endDate = new Date(year, month + 1, 1);
|
|
482
|
+
days = (endDate - startDate) / millisecond;
|
|
483
|
+
return days;
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
let getNextQuarterFirstDay = (year, month) => {
|
|
487
|
+
if (!year) {
|
|
488
|
+
year = new Date().getFullYear();
|
|
489
|
+
}
|
|
490
|
+
if (!month) {
|
|
491
|
+
month = new Date().getMonth();
|
|
492
|
+
}
|
|
493
|
+
if (month < 3) {
|
|
494
|
+
month = 3;
|
|
495
|
+
} else if (month < 6) {
|
|
496
|
+
month = 6;
|
|
497
|
+
} else if (month < 9) {
|
|
498
|
+
month = 9;
|
|
499
|
+
} else {
|
|
500
|
+
year++;
|
|
501
|
+
month = 0;
|
|
502
|
+
}
|
|
503
|
+
return new Date(year, month, 1);
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
let getLastMonthFirstDay = (year, month) => {
|
|
507
|
+
if (!year) {
|
|
508
|
+
year = new Date().getFullYear();
|
|
509
|
+
}
|
|
510
|
+
if (!month) {
|
|
511
|
+
month = new Date().getMonth();
|
|
512
|
+
}
|
|
513
|
+
// 月份为0代表本年的第一月
|
|
514
|
+
if (month === 0) {
|
|
515
|
+
month = 11;
|
|
516
|
+
year--;
|
|
517
|
+
return new Date(year, month, 1);
|
|
518
|
+
}
|
|
519
|
+
// 否则,只减去月份
|
|
520
|
+
month--;
|
|
521
|
+
return new Date(year, month, 1);
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
let getQuarterStartMonth = (month) => {
|
|
525
|
+
if (!month) {
|
|
526
|
+
month = new Date().getMonth();
|
|
527
|
+
}
|
|
528
|
+
if (month < 3) {
|
|
529
|
+
return 0;
|
|
530
|
+
} else if (month < 6) {
|
|
531
|
+
return 3;
|
|
532
|
+
} else if (month < 9) {
|
|
533
|
+
return 6;
|
|
534
|
+
}
|
|
535
|
+
return 9;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
let getLastQuarterFirstDay = (year, month) => {
|
|
539
|
+
if (!year) {
|
|
540
|
+
year = new Date().getFullYear();
|
|
541
|
+
}
|
|
542
|
+
if (!month) {
|
|
543
|
+
month = new Date().getMonth();
|
|
544
|
+
}
|
|
545
|
+
if (month < 3) {
|
|
546
|
+
year--;
|
|
547
|
+
month = 9;
|
|
548
|
+
} else if (month < 6) {
|
|
549
|
+
month = 0;
|
|
550
|
+
} else if (month < 9) {
|
|
551
|
+
month = 3;
|
|
552
|
+
} else {
|
|
553
|
+
month = 6;
|
|
554
|
+
}
|
|
555
|
+
return new Date(year, month, 1);
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
let getBetweenTimeBuiltinValueItem = (key, utcOffset) => {
|
|
559
|
+
// 过滤器between运算符,现算日期/日期时间类型字段的values值
|
|
560
|
+
var currentMonth, currentYear, endValue, firstDay, label, lastDay, lastMonday, lastMonthFinalDay, lastMonthFirstDay, lastQuarterEndDay, lastQuarterStartDay, lastSunday, last_120_days, last_30_days, last_60_days, last_7_days, last_90_days, millisecond, minusDay, monday, month, nextMonday, nextMonthFinalDay, nextMonthFirstDay, nextQuarterEndDay, nextQuarterStartDay, nextSunday, nextYear, next_120_days, next_30_days, next_60_days, next_7_days, next_90_days, now, previousYear, startValue, strEndDay, strFirstDay, strLastDay, strMonday, strStartDay, strSunday, strToday, strTomorrow, strYestday, sunday, thisQuarterEndDay, thisQuarterStartDay, tomorrow, values, week, year, yestday;
|
|
561
|
+
now = new Date();
|
|
562
|
+
// 一天的毫秒数
|
|
563
|
+
millisecond = 1000 * 60 * 60 * 24;
|
|
564
|
+
yestday = new Date(now.getTime() - millisecond);
|
|
565
|
+
tomorrow = new Date(now.getTime() + millisecond);
|
|
566
|
+
// 一周中的某一天
|
|
567
|
+
week = now.getDay();
|
|
568
|
+
// 减去的天数
|
|
569
|
+
minusDay = week !== 0 ? week - 1 : 6;
|
|
570
|
+
monday = new Date(now.getTime() - (minusDay * millisecond));
|
|
571
|
+
sunday = new Date(monday.getTime() + (6 * millisecond));
|
|
572
|
+
// 上周日
|
|
573
|
+
lastSunday = new Date(monday.getTime() - millisecond);
|
|
574
|
+
// 上周一
|
|
575
|
+
lastMonday = new Date(lastSunday.getTime() - (millisecond * 6));
|
|
576
|
+
// 下周一
|
|
577
|
+
nextMonday = new Date(sunday.getTime() + millisecond);
|
|
578
|
+
// 下周日
|
|
579
|
+
nextSunday = new Date(nextMonday.getTime() + (millisecond * 6));
|
|
580
|
+
currentYear = now.getFullYear();
|
|
581
|
+
previousYear = currentYear - 1;
|
|
582
|
+
nextYear = currentYear + 1;
|
|
583
|
+
// 当前月份
|
|
584
|
+
currentMonth = now.getMonth();
|
|
585
|
+
// 计数年、月
|
|
586
|
+
year = now.getFullYear();
|
|
587
|
+
month = now.getMonth();
|
|
588
|
+
// 本月第一天
|
|
589
|
+
firstDay = new Date(currentYear, currentMonth, 1);
|
|
590
|
+
// 当为12月的时候年份需要加1
|
|
591
|
+
// 月份需要更新为0 也就是下一年的第一个月
|
|
592
|
+
if (currentMonth === 11) {
|
|
593
|
+
year++;
|
|
594
|
+
month++;
|
|
595
|
+
} else {
|
|
596
|
+
month++;
|
|
597
|
+
}
|
|
598
|
+
nextMonthFirstDay = new Date(year, month, 1);
|
|
599
|
+
nextMonthFinalDay = new Date(year, month, getMonthDays(year, month));
|
|
600
|
+
lastDay = new Date(nextMonthFirstDay.getTime() - millisecond);
|
|
601
|
+
lastMonthFirstDay = getLastMonthFirstDay(currentYear, currentMonth);
|
|
602
|
+
lastMonthFinalDay = new Date(firstDay.getTime() - millisecond);
|
|
603
|
+
thisQuarterStartDay = new Date(currentYear, getQuarterStartMonth(currentMonth), 1);
|
|
604
|
+
thisQuarterEndDay = new Date(currentYear, getQuarterStartMonth(currentMonth) + 2, getMonthDays(currentYear, getQuarterStartMonth(currentMonth) + 2));
|
|
605
|
+
lastQuarterStartDay = getLastQuarterFirstDay(currentYear, currentMonth);
|
|
606
|
+
lastQuarterEndDay = new Date(lastQuarterStartDay.getFullYear(), lastQuarterStartDay.getMonth() + 2, getMonthDays(lastQuarterStartDay.getFullYear(), lastQuarterStartDay.getMonth() + 2));
|
|
607
|
+
nextQuarterStartDay = getNextQuarterFirstDay(currentYear, currentMonth);
|
|
608
|
+
nextQuarterEndDay = new Date(nextQuarterStartDay.getFullYear(), nextQuarterStartDay.getMonth() + 2, getMonthDays(nextQuarterStartDay.getFullYear(), nextQuarterStartDay.getMonth() + 2));
|
|
609
|
+
last_7_days = new Date(now.getTime() - (6 * millisecond));
|
|
610
|
+
last_30_days = new Date(now.getTime() - (29 * millisecond));
|
|
611
|
+
last_60_days = new Date(now.getTime() - (59 * millisecond));
|
|
612
|
+
last_90_days = new Date(now.getTime() - (89 * millisecond));
|
|
613
|
+
last_120_days = new Date(now.getTime() - (119 * millisecond));
|
|
614
|
+
next_7_days = new Date(now.getTime() + (6 * millisecond));
|
|
615
|
+
next_30_days = new Date(now.getTime() + (29 * millisecond));
|
|
616
|
+
next_60_days = new Date(now.getTime() + (59 * millisecond));
|
|
617
|
+
next_90_days = new Date(now.getTime() + (89 * millisecond));
|
|
618
|
+
next_120_days = new Date(now.getTime() + (119 * millisecond));
|
|
619
|
+
switch (key) {
|
|
620
|
+
case "last_year":
|
|
621
|
+
// 去年
|
|
622
|
+
label = t("creator_filter_operation_between_last_year");
|
|
623
|
+
startValue = new Date(previousYear + "-01-01T00:00:00Z");
|
|
624
|
+
endValue = new Date(previousYear + "-12-31T23:59:59Z");
|
|
625
|
+
break;
|
|
626
|
+
case "this_year":
|
|
627
|
+
// 今年
|
|
628
|
+
label = t("creator_filter_operation_between_this_year");
|
|
629
|
+
startValue = new Date(currentYear + "-01-01T00:00:00Z");
|
|
630
|
+
endValue = new Date(currentYear + "-12-31T23:59:59Z");
|
|
631
|
+
break;
|
|
632
|
+
case "next_year":
|
|
633
|
+
// 明年
|
|
634
|
+
label = t("creator_filter_operation_between_next_year");
|
|
635
|
+
startValue = new Date(nextYear + "-01-01T00:00:00Z");
|
|
636
|
+
endValue = new Date(nextYear + "-12-31T23:59:59Z");
|
|
637
|
+
break;
|
|
638
|
+
case "last_quarter":
|
|
639
|
+
// 上季度
|
|
640
|
+
strFirstDay = moment__default["default"](lastQuarterStartDay).format("YYYY-MM-DD");
|
|
641
|
+
strLastDay = moment__default["default"](lastQuarterEndDay).format("YYYY-MM-DD");
|
|
642
|
+
label = t("creator_filter_operation_between_last_quarter");
|
|
643
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
644
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
645
|
+
break;
|
|
646
|
+
case "this_quarter":
|
|
647
|
+
// 本季度
|
|
648
|
+
strFirstDay = moment__default["default"](thisQuarterStartDay).format("YYYY-MM-DD");
|
|
649
|
+
strLastDay = moment__default["default"](thisQuarterEndDay).format("YYYY-MM-DD");
|
|
650
|
+
label = t("creator_filter_operation_between_this_quarter");
|
|
651
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
652
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
653
|
+
break;
|
|
654
|
+
case "next_quarter":
|
|
655
|
+
// 下季度
|
|
656
|
+
strFirstDay = moment__default["default"](nextQuarterStartDay).format("YYYY-MM-DD");
|
|
657
|
+
strLastDay = moment__default["default"](nextQuarterEndDay).format("YYYY-MM-DD");
|
|
658
|
+
label = t("creator_filter_operation_between_next_quarter");
|
|
659
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
660
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
661
|
+
break;
|
|
662
|
+
case "last_month":
|
|
663
|
+
// 上月
|
|
664
|
+
strFirstDay = moment__default["default"](lastMonthFirstDay).format("YYYY-MM-DD");
|
|
665
|
+
strLastDay = moment__default["default"](lastMonthFinalDay).format("YYYY-MM-DD");
|
|
666
|
+
label = t("creator_filter_operation_between_last_month");
|
|
667
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
668
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
669
|
+
break;
|
|
670
|
+
case "this_month":
|
|
671
|
+
// 本月
|
|
672
|
+
strFirstDay = moment__default["default"](firstDay).format("YYYY-MM-DD");
|
|
673
|
+
strLastDay = moment__default["default"](lastDay).format("YYYY-MM-DD");
|
|
674
|
+
label = t("creator_filter_operation_between_this_month");
|
|
675
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
676
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
677
|
+
break;
|
|
678
|
+
case "next_month":
|
|
679
|
+
// 下月
|
|
680
|
+
strFirstDay = moment__default["default"](nextMonthFirstDay).format("YYYY-MM-DD");
|
|
681
|
+
strLastDay = moment__default["default"](nextMonthFinalDay).format("YYYY-MM-DD");
|
|
682
|
+
label = t("creator_filter_operation_between_next_month");
|
|
683
|
+
startValue = new Date(strFirstDay + "T00:00:00Z");
|
|
684
|
+
endValue = new Date(strLastDay + "T23:59:59Z");
|
|
685
|
+
break;
|
|
686
|
+
case "last_week":
|
|
687
|
+
// 上周
|
|
688
|
+
strMonday = moment__default["default"](lastMonday).format("YYYY-MM-DD");
|
|
689
|
+
strSunday = moment__default["default"](lastSunday).format("YYYY-MM-DD");
|
|
690
|
+
label = t("creator_filter_operation_between_last_week");
|
|
691
|
+
startValue = new Date(strMonday + "T00:00:00Z");
|
|
692
|
+
endValue = new Date(strSunday + "T23:59:59Z");
|
|
693
|
+
break;
|
|
694
|
+
case "this_week":
|
|
695
|
+
// 本周
|
|
696
|
+
strMonday = moment__default["default"](monday).format("YYYY-MM-DD");
|
|
697
|
+
strSunday = moment__default["default"](sunday).format("YYYY-MM-DD");
|
|
698
|
+
label = t("creator_filter_operation_between_this_week");
|
|
699
|
+
startValue = new Date(strMonday + "T00:00:00Z");
|
|
700
|
+
endValue = new Date(strSunday + "T23:59:59Z");
|
|
701
|
+
break;
|
|
702
|
+
case "next_week":
|
|
703
|
+
// 下周
|
|
704
|
+
strMonday = moment__default["default"](nextMonday).format("YYYY-MM-DD");
|
|
705
|
+
strSunday = moment__default["default"](nextSunday).format("YYYY-MM-DD");
|
|
706
|
+
label = t("creator_filter_operation_between_next_week");
|
|
707
|
+
startValue = new Date(strMonday + "T00:00:00Z");
|
|
708
|
+
endValue = new Date(strSunday + "T23:59:59Z");
|
|
709
|
+
break;
|
|
710
|
+
case "yestday":
|
|
711
|
+
// 昨天
|
|
712
|
+
strYestday = moment__default["default"](yestday).format("YYYY-MM-DD");
|
|
713
|
+
label = t("creator_filter_operation_between_yestday");
|
|
714
|
+
startValue = new Date(strYestday + "T00:00:00Z");
|
|
715
|
+
endValue = new Date(strYestday + "T23:59:59Z");
|
|
716
|
+
break;
|
|
717
|
+
case "today":
|
|
718
|
+
// 今天
|
|
719
|
+
strToday = moment__default["default"](now).format("YYYY-MM-DD");
|
|
720
|
+
label = t("creator_filter_operation_between_today");
|
|
721
|
+
startValue = new Date(strToday + "T00:00:00Z");
|
|
722
|
+
endValue = new Date(strToday + "T23:59:59Z");
|
|
723
|
+
break;
|
|
724
|
+
case "tomorrow":
|
|
725
|
+
// 明天
|
|
726
|
+
strTomorrow = moment__default["default"](tomorrow).format("YYYY-MM-DD");
|
|
727
|
+
label = t("creator_filter_operation_between_tomorrow");
|
|
728
|
+
startValue = new Date(strTomorrow + "T00:00:00Z");
|
|
729
|
+
endValue = new Date(strTomorrow + "T23:59:59Z");
|
|
730
|
+
break;
|
|
731
|
+
case "last_7_days":
|
|
732
|
+
// 过去7天
|
|
733
|
+
strStartDay = moment__default["default"](last_7_days).format("YYYY-MM-DD");
|
|
734
|
+
strEndDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
735
|
+
label = t("creator_filter_operation_between_last_7_days");
|
|
736
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
737
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
738
|
+
break;
|
|
739
|
+
case "last_30_days":
|
|
740
|
+
// 过去30天
|
|
741
|
+
strStartDay = moment__default["default"](last_30_days).format("YYYY-MM-DD");
|
|
742
|
+
strEndDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
743
|
+
label = t("creator_filter_operation_between_last_30_days");
|
|
744
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
745
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
746
|
+
break;
|
|
747
|
+
case "last_60_days":
|
|
748
|
+
// 过去60天
|
|
749
|
+
strStartDay = moment__default["default"](last_60_days).format("YYYY-MM-DD");
|
|
750
|
+
strEndDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
751
|
+
label = t("creator_filter_operation_between_last_60_days");
|
|
752
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
753
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
754
|
+
break;
|
|
755
|
+
case "last_90_days":
|
|
756
|
+
// 过去90天
|
|
757
|
+
strStartDay = moment__default["default"](last_90_days).format("YYYY-MM-DD");
|
|
758
|
+
strEndDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
759
|
+
label = t("creator_filter_operation_between_last_90_days");
|
|
760
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
761
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
762
|
+
break;
|
|
763
|
+
case "last_120_days":
|
|
764
|
+
// 过去120天
|
|
765
|
+
strStartDay = moment__default["default"](last_120_days).format("YYYY-MM-DD");
|
|
766
|
+
strEndDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
767
|
+
label = t("creator_filter_operation_between_last_120_days");
|
|
768
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
769
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
770
|
+
break;
|
|
771
|
+
case "next_7_days":
|
|
772
|
+
// 未来7天
|
|
773
|
+
strStartDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
774
|
+
strEndDay = moment__default["default"](next_7_days).format("YYYY-MM-DD");
|
|
775
|
+
label = t("creator_filter_operation_between_next_7_days");
|
|
776
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
777
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
778
|
+
break;
|
|
779
|
+
case "next_30_days":
|
|
780
|
+
// 未来30天
|
|
781
|
+
strStartDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
782
|
+
strEndDay = moment__default["default"](next_30_days).format("YYYY-MM-DD");
|
|
783
|
+
label = t("creator_filter_operation_between_next_30_days");
|
|
784
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
785
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
786
|
+
break;
|
|
787
|
+
case "next_60_days":
|
|
788
|
+
// 未来60天
|
|
789
|
+
strStartDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
790
|
+
strEndDay = moment__default["default"](next_60_days).format("YYYY-MM-DD");
|
|
791
|
+
label = t("creator_filter_operation_between_next_60_days");
|
|
792
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
793
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
794
|
+
break;
|
|
795
|
+
case "next_90_days":
|
|
796
|
+
// 未来90天
|
|
797
|
+
strStartDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
798
|
+
strEndDay = moment__default["default"](next_90_days).format("YYYY-MM-DD");
|
|
799
|
+
label = t("creator_filter_operation_between_next_90_days");
|
|
800
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
801
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
802
|
+
break;
|
|
803
|
+
case "next_120_days":
|
|
804
|
+
// 未来120天
|
|
805
|
+
strStartDay = moment__default["default"](now).format("YYYY-MM-DD");
|
|
806
|
+
strEndDay = moment__default["default"](next_120_days).format("YYYY-MM-DD");
|
|
807
|
+
label = t("creator_filter_operation_between_next_120_days");
|
|
808
|
+
startValue = new Date(strStartDay + "T00:00:00Z");
|
|
809
|
+
endValue = new Date(strEndDay + "T23:59:59Z");
|
|
810
|
+
}
|
|
811
|
+
values = [startValue, endValue];
|
|
812
|
+
// 时间类型字段,应该考虑偏移时区值,否则过滤数据存在偏差
|
|
813
|
+
// 日期类型字段,数据库本来就存的是UTC的0点;
|
|
814
|
+
// 日期类型字段,目前creator代码(2019年08月07号存的)存的是UTC的16点,见:https://github.com/steedos/creator/issues/1271;
|
|
815
|
+
// 比如用户想搜索2019-08-07的数据,请求会是:((created ge 2019-08-06T16:00:00Z) and (created le 2019-08-07T15:59:59Z)) ,
|
|
816
|
+
// 如果数据库中存储的是2019-08-07T16:00:00Z而不是2019-08-07T00:00:00Z,那么就搜索不到数据。
|
|
817
|
+
// 所以,日期类型字段,要求存储的是UTC的0点,而不可以是16点,否则可能搜索不到数据。
|
|
818
|
+
if (utcOffset) {
|
|
819
|
+
values = values.map(function (fv) {
|
|
820
|
+
if (fv) {
|
|
821
|
+
// 注意这里取的值是moment().utcOffset() / 60得到的,不是new Date().getTimezoneOffset() / 60
|
|
822
|
+
// 它们的值正好为正负关系,北京时间前者为 +8,后者为 -8
|
|
823
|
+
fv = new Date(fv.getTime());// clone fv的值以防止原来的值被更改
|
|
824
|
+
fv.setHours(fv.getHours() - utcOffset);
|
|
825
|
+
}
|
|
826
|
+
return fv;
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
label: label,
|
|
831
|
+
key: key,
|
|
832
|
+
values: values
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
let getBetweenBuiltinValueItem = (key, utcOffset) => {
|
|
837
|
+
return getBetweenTimeBuiltinValueItem(key, utcOffset);
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
let isBetweenFilterOperation = (operation) => {
|
|
841
|
+
return operation === "between";
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
// "{userId}"或"{user.name}"格式
|
|
845
|
+
let checkFormula = (formula) => {
|
|
846
|
+
return typeof formula === "string" && /\{\w+(\.\w+)?\}/.test(formula);
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// "{userId}"转换为"this['userId']","{user.name}"转换为"this['user'].['name']"
|
|
850
|
+
let prepareFormula = (formula, prefix = "this") => {
|
|
851
|
+
var reg, rev;
|
|
852
|
+
reg = /(\{[^{}]*\})/g;
|
|
853
|
+
rev = formula.replace(reg, function (m, $1) {
|
|
854
|
+
return prefix + $1.replace(/\{\s*/, "[\"").replace(/\s*\}/, "\"]").replace(/\s*\.\s*/g, "\"][\"");
|
|
855
|
+
});
|
|
856
|
+
return rev;
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
let evaluateFormula = (formula, context) => {
|
|
860
|
+
if (checkFormula(formula)) {
|
|
861
|
+
formula = prepareFormula(formula);
|
|
862
|
+
return function () {
|
|
863
|
+
return eval(formula);
|
|
864
|
+
}.call(context);
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
return formula;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
const _evaluateFormula = evaluateFormula;
|
|
872
|
+
|
|
873
|
+
// 正则包括encodeURIComponent函数编码的11个特殊符号;/?:@&=+$,#
|
|
874
|
+
// 还包括convertSpecialCharacter函数中转义的特殊符号^$()*+?.\|[]{}
|
|
875
|
+
// 注意encodeURIComponent("\\(")的结果是%5C(,需要特别处理
|
|
876
|
+
// 注意encodeURIComponent("\\.")的结果是%5C.,需要特别处理
|
|
877
|
+
// 注意encodeURIComponent("\\*")的结果是%5C*,因为不需要encodeURIComponent函数编码,所以不用加入REG_FOR_ENCORD变量
|
|
878
|
+
const REG_FOR_ENCORD = /\;|\/|\?|\:|\@|\&|\=|\+|\$|\,|\#|\^|(\\\()|(\\\))|(\\\.)|\\|\||\[|\]|\{|\}/;
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
^$()*+?.\|[]{}等特殊符号需要转义,否则有可能会报错且无法正确识别
|
|
882
|
+
encodeURIComponent函数并不能完全编码上述所有特殊符号
|
|
883
|
+
这里保持跟版本1.23一样的处理逻辑,只是额外判断了下避免重复转义或重复执行encodeURIComponent编码的可能
|
|
884
|
+
*/
|
|
885
|
+
const convertSpecialCharacter = (str) => {
|
|
886
|
+
// if(str.indexOf("\\") > -1){
|
|
887
|
+
// // 如果有转义符号就按已经执行过转义处理,否则重复转义会有问题
|
|
888
|
+
// return str;
|
|
889
|
+
// }
|
|
890
|
+
// encodeURIComponent("\\(")的结果是%5C(,进一步转义的话会变成%5C\(,里面包括了符号\,会通过上面的正则REG_FOR_ENCORD,
|
|
891
|
+
// 从而造成重复执行encodeURIComponent,所以这个不可以进一步转义,否则会搜索不到正确结果
|
|
892
|
+
// 类似的有符号.*
|
|
893
|
+
if(str.indexOf("%5C(") > -1 || str.indexOf("%5C)") > -1){
|
|
894
|
+
return str;
|
|
895
|
+
}
|
|
896
|
+
if(str.indexOf("%5C.") > -1){
|
|
897
|
+
return str;
|
|
898
|
+
}
|
|
899
|
+
if(str.indexOf("%5C*") > -1){
|
|
900
|
+
return str;
|
|
901
|
+
}
|
|
902
|
+
return str.replace(/([\^\$\(\)\*\+\?\.\\\|\[\]\{\}])/g, "\\$1");
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
let extendUserContext = (userContext, utcOffset) => {
|
|
906
|
+
if (!userContext.now) {
|
|
907
|
+
userContext.now = new Date();
|
|
908
|
+
}
|
|
909
|
+
return userContext;
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
let formatFiltersToDev = (filters, userContext = { userId: null, spaceId: null, user: { utcOffset: 0 } }) => {
|
|
913
|
+
if(lodash.isNull(filters) || lodash.isUndefined(filters)){
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
let utcOffset = userContext.user ? userContext.user.utcOffset : 0;
|
|
917
|
+
userContext = extendUserContext(userContext);
|
|
918
|
+
// 2019-03-23T01:00:33.524Z、2019-03-23T01:00:33Z、2022-06-11T00:00:00.444+08:00这种格式
|
|
919
|
+
var regDate = /^\d{4}-\d{1,2}-\d{1,2}(T|\s)\d{1,2}\:\d{1,2}(\:\d{1,2}(\.\d{1,3})?)?(Z|((\+|\-)\d{1,2}\:\d{1,2}))?$/;
|
|
920
|
+
var filtersLooper, selector;
|
|
921
|
+
if (!lodash.isFunction(filters) && !filters.length) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
selector = [];
|
|
925
|
+
filtersLooper = function (filters_loop) {
|
|
926
|
+
var builtinValue, field, i, isBetweenOperation, option, ref, sub_selector, tempFilters, tempLooperResult, value;
|
|
927
|
+
tempFilters = [];
|
|
928
|
+
tempLooperResult = null;
|
|
929
|
+
if (filters_loop === "!") {
|
|
930
|
+
return filters_loop;
|
|
931
|
+
}
|
|
932
|
+
if (lodash.isFunction(filters_loop)) {
|
|
933
|
+
filters_loop = filters_loop();
|
|
934
|
+
}
|
|
935
|
+
if (!lodash.isArray(filters_loop)) {
|
|
936
|
+
if (lodash.isObject(filters_loop)) {
|
|
937
|
+
// 当filters不是[Array]类型而是[Object]类型时,进行格式转换
|
|
938
|
+
if (filters_loop.operation) {
|
|
939
|
+
filters_loop = [filters_loop.field, filters_loop.operation, filters_loop.value];
|
|
940
|
+
} else {
|
|
941
|
+
return null;
|
|
942
|
+
}
|
|
943
|
+
} else {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (filters_loop.length === 1) {
|
|
948
|
+
// 只有一个元素,进一步解析其内容
|
|
949
|
+
tempLooperResult = filtersLooper(filters_loop[0]);
|
|
950
|
+
if (tempLooperResult) {
|
|
951
|
+
tempFilters.push(tempLooperResult);
|
|
952
|
+
}
|
|
953
|
+
} else if (filters_loop.length === 2) {
|
|
954
|
+
// 只有两个元素,进一步解析其内容,省略"and"连接符,但是有"and"效果
|
|
955
|
+
filters_loop.forEach(function (n, i) {
|
|
956
|
+
tempLooperResult = filtersLooper(n);
|
|
957
|
+
if (tempLooperResult) {
|
|
958
|
+
return tempFilters.push(tempLooperResult);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
} else if (filters_loop.length === 3) {
|
|
962
|
+
// 只有三个元素,可能中间是"or","and"连接符也可能是普通数组,区别对待解析
|
|
963
|
+
if (lodash.includes(["or", "and"], filters_loop[1])) {
|
|
964
|
+
// 中间有"or","and"连接符,则循环filters_loop,依次用filtersLooper解析其过虑条件
|
|
965
|
+
// 最后生成的结果格式:tempFilters = [filtersLooper(filters_loop[0]), filters_loop[1], filtersLooper(filters_loop[2]), ...]
|
|
966
|
+
// 因要判断filtersLooper(filters_loop[0])及filtersLooper(filters_loop[2])是否为空
|
|
967
|
+
// 所以不能直接写:tempFilters = [filtersLooper(filters_loop[0]), filters_loop[1], filtersLooper(filters_loop[2])]
|
|
968
|
+
tempFilters = [];
|
|
969
|
+
i = 0;
|
|
970
|
+
while (i < filters_loop.length) {
|
|
971
|
+
if (lodash.includes(["or", "and"], filters_loop[i])) {
|
|
972
|
+
i++;
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
tempLooperResult = filtersLooper(filters_loop[i]);
|
|
976
|
+
if (!tempLooperResult) {
|
|
977
|
+
i++;
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (i > 0) {
|
|
981
|
+
tempFilters.push(filters_loop[i - 1]);
|
|
982
|
+
}
|
|
983
|
+
tempFilters.push(tempLooperResult);
|
|
984
|
+
i++;
|
|
985
|
+
}
|
|
986
|
+
if (lodash.includes(["or", "and"], tempFilters[0])) {
|
|
987
|
+
tempFilters.shift();
|
|
988
|
+
}
|
|
989
|
+
} else {
|
|
990
|
+
if (lodash.isString(filters_loop[1])) {
|
|
991
|
+
// 第二个元素为字符串,则认为是某一个具体的过虑条件
|
|
992
|
+
field = filters_loop[0];
|
|
993
|
+
option = filters_loop[1];
|
|
994
|
+
value = filters_loop[2];
|
|
995
|
+
if (lodash.isFunction(value)) {
|
|
996
|
+
value = value();
|
|
997
|
+
}
|
|
998
|
+
if (option === "!=") {
|
|
999
|
+
// 支持!=为不等于操作
|
|
1000
|
+
option = "<>";
|
|
1001
|
+
}
|
|
1002
|
+
value = _evaluateFormula(value, userContext);
|
|
1003
|
+
sub_selector = [];
|
|
1004
|
+
isBetweenOperation = isBetweenFilterOperation(option);
|
|
1005
|
+
if (isBetweenOperation && lodash.isString(value)) {
|
|
1006
|
+
// 如果是between运算符内置值,则取出对应values作为过滤值
|
|
1007
|
+
// 比如value为last_year,返回对应的时间值
|
|
1008
|
+
builtinValue = getBetweenBuiltinValueItem(value, utcOffset);
|
|
1009
|
+
if (builtinValue) {
|
|
1010
|
+
value = builtinValue.values;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
if (lodash.isArray(value)) {
|
|
1014
|
+
value = value.map(function (item) {
|
|
1015
|
+
if (typeof item === "string") {
|
|
1016
|
+
if(["contains", "startswith", "endswith", "notcontains", "notstartswith", "notendswith"].indexOf(option) > -1){
|
|
1017
|
+
item = convertSpecialCharacter(item);
|
|
1018
|
+
}
|
|
1019
|
+
if(regDate.test(item)){
|
|
1020
|
+
// 如果item正好是regDate格式,则转换为Date类型
|
|
1021
|
+
item = new Date(item);
|
|
1022
|
+
}
|
|
1023
|
+
else if(REG_FOR_ENCORD.test(item)){
|
|
1024
|
+
item = encodeURIComponent(item);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return item;
|
|
1028
|
+
});
|
|
1029
|
+
if (["=", "in"].indexOf(option) > -1) {
|
|
1030
|
+
if(value.length){
|
|
1031
|
+
sub_selector.push([field, "in", `(${JSON.stringify(value).replace(/\"/g, "'").slice(1).slice(0, -1)})`], "and");
|
|
1032
|
+
// _.each(value, function (v) {
|
|
1033
|
+
// return sub_selector.push([field, "=", v], "or");
|
|
1034
|
+
// });
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
// 空数组返回空值
|
|
1038
|
+
sub_selector.push([field, "=", "__badQueryForEmptyArray"], "and");
|
|
1039
|
+
}
|
|
1040
|
+
} else if (["<>", "notin"].indexOf(option) > -1) {
|
|
1041
|
+
sub_selector.push([field, "notin", `(${JSON.stringify(value).replace(/\"/g, "'").slice(1).slice(0, -1)})`], "and");
|
|
1042
|
+
// _.each(value, function (v) {
|
|
1043
|
+
// return sub_selector.push([field, "<>", v], "and");
|
|
1044
|
+
// });
|
|
1045
|
+
} else if (["notcontains", "notstartswith", "notendswith"].indexOf(option) > -1) {
|
|
1046
|
+
lodash.each(value, function (v) {
|
|
1047
|
+
return sub_selector.push([field, option, v], "and");
|
|
1048
|
+
});
|
|
1049
|
+
} else if (isBetweenOperation) {
|
|
1050
|
+
if(value.length > 0){
|
|
1051
|
+
if ([null, undefined, ''].indexOf(value[0]) < 0 || [null, undefined, ''].indexOf(value[1]) < 0) {
|
|
1052
|
+
if ([null, undefined, ''].indexOf(value[0]) < 0) {
|
|
1053
|
+
sub_selector.push([field, ">=", value[0]], "and");
|
|
1054
|
+
}
|
|
1055
|
+
if ([null, undefined, ''].indexOf(value[1]) < 0) {
|
|
1056
|
+
sub_selector.push([field, "<=", value[1]], "and");
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
} else {
|
|
1061
|
+
// contains、startswith、endswith等,如果value为空数组,不加任何条件,即查找所有数据
|
|
1062
|
+
lodash.each(value, function (v) {
|
|
1063
|
+
return sub_selector.push([field, option, v], "or");
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
if (sub_selector[sub_selector.length - 1] === "and" || sub_selector[sub_selector.length - 1] === "or") {
|
|
1067
|
+
sub_selector.pop();
|
|
1068
|
+
}
|
|
1069
|
+
if (sub_selector.length) {
|
|
1070
|
+
tempFilters = sub_selector;
|
|
1071
|
+
}
|
|
1072
|
+
} else if(value === false) {
|
|
1073
|
+
// boolean类型字段优化,选择否时,应该兼容undefined值的情况
|
|
1074
|
+
// 主要是为了落地版本,目前我们有的项目yml中一些字段是项目交付上线后再加的,
|
|
1075
|
+
// 就造成按false搜索时搜索不到老数据(因为老数据中该字段值为空)
|
|
1076
|
+
if(option === "="){
|
|
1077
|
+
tempFilters = [[field, "=", false], "or", [field, "=", null]];
|
|
1078
|
+
}
|
|
1079
|
+
else if(option === "<>"){
|
|
1080
|
+
tempFilters = [field, "=", true];
|
|
1081
|
+
}
|
|
1082
|
+
} else {
|
|
1083
|
+
if (isBetweenOperation && !lodash.isArray(value)) ;
|
|
1084
|
+
else {
|
|
1085
|
+
if (typeof value === "string") {
|
|
1086
|
+
if(["contains", "startswith", "endswith", "notcontains", "notstartswith", "notendswith"].indexOf(option) > -1){
|
|
1087
|
+
value = convertSpecialCharacter(value);
|
|
1088
|
+
}
|
|
1089
|
+
if(regDate.test(value)){
|
|
1090
|
+
// 如果value正好是regDate格式,则转换为Date类型
|
|
1091
|
+
value = new Date(value);
|
|
1092
|
+
}
|
|
1093
|
+
else if(REG_FOR_ENCORD.test(value)){
|
|
1094
|
+
value = encodeURIComponent(value);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
tempFilters = [field, option, value];
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
} else {
|
|
1101
|
+
// 普通数组,当成完整过虑条件进一步循环解析每个条件
|
|
1102
|
+
filters_loop.forEach(function (n, i) {
|
|
1103
|
+
tempLooperResult = filtersLooper(n);
|
|
1104
|
+
if (tempLooperResult) {
|
|
1105
|
+
return tempFilters.push(tempLooperResult);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
} else {
|
|
1111
|
+
// 超过3个元素的数组,可能中间是"or","and"连接符也可能是普通数组,区别对待解析
|
|
1112
|
+
if ((ref = lodash.intersection(["or", "and"], filters_loop)) != null ? ref.length : void 0) {
|
|
1113
|
+
// 中间有"or","and"连接符,则循环filters_loop,依次用filtersLooper解析其过虑条件
|
|
1114
|
+
// 最后生成的结果格式:tempFilters = [filtersLooper(filters_loop[0]), filters_loop[1], filtersLooper(filters_loop[2]), ...]
|
|
1115
|
+
// 因要判断filtersLooper(filters_loop[0])及filtersLooper(filters_loop[2])是否为空
|
|
1116
|
+
// 所以不能直接写:tempFilters = [filtersLooper(filters_loop[0]), filters_loop[1], filtersLooper(filters_loop[2])]
|
|
1117
|
+
tempFilters = [];
|
|
1118
|
+
i = 0;
|
|
1119
|
+
while (i < filters_loop.length) {
|
|
1120
|
+
if (lodash.includes(["or", "and"], filters_loop[i])) {
|
|
1121
|
+
i++;
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
tempLooperResult = filtersLooper(filters_loop[i]);
|
|
1125
|
+
if (!tempLooperResult) {
|
|
1126
|
+
i++;
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
if (i > 0) {
|
|
1130
|
+
tempFilters.push(filters_loop[i - 1]);
|
|
1131
|
+
}
|
|
1132
|
+
tempFilters.push(tempLooperResult);
|
|
1133
|
+
i++;
|
|
1134
|
+
}
|
|
1135
|
+
if (lodash.includes(["or", "and"], tempFilters[0])) {
|
|
1136
|
+
tempFilters.shift();
|
|
1137
|
+
}
|
|
1138
|
+
} else {
|
|
1139
|
+
// 普通过虑条件,当成完整过虑条件进一步循环解析每个条件
|
|
1140
|
+
filters_loop.forEach(function (n, i) {
|
|
1141
|
+
tempLooperResult = filtersLooper(n);
|
|
1142
|
+
if (tempLooperResult) {
|
|
1143
|
+
return tempFilters.push(tempLooperResult);
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (tempFilters.length) {
|
|
1149
|
+
return tempFilters;
|
|
1150
|
+
} else {
|
|
1151
|
+
return null;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
selector = filtersLooper(filters);
|
|
1155
|
+
return selector;
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
let formatFiltersToODataQuery = (filters, userContext, odataProtocolVersion, forceLowerCase) => {
|
|
1159
|
+
let devFilters = formatFiltersToDev(filters, userContext);
|
|
1160
|
+
return new SteedosFilter(devFilters, odataProtocolVersion, forceLowerCase).formatFiltersToODataQuery();
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
const _formatFiltersToDev = formatFiltersToDev;
|
|
1164
|
+
const _formatFiltersToODataQuery = formatFiltersToODataQuery;
|
|
1165
|
+
|
|
1166
|
+
// 把"a.b.c"这种字符fieldName转换为{"a":{"b":{"c":{}}}}这种json
|
|
1167
|
+
let expandFieldName = (initial, fieldName) => {
|
|
1168
|
+
lodash.reduce(fieldName.split("."),function(m, k){
|
|
1169
|
+
if(!m[k]){
|
|
1170
|
+
m[k] = {};
|
|
1171
|
+
}
|
|
1172
|
+
return m[k]
|
|
1173
|
+
}, initial);
|
|
1174
|
+
return initial;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
// 把["a.b.c","x.y","x.z","m"]这种字符fieldName转换为{"a":{"b":{"c":{}}},"x":{"y":{},"z":{}},"m":{}}这种json对象格式
|
|
1179
|
+
let expandFieldNames = (fieldNames) => {
|
|
1180
|
+
let initial = {};
|
|
1181
|
+
fieldNames.forEach((n) => {
|
|
1182
|
+
expandFieldName(initial, n);
|
|
1183
|
+
});
|
|
1184
|
+
return initial;
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
let generateIndents = (count) =>{
|
|
1188
|
+
return Array(count).fill(" ").join("");
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
把{"a":{"b":{"c":{}}}}这种json转换为字符格式:
|
|
1193
|
+
{
|
|
1194
|
+
a {
|
|
1195
|
+
b {
|
|
1196
|
+
c
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
*/
|
|
1201
|
+
let reduceGraphqlFieldsQuery = (fields, indentsCount) => {
|
|
1202
|
+
if(!indentsCount){
|
|
1203
|
+
indentsCount = 0;
|
|
1204
|
+
}
|
|
1205
|
+
let itemQuery;
|
|
1206
|
+
return ` {
|
|
1207
|
+
${
|
|
1208
|
+
lodash.map(fields, (fieldValue, fieldKey) => {
|
|
1209
|
+
itemQuery = generateIndents(indentsCount) + generateIndents(1) + fieldKey;
|
|
1210
|
+
if(lodash.isEmpty(fieldValue)){
|
|
1211
|
+
itemQuery += "\n";
|
|
1212
|
+
}
|
|
1213
|
+
else {
|
|
1214
|
+
indentsCount += 1;
|
|
1215
|
+
itemQuery += reduceGraphqlFieldsQuery(fieldValue, indentsCount);
|
|
1216
|
+
indentsCount -= 1;
|
|
1217
|
+
}
|
|
1218
|
+
return itemQuery;
|
|
1219
|
+
}).join("")
|
|
1220
|
+
}${generateIndents(indentsCount)}}
|
|
1221
|
+
`;
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
let formatFieldsToGraphqlQuery = (fields) => {
|
|
1225
|
+
if(lodash.isString(fields)){
|
|
1226
|
+
fields = fields.split(",");
|
|
1227
|
+
}
|
|
1228
|
+
let expandedFields = expandFieldNames(fields);
|
|
1229
|
+
return reduceGraphqlFieldsQuery(expandedFields, 3);
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
*
|
|
1234
|
+
*
|
|
1235
|
+
* 把filters和fields转换为如下格式的graphql请求串
|
|
1236
|
+
query {
|
|
1237
|
+
contracts(filters:[
|
|
1238
|
+
[
|
|
1239
|
+
"create_date",
|
|
1240
|
+
"between",
|
|
1241
|
+
"this_year"
|
|
1242
|
+
]
|
|
1243
|
+
]) {
|
|
1244
|
+
name
|
|
1245
|
+
amount
|
|
1246
|
+
contract_type {
|
|
1247
|
+
name
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
* @param {*} filters ,请求的过滤条件
|
|
1252
|
+
* @param {*} fields ,请求的字段,支持["a.b.c","m","n"]或"a.b.c,m,n"这种语法
|
|
1253
|
+
*/
|
|
1254
|
+
let formatFiltersToGraphqlQuery = (objectName, filters, fields, userContext, odataProtocolVersion, forceLowerCase) => {
|
|
1255
|
+
if(!lodash.isString(filters)){
|
|
1256
|
+
filters = _formatFiltersToODataQuery(filters, userContext, odataProtocolVersion, forceLowerCase);
|
|
1257
|
+
}
|
|
1258
|
+
let filtersWrap = filters ? `(filters:"${filters}")` : "";
|
|
1259
|
+
let graphqlFields = formatFieldsToGraphqlQuery(fields);
|
|
1260
|
+
let graphqlQuery = `
|
|
1261
|
+
query {
|
|
1262
|
+
${objectName}${filtersWrap}${graphqlFields}
|
|
1263
|
+
}
|
|
1264
|
+
`;
|
|
1265
|
+
return graphqlQuery;
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
const _formatFiltersToGraphqlQuery = formatFiltersToGraphqlQuery;
|
|
1269
|
+
|
|
1270
|
+
exports.SteedosFilter = filter;
|
|
1271
|
+
exports.evaluateFormula = _evaluateFormula;
|
|
1272
|
+
exports.formatFiltersToDev = _formatFiltersToDev;
|
|
1273
|
+
exports.formatFiltersToGraphqlQuery = _formatFiltersToGraphqlQuery;
|
|
1274
|
+
exports.formatFiltersToODataQuery = _formatFiltersToODataQuery;
|
|
1275
|
+
exports.getBetweenBuiltinValueItem = getBetweenBuiltinValueItem;
|
|
1276
|
+
exports.getBetweenTimeBuiltinValueItem = getBetweenTimeBuiltinValueItem;
|
|
1277
|
+
exports.getLastMonthFirstDay = getLastMonthFirstDay;
|
|
1278
|
+
exports.getLastQuarterFirstDay = getLastQuarterFirstDay;
|
|
1279
|
+
exports.getMonthDays = getMonthDays;
|
|
1280
|
+
exports.getNextQuarterFirstDay = getNextQuarterFirstDay;
|
|
1281
|
+
exports.getQuarterStartMonth = getQuarterStartMonth;
|
|
1282
|
+
exports.isBetweenFilterOperation = isBetweenFilterOperation;
|
|
1283
|
+
|
|
1284
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1285
|
+
|
|
1286
|
+
}));
|