weaver-e10-builder 1.6.0 → 1.6.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/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +109 -51
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/form-attachment-setting.d.ts +3 -0
- package/dist/commands/form-attachment-setting.d.ts.map +1 -0
- package/dist/commands/form-attachment-setting.js +422 -0
- package/dist/commands/form-attachment-setting.js.map +1 -0
- package/dist/commands/form-data.d.ts.map +1 -1
- package/dist/commands/form-data.js +49 -1
- package/dist/commands/form-data.js.map +1 -1
- package/dist/commands/form-field-linkage.d.ts +6 -1
- package/dist/commands/form-field-linkage.d.ts.map +1 -1
- package/dist/commands/form-field-linkage.js +138 -31
- package/dist/commands/form-field-linkage.js.map +1 -1
- package/dist/commands/form.d.ts.map +1 -1
- package/dist/commands/form.js +47 -2
- package/dist/commands/form.js.map +1 -1
- package/dist/commands/project.d.ts.map +1 -1
- package/dist/commands/project.js +39 -6
- package/dist/commands/project.js.map +1 -1
- package/dist/services/form-attachment-settings.d.ts +110 -0
- package/dist/services/form-attachment-settings.d.ts.map +1 -0
- package/dist/services/form-attachment-settings.js +332 -0
- package/dist/services/form-attachment-settings.js.map +1 -0
- package/dist/services/form-attachment-upload.d.ts +30 -0
- package/dist/services/form-attachment-upload.d.ts.map +1 -0
- package/dist/services/form-attachment-upload.js +76 -0
- package/dist/services/form-attachment-upload.js.map +1 -0
- package/dist/services/form-data-openapi.d.ts +2 -0
- package/dist/services/form-data-openapi.d.ts.map +1 -1
- package/dist/services/form-data-openapi.js +1 -0
- package/dist/services/form-data-openapi.js.map +1 -1
- package/package.json +1 -1
- package/skill-docs/SKILL.md +163 -160
- package/skill-docs/_catalog.md +6 -4
- package/skill-docs/assets/sample/api/formApi.js +689 -510
- package/skill-docs/assets/sample/app/config.js +4 -0
- package/skill-docs/assets/sample/app/fields.js +25 -0
- package/skill-docs/assets/sample/entry.js +24 -22
- package/skill-docs/assets/sample/eslint.config.cjs +1 -0
- package/skill-docs/assets/sample/pages/Items.js +247 -0
- package/skill-docs/assets/sample/styles/prototypeStyles.js +137 -0
- package/skill-docs/references/coding/guide-edit-backfill.md +102 -150
- package/skill-docs/references/coding/guide-form-crud.md +195 -172
- package/skill-docs/references/coding/guide-html-to-react.md +250 -0
- package/skill-docs/references/coding/guide-page-code.md +194 -167
- package/skill-docs/references/coding/guide-page-export.md +27 -18
- package/skill-docs/references/coding/ref-compile-rules.md +7 -7
- package/skill-docs/references/common/map.md +2 -1
- package/skill-docs/references/common/ref-cli-commands.md +13 -6
- package/skill-docs/references/components/display-FilePreview.md +5 -4
- package/skill-docs/references/form/guide-field-linkage.md +4 -1
- package/skill-docs/references/form/guide-form-attachment-setting.md +95 -0
- package/skill-docs/references/form/guide-form-data.md +22 -1
- package/skill-docs/assets/sample/config/config.js +0 -0
- package/skill-docs/assets/sample/config/configLoad.js +0 -0
- package/skill-docs/assets/sample/config/configLoad_default.js +0 -0
- package/skill-docs/assets/sample/config/config_default.js +0 -0
- package/skill-docs/assets/sample/memo.md +0 -0
- package/skill-docs/assets/sample/readme.js +0 -8
|
@@ -1,510 +1,689 @@
|
|
|
1
|
-
import { appInfo } from '@weapp/utils';
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
1
|
+
import { appInfo } from '@weapp/utils';
|
|
2
|
+
|
|
3
|
+
var SDK_INFO = appInfo('@weapp/ecodesdk');
|
|
4
|
+
var PUBLIC_URL = SDK_INFO.publicUrl;
|
|
5
|
+
var API_BASE = PUBLIC_URL + '/api/ebuilder/form/dataset';
|
|
6
|
+
|
|
7
|
+
function getTeams() {
|
|
8
|
+
if (typeof TEAMS !== 'undefined') return TEAMS;
|
|
9
|
+
if (typeof window !== 'undefined' && window.TEAMS) return window.TEAMS;
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var TEAMS_OBJ = getTeams();
|
|
14
|
+
var USER_ID = (TEAMS_OBJ.currentUser && TEAMS_OBJ.currentUser.id) || '';
|
|
15
|
+
var TENANT_KEY = (TEAMS_OBJ.currentTenant && TEAMS_OBJ.currentTenant.tenantKey) || '';
|
|
16
|
+
|
|
17
|
+
var clients = {};
|
|
18
|
+
|
|
19
|
+
function headers(appId) {
|
|
20
|
+
var result = {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
'Accept': 'application/json'
|
|
23
|
+
};
|
|
24
|
+
if (appId) result.ebbusinessid = String(appId);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function multipartHeaders(appId) {
|
|
29
|
+
var result = { 'Accept': 'application/json' };
|
|
30
|
+
if (appId) result.ebbusinessid = String(appId);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseResponse(res) {
|
|
35
|
+
return res.text().then(function (text) {
|
|
36
|
+
var data = {};
|
|
37
|
+
try {
|
|
38
|
+
data = text ? JSON.parse(text) : {};
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error('接口返回不是 JSON(HTTP ' + res.status + ')');
|
|
41
|
+
}
|
|
42
|
+
if (!res.ok) {
|
|
43
|
+
throw new Error('请求失败(HTTP ' + res.status + ')' + (data && data.msg ? ':' + data.msg : ''));
|
|
44
|
+
}
|
|
45
|
+
return data;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function readRequest(url, options, retries) {
|
|
50
|
+
if (retries === undefined) retries = 1;
|
|
51
|
+
var timeout = 15000;
|
|
52
|
+
|
|
53
|
+
function attempt(n) {
|
|
54
|
+
var controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
55
|
+
var timer = null;
|
|
56
|
+
var opts = Object.assign({}, options);
|
|
57
|
+
if (controller) {
|
|
58
|
+
opts.signal = controller.signal;
|
|
59
|
+
timer = setTimeout(function () { controller.abort(); }, timeout);
|
|
60
|
+
}
|
|
61
|
+
return fetch(url, opts).then(function (res) {
|
|
62
|
+
if (timer) clearTimeout(timer);
|
|
63
|
+
return parseResponse(res);
|
|
64
|
+
}).catch(function (err) {
|
|
65
|
+
if (timer) clearTimeout(timer);
|
|
66
|
+
if (n < retries) {
|
|
67
|
+
return new Promise(function (resolve) {
|
|
68
|
+
setTimeout(function () { resolve(attempt(n + 1)); }, 500 * (n + 1));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
throw err;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return attempt(0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function writeRequest(url, body, appId) {
|
|
79
|
+
return fetch(url, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: headers(appId),
|
|
82
|
+
body: JSON.stringify(body)
|
|
83
|
+
}).then(parseResponse);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function innerOf(res) {
|
|
87
|
+
return res && res.data && res.data.datajson ? res.data.datajson : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function assertOk(res, action) {
|
|
91
|
+
var message = res && res.message;
|
|
92
|
+
if (message && message.code !== undefined
|
|
93
|
+
&& String(message.code) !== '0' && String(message.code) !== '200') {
|
|
94
|
+
throw new Error(action + '失败:' + (message.msg || String(message.code)));
|
|
95
|
+
}
|
|
96
|
+
var inner = innerOf(res);
|
|
97
|
+
if (inner && inner.status === false) {
|
|
98
|
+
throw new Error(action + '失败:' + (inner.message || '平台返回失败'));
|
|
99
|
+
}
|
|
100
|
+
if (res && res.code !== undefined
|
|
101
|
+
&& String(res.code) !== '200' && String(res.code) !== '0') {
|
|
102
|
+
throw new Error(action + '失败:' + (res.msg || String(res.code)));
|
|
103
|
+
}
|
|
104
|
+
return res;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function textOf(cell) {
|
|
108
|
+
if (cell === undefined || cell === null) return '';
|
|
109
|
+
if (Array.isArray(cell)) {
|
|
110
|
+
return cell.map(textOf).filter(function (x) { return x !== ''; }).join(',');
|
|
111
|
+
}
|
|
112
|
+
if (typeof cell === 'object') {
|
|
113
|
+
if (cell.fieldOptionName) return String(cell.fieldOptionName);
|
|
114
|
+
if (cell.fieldTextValue) return String(cell.fieldTextValue);
|
|
115
|
+
if (cell.fieldValue !== undefined && cell.fieldValue !== null) return String(cell.fieldValue);
|
|
116
|
+
return '';
|
|
117
|
+
}
|
|
118
|
+
return String(cell);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function valueOf(cell) {
|
|
122
|
+
if (cell === undefined || cell === null) return '';
|
|
123
|
+
if (Array.isArray(cell)) {
|
|
124
|
+
return cell.map(valueOf).filter(function (x) { return x !== ''; }).join(',');
|
|
125
|
+
}
|
|
126
|
+
if (typeof cell === 'object') {
|
|
127
|
+
if (cell.fieldValue !== undefined && cell.fieldValue !== null) return String(cell.fieldValue);
|
|
128
|
+
if (cell.fieldOptionId !== undefined && cell.fieldOptionId !== null) return String(cell.fieldOptionId);
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
return String(cell);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function itemsOf(cell) {
|
|
135
|
+
if (cell === undefined || cell === null) return [];
|
|
136
|
+
var source = Array.isArray(cell) ? cell : [cell];
|
|
137
|
+
var result = [];
|
|
138
|
+
source.forEach(function (item) {
|
|
139
|
+
if (item === undefined || item === null || item === '') return;
|
|
140
|
+
if (typeof item !== 'object') {
|
|
141
|
+
result.push({ id: String(item), name: String(item) });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
var id = item.fieldOptionId;
|
|
145
|
+
if (id === undefined || id === null || id === '') id = item.fieldValue;
|
|
146
|
+
if (id === undefined || id === null || id === '') return;
|
|
147
|
+
var name = item.fieldOptionName || item.fieldTextValue || item.fieldValue || String(id);
|
|
148
|
+
result.push({ id: String(id), name: String(name) });
|
|
149
|
+
});
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function idsOf(cell) {
|
|
154
|
+
return itemsOf(cell).map(function (item) { return item.id; }).join(',');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var ID_FIELD_TYPES = [
|
|
158
|
+
'Select', 'RadioBox', 'CheckBox', 'Employee', 'Department',
|
|
159
|
+
'FileComponent', 'Ebuilder', 'Browser', 'RelateBrowser'
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
function isIdField(field) {
|
|
163
|
+
return ID_FIELD_TYPES.indexOf(field && field.fieldType) >= 0;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function normalizeWriteValue(value) {
|
|
167
|
+
if (!Array.isArray(value)) return value;
|
|
168
|
+
return value.map(function (item) {
|
|
169
|
+
if (item && typeof item === 'object') {
|
|
170
|
+
return String(item.id || item.valueKey || item.fieldOptionId || '');
|
|
171
|
+
}
|
|
172
|
+
return String(item);
|
|
173
|
+
}).filter(function (item) { return item !== ''; }).join(',');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function requestKeyOf(field) {
|
|
177
|
+
var id = String(field.id || '');
|
|
178
|
+
var name = String(field.name || '');
|
|
179
|
+
var dataKey = field.config && field.config.dataKey ? String(field.config.dataKey) : '';
|
|
180
|
+
if (name === id && dataKey) return dataKey;
|
|
181
|
+
return name || dataKey || id;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function cellMap(mainTable) {
|
|
185
|
+
var result = {};
|
|
186
|
+
Object.keys(mainTable || {}).forEach(function (key) {
|
|
187
|
+
var value = mainTable[key];
|
|
188
|
+
if (value === undefined || value === null) return;
|
|
189
|
+
var fieldId = '';
|
|
190
|
+
if (Array.isArray(value)) fieldId = value[0] && value[0].fieldId;
|
|
191
|
+
else if (typeof value === 'object') fieldId = value.fieldId;
|
|
192
|
+
else fieldId = key;
|
|
193
|
+
if (fieldId) result[String(fieldId)] = value;
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function idOfCell(value) {
|
|
199
|
+
if (value && typeof value === 'object') {
|
|
200
|
+
return String(value.fieldValue || value.fieldOptionId || '');
|
|
201
|
+
}
|
|
202
|
+
if (value !== undefined && value !== null) return String(value);
|
|
203
|
+
return '';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function toFlatRow(row, fields, idFallback) {
|
|
207
|
+
var cells = cellMap(row);
|
|
208
|
+
var values = {};
|
|
209
|
+
var display = {};
|
|
210
|
+
var items = {};
|
|
211
|
+
|
|
212
|
+
fields.forEach(function (field) {
|
|
213
|
+
var cell = cells[String(field.fieldId)];
|
|
214
|
+
if (cell === undefined) return;
|
|
215
|
+
var idField = isIdField(field);
|
|
216
|
+
values[field.fieldId] = idField ? idsOf(cell) : valueOf(cell);
|
|
217
|
+
display[field.fieldId] = textOf(cell);
|
|
218
|
+
if (idField) items[field.fieldId] = itemsOf(cell);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
var id = idOfCell(row && row.id);
|
|
222
|
+
if (!id && idFallback !== undefined && idFallback !== null) id = String(idFallback);
|
|
223
|
+
return {
|
|
224
|
+
id: id,
|
|
225
|
+
values: values,
|
|
226
|
+
display: display,
|
|
227
|
+
items: items,
|
|
228
|
+
raw: row
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function toRow(raw, fields, detailMeta) {
|
|
233
|
+
var mainTable = raw && raw.mainTable ? raw.mainTable : {};
|
|
234
|
+
var result = toFlatRow(mainTable, fields, raw && raw.id);
|
|
235
|
+
var details = {};
|
|
236
|
+
var detailRows = {};
|
|
237
|
+
|
|
238
|
+
Object.keys(raw || {}).forEach(function (node) {
|
|
239
|
+
if (node.indexOf('detail') !== 0 || !Array.isArray(raw[node])) return;
|
|
240
|
+
details[node] = raw[node];
|
|
241
|
+
var def = detailMeta && detailMeta[node];
|
|
242
|
+
if (def && def.fields) {
|
|
243
|
+
detailRows[def.subFormId || node] = raw[node].map(function (line) {
|
|
244
|
+
return toFlatRow(line, def.fields);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
result.details = details;
|
|
250
|
+
result.detailRows = detailRows;
|
|
251
|
+
result.raw = raw;
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function totalOf(inner) {
|
|
256
|
+
if (!inner) return null;
|
|
257
|
+
var candidates = [inner.total, inner.totalCount, inner.recordCount];
|
|
258
|
+
if (inner.pageInfo) candidates.push(inner.pageInfo.total, inner.pageInfo.totalCount);
|
|
259
|
+
for (var i = 0; i < candidates.length; i++) {
|
|
260
|
+
if (candidates[i] !== undefined && candidates[i] !== null) return Number(candidates[i]);
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function createClient(options) {
|
|
266
|
+
var state = {
|
|
267
|
+
objId: String(options.objId),
|
|
268
|
+
appId: options.appId ? String(options.appId) : '',
|
|
269
|
+
fieldsPromise: null,
|
|
270
|
+
formIdPromise: null,
|
|
271
|
+
dsFieldsPromise: null,
|
|
272
|
+
requestKeysPromise: null,
|
|
273
|
+
detailMetaPromise: null,
|
|
274
|
+
optionsCache: {}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
function fields() {
|
|
278
|
+
if (!state.fieldsPromise) {
|
|
279
|
+
var body = { userid: USER_ID, objId: state.objId };
|
|
280
|
+
if (TENANT_KEY) body.tenantKey = TENANT_KEY;
|
|
281
|
+
state.fieldsPromise = readRequest(API_BASE + '/v1/getFields', {
|
|
282
|
+
method: 'POST',
|
|
283
|
+
headers: headers(state.appId),
|
|
284
|
+
body: JSON.stringify(body)
|
|
285
|
+
}).then(function (res) {
|
|
286
|
+
assertOk(res, '读取字段');
|
|
287
|
+
var mainFields = res.data && res.data.mainFields ? res.data.mainFields : [];
|
|
288
|
+
mainFields.sort(function (a, b) {
|
|
289
|
+
return (Number(a.number) || 0) - (Number(b.number) || 0);
|
|
290
|
+
});
|
|
291
|
+
return mainFields;
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return state.fieldsPromise;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function formId() {
|
|
298
|
+
if (!state.formIdPromise) {
|
|
299
|
+
state.formIdPromise = readRequest(
|
|
300
|
+
PUBLIC_URL + '/api/ebuilder/form/obj/getInfo/' + encodeURIComponent(state.objId),
|
|
301
|
+
{ method: 'GET', headers: headers(state.appId) }
|
|
302
|
+
).then(function (res) {
|
|
303
|
+
if (!res || String(res.code) !== '200' || !res.status) {
|
|
304
|
+
throw new Error('读取表单信息失败:' + ((res && res.msg) || '未知错误'));
|
|
305
|
+
}
|
|
306
|
+
return res.data && res.data.formId;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return state.formIdPromise;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function loadOptions(fieldId) {
|
|
313
|
+
var key = String(fieldId);
|
|
314
|
+
if (state.optionsCache[key]) return Promise.resolve(state.optionsCache[key]);
|
|
315
|
+
return formId().then(function (id) {
|
|
316
|
+
if (!id) throw new Error('未读到表单 formId,无法读取字段选项');
|
|
317
|
+
var body = {
|
|
318
|
+
module: 'ebuilderform',
|
|
319
|
+
formTableField: {
|
|
320
|
+
formField: {
|
|
321
|
+
id: String(fieldId),
|
|
322
|
+
form: { id: id }
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
return readRequest(PUBLIC_URL + '/api/ebuilder/form/form/field/manage/getFormField', {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
headers: headers(state.appId),
|
|
329
|
+
body: JSON.stringify(body)
|
|
330
|
+
});
|
|
331
|
+
}).then(function (res) {
|
|
332
|
+
assertOk(res, '读取字段选项');
|
|
333
|
+
var rawOptions = (res.data && res.data.options) || [];
|
|
334
|
+
var result = rawOptions.map(function (item) {
|
|
335
|
+
return {
|
|
336
|
+
id: String(item.valueKey),
|
|
337
|
+
valueKey: String(item.valueKey),
|
|
338
|
+
name: item.name
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
state.optionsCache[key] = result;
|
|
342
|
+
return result;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function dsFields() {
|
|
347
|
+
if (!state.dsFieldsPromise) {
|
|
348
|
+
var form = new FormData();
|
|
349
|
+
form.append('groupId', state.appId || state.objId);
|
|
350
|
+
form.append('sourceId', state.objId);
|
|
351
|
+
form.append('sourceType', 'FORM');
|
|
352
|
+
form.append('detailFieldsGroup', 'true');
|
|
353
|
+
form.append('enableMerge', 'true');
|
|
354
|
+
form.append('customParam', '{"terminal":""}');
|
|
355
|
+
form.append('params', '[]');
|
|
356
|
+
state.dsFieldsPromise = fetch(PUBLIC_URL + '/api/ebuilder/common/ds/fields', {
|
|
357
|
+
method: 'POST',
|
|
358
|
+
headers: multipartHeaders(state.appId),
|
|
359
|
+
body: form
|
|
360
|
+
}).then(parseResponse).then(function (res) {
|
|
361
|
+
assertOk(res, '读取字段定义');
|
|
362
|
+
return Array.isArray(res.data) ? res.data : [];
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return state.dsFieldsPromise;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function requestKeys() {
|
|
369
|
+
if (!state.requestKeysPromise) {
|
|
370
|
+
state.requestKeysPromise = dsFields().then(function (groups) {
|
|
371
|
+
var map = {};
|
|
372
|
+
groups.forEach(function (group) {
|
|
373
|
+
(group.fields || []).forEach(function (field) {
|
|
374
|
+
if (field.isDetailtable) return;
|
|
375
|
+
map[String(field.id)] = requestKeyOf(field);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
return map;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return state.requestKeysPromise;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function detailMeta() {
|
|
385
|
+
if (!state.detailMetaPromise) {
|
|
386
|
+
var url = API_BASE + '/v1/getTableMapping?objId=' + encodeURIComponent(state.objId) + '&reverse=false';
|
|
387
|
+
state.detailMetaPromise = Promise.all([
|
|
388
|
+
dsFields(),
|
|
389
|
+
readRequest(url, { method: 'GET', headers: headers(state.appId) })
|
|
390
|
+
]).then(function (results) {
|
|
391
|
+
var groups = results[0];
|
|
392
|
+
var res = results[1];
|
|
393
|
+
assertOk(res, '读取明细映射');
|
|
394
|
+
var mapping = res.data || {};
|
|
395
|
+
var bySubForm = {};
|
|
396
|
+
groups.forEach(function (group) {
|
|
397
|
+
(group.fields || []).forEach(function (field) {
|
|
398
|
+
if (!field.isDetailtable) return;
|
|
399
|
+
bySubForm[String(field.id)] = {
|
|
400
|
+
subFormId: String(field.id),
|
|
401
|
+
fields: (field.fields || []).map(function (item) {
|
|
402
|
+
return {
|
|
403
|
+
fieldId: String(item.id),
|
|
404
|
+
fieldType: String(item.type || item.compType || ''),
|
|
405
|
+
fieldName: String(item.text || item.name || ''),
|
|
406
|
+
requestKey: requestKeyOf(item)
|
|
407
|
+
};
|
|
408
|
+
})
|
|
409
|
+
};
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
var nodes = {};
|
|
413
|
+
Object.keys(mapping).forEach(function (node) {
|
|
414
|
+
if (node === 'mainTable') return;
|
|
415
|
+
var def = bySubForm[String(mapping[node])];
|
|
416
|
+
if (def) nodes[node] = def;
|
|
417
|
+
});
|
|
418
|
+
return nodes;
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return state.detailMetaPromise;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function optionId(fieldId, nameOrId) {
|
|
425
|
+
return loadOptions(fieldId).then(function (opts) {
|
|
426
|
+
var key = String(nameOrId);
|
|
427
|
+
var hit = null;
|
|
428
|
+
opts.forEach(function (item) {
|
|
429
|
+
if (!hit && (item.name === key || item.valueKey === key || item.id === key)) hit = item;
|
|
430
|
+
});
|
|
431
|
+
if (!hit) {
|
|
432
|
+
throw new Error('字段 ' + fieldId + ' 没有选项「' + nameOrId + '」,可选:'
|
|
433
|
+
+ opts.map(function (item) { return item.name; }).join('、'));
|
|
434
|
+
}
|
|
435
|
+
return hit.valueKey;
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function optionIds(fieldId, names) {
|
|
440
|
+
var list = Array.isArray(names) ? names : String(names || '').split(/[,,、]/);
|
|
441
|
+
return Promise.all(list.map(function (name) {
|
|
442
|
+
return optionId(fieldId, name);
|
|
443
|
+
})).then(function (ids) {
|
|
444
|
+
return ids.join(',');
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function optionMap(fieldId) {
|
|
449
|
+
return loadOptions(fieldId).then(function (opts) {
|
|
450
|
+
var map = {};
|
|
451
|
+
opts.forEach(function (item) { map[item.name] = item.valueKey; });
|
|
452
|
+
return map;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function toRequestValues(values) {
|
|
457
|
+
return requestKeys().then(function (map) {
|
|
458
|
+
var result = {};
|
|
459
|
+
Object.keys(values || {}).forEach(function (key) {
|
|
460
|
+
var target = map[String(key)] || String(key);
|
|
461
|
+
result[target] = normalizeWriteValue(values[key]);
|
|
462
|
+
});
|
|
463
|
+
return result;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function toRequestDetails(details) {
|
|
468
|
+
if (!details) return Promise.resolve(null);
|
|
469
|
+
return detailMeta().then(function (nodes) {
|
|
470
|
+
var lookup = {};
|
|
471
|
+
Object.keys(nodes).forEach(function (node) {
|
|
472
|
+
lookup[node] = node;
|
|
473
|
+
if (nodes[node].subFormId) lookup[nodes[node].subFormId] = node;
|
|
474
|
+
});
|
|
475
|
+
var result = {};
|
|
476
|
+
Object.keys(details).forEach(function (key) {
|
|
477
|
+
var node = lookup[key];
|
|
478
|
+
if (!node) throw new Error('未找到明细节点或 subFormId:' + key);
|
|
479
|
+
var def = nodes[node];
|
|
480
|
+
if (!Array.isArray(details[key])) throw new Error('明细 ' + key + ' 必须是数组');
|
|
481
|
+
var map = {};
|
|
482
|
+
def.fields.forEach(function (field) { map[field.fieldId] = field.requestKey; });
|
|
483
|
+
result[node] = details[key].map(function (row) {
|
|
484
|
+
var out = {};
|
|
485
|
+
Object.keys(row || {}).forEach(function (fieldKey) {
|
|
486
|
+
out[map[String(fieldKey)] || String(fieldKey)] = normalizeWriteValue(row[fieldKey]);
|
|
487
|
+
});
|
|
488
|
+
return out;
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
return result;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function list(query) {
|
|
496
|
+
query = query || {};
|
|
497
|
+
var datajson = {
|
|
498
|
+
header: { objId: state.objId },
|
|
499
|
+
pageInfo: {
|
|
500
|
+
pageNo: String(query.page || 1),
|
|
501
|
+
pageSize: String(query.size || 1000)
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
if (TENANT_KEY) datajson.header.tenantKey = TENANT_KEY;
|
|
505
|
+
if (query.withDetail) datajson.operationinfo = { isReturnDetail: 'y' };
|
|
506
|
+
|
|
507
|
+
var url = API_BASE + '/v2/getAllData';
|
|
508
|
+
if (TENANT_KEY) url += '?tenantkey=' + encodeURIComponent(TENANT_KEY);
|
|
509
|
+
|
|
510
|
+
var request = Promise.resolve(null).then(function () {
|
|
511
|
+
return query.filter ? toRequestValues(query.filter) : null;
|
|
512
|
+
}).then(function (filter) {
|
|
513
|
+
if (filter) datajson.mainTable = filter;
|
|
514
|
+
return readRequest(url, {
|
|
515
|
+
method: 'POST',
|
|
516
|
+
headers: headers(state.appId),
|
|
517
|
+
body: JSON.stringify({ userid: USER_ID, datajson: datajson })
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
var detailPromise = query.withDetail ? detailMeta() : Promise.resolve(null);
|
|
522
|
+
|
|
523
|
+
return Promise.all([fields(), detailPromise, request]).then(function (results) {
|
|
524
|
+
var fieldList = results[0];
|
|
525
|
+
var detail = results[1];
|
|
526
|
+
var res = results[2];
|
|
527
|
+
assertOk(res, '读取数据');
|
|
528
|
+
var inner = innerOf(res) || {};
|
|
529
|
+
var datas = Array.isArray(inner.datas) ? inner.datas : [];
|
|
530
|
+
return {
|
|
531
|
+
rows: datas.map(function (raw) { return toRow(raw, fieldList, detail); }),
|
|
532
|
+
total: totalOf(inner),
|
|
533
|
+
raw: res
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function get(dataId, query) {
|
|
539
|
+
query = query || {};
|
|
540
|
+
var operationinfo = { fieldNoFindIgnore: 'false' };
|
|
541
|
+
if (query.withDetail) operationinfo.isReturnDetail = 'y';
|
|
542
|
+
var datajson = {
|
|
543
|
+
header: { objId: state.objId },
|
|
544
|
+
mainTable: { id: String(dataId) },
|
|
545
|
+
operationinfo: operationinfo
|
|
546
|
+
};
|
|
547
|
+
if (TENANT_KEY) datajson.header.tenantKey = TENANT_KEY;
|
|
548
|
+
|
|
549
|
+
var detailPromise = query.withDetail ? detailMeta() : Promise.resolve(null);
|
|
550
|
+
|
|
551
|
+
return Promise.all([
|
|
552
|
+
fields(),
|
|
553
|
+
detailPromise,
|
|
554
|
+
readRequest(API_BASE + '/v2/getDataById', {
|
|
555
|
+
method: 'POST',
|
|
556
|
+
headers: headers(state.appId),
|
|
557
|
+
body: JSON.stringify({ userid: USER_ID, datajson: datajson })
|
|
558
|
+
})
|
|
559
|
+
]).then(function (results) {
|
|
560
|
+
var fieldList = results[0];
|
|
561
|
+
var detail = results[1];
|
|
562
|
+
var res = results[2];
|
|
563
|
+
assertOk(res, '读取数据');
|
|
564
|
+
var inner = innerOf(res) || {};
|
|
565
|
+
var datas = Array.isArray(inner.datas) ? inner.datas : [];
|
|
566
|
+
return datas.length ? toRow(datas[0], fieldList, detail) : null;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function save(values, writeOptions) {
|
|
571
|
+
writeOptions = writeOptions || {};
|
|
572
|
+
return Promise.all([
|
|
573
|
+
toRequestValues(values),
|
|
574
|
+
toRequestDetails(writeOptions.details)
|
|
575
|
+
]).then(function (results) {
|
|
576
|
+
var mainTable = results[0];
|
|
577
|
+
var details = results[1];
|
|
578
|
+
var data = { mainTable: mainTable };
|
|
579
|
+
if (details) {
|
|
580
|
+
Object.keys(details).forEach(function (key) {
|
|
581
|
+
data[key] = details[key];
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
var operationinfo = { fieldNoFindIgnore: 'false' };
|
|
585
|
+
if (writeOptions.triggerAction === true) operationinfo.doAction = 'true';
|
|
586
|
+
|
|
587
|
+
var datajson = { header: { objId: state.objId }, datas: [data], operationinfo: operationinfo };
|
|
588
|
+
if (TENANT_KEY) datajson.header.tenantKey = TENANT_KEY;
|
|
589
|
+
|
|
590
|
+
return writeRequest(API_BASE + '/v2/saveFormData', {
|
|
591
|
+
userid: USER_ID,
|
|
592
|
+
datajson: datajson
|
|
593
|
+
}, state.appId).then(function (res) {
|
|
594
|
+
assertOk(res, '保存数据');
|
|
595
|
+
var inner = innerOf(res) || {};
|
|
596
|
+
if (Array.isArray(inner.dataIds)) return String(inner.dataIds[0] || '');
|
|
597
|
+
return String(inner.dataIds || '');
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function update(dataId, values, writeOptions) {
|
|
603
|
+
writeOptions = writeOptions || {};
|
|
604
|
+
return Promise.all([
|
|
605
|
+
toRequestValues(values),
|
|
606
|
+
toRequestDetails(writeOptions.details)
|
|
607
|
+
]).then(function (results) {
|
|
608
|
+
var mainTable = results[0];
|
|
609
|
+
var details = results[1];
|
|
610
|
+
mainTable.id = String(dataId);
|
|
611
|
+
|
|
612
|
+
var data = { mainTable: mainTable };
|
|
613
|
+
if (details) {
|
|
614
|
+
Object.keys(details).forEach(function (key) {
|
|
615
|
+
data[key] = details[key];
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
var operationinfo = {
|
|
620
|
+
updateType: 'ids',
|
|
621
|
+
needAdd: 'false',
|
|
622
|
+
fieldNoFindIgnore: 'false'
|
|
623
|
+
};
|
|
624
|
+
if (writeOptions.detailMode === 'cover' && details) {
|
|
625
|
+
var operateType = {};
|
|
626
|
+
Object.keys(details).forEach(function (key) { operateType[key] = 'cover'; });
|
|
627
|
+
if (Object.keys(operateType).length) operationinfo.operateType = operateType;
|
|
628
|
+
}
|
|
629
|
+
if (writeOptions.triggerAction === true) operationinfo.doAction = 'true';
|
|
630
|
+
|
|
631
|
+
var datajson = { header: { objId: state.objId }, datas: [data], operationinfo: operationinfo };
|
|
632
|
+
if (TENANT_KEY) datajson.header.tenantKey = TENANT_KEY;
|
|
633
|
+
|
|
634
|
+
return writeRequest(API_BASE + '/v2/updateFormData', {
|
|
635
|
+
userid: USER_ID,
|
|
636
|
+
datajson: datajson
|
|
637
|
+
}, state.appId).then(function (res) {
|
|
638
|
+
assertOk(res, '更新数据');
|
|
639
|
+
return true;
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function remove(dataId) {
|
|
645
|
+
var datajson = {
|
|
646
|
+
header: { objId: state.objId },
|
|
647
|
+
mainTable: { id: String(dataId) },
|
|
648
|
+
operationinfo: { fieldNoFindIgnore: 'false' }
|
|
649
|
+
};
|
|
650
|
+
if (TENANT_KEY) datajson.header.tenantKey = TENANT_KEY;
|
|
651
|
+
|
|
652
|
+
return writeRequest(API_BASE + '/v2/deleteData', {
|
|
653
|
+
userid: USER_ID,
|
|
654
|
+
datajson: datajson
|
|
655
|
+
}, state.appId).then(function (res) {
|
|
656
|
+
assertOk(res, '删除数据');
|
|
657
|
+
return true;
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return {
|
|
662
|
+
objId: state.objId,
|
|
663
|
+
appId: state.appId,
|
|
664
|
+
fields: fields,
|
|
665
|
+
options: loadOptions,
|
|
666
|
+
optionId: optionId,
|
|
667
|
+
optionIds: optionIds,
|
|
668
|
+
optionMap: optionMap,
|
|
669
|
+
list: list,
|
|
670
|
+
get: get,
|
|
671
|
+
save: save,
|
|
672
|
+
update: update,
|
|
673
|
+
remove: remove
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* 取得某个表单的数据客户端。同一 objId + appId 只创建一次,字段和选项缓存会复用。
|
|
679
|
+
* 在模块顶层调用一次,不要放在组件 render 里。
|
|
680
|
+
*/
|
|
681
|
+
export function formClient(input) {
|
|
682
|
+
var options = typeof input === 'string' ? { objId: input } : (input || {});
|
|
683
|
+
if (!options.objId) {
|
|
684
|
+
throw new Error('formClient 需要 objId,例如 formClient({ objId: OBJ_ID, appId: APP_ID })');
|
|
685
|
+
}
|
|
686
|
+
var key = String(options.objId) + '|' + String(options.appId || '');
|
|
687
|
+
if (!clients[key]) clients[key] = createClient(options);
|
|
688
|
+
return clients[key];
|
|
689
|
+
}
|