pome-ui 2.0.0-preview44 → 2.0.0-preview46
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/LICENSE-VUEJS +23 -23
- package/package.json +1 -1
- package/pome-cache-query.js +365 -357
- package/pome-cache-query.min.js +1 -1
- package/pome-ui.dev.js +99 -259
- package/pome-ui.dev.min.js +23 -23
- package/pome-ui.js +99 -259
- package/pome-ui.min.js +3 -3
package/pome-cache-query.js
CHANGED
|
@@ -1,358 +1,366 @@
|
|
|
1
|
-
// Copyright (c) Yuko(Yisheng) Zheng. All rights reserved.
|
|
2
|
-
// Licensed under the GPL v3. See LICENSE in the project root for license information.
|
|
3
|
-
|
|
4
|
-
(function (exports) {
|
|
5
|
-
if (typeof exports != 'undefined' && exports.get) {
|
|
6
|
-
return exports;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function _combineObject(src, dest) {
|
|
10
|
-
if (!src) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
var fields = Object.getOwnPropertyNames(src);
|
|
15
|
-
for (var i = 0; i < fields.length; ++i) {
|
|
16
|
-
dest[fields[i]] = src[fields[i]];
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var _options = {
|
|
21
|
-
isPagedResult(result) {
|
|
22
|
-
if (result.totalRecords == undefined
|
|
23
|
-
|| result.totalPages === undefined
|
|
24
|
-
|| result.currentPage === undefined
|
|
25
|
-
|| result.pageSize === undefined)
|
|
26
|
-
return false;
|
|
27
|
-
else
|
|
28
|
-
return true;
|
|
29
|
-
},
|
|
30
|
-
beforeSend: function (xhr) {
|
|
31
|
-
},
|
|
32
|
-
onError: function (err, xhr) {
|
|
33
|
-
return Promise.resolve(err);
|
|
34
|
-
},
|
|
35
|
-
onSucceeded: function (ret, xhr) {
|
|
36
|
-
return Promise.resolve(ret);
|
|
37
|
-
},
|
|
38
|
-
baseUrl: null,
|
|
39
|
-
batch: null,
|
|
40
|
-
batchInterval: null,
|
|
41
|
-
batchTimeout: 10
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var _batchRequests = [];
|
|
45
|
-
|
|
46
|
-
var cloneArray = function (array) {
|
|
47
|
-
var ret = [];
|
|
48
|
-
for (var i = 0; i < array.length; ++i) {
|
|
49
|
-
ret.push(array[i]);
|
|
50
|
-
}
|
|
51
|
-
return ret;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (_options.batch) {
|
|
55
|
-
setInterval(function () {
|
|
56
|
-
if (!_batchRequests.length) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
_options.batch(_batchRequests, _xhrRequest, _options);
|
|
60
|
-
_batchRequests = [];
|
|
61
|
-
}, _options.batchInterval || 50);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function clone(x) {
|
|
65
|
-
var json = JSON.stringify(x);
|
|
66
|
-
return JSON.parse(json);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function getFields(obj) {
|
|
70
|
-
var ret = [];
|
|
71
|
-
if (!obj || typeof obj !== 'object') return ret;
|
|
72
|
-
|
|
73
|
-
for (var x in obj) {
|
|
74
|
-
if (obj[x])
|
|
75
|
-
ret.push(x);
|
|
76
|
-
}
|
|
77
|
-
return ret;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
var __cache = {};
|
|
81
|
-
var __cacheDictionary = {};
|
|
82
|
-
var __cacheExpire = {};
|
|
83
|
-
|
|
84
|
-
function randomString(length, chars = null) {
|
|
85
|
-
chars = chars || '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
|
|
86
|
-
var result = '';
|
|
87
|
-
for (var i = length; i > 0; --i) {
|
|
88
|
-
result += chars[Math.floor(Math.random() * chars.length)]
|
|
89
|
-
};
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function UseConfig(options) {
|
|
94
|
-
_combineObject(options, _options);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function _toUrlString(params, questionMark = true, ignore = null) {
|
|
98
|
-
var keys = Object.keys(params).sort();
|
|
99
|
-
if (!keys.length)
|
|
100
|
-
return '';
|
|
101
|
-
var ret = questionMark ? '?' : '';
|
|
102
|
-
for (var i = 0; i < keys.length; i++) {
|
|
103
|
-
if (ignore) {
|
|
104
|
-
if (ignore.some(x => x == keys[i])) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
ret += keys[i] + '=' + encodeURI(params[keys[i]]) + '&';
|
|
109
|
-
}
|
|
110
|
-
return ret.substr(0, ret.length - 1);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
function _urlStringToObject(str) {
|
|
114
|
-
str = str.substr(str.indexOf('?') + 1);
|
|
115
|
-
var splitedKeyValuePairs = str.split('&');
|
|
116
|
-
var ret = {};
|
|
117
|
-
for (var i = 0; i < splitedKeyValuePairs.length; i++) {
|
|
118
|
-
var splitedKeyValuePair = splitedKeyValuePairs[i].split('=');
|
|
119
|
-
ret[splitedKeyValuePair[0]] = decodeURI(splitedKeyValuePair[1]);
|
|
120
|
-
}
|
|
121
|
-
return ret;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
function _generateCacheKey(endpoint, params, isPaged) {
|
|
125
|
-
var par = clone(params);
|
|
126
|
-
if (isPaged && par.page) delete par.page;
|
|
127
|
-
return endpoint + _toUrlString(par);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
function _isPagedResult(result) {
|
|
131
|
-
return _options.isPagedResult(result);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
function _xhrRequest(options) {
|
|
135
|
-
var xhr = new XMLHttpRequest();
|
|
136
|
-
xhr.open(options.type, options.url);
|
|
137
|
-
xhr.setRequestHeader('Content-Type', options.contentType);
|
|
138
|
-
if (options.beforeSend) {
|
|
139
|
-
options.beforeSend(xhr);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (typeof options.data !== 'string') {
|
|
143
|
-
if (options.contentType.toLocaleLowerCase() == 'application/json') {
|
|
144
|
-
options.data = JSON.stringify(options.data);
|
|
145
|
-
} else if (options.contentType.toLocaleLowerCase() == 'application/octet-stream') {
|
|
146
|
-
} else {
|
|
147
|
-
options.data = _toUrlString(options.data, false);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
xhr.send(options.data);
|
|
152
|
-
xhr.onreadystatechange = function () {
|
|
153
|
-
if (xhr.readyState == 4) {
|
|
154
|
-
var ret = options.dataType == 'json' ? JSON.parse(xhr.responseText) : xhr.responseText;
|
|
155
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
156
|
-
options.success(ret, xhr);
|
|
157
|
-
} else {
|
|
158
|
-
options.error(ret, xhr);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
return xhr;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
function parseUrl(url) {
|
|
167
|
-
if (url.indexOf('//') >= 0) {
|
|
168
|
-
return url;
|
|
169
|
-
} else if (_options.baseUrl) {
|
|
170
|
-
return _options.baseUrl + url
|
|
171
|
-
} else {
|
|
172
|
-
return url;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function request(endpoint, method, params, dataType, contentType, headers) {
|
|
177
|
-
dataType = dataType || 'json';
|
|
178
|
-
contentType = contentType || 'application/json';
|
|
179
|
-
params = method == 'GET' ? null : params;
|
|
180
|
-
endpoint = parseUrl(endpoint);
|
|
181
|
-
|
|
182
|
-
if (!_options.batch || dataType != 'json' || contentType != 'application/json') {
|
|
183
|
-
var self = this;
|
|
184
|
-
return new Promise(function (resolve, reject) {
|
|
185
|
-
var xhr = _xhrRequest({
|
|
186
|
-
url: endpoint,
|
|
187
|
-
type: method,
|
|
188
|
-
dataType: dataType,
|
|
189
|
-
contentType: contentType || 'application/json',
|
|
190
|
-
data: method == 'GET' ? null : params,
|
|
191
|
-
success: function (ret) {
|
|
192
|
-
_options.onSucceeded(ret, xhr).then(function (ret) {
|
|
193
|
-
resolve(ret);
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
error: function (err) {
|
|
197
|
-
return _options.onError(err, xhr).then(function (err) {
|
|
198
|
-
reject(err);
|
|
199
|
-
});
|
|
200
|
-
},
|
|
201
|
-
beforeSend: function (xhr) {
|
|
202
|
-
_options.beforeSend(xhr);
|
|
203
|
-
if (headers) {
|
|
204
|
-
var fields = Object.getOwnPropertyNames(headers);
|
|
205
|
-
for (var i = 0; i < fields.length; ++i) {
|
|
206
|
-
xhr.setRequestHeader(fields[i], headers[fields[i]]);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
} else {
|
|
213
|
-
return new Promise(function (res, rej) {
|
|
214
|
-
_batchRequests.push({
|
|
215
|
-
resolve: res,
|
|
216
|
-
reject: rej,
|
|
217
|
-
request: {
|
|
218
|
-
requestId: randomString(32),
|
|
219
|
-
url: endpoint,
|
|
220
|
-
method: method,
|
|
221
|
-
body: params
|
|
222
|
-
? JSON.stringify(params)
|
|
223
|
-
: null,
|
|
224
|
-
contentType: 'application/json',
|
|
225
|
-
timeout: _options.batchTimeout
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function
|
|
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
|
-
return request(endpoint, '
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
function
|
|
291
|
-
return request(endpoint, '
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
function
|
|
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
|
-
function
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (!
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
exports.
|
|
353
|
-
exports.
|
|
354
|
-
exports.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
1
|
+
// Copyright (c) Yuko(Yisheng) Zheng. All rights reserved.
|
|
2
|
+
// Licensed under the GPL v3. See LICENSE in the project root for license information.
|
|
3
|
+
|
|
4
|
+
(function (exports) {
|
|
5
|
+
if (typeof exports != 'undefined' && exports.get) {
|
|
6
|
+
return exports;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function _combineObject(src, dest) {
|
|
10
|
+
if (!src) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var fields = Object.getOwnPropertyNames(src);
|
|
15
|
+
for (var i = 0; i < fields.length; ++i) {
|
|
16
|
+
dest[fields[i]] = src[fields[i]];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var _options = {
|
|
21
|
+
isPagedResult(result) {
|
|
22
|
+
if (result.totalRecords == undefined
|
|
23
|
+
|| result.totalPages === undefined
|
|
24
|
+
|| result.currentPage === undefined
|
|
25
|
+
|| result.pageSize === undefined)
|
|
26
|
+
return false;
|
|
27
|
+
else
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
beforeSend: function (xhr) {
|
|
31
|
+
},
|
|
32
|
+
onError: function (err, xhr) {
|
|
33
|
+
return Promise.resolve(err);
|
|
34
|
+
},
|
|
35
|
+
onSucceeded: function (ret, xhr) {
|
|
36
|
+
return Promise.resolve(ret);
|
|
37
|
+
},
|
|
38
|
+
baseUrl: null,
|
|
39
|
+
batch: null,
|
|
40
|
+
batchInterval: null,
|
|
41
|
+
batchTimeout: 10
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var _batchRequests = [];
|
|
45
|
+
|
|
46
|
+
var cloneArray = function (array) {
|
|
47
|
+
var ret = [];
|
|
48
|
+
for (var i = 0; i < array.length; ++i) {
|
|
49
|
+
ret.push(array[i]);
|
|
50
|
+
}
|
|
51
|
+
return ret;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (_options.batch) {
|
|
55
|
+
setInterval(function () {
|
|
56
|
+
if (!_batchRequests.length) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
_options.batch(_batchRequests, _xhrRequest, _options);
|
|
60
|
+
_batchRequests = [];
|
|
61
|
+
}, _options.batchInterval || 50);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function clone(x) {
|
|
65
|
+
var json = JSON.stringify(x);
|
|
66
|
+
return JSON.parse(json);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getFields(obj) {
|
|
70
|
+
var ret = [];
|
|
71
|
+
if (!obj || typeof obj !== 'object') return ret;
|
|
72
|
+
|
|
73
|
+
for (var x in obj) {
|
|
74
|
+
if (obj[x])
|
|
75
|
+
ret.push(x);
|
|
76
|
+
}
|
|
77
|
+
return ret;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var __cache = {};
|
|
81
|
+
var __cacheDictionary = {};
|
|
82
|
+
var __cacheExpire = {};
|
|
83
|
+
|
|
84
|
+
function randomString(length, chars = null) {
|
|
85
|
+
chars = chars || '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
|
|
86
|
+
var result = '';
|
|
87
|
+
for (var i = length; i > 0; --i) {
|
|
88
|
+
result += chars[Math.floor(Math.random() * chars.length)]
|
|
89
|
+
};
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function UseConfig(options) {
|
|
94
|
+
_combineObject(options, _options);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function _toUrlString(params, questionMark = true, ignore = null) {
|
|
98
|
+
var keys = Object.keys(params).sort();
|
|
99
|
+
if (!keys.length)
|
|
100
|
+
return '';
|
|
101
|
+
var ret = questionMark ? '?' : '';
|
|
102
|
+
for (var i = 0; i < keys.length; i++) {
|
|
103
|
+
if (ignore) {
|
|
104
|
+
if (ignore.some(x => x == keys[i])) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
ret += keys[i] + '=' + encodeURI(params[keys[i]]) + '&';
|
|
109
|
+
}
|
|
110
|
+
return ret.substr(0, ret.length - 1);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
function _urlStringToObject(str) {
|
|
114
|
+
str = str.substr(str.indexOf('?') + 1);
|
|
115
|
+
var splitedKeyValuePairs = str.split('&');
|
|
116
|
+
var ret = {};
|
|
117
|
+
for (var i = 0; i < splitedKeyValuePairs.length; i++) {
|
|
118
|
+
var splitedKeyValuePair = splitedKeyValuePairs[i].split('=');
|
|
119
|
+
ret[splitedKeyValuePair[0]] = decodeURI(splitedKeyValuePair[1]);
|
|
120
|
+
}
|
|
121
|
+
return ret;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
function _generateCacheKey(endpoint, params, isPaged) {
|
|
125
|
+
var par = clone(params);
|
|
126
|
+
if (isPaged && par.page) delete par.page;
|
|
127
|
+
return endpoint + _toUrlString(par);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
function _isPagedResult(result) {
|
|
131
|
+
return _options.isPagedResult(result);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
function _xhrRequest(options) {
|
|
135
|
+
var xhr = new XMLHttpRequest();
|
|
136
|
+
xhr.open(options.type, options.url);
|
|
137
|
+
xhr.setRequestHeader('Content-Type', options.contentType);
|
|
138
|
+
if (options.beforeSend) {
|
|
139
|
+
options.beforeSend(xhr);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (typeof options.data !== 'string') {
|
|
143
|
+
if (options.contentType.toLocaleLowerCase() == 'application/json') {
|
|
144
|
+
options.data = JSON.stringify(options.data);
|
|
145
|
+
} else if (options.contentType.toLocaleLowerCase() == 'application/octet-stream') {
|
|
146
|
+
} else {
|
|
147
|
+
options.data = _toUrlString(options.data, false);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
xhr.send(options.data);
|
|
152
|
+
xhr.onreadystatechange = function () {
|
|
153
|
+
if (xhr.readyState == 4) {
|
|
154
|
+
var ret = options.dataType == 'json' ? JSON.parse(xhr.responseText) : xhr.responseText;
|
|
155
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
156
|
+
options.success(ret, xhr);
|
|
157
|
+
} else {
|
|
158
|
+
options.error(ret, xhr);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
return xhr;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
function parseUrl(url) {
|
|
167
|
+
if (url.indexOf('//') >= 0) {
|
|
168
|
+
return url;
|
|
169
|
+
} else if (_options.baseUrl) {
|
|
170
|
+
return _options.baseUrl + url
|
|
171
|
+
} else {
|
|
172
|
+
return url;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function request(endpoint, method, params, dataType, contentType, headers) {
|
|
177
|
+
dataType = dataType || 'json';
|
|
178
|
+
contentType = contentType || 'application/json';
|
|
179
|
+
params = method == 'GET' ? null : params;
|
|
180
|
+
endpoint = parseUrl(endpoint);
|
|
181
|
+
|
|
182
|
+
if (!_options.batch || dataType != 'json' || contentType != 'application/json') {
|
|
183
|
+
var self = this;
|
|
184
|
+
return new Promise(function (resolve, reject) {
|
|
185
|
+
var xhr = _xhrRequest({
|
|
186
|
+
url: endpoint,
|
|
187
|
+
type: method,
|
|
188
|
+
dataType: dataType,
|
|
189
|
+
contentType: contentType || 'application/json',
|
|
190
|
+
data: method == 'GET' ? null : params,
|
|
191
|
+
success: function (ret) {
|
|
192
|
+
_options.onSucceeded(ret, xhr).then(function (ret) {
|
|
193
|
+
resolve(ret);
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
error: function (err) {
|
|
197
|
+
return _options.onError(err, xhr).then(function (err) {
|
|
198
|
+
reject(err);
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
beforeSend: function (xhr) {
|
|
202
|
+
_options.beforeSend(xhr);
|
|
203
|
+
if (headers) {
|
|
204
|
+
var fields = Object.getOwnPropertyNames(headers);
|
|
205
|
+
for (var i = 0; i < fields.length; ++i) {
|
|
206
|
+
xhr.setRequestHeader(fields[i], headers[fields[i]]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
return new Promise(function (res, rej) {
|
|
214
|
+
_batchRequests.push({
|
|
215
|
+
resolve: res,
|
|
216
|
+
reject: rej,
|
|
217
|
+
request: {
|
|
218
|
+
requestId: randomString(32),
|
|
219
|
+
url: endpoint,
|
|
220
|
+
method: method,
|
|
221
|
+
body: params
|
|
222
|
+
? JSON.stringify(params)
|
|
223
|
+
: null,
|
|
224
|
+
contentType: 'application/json',
|
|
225
|
+
timeout: _options.batchTimeout
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function safeParseEmptyValue(val) {
|
|
233
|
+
if (val == null || val == undefined) {
|
|
234
|
+
return '';
|
|
235
|
+
} else {
|
|
236
|
+
return val;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getSync(endpoint, params, dataType = 'json') {
|
|
241
|
+
var names = Object.getOwnPropertyNames(params || {});
|
|
242
|
+
if (names.length) {
|
|
243
|
+
if (endpoint.indexOf('?') >= 0) {
|
|
244
|
+
endpoint += '&';
|
|
245
|
+
} else {
|
|
246
|
+
endpoint += '?';
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
for (var i = 0; i < names.length; ++i) {
|
|
251
|
+
var name = names[i];
|
|
252
|
+
endpoint += encodeURIComponent(name) + '=' + encodeURIComponent(safeParseEmptyValue(params[name])) + '&';
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (names.length) {
|
|
256
|
+
endpoint = endpoint.substr(0, endpoint.length - 1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
var xhr = new XMLHttpRequest();
|
|
260
|
+
xhr.open('get', endpoint, false);
|
|
261
|
+
if (_options.beforeSend) {
|
|
262
|
+
_options.beforeSend(xhr);
|
|
263
|
+
}
|
|
264
|
+
xhr.send();
|
|
265
|
+
return dataType == 'json' ? JSON.parse(xhr.responseText) : xhr.responseText;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
function get(endpoint, params, dataType, contentType) {
|
|
269
|
+
var names = Object.getOwnPropertyNames(params || {});
|
|
270
|
+
if (names.length) {
|
|
271
|
+
if (endpoint.indexOf('?') >= 0) {
|
|
272
|
+
endpoint += '&';
|
|
273
|
+
} else {
|
|
274
|
+
endpoint += '?';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
for (var i = 0; i < names.length; ++i) {
|
|
279
|
+
var name = names[i];
|
|
280
|
+
endpoint += encodeURIComponent(name) + '=' + encodeURIComponent(safeParseEmptyValue(params[name])) + '&';
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (names.length) {
|
|
284
|
+
endpoint = endpoint.substr(0, endpoint.length - 1);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return request(endpoint, 'GET', params, dataType, contentType);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
function post(endpoint, params, dataType, contentType) {
|
|
291
|
+
return request(endpoint, 'POST', params, dataType, contentType);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
function patch(endpoint, params, dataType, contentType) {
|
|
295
|
+
return request(endpoint, 'PATCH', params, dataType, contentType);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
function put(endpoint, params, dataType, contentType) {
|
|
299
|
+
return request(endpoint, 'PUT', params, dataType, contentType);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
function _delete(endpoint, params, dataType) {
|
|
303
|
+
var names = Object.getOwnPropertyNames(params || {});
|
|
304
|
+
if (names.length) {
|
|
305
|
+
if (endpoint.indexOf('?') >= 0) {
|
|
306
|
+
endpoint += '&';
|
|
307
|
+
} else {
|
|
308
|
+
endpoint += '?';
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
for (var i = 0; i < names.length; ++i) {
|
|
313
|
+
var name = names[i];
|
|
314
|
+
endpoint += encodeURIComponent(name) + '=' + encodeURIComponent(safeParseEmptyValue(params[name])) + '&';
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (names.length) {
|
|
318
|
+
endpoint = endpoint.substr(0, endpoint.length - 1);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return request(endpoint, 'DELETE', params, dataType);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
function removeCache(endpoint, params) {
|
|
325
|
+
var fields = getFields(params);
|
|
326
|
+
var key = _generateCacheKey(endpoint, params, fields.some(x => x === 'page'));
|
|
327
|
+
if (__cache[key]) {
|
|
328
|
+
delete __cache[key];
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
function cache(endpoint, params, result, expire) {
|
|
333
|
+
var key;
|
|
334
|
+
if (!__cacheDictionary[endpoint])
|
|
335
|
+
__cacheDictionary[endpoint] = [];
|
|
336
|
+
var isPagedResult = _isPagedResult(result);
|
|
337
|
+
if (!isPagedResult) {
|
|
338
|
+
key = _generateCacheKey(endpoint, params);
|
|
339
|
+
__cache[key] = result;
|
|
340
|
+
} else {
|
|
341
|
+
key = _generateCacheKey(endpoint, params, true);
|
|
342
|
+
if (!__cache[key]) __cache[key] = { isPaged: true };
|
|
343
|
+
__cache[key][result.data.current] = result;
|
|
344
|
+
}
|
|
345
|
+
if (!__cacheDictionary[endpoint].some(x => x == key))
|
|
346
|
+
__cacheDictionary[endpoint].push(key);
|
|
347
|
+
|
|
348
|
+
if (expire)
|
|
349
|
+
__cacheExpire[key] = new Date().getTime() + expire;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
exports.generateQueryStringFromObject = _toUrlString;
|
|
353
|
+
exports.generateObjectFromQueryString = _urlStringToObject;
|
|
354
|
+
exports.xhrRequest = _xhrRequest;
|
|
355
|
+
exports.request = request;
|
|
356
|
+
exports.get = get;
|
|
357
|
+
exports.getSync = getSync;
|
|
358
|
+
exports.post = post;
|
|
359
|
+
exports.put = put;
|
|
360
|
+
exports.patch = patch;
|
|
361
|
+
exports.delete = _delete;
|
|
362
|
+
exports.useConfig = UseConfig;
|
|
363
|
+
|
|
364
|
+
return exports;
|
|
365
|
+
|
|
358
366
|
})(typeof exports === 'object' && typeof module !== 'undefined' ? exports : (function () { window.cq = {}; return window.cq })());
|