cloud-web-corejs 1.1.0-dev.11 → 1.1.0-dev.13

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.
Files changed (48) hide show
  1. package/package.json +1 -1
  2. package/src/components/VabUpload/view.vue +25 -25
  3. package/src/components/excelExport/exportColumnMemory.js +118 -0
  4. package/src/components/excelExport/exportFieldDialog.vue +50 -38
  5. package/src/components/excelExport/index.js +30 -13
  6. package/src/components/excelExport/mixins.js +390 -64
  7. package/src/components/excelImport/mixins.js +898 -850
  8. package/src/components/mobile/wf/addTaskUserdialog.vue +100 -100
  9. package/src/components/mobile/wf/content.vue +4 -4
  10. package/src/components/mobile/wf/deleteTaskUserDialog.vue +73 -73
  11. package/src/components/mobile/wf/setCandidateDialog.vue +69 -69
  12. package/src/components/mobile/wf/urgingDialog.vue +75 -75
  13. package/src/components/table/index.js +14 -1
  14. package/src/components/table/vxeFilter/mixin.js +28 -18
  15. package/src/components/xform/docs/2026-07 table/344/270/216excelExport/344/277/256/345/244/215/345/217/212/345/257/274/345/207/272/344/274/230/345/214/226.md" +64 -57
  16. package/src/components/xform/docs/2026-08 xform H5 P0 /345/256/236/347/216/260/350/247/204/346/240/274.md" +528 -0
  17. package/src/components/xform/docs/2026-08 xform H5 P1 /345/256/236/347/216/260/350/247/204/346/240/274.md" +412 -0
  18. package/src/components/xform/docs/2026-08 xform H5 P2 /345/256/236/347/216/260/350/247/204/346/240/274.md" +287 -0
  19. package/src/components/xform/docs/2026-08 xform /347/247/273/345/212/250/347/253/257/345/270/203/345/261/200/345/257/271/351/275/220 bill_setting /346/226/271/346/241/210.md" +400 -0
  20. package/src/components/xform/docs/2026-09 /346/235/241/344/273/266/345/257/274/345/207/272/345/244/247/346/225/260/346/215/256/351/207/217/345/264/251/346/272/203/346/216/222/346/237/245.md" +389 -0
  21. package/src/components/xform/form-designer/form-widget/container-widget/detail-h5-widget.vue +243 -243
  22. package/src/components/xform/form-designer/form-widget/container-widget/h5-card-pane-widget.vue +228 -228
  23. package/src/components/xform/form-designer/form-widget/container-widget/h5-card-widget.vue +165 -165
  24. package/src/components/xform/form-designer/form-widget/dialog/importDialogMixin.js +61 -2
  25. package/src/components/xform/form-designer/form-widget/field-widget/select-export-item-button-widget.vue +3 -0
  26. package/src/components/xform/form-designer/form-widget/field-widget/singleUpload-widget.vue +145 -145
  27. package/src/components/xform/form-render/container-item/data-table-item.vue +350 -347
  28. package/src/components/xform/form-render/container-item/data-table-mixin.js +240 -37
  29. package/src/components/xform/form-render/container-item/list-h5-item.vue +1 -1
  30. package/src/components/xform/utils/dynamicSchemaUtil.js +385 -361
  31. package/src/layout/components/TagsView/index.vue +325 -323
  32. package/src/store/modules/tagsView.js +241 -217
  33. package/src/utils/importLimit.js +72 -0
  34. package/src/utils/pdfUtil.js +6 -1
  35. package/src/utils/request.js +17 -0
  36. package/src/views/demo/bizTab/bill/billConfig.js +41 -0
  37. package/src/views/demo/bizTab/bill/detail.vue +436 -0
  38. package/src/views/demo/bizTab/bill/list.vue +288 -0
  39. package/src/views/demo/bizTab/bill/productDialog.vue +176 -0
  40. package/src/views/demo/bizTab/simple/billApi.js +123 -0
  41. package/src/views/demo/bizTab/simple/detail.vue +407 -0
  42. package/src/views/demo/bizTab/simple/list.vue +217 -0
  43. package/src/views/demo/bizTab/standalone/index.vue +121 -0
  44. package/src/views/demo/bizTab/wf/billConfig.js +44 -0
  45. package/src/views/demo/bizTab/wf/detail.vue +661 -0
  46. package/src/views/demo/bizTab/wf/list.vue +242 -0
  47. package/src/views/user/home/wjl/content.vue +1569 -0
  48. package/src/views/user/outLink/cc_form_view.vue +188 -0
@@ -1,850 +1,898 @@
1
- /**version-1.0*/
2
- import { read, utils } from "xlsx";
3
-
4
- let tmixins = {};
5
- var XLSX = window.XLSX || { read, utils };
6
- import { getToken } from "../../utils/auth";
7
- import XEUtils from "xe-utils";
8
- import { getErrorMsg } from "@base/utils/index.js";
9
-
10
- let configUtil = {
11
- baseUrl: process.env.VUE_APP_BASE_API,
12
- XLSX,
13
- getToken,
14
- };
15
- let importTimer = null;
16
- let loadingObj = null;
17
- tmixins = {
18
- name: "excelImport",
19
- props: ["param"],
20
- data() {
21
- return {
22
- excTime: 0,
23
- showImportDialog: false,
24
- showImportDialog2: false,
25
- falseValue: false,
26
- fileRaw: false,
27
- isEnd: false,
28
- currentIndex: 0,
29
- excelTemplate: "",
30
- prefix: "/user",
31
- dataSize: 0,
32
- totalSuccessNum: 0,
33
- totalErrorNum: 0,
34
- percentageNum: 0,
35
- successRows: [],
36
- failRows: [],
37
- oriCols: [],
38
- showImportResult: false,
39
- resultType: "",
40
- option: {},
41
- showContent: false,
42
- resOption: {},
43
- };
44
- },
45
- created() {},
46
- beforeDestroy() {
47
- this.clearImportTimer();
48
- },
49
- methods: {
50
- initResGird() {
51
- var that = this;
52
- let tableRef = "resGrid";
53
- let columns = [
54
- {
55
- type: "checkbox",
56
- fixed: "left",
57
- width: 48,
58
- resizable: false,
59
- headerClassName: "vxe-hcs",
60
- className: "vxe-hcs",
61
- },
62
- {
63
- field: "impNumber",
64
- title: this.$t2("行号", "components.excelImport.impNumber"),
65
- width: 100,
66
- fixed: "left",
67
- },
68
- {
69
- field: "_resultContent",
70
- title: this.$t2("结果", "components.excelImport.resultContent"),
71
- width: 250,
72
- fixed: "left",
73
- slots: {
74
- default: ({ row, $rowIndex, $table }) => {
75
- return that.handleRes(row._resultContent);
76
- },
77
- },
78
- },
79
- ];
80
- let cCols = this.oriCols.map((oriCol, index) => {
81
- let col = {
82
- field: oriCol.field,
83
- title: oriCol.title,
84
- width: 150,
85
- };
86
- if (index === 0) {
87
- col.fixed = "left";
88
- }
89
- return col;
90
- });
91
- columns = columns.concat(cCols);
92
-
93
- let tableOption = {
94
- vue: this,
95
- tableRef: tableRef,
96
- tableNameRequired: false,
97
- columns: columns,
98
- config: {
99
- toolbarConfig: {
100
- custom: false,
101
- },
102
- },
103
- };
104
-
105
- this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
106
- this.resOption = opts;
107
- });
108
- },
109
- exc() {
110
- this.option = this.param;
111
- this.showContent = true;
112
- this.showImportDialog = true;
113
- this.showImportDialog2 = false;
114
- },
115
- showSuccessResult() {
116
- this.showImportResult = true;
117
- this.resultType = 1;
118
- this.$nextTick(() => {
119
- this.initResGird();
120
- this.$nextTick(() => {
121
- let tDatas = this.successRows.map((item, index) => {
122
- item.id = index;
123
- return item;
124
- });
125
- this.$refs.resGrid.loadData(tDatas);
126
- });
127
- });
128
- },
129
- showErrorResult() {
130
- this.showImportResult = true;
131
- this.resultType = 0;
132
- this.$nextTick(() => {
133
- this.initResGird();
134
- this.$nextTick(() => {
135
- let tDatas = this.failRows.map((item, index) => {
136
- item.id = index;
137
- return item;
138
- });
139
- this.$refs.resGrid.loadData(tDatas);
140
- });
141
- });
142
- },
143
- fileChange(file) {
144
- if (file) {
145
- this.fileRaw = file.raw;
146
- } else {
147
- this.fileRaw = false;
148
- }
149
- },
150
- dialogClose1() {
151
- this.$emit("update:visiable", false);
152
- this.showContent = false;
153
- },
154
- async dialogPrimary1() {
155
- let that = this;
156
- let option = this.option;
157
- let saveUrl = option.saveUrl;
158
- if (!saveUrl) {
159
- this.dialogPrimary3();
160
- return false;
161
- }
162
-
163
- if (!this.fileRaw) {
164
- this.$baseAlert(
165
- this.$t2("请上传附件", "components.excelImport.warmMsg1")
166
- );
167
- return false;
168
- }
169
- this.createImportTimer();
170
- this.showImportDialog = false;
171
- if (!option.onConfirm) {
172
- this.showImportDialog2 = true;
173
- }
174
- this.$nextTick(() => {
175
- try {
176
- this.readExcel(this.fileRaw, function (resultData) {
177
- if (option.onConfirm) {
178
- option.onConfirm(resultData.data, that.fileRaw);
179
- } else {
180
- that.syncDataForImport({
181
- multi: false,
182
- data: resultData,
183
- saveUrl: saveUrl,
184
- });
185
- }
186
- });
187
- } catch (et) {
188
- that.clearImportTimer();
189
- console.error(et);
190
- }
191
- });
192
- },
193
- handleBeforeClose(hide) {
194
- this.option.onCancel
195
- && this.option.onCancel(this.getCallbackData(), this.fileRaw);
196
- hide();
197
- },
198
- dialogClose2() {
199
- this.showImportDialog2 = false;
200
- this.option.onBeforeCancel
201
- && this.option.onBeforeCancel(this.getCallbackData(), this.fileRaw);
202
- },
203
- handleClose2() {
204
- this.clearImportTimer();
205
- this.showImportDialog2 = false;
206
- this.showContent = false;
207
- this.option.onClose
208
- && this.option.onClose(this.getCallbackData(), this.fileRaw);
209
- this.option.callback
210
- && this.option.callback(this.getCallbackData(), this.fileRaw);
211
- },
212
- dialogPrimary2() {
213
- this.showImportDialog2 = false;
214
- this.option.onBeforeConfirm
215
- && this.option.onBeforeConfirm(this.getCallbackData(), this.fileRaw);
216
- },
217
- getCallbackData() {
218
- return {
219
- ...this.resultData,
220
- successRows: this.successRows,
221
- failRows: this.failRows,
222
- };
223
- },
224
- async readExcel(file, callback) {
225
- let that = this;
226
- let option = this.option;
227
-
228
- const fileReader = new FileReader();
229
- fileReader.onload = async (ev) => {
230
- var resultData;
231
- try {
232
- const data = ev.target.result;
233
- const workbook = configUtil.XLSX.read(data, {
234
- type: "binary",
235
- });
236
-
237
- var sheet = workbook.Sheets[workbook.SheetNames[0]];
238
- if (sheet["!ref"] === undefined) {
239
- that.showImportDialog2 = false;
240
- that.showContent = false;
241
- that.clearImportTimer();
242
- that.$baseAlert(
243
- this.$t2(
244
- "请使用正确的导入模版!",
245
- "components.excelImport.warmMsg2"
246
- )
247
- );
248
- return false;
249
- }
250
- var range = configUtil.XLSX.utils.decode_range(sheet["!ref"]);
251
- var dataSize = range.e.r + 1; //行数
252
- that.dataSize = dataSize - 3 >= 0 ? dataSize - 3 : 0;
253
- var titles = [];
254
- var fields = [];
255
-
256
- const ws = workbook.Sheets[sheet];
257
-
258
- let prefix = option.prefix;
259
- let excelUrl = option.excel;
260
-
261
- var excelRows = [];
262
- var row;
263
- var rowNum;
264
- var colNum;
265
- for (rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
266
- row = [];
267
- for (colNum = range.s.c; colNum <= range.e.c; colNum++) {
268
- var nextCell
269
- = sheet[
270
- configUtil.XLSX.utils.encode_cell({
271
- r: rowNum,
272
- c: colNum,
273
- })
274
- ];
275
- if (typeof nextCell === "undefined") {
276
- row.push(void 0);
277
- } else {
278
- row.push(nextCell.w.trim());
279
- }
280
- }
281
- if (rowNum === 1) {
282
- titles = row;
283
- }
284
- if (rowNum === 2) {
285
- fields = row;
286
- let checkResult = true;
287
- if (!option.importAttachCode) {
288
- await that
289
- .checkExcelForImport(titles, fields, excelUrl, prefix)
290
- .then((res) => {
291
- if (res.type != "success") {
292
- checkResult = false;
293
- }
294
- });
295
- if (!checkResult) {
296
- that.showContent = false;
297
- that.clearImportTimer();
298
- return false;
299
- }
300
- }
301
- }
302
- if (rowNum > 2) {
303
- let item = {};
304
- for (let i = 0; i < fields.length; i++) {
305
- let field = fields[i];
306
- item[field] = row[i];
307
- }
308
- excelRows.push(item);
309
- }
310
- }
311
- if (
312
- !titles.length
313
- || !fields.length
314
- || titles.length != fields.length
315
- ) {
316
- that.showContent = false;
317
- that.clearImportTimer();
318
- that.$baseAlert(
319
- this.$t2(
320
- "请使用正确的导入模版!",
321
- "components.excelImport.warmMsg2"
322
- )
323
- );
324
- return false;
325
- }
326
-
327
- var columns = [];
328
- var cols = [];
329
- let uniqueFields = [];
330
- for (let i = 0; i < titles.length; i++) {
331
- let title = titles[i];
332
- if (title) {
333
- let field = fields[i];
334
- if (field === null) {
335
- that.showContent = false;
336
- that.clearImportTimer();
337
- that.$baseAlert(
338
- this.$t2(
339
- "请使用正确的导入模版!",
340
- "components.excelImport.warmMsg2"
341
- )
342
- );
343
- return false;
344
- }
345
- let t = title.substr(-1);
346
- let u = title.length >= 2 ? title.substr(-2) : title;
347
- let isNeed = false;
348
- if (t === "*") {
349
- isNeed = true;
350
- }
351
- let isUnique = false;
352
- if (u === "**") {
353
- uniqueFields.push(field);
354
- isUnique = true;
355
- }
356
- let col = {
357
- field: field,
358
- title: title,
359
- width: 100,
360
- isNeed: isNeed,
361
- isUnique: isUnique,
362
- };
363
- cols.push(col);
364
- }
365
- }
366
-
367
- var oriCols = JSON.parse(JSON.stringify(cols)); //列信息
368
- if (uniqueFields.length) {
369
- //分组唯一字段为空时,全部不发包。
370
- for (let i = 0; i < oriCols.length; i++) {
371
- let oriCol = oriCols[i];
372
- if (oriCol.isNeed) {
373
- for (let j = 0; j < excelRows.length; j++) {
374
- let data = excelRows[j];
375
- let value = data[oriCol.field];
376
- if (value === null || value === "") {
377
- that.clearImportTimer();
378
- that.$baseAlert(
379
- this.$t2(
380
- "第" + (j + 4) + "行[" + oriCol.title + "]不能为空;",
381
- "components.excelImport.warmMsg3",
382
- {
383
- lineNo: j + 4,
384
- title: oriCol.title,
385
- }
386
- )
387
- );
388
- return false;
389
- }
390
- }
391
- }
392
- }
393
- }
394
-
395
- this.oriCols = oriCols;
396
-
397
- resultData = {
398
- data: excelRows,
399
- titles: titles,
400
- fields: fields,
401
- uniqueFields: uniqueFields,
402
- oriCols: oriCols,
403
- };
404
- this.resultData = resultData;
405
- callback(resultData);
406
- } catch (et) {
407
- that.showContent = false;
408
- that.clearImportTimer();
409
- console.error(et);
410
- }
411
- };
412
- fileReader.readAsBinaryString(file);
413
- },
414
- async checkExcelForImport(titles, fields, turl, prefix) {
415
- let that = this;
416
- var data = {
417
- filed_name: fields,
418
- field_note: titles,
419
- url: turl,
420
- };
421
- var param = JSON.stringify(data);
422
- return this.$http({
423
- url: prefix + "/sf_common/compareExcelFields",
424
- method: "post",
425
- headers: {
426
- "Content-Type": "application/json;charset=utf-8",
427
- },
428
- // data: param,
429
- data: data,
430
- });
431
- },
432
- syncDataForImport(opts) {
433
- let that = this;
434
- var multi = this.option.multi;
435
- var resultData = opts.data;
436
- var datas = resultData.data;
437
- var titles = resultData.titles;
438
- var fields = resultData.fields;
439
- let uniqueFields = resultData.uniqueFields;
440
- var saveUrl = opts.saveUrl;
441
- var size = datas.length;
442
- var index = 0;
443
- var successNum = 0;
444
- var failNum = 0;
445
- var dialogObj = this.$refs.importDialog.$el;
446
- var successNumObj = dialogObj.querySelector(".successNum");
447
- var failNumObj = dialogObj.querySelector(".failNum");
448
- var percentageObj = dialogObj.querySelector(".percentage");
449
- var doneNumObj = dialogObj.querySelector(".doneNum");
450
- dialogObj.querySelector(".dataSize").innerText = size;
451
-
452
- that.successRows = [];
453
- that.failRows = [];
454
-
455
- var multiSize = opts.multiSize || 2;
456
-
457
- let groupIndex = 0;
458
- let groupDatas = [];
459
- if (uniqueFields.length) {
460
- let d = XEUtils.groupBy(datas, function (item, itemIndex, items) {
461
- let keyArr = [];
462
- uniqueFields.forEach((field) => {
463
- keyArr.push(item[field]);
464
- });
465
- return keyArr.join("&_&");
466
- });
467
- for (let key in d) {
468
- groupDatas.push(d[key]);
469
- }
470
- datas.forEach((item, itemIndex) => {
471
- item.impSeq = itemIndex;
472
- item.impNumber = itemIndex + 4;
473
- });
474
- }
475
-
476
- var compareV = function (property) {
477
- return function (a, b) {
478
- var value1 = a[property];
479
- var value2 = b[property];
480
- return value1 - value2;
481
- };
482
- };
483
-
484
- var prevHandleData = function (percentageStr, excNum) {
485
- successNumObj.innerText = successNum;
486
- failNumObj.innerText = failNum;
487
- doneNumObj.innerText = successNum + failNum;
488
- that.percentageNum = percentageStr;
489
- let isEnd = false;
490
- if (uniqueFields.length) {
491
- isEnd = groupIndex + 1 >= groupDatas.length;
492
- } else {
493
- isEnd = index + excNum >= size;
494
- }
495
- if (!isEnd) {
496
- index = index + excNum;
497
- groupIndex = groupIndex + 1;
498
- setTimeout(function () {
499
- handleData();
500
- }, 1);
501
- } else {
502
- setTimeout(function () {
503
- that.clearImportTimer();
504
- }, 300);
505
- }
506
- };
507
-
508
- let getDefaultValue = (row) => {
509
- let value = null;
510
- let defaultValue = this.option.defaultValue;
511
- if (defaultValue) {
512
- if (typeof defaultValue === "function") {
513
- value = defaultValue(row) || {};
514
- } else {
515
- value = defaultValue || {};
516
- }
517
- }
518
- return value;
519
- };
520
-
521
- let handleData = () => {
522
- if (!that.isEnd && index < size) {
523
- var param;
524
- var excNum;
525
- if (multi) {
526
- if (!uniqueFields.length) {
527
- if (index + multiSize < size) {
528
- excNum = multiSize;
529
- } else {
530
- excNum = size - index;
531
- }
532
-
533
- let dataList = [];
534
- for (let i = 0; i < excNum; i++) {
535
- var mIndex = index + i;
536
- let mData = datas[mIndex];
537
- mData.impSeq = mIndex;
538
- mData.impNumber = mIndex + 4;
539
-
540
- let errorInfo = that.vailData(mData, opts);
541
- if (errorInfo.length > 0) {
542
- mData._resultType = "error";
543
- mData._resultContent = errorInfo;
544
- failNum++;
545
- that.failRows.push(mData);
546
- } else {
547
- let defaultValue = getDefaultValue(mData);
548
- if (defaultValue) {
549
- Object.assign(mData, defaultValue);
550
- }
551
- dataList.push(mData);
552
- }
553
-
554
- datas[mIndex] = mData;
555
- }
556
- if (dataList.length > 0) {
557
- param = dataList;
558
- }
559
- } else {
560
- excNum = groupDatas[groupIndex].length;
561
- param = groupDatas[groupIndex];
562
- }
563
- } else {
564
- var data = datas[index];
565
- data.impSeq = index;
566
- data.impNumber = index + 4;
567
- excNum = 1;
568
- datas[index] = data;
569
-
570
- let errorInfo = that.vailData(data, opts);
571
- if (errorInfo.length > 0) {
572
- data._resultType = "error";
573
- data._resultContent = errorInfo;
574
- failNum++;
575
- that.failRows.push(data);
576
- } else {
577
- param = data;
578
- let defaultValue = getDefaultValue(data);
579
- if (defaultValue) {
580
- Object.assign(param, defaultValue);
581
- }
582
- }
583
- }
584
-
585
- var percentageStr = parseInt(((index + excNum) * 100) / size);
586
- if (param === null || param.length === 0) {
587
- if (that.showContent) {
588
- prevHandleData(percentageStr, excNum);
589
- }
590
- return;
591
- }
592
-
593
- that
594
- .$http({
595
- url: saveUrl,
596
- method: "post",
597
- data: param,
598
- resultType: "special",
599
- modal: false,
600
- callback: (resultMsg) => {
601
- if (multi) {
602
- if (resultMsg.type === "success") {
603
- var multiRows = resultMsg.objx;
604
- for (let i = 0; i < multiRows.length; i++) {
605
- var multiRow = multiRows[i];
606
- var data = { ...datas[multiRow.impSeq] };
607
- data._rqeData = { ...datas[multiRow.impSeq] };
608
- data._resultData = multiRow;
609
- data._resultType = multiRow.impReturnType;
610
- data._resultContent
611
- = multiRow.impReturnType === "success"
612
- ? this.$t2(
613
- "导入成功",
614
- "components.excelImport.importSucess"
615
- )
616
- : multiRow.impReturnMsg;
617
- if (multiRow.impReturnType === "success") {
618
- successNum++;
619
- that.successRows.push(data);
620
- } else {
621
- failNum++;
622
- that.failRows.push(data);
623
- }
624
- }
625
-
626
- that.failRows = that.failRows.sort(compareV("impSeq"));
627
- } else {
628
- // error_win(resultMsg);
629
- // layer.close(opts.dialogObjIndex);
630
- that.$errorMsg(resultMsg);
631
- that.showContent = false;
632
- that.clearImportTimer();
633
- return;
634
- }
635
- } else {
636
- var data = { ...datas[index] };
637
- data._resultType = resultMsg.type;
638
- data._resultContent
639
- = resultMsg.type === "success"
640
- ? this.$t2(
641
- "导入成功",
642
- "components.excelImport.importSucess"
643
- )
644
- : this.handleRes(resultMsg.content);
645
- data._rqeData = { ...datas[index] };
646
- data._resultData = resultMsg.objx;
647
- if (resultMsg.type === "success") {
648
- successNum++;
649
- that.successRows.push(data);
650
- } else {
651
- failNum++;
652
- that.failRows.push(data);
653
- }
654
- }
655
- if (that.showContent) {
656
- prevHandleData(percentageStr, excNum);
657
- }
658
- },
659
- })
660
- .catch(function (et) {
661
- that.isEnd = true;
662
- that.clearImportTimer();
663
- console.error(et);
664
- });
665
- }
666
- };
667
- handleData();
668
- },
669
- commonLocalDownload() {
670
- if (this.option.importAttachCode) {
671
- this.commonLocalDownload2();
672
- return;
673
- }
674
- let path = this.option.excel;
675
- let prefix = this.option.prefix;
676
- prefix = prefix || "";
677
- var url = configUtil.baseUrl + prefix + "/sf_common/download";
678
- if (path) {
679
- var params = {
680
- url: path,
681
- };
682
- params["access_token"] = configUtil.getToken();
683
-
684
- var form = document.createElement("form");
685
-
686
- let randomNum
687
- = new Date().valueOf() + Math.floor(Math.random() * 1000000);
688
- let formId = "formId-" + randomNum;
689
- let formName = "formName-" + randomNum;
690
-
691
- form.id = formId;
692
- form.name = formName;
693
- form.target = "_blank";
694
- document.body.appendChild(form);
695
- for (let obj in params) {
696
- if (params.hasOwnProperty(obj)) {
697
- let input = document.createElement("input");
698
- input.tpye = "hidden";
699
- input.name = obj;
700
- input.value = params[obj];
701
- form.appendChild(input);
702
- }
703
- }
704
- form.method = "post"; //请求方式
705
- form.action = url;
706
- form.submit();
707
- document.body.removeChild(form);
708
- }
709
- },
710
- commonLocalDownload2() {
711
- let importAttachCode = this.option.importAttachCode;
712
- if (!importAttachCode) return;
713
- this.$http({
714
- url: USER_PREFIX + "/bd_attach_setting/getByCode",
715
- method: "post",
716
- data: {
717
- stringOne: importAttachCode,
718
- },
719
- success: (res) => {
720
- let fileObj = res.objx;
721
- let url = fileObj?.url;
722
- if (fileObj && url) {
723
- this.$commonFileUtil.downloadFile(url, fileObj.name);
724
- }
725
- },
726
- });
727
- },
728
- vailData(data, opts) {
729
- var oriCols = opts.data.oriCols;
730
- var errorInfo = [];
731
- for (let i = 0; i < oriCols.length; i++) {
732
- let oriCol = oriCols[i];
733
- if (oriCol.isNeed) {
734
- let value = data[oriCol.field];
735
- if (value === null || value === "") {
736
- errorInfo.push(
737
- this.$t2(
738
- "[" + oriCol.title + "]不能为空;",
739
- "components.excelImport.warmMsg4",
740
- { title: oriCol.title }
741
- )
742
- );
743
- }
744
- }
745
- }
746
- return errorInfo.join("");
747
- },
748
- handleRes(val) {
749
- /* var content = val;
750
- var text = content;
751
- if (content && content.indexOf("Exception") >= 0) {
752
- var index0 = content.lastIndexOf("*]");
753
- if (index0 >= 0) {
754
- text = content.substr(index0);
755
- if (text) {
756
- var index1 = text.indexOf("Exception:");
757
- if (index1 >= 0) {
758
- text = text.substr(index1 + 10);
759
- }
760
- }
761
- }
762
- } */
763
- let text = getErrorMsg(val);
764
- return text;
765
- },
766
- exportToExcel() {
767
- let str
768
- = this.resultType === 1
769
- ? this.$t2("成功", "components.excelImport.success")
770
- : this.$t2("失败", "components.excelImport.fail");
771
- let fileName
772
- = this.$t2("导入结果导出", "components.excelImport.exportFileName")
773
- + "("
774
- + str
775
- + ")";
776
- let $grid = this.$refs.resGrid;
777
- let columns = $grid.getColumns();
778
- if (columns && columns.length) {
779
- let fields = columns
780
- .filter((item, index) => {
781
- return index > 0 && item.property;
782
- })
783
- .map((item, index) => {
784
- return item.property;
785
- });
786
- this.$refs.resGrid.exportData({
787
- filename: fileName,
788
- mode: "all",
789
- type: "csv",
790
- columns: fields,
791
- });
792
- }
793
- },
794
- createImportTimer() {
795
- this.excTime = 0;
796
- let beginTime = new Date().getTime();
797
- importTimer = setInterval(() => {
798
- let nowTime = new Date().getTime();
799
- let diffTime = (nowTime - beginTime) / 1000;
800
- this.$set(this, "excTime", this.$baseLodash.round(diffTime, 2));
801
- }, 100);
802
- },
803
- clearImportTimer() {
804
- clearInterval(importTimer);
805
- loadingObj && loadingObj.close();
806
- },
807
- async dialogPrimary3() {
808
- if (!this.fileRaw) {
809
- this.$baseAlert(
810
- this.$t2("请上传附件", "components.excelImport.warmMsg1")
811
- );
812
- return false;
813
- }
814
- let that = this;
815
- let option = this.option;
816
- let done = () => {
817
- that.showImportDialog = false;
818
- };
819
- if (!option.excel) {
820
- if (
821
- option.callback
822
- && option.callback(null, this.fileRaw, done) !== false
823
- ) {
824
- that.showImportDialog = false;
825
- }
826
- return;
827
- }
828
- loadingObj = this.$baseLoading({
829
- target: document.body,
830
- background: "unset",
831
- });
832
- this.readExcel(this.fileRaw, function (resultData) {
833
- try {
834
- if (
835
- option.callback
836
- && option.callback(resultData, that.fileRaw, done) !== false
837
- ) {
838
- that.showImportDialog = false;
839
- }
840
- } catch (et) {
841
- console.error(et);
842
- }
843
- setTimeout(function () {
844
- loadingObj && loadingObj.close();
845
- }, 200);
846
- });
847
- },
848
- },
849
- };
850
- export const mixins = tmixins;
1
+ /**version-1.0*/
2
+ import { read, utils } from "xlsx";
3
+
4
+ let tmixins = {};
5
+ var XLSX = window.XLSX || { read, utils };
6
+ import { getToken } from "../../utils/auth";
7
+ import XEUtils from "xe-utils";
8
+ import { getErrorMsg } from "@base/utils/index.js";
9
+ import {
10
+ getImportCellText,
11
+ getImportFileSizeLimit,
12
+ getImportRowLimit,
13
+ isImportFileOversize,
14
+ isImportRowsOverLimit,
15
+ toFileSizeMb,
16
+ } from "../../utils/importLimit";
17
+
18
+ let configUtil = {
19
+ baseUrl: process.env.VUE_APP_BASE_API,
20
+ XLSX,
21
+ getToken,
22
+ };
23
+ // 计时器与遮罩句柄必须挂实例:模块级单例在 tagsView 同时开两个导入页时会被后开的
24
+ // 那个覆盖,先开的 100ms interval 永远停不掉,还会把整个组件钉住不被回收。
25
+ tmixins = {
26
+ name: "excelImport",
27
+ props: ["param"],
28
+ data() {
29
+ return {
30
+ excTime: 0,
31
+ showImportDialog: false,
32
+ showImportDialog2: false,
33
+ falseValue: false,
34
+ fileRaw: false,
35
+ isEnd: false,
36
+ currentIndex: 0,
37
+ excelTemplate: "",
38
+ prefix: "/user",
39
+ dataSize: 0,
40
+ totalSuccessNum: 0,
41
+ totalErrorNum: 0,
42
+ percentageNum: 0,
43
+ successRows: [],
44
+ failRows: [],
45
+ oriCols: [],
46
+ showImportResult: false,
47
+ resultType: "",
48
+ option: {},
49
+ showContent: false,
50
+ resOption: {},
51
+ importTimer: null,
52
+ loadingObj: null,
53
+ };
54
+ },
55
+ created() {},
56
+ beforeDestroy() {
57
+ this.clearImportTimer();
58
+ },
59
+ methods: {
60
+ initResGird() {
61
+ var that = this;
62
+ let tableRef = "resGrid";
63
+ let columns = [
64
+ {
65
+ type: "checkbox",
66
+ fixed: "left",
67
+ width: 48,
68
+ resizable: false,
69
+ headerClassName: "vxe-hcs",
70
+ className: "vxe-hcs",
71
+ },
72
+ {
73
+ field: "impNumber",
74
+ title: this.$t2("行号", "components.excelImport.impNumber"),
75
+ width: 100,
76
+ fixed: "left",
77
+ },
78
+ {
79
+ field: "_resultContent",
80
+ title: this.$t2("结果", "components.excelImport.resultContent"),
81
+ width: 250,
82
+ fixed: "left",
83
+ slots: {
84
+ default: ({ row, $rowIndex, $table }) => {
85
+ return that.handleRes(row._resultContent);
86
+ },
87
+ },
88
+ },
89
+ ];
90
+ let cCols = this.oriCols.map((oriCol, index) => {
91
+ let col = {
92
+ field: oriCol.field,
93
+ title: oriCol.title,
94
+ width: 150,
95
+ };
96
+ if (index === 0) {
97
+ col.fixed = "left";
98
+ }
99
+ return col;
100
+ });
101
+ columns = columns.concat(cCols);
102
+
103
+ let tableOption = {
104
+ vue: this,
105
+ tableRef: tableRef,
106
+ tableNameRequired: false,
107
+ columns: columns,
108
+ config: {
109
+ toolbarConfig: {
110
+ custom: false,
111
+ },
112
+ },
113
+ };
114
+
115
+ this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
116
+ this.resOption = opts;
117
+ });
118
+ },
119
+ exc() {
120
+ this.option = this.param;
121
+ this.showContent = true;
122
+ this.showImportDialog = true;
123
+ this.showImportDialog2 = false;
124
+ },
125
+ showSuccessResult() {
126
+ this.showImportResult = true;
127
+ this.resultType = 1;
128
+ this.$nextTick(() => {
129
+ this.initResGird();
130
+ this.$nextTick(() => {
131
+ let tDatas = this.successRows.map((item, index) => {
132
+ item.id = index;
133
+ return item;
134
+ });
135
+ this.$refs.resGrid.loadData(tDatas);
136
+ });
137
+ });
138
+ },
139
+ showErrorResult() {
140
+ this.showImportResult = true;
141
+ this.resultType = 0;
142
+ this.$nextTick(() => {
143
+ this.initResGird();
144
+ this.$nextTick(() => {
145
+ let tDatas = this.failRows.map((item, index) => {
146
+ item.id = index;
147
+ return item;
148
+ });
149
+ this.$refs.resGrid.loadData(tDatas);
150
+ });
151
+ });
152
+ },
153
+ fileChange(file) {
154
+ if (file) {
155
+ this.fileRaw = file.raw;
156
+ } else {
157
+ this.fileRaw = false;
158
+ }
159
+ },
160
+ dialogClose1() {
161
+ this.$emit("update:visiable", false);
162
+ this.showContent = false;
163
+ },
164
+ async dialogPrimary1() {
165
+ let that = this;
166
+ let option = this.option;
167
+ let saveUrl = option.saveUrl;
168
+ if (!saveUrl) {
169
+ this.dialogPrimary3();
170
+ return false;
171
+ }
172
+
173
+ if (!this.fileRaw) {
174
+ this.$baseAlert(
175
+ this.$t2("请上传附件", "components.excelImport.warmMsg1")
176
+ );
177
+ return false;
178
+ }
179
+ this.createImportTimer();
180
+ this.showImportDialog = false;
181
+ if (!option.onConfirm) {
182
+ this.showImportDialog2 = true;
183
+ }
184
+ this.$nextTick(() => {
185
+ try {
186
+ this.readExcel(this.fileRaw, function (resultData) {
187
+ if (option.onConfirm) {
188
+ option.onConfirm(resultData.data, that.fileRaw);
189
+ } else {
190
+ that.syncDataForImport({
191
+ multi: false,
192
+ data: resultData,
193
+ saveUrl: saveUrl,
194
+ });
195
+ }
196
+ });
197
+ } catch (et) {
198
+ that.clearImportTimer();
199
+ console.error(et);
200
+ }
201
+ });
202
+ },
203
+ handleBeforeClose(hide) {
204
+ this.option.onCancel
205
+ && this.option.onCancel(this.getCallbackData(), this.fileRaw);
206
+ hide();
207
+ },
208
+ dialogClose2() {
209
+ this.showImportDialog2 = false;
210
+ this.option.onBeforeCancel
211
+ && this.option.onBeforeCancel(this.getCallbackData(), this.fileRaw);
212
+ },
213
+ handleClose2() {
214
+ this.clearImportTimer();
215
+ this.showImportDialog2 = false;
216
+ this.showContent = false;
217
+ this.option.onClose
218
+ && this.option.onClose(this.getCallbackData(), this.fileRaw);
219
+ this.option.callback
220
+ && this.option.callback(this.getCallbackData(), this.fileRaw);
221
+ },
222
+ dialogPrimary2() {
223
+ this.showImportDialog2 = false;
224
+ this.option.onBeforeConfirm
225
+ && this.option.onBeforeConfirm(this.getCallbackData(), this.fileRaw);
226
+ },
227
+ getCallbackData() {
228
+ return {
229
+ ...this.resultData,
230
+ successRows: this.successRows,
231
+ failRows: this.failRows,
232
+ };
233
+ },
234
+ async readExcel(file, callback) {
235
+ let that = this;
236
+ let option = this.option;
237
+
238
+ // 整文件读进内存前先卡一刀:下面的 readAsBinaryString + XLSX.read 是同步的,
239
+ // 占用约为文件体积的 5~20 倍,超限时崩在库内部,连提示都给不出来。
240
+ if (isImportFileOversize(file, option)) {
241
+ this.showImportDialog2 = false;
242
+ this.showContent = false;
243
+ this.clearImportTimer();
244
+ this.$baseAlert(
245
+ this.$t1(
246
+ "导入文件过大({size}MB),当前最多支持 {limit}MB,请拆分后分批导入",
247
+ {
248
+ size: toFileSizeMb(file.size),
249
+ limit: toFileSizeMb(getImportFileSizeLimit(option)),
250
+ }
251
+ )
252
+ );
253
+ return false;
254
+ }
255
+
256
+ const fileReader = new FileReader();
257
+ fileReader.onload = async (ev) => {
258
+ var resultData;
259
+ try {
260
+ const data = ev.target.result;
261
+ const workbook = configUtil.XLSX.read(data, {
262
+ type: "binary",
263
+ });
264
+
265
+ var sheet = workbook.Sheets[workbook.SheetNames[0]];
266
+ if (sheet["!ref"] === undefined) {
267
+ that.showImportDialog2 = false;
268
+ that.showContent = false;
269
+ that.clearImportTimer();
270
+ that.$baseAlert(
271
+ this.$t2(
272
+ "请使用正确的导入模版!",
273
+ "components.excelImport.warmMsg2"
274
+ )
275
+ );
276
+ return false;
277
+ }
278
+ var range = configUtil.XLSX.utils.decode_range(sheet["!ref"]);
279
+ var dataSize = range.e.r + 1; //行数
280
+ that.dataSize = dataSize - 3 >= 0 ? dataSize - 3 : 0;
281
+ // 行数闸门:下面逐格取值、建行对象、再整批发包全是同步的,行数失控时
282
+ // 主线程会被占死甚至 OOM。文件本身不大但行极多(窄表)时只有这一道能拦。
283
+ if (isImportRowsOverLimit(that.dataSize, option)) {
284
+ that.showImportDialog2 = false;
285
+ that.showContent = false;
286
+ that.clearImportTimer();
287
+ that.$baseAlert(
288
+ that.$t1(
289
+ "导入数据 {size} 行,超过单次上限 {limit} 行,请拆分后分批导入",
290
+ {
291
+ size: that.dataSize,
292
+ limit: getImportRowLimit(option),
293
+ }
294
+ )
295
+ );
296
+ return false;
297
+ }
298
+ var titles = [];
299
+ var fields = [];
300
+
301
+ const ws = workbook.Sheets[sheet];
302
+
303
+ let prefix = option.prefix;
304
+ let excelUrl = option.excel;
305
+
306
+ var excelRows = [];
307
+ var row;
308
+ var rowNum;
309
+ var colNum;
310
+ for (rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
311
+ row = [];
312
+ for (colNum = range.s.c; colNum <= range.e.c; colNum++) {
313
+ var nextCell
314
+ = sheet[
315
+ configUtil.XLSX.utils.encode_cell({
316
+ r: rowNum,
317
+ c: colNum,
318
+ })
319
+ ];
320
+ if (typeof nextCell === "undefined") {
321
+ row.push(void 0);
322
+ } else {
323
+ row.push(getImportCellText(nextCell));
324
+ }
325
+ }
326
+ if (rowNum === 1) {
327
+ titles = row;
328
+ }
329
+ if (rowNum === 2) {
330
+ fields = row;
331
+ let checkResult = true;
332
+ if (!option.importAttachCode) {
333
+ await that
334
+ .checkExcelForImport(titles, fields, excelUrl, prefix)
335
+ .then((res) => {
336
+ if (res.type != "success") {
337
+ checkResult = false;
338
+ }
339
+ });
340
+ if (!checkResult) {
341
+ that.showContent = false;
342
+ that.clearImportTimer();
343
+ return false;
344
+ }
345
+ }
346
+ }
347
+ if (rowNum > 2) {
348
+ let item = {};
349
+ for (let i = 0; i < fields.length; i++) {
350
+ let field = fields[i];
351
+ item[field] = row[i];
352
+ }
353
+ excelRows.push(item);
354
+ }
355
+ }
356
+ if (
357
+ !titles.length
358
+ || !fields.length
359
+ || titles.length != fields.length
360
+ ) {
361
+ that.showContent = false;
362
+ that.clearImportTimer();
363
+ that.$baseAlert(
364
+ this.$t2(
365
+ "请使用正确的导入模版!",
366
+ "components.excelImport.warmMsg2"
367
+ )
368
+ );
369
+ return false;
370
+ }
371
+
372
+ var columns = [];
373
+ var cols = [];
374
+ let uniqueFields = [];
375
+ for (let i = 0; i < titles.length; i++) {
376
+ let title = titles[i];
377
+ if (title) {
378
+ let field = fields[i];
379
+ if (field === null) {
380
+ that.showContent = false;
381
+ that.clearImportTimer();
382
+ that.$baseAlert(
383
+ this.$t2(
384
+ "请使用正确的导入模版!",
385
+ "components.excelImport.warmMsg2"
386
+ )
387
+ );
388
+ return false;
389
+ }
390
+ let t = title.substr(-1);
391
+ let u = title.length >= 2 ? title.substr(-2) : title;
392
+ let isNeed = false;
393
+ if (t === "*") {
394
+ isNeed = true;
395
+ }
396
+ let isUnique = false;
397
+ if (u === "**") {
398
+ uniqueFields.push(field);
399
+ isUnique = true;
400
+ }
401
+ let col = {
402
+ field: field,
403
+ title: title,
404
+ width: 100,
405
+ isNeed: isNeed,
406
+ isUnique: isUnique,
407
+ };
408
+ cols.push(col);
409
+ }
410
+ }
411
+
412
+ var oriCols = JSON.parse(JSON.stringify(cols)); //列信息
413
+ if (uniqueFields.length) {
414
+ //分组唯一字段为空时,全部不发包。
415
+ for (let i = 0; i < oriCols.length; i++) {
416
+ let oriCol = oriCols[i];
417
+ if (oriCol.isNeed) {
418
+ for (let j = 0; j < excelRows.length; j++) {
419
+ let data = excelRows[j];
420
+ let value = data[oriCol.field];
421
+ if (value === null || value === "") {
422
+ that.clearImportTimer();
423
+ that.$baseAlert(
424
+ this.$t2(
425
+ "第" + (j + 4) + "行[" + oriCol.title + "]不能为空;",
426
+ "components.excelImport.warmMsg3",
427
+ {
428
+ lineNo: j + 4,
429
+ title: oriCol.title,
430
+ }
431
+ )
432
+ );
433
+ return false;
434
+ }
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
+ this.oriCols = oriCols;
441
+
442
+ resultData = {
443
+ data: excelRows,
444
+ titles: titles,
445
+ fields: fields,
446
+ uniqueFields: uniqueFields,
447
+ oriCols: oriCols,
448
+ };
449
+ this.resultData = resultData;
450
+ callback(resultData);
451
+ } catch (et) {
452
+ that.showContent = false;
453
+ that.clearImportTimer();
454
+ console.error(et);
455
+ }
456
+ };
457
+ fileReader.readAsBinaryString(file);
458
+ },
459
+ async checkExcelForImport(titles, fields, turl, prefix) {
460
+ let that = this;
461
+ var data = {
462
+ filed_name: fields,
463
+ field_note: titles,
464
+ url: turl,
465
+ };
466
+ var param = JSON.stringify(data);
467
+ return this.$http({
468
+ url: prefix + "/sf_common/compareExcelFields",
469
+ method: "post",
470
+ headers: {
471
+ "Content-Type": "application/json;charset=utf-8",
472
+ },
473
+ // data: param,
474
+ data: data,
475
+ });
476
+ },
477
+ syncDataForImport(opts) {
478
+ let that = this;
479
+ var multi = this.option.multi;
480
+ var resultData = opts.data;
481
+ var datas = resultData.data;
482
+ var titles = resultData.titles;
483
+ var fields = resultData.fields;
484
+ let uniqueFields = resultData.uniqueFields;
485
+ var saveUrl = opts.saveUrl;
486
+ var size = datas.length;
487
+ var index = 0;
488
+ var successNum = 0;
489
+ var failNum = 0;
490
+ var dialogObj = this.$refs.importDialog.$el;
491
+ var successNumObj = dialogObj.querySelector(".successNum");
492
+ var failNumObj = dialogObj.querySelector(".failNum");
493
+ var percentageObj = dialogObj.querySelector(".percentage");
494
+ var doneNumObj = dialogObj.querySelector(".doneNum");
495
+ dialogObj.querySelector(".dataSize").innerText = size;
496
+
497
+ that.successRows = [];
498
+ that.failRows = [];
499
+
500
+ var multiSize = opts.multiSize || 2;
501
+
502
+ let groupIndex = 0;
503
+ let groupDatas = [];
504
+ if (uniqueFields.length) {
505
+ let d = XEUtils.groupBy(datas, function (item, itemIndex, items) {
506
+ let keyArr = [];
507
+ uniqueFields.forEach((field) => {
508
+ keyArr.push(item[field]);
509
+ });
510
+ return keyArr.join("&_&");
511
+ });
512
+ for (let key in d) {
513
+ groupDatas.push(d[key]);
514
+ }
515
+ datas.forEach((item, itemIndex) => {
516
+ item.impSeq = itemIndex;
517
+ item.impNumber = itemIndex + 4;
518
+ });
519
+ }
520
+
521
+ var compareV = function (property) {
522
+ return function (a, b) {
523
+ var value1 = a[property];
524
+ var value2 = b[property];
525
+ return value1 - value2;
526
+ };
527
+ };
528
+
529
+ var prevHandleData = function (percentageStr, excNum) {
530
+ successNumObj.innerText = successNum;
531
+ failNumObj.innerText = failNum;
532
+ doneNumObj.innerText = successNum + failNum;
533
+ that.percentageNum = percentageStr;
534
+ let isEnd = false;
535
+ if (uniqueFields.length) {
536
+ isEnd = groupIndex + 1 >= groupDatas.length;
537
+ } else {
538
+ isEnd = index + excNum >= size;
539
+ }
540
+ if (!isEnd) {
541
+ index = index + excNum;
542
+ groupIndex = groupIndex + 1;
543
+ setTimeout(function () {
544
+ handleData();
545
+ }, 1);
546
+ } else {
547
+ setTimeout(function () {
548
+ that.clearImportTimer();
549
+ }, 300);
550
+ }
551
+ };
552
+
553
+ let getDefaultValue = (row) => {
554
+ let value = null;
555
+ let defaultValue = this.option.defaultValue;
556
+ if (defaultValue) {
557
+ if (typeof defaultValue === "function") {
558
+ value = defaultValue(row) || {};
559
+ } else {
560
+ value = defaultValue || {};
561
+ }
562
+ }
563
+ return value;
564
+ };
565
+
566
+ let handleData = () => {
567
+ if (!that.isEnd && index < size) {
568
+ var param;
569
+ var excNum;
570
+ if (multi) {
571
+ if (!uniqueFields.length) {
572
+ if (index + multiSize < size) {
573
+ excNum = multiSize;
574
+ } else {
575
+ excNum = size - index;
576
+ }
577
+
578
+ let dataList = [];
579
+ for (let i = 0; i < excNum; i++) {
580
+ var mIndex = index + i;
581
+ let mData = datas[mIndex];
582
+ mData.impSeq = mIndex;
583
+ mData.impNumber = mIndex + 4;
584
+
585
+ let errorInfo = that.vailData(mData, opts);
586
+ if (errorInfo.length > 0) {
587
+ mData._resultType = "error";
588
+ mData._resultContent = errorInfo;
589
+ failNum++;
590
+ that.failRows.push(mData);
591
+ } else {
592
+ let defaultValue = getDefaultValue(mData);
593
+ if (defaultValue) {
594
+ Object.assign(mData, defaultValue);
595
+ }
596
+ dataList.push(mData);
597
+ }
598
+
599
+ datas[mIndex] = mData;
600
+ }
601
+ if (dataList.length > 0) {
602
+ param = dataList;
603
+ }
604
+ } else {
605
+ excNum = groupDatas[groupIndex].length;
606
+ param = groupDatas[groupIndex];
607
+ }
608
+ } else {
609
+ var data = datas[index];
610
+ data.impSeq = index;
611
+ data.impNumber = index + 4;
612
+ excNum = 1;
613
+ datas[index] = data;
614
+
615
+ let errorInfo = that.vailData(data, opts);
616
+ if (errorInfo.length > 0) {
617
+ data._resultType = "error";
618
+ data._resultContent = errorInfo;
619
+ failNum++;
620
+ that.failRows.push(data);
621
+ } else {
622
+ param = data;
623
+ let defaultValue = getDefaultValue(data);
624
+ if (defaultValue) {
625
+ Object.assign(param, defaultValue);
626
+ }
627
+ }
628
+ }
629
+
630
+ var percentageStr = parseInt(((index + excNum) * 100) / size);
631
+ if (param === null || param.length === 0) {
632
+ if (that.showContent) {
633
+ prevHandleData(percentageStr, excNum);
634
+ }
635
+ return;
636
+ }
637
+
638
+ that
639
+ .$http({
640
+ url: saveUrl,
641
+ method: "post",
642
+ data: param,
643
+ resultType: "special",
644
+ modal: false,
645
+ callback: (resultMsg) => {
646
+ if (multi) {
647
+ if (resultMsg.type === "success") {
648
+ var multiRows = resultMsg.objx;
649
+ for (let i = 0; i < multiRows.length; i++) {
650
+ var multiRow = multiRows[i];
651
+ var data = { ...datas[multiRow.impSeq] };
652
+ data._rqeData = { ...datas[multiRow.impSeq] };
653
+ data._resultData = multiRow;
654
+ data._resultType = multiRow.impReturnType;
655
+ data._resultContent
656
+ = multiRow.impReturnType === "success"
657
+ ? this.$t2(
658
+ "导入成功",
659
+ "components.excelImport.importSucess"
660
+ )
661
+ : multiRow.impReturnMsg;
662
+ if (multiRow.impReturnType === "success") {
663
+ successNum++;
664
+ that.successRows.push(data);
665
+ } else {
666
+ failNum++;
667
+ that.failRows.push(data);
668
+ }
669
+ }
670
+
671
+ that.failRows = that.failRows.sort(compareV("impSeq"));
672
+ } else {
673
+ // error_win(resultMsg);
674
+ // layer.close(opts.dialogObjIndex);
675
+ that.$errorMsg(resultMsg);
676
+ that.showContent = false;
677
+ that.clearImportTimer();
678
+ return;
679
+ }
680
+ } else {
681
+ var data = { ...datas[index] };
682
+ data._resultType = resultMsg.type;
683
+ data._resultContent
684
+ = resultMsg.type === "success"
685
+ ? this.$t2(
686
+ "导入成功",
687
+ "components.excelImport.importSucess"
688
+ )
689
+ : this.handleRes(resultMsg.content);
690
+ data._rqeData = { ...datas[index] };
691
+ data._resultData = resultMsg.objx;
692
+ if (resultMsg.type === "success") {
693
+ successNum++;
694
+ that.successRows.push(data);
695
+ } else {
696
+ failNum++;
697
+ that.failRows.push(data);
698
+ }
699
+ }
700
+ if (that.showContent) {
701
+ prevHandleData(percentageStr, excNum);
702
+ }
703
+ },
704
+ })
705
+ .catch(function (et) {
706
+ that.isEnd = true;
707
+ that.clearImportTimer();
708
+ console.error(et);
709
+ });
710
+ }
711
+ };
712
+ handleData();
713
+ },
714
+ commonLocalDownload() {
715
+ if (this.option.importAttachCode) {
716
+ this.commonLocalDownload2();
717
+ return;
718
+ }
719
+ let path = this.option.excel;
720
+ let prefix = this.option.prefix;
721
+ prefix = prefix || "";
722
+ var url = configUtil.baseUrl + prefix + "/sf_common/download";
723
+ if (path) {
724
+ var params = {
725
+ url: path,
726
+ };
727
+ params["access_token"] = configUtil.getToken();
728
+
729
+ var form = document.createElement("form");
730
+
731
+ let randomNum
732
+ = new Date().valueOf() + Math.floor(Math.random() * 1000000);
733
+ let formId = "formId-" + randomNum;
734
+ let formName = "formName-" + randomNum;
735
+
736
+ form.id = formId;
737
+ form.name = formName;
738
+ form.target = "_blank";
739
+ document.body.appendChild(form);
740
+ for (let obj in params) {
741
+ if (params.hasOwnProperty(obj)) {
742
+ let input = document.createElement("input");
743
+ input.tpye = "hidden";
744
+ input.name = obj;
745
+ input.value = params[obj];
746
+ form.appendChild(input);
747
+ }
748
+ }
749
+ form.method = "post"; //请求方式
750
+ form.action = url;
751
+ form.submit();
752
+ document.body.removeChild(form);
753
+ }
754
+ },
755
+ commonLocalDownload2() {
756
+ let importAttachCode = this.option.importAttachCode;
757
+ if (!importAttachCode) return;
758
+ this.$http({
759
+ url: USER_PREFIX + "/bd_attach_setting/getByCode",
760
+ method: "post",
761
+ data: {
762
+ stringOne: importAttachCode,
763
+ },
764
+ success: (res) => {
765
+ let fileObj = res.objx;
766
+ let url = fileObj?.url;
767
+ if (fileObj && url) {
768
+ this.$commonFileUtil.downloadFile(url, fileObj.name);
769
+ }
770
+ },
771
+ });
772
+ },
773
+ vailData(data, opts) {
774
+ var oriCols = opts.data.oriCols;
775
+ var errorInfo = [];
776
+ for (let i = 0; i < oriCols.length; i++) {
777
+ let oriCol = oriCols[i];
778
+ if (oriCol.isNeed) {
779
+ let value = data[oriCol.field];
780
+ if (value === null || value === "") {
781
+ errorInfo.push(
782
+ this.$t2(
783
+ "[" + oriCol.title + "]不能为空;",
784
+ "components.excelImport.warmMsg4",
785
+ { title: oriCol.title }
786
+ )
787
+ );
788
+ }
789
+ }
790
+ }
791
+ return errorInfo.join("");
792
+ },
793
+ handleRes(val) {
794
+ /* var content = val;
795
+ var text = content;
796
+ if (content && content.indexOf("Exception") >= 0) {
797
+ var index0 = content.lastIndexOf("*]");
798
+ if (index0 >= 0) {
799
+ text = content.substr(index0);
800
+ if (text) {
801
+ var index1 = text.indexOf("Exception:");
802
+ if (index1 >= 0) {
803
+ text = text.substr(index1 + 10);
804
+ }
805
+ }
806
+ }
807
+ } */
808
+ let text = getErrorMsg(val);
809
+ return text;
810
+ },
811
+ exportToExcel() {
812
+ let str
813
+ = this.resultType === 1
814
+ ? this.$t2("成功", "components.excelImport.success")
815
+ : this.$t2("失败", "components.excelImport.fail");
816
+ let fileName
817
+ = this.$t2("导入结果导出", "components.excelImport.exportFileName")
818
+ + "("
819
+ + str
820
+ + ")";
821
+ let $grid = this.$refs.resGrid;
822
+ let columns = $grid.getColumns();
823
+ if (columns && columns.length) {
824
+ let fields = columns
825
+ .filter((item, index) => {
826
+ return index > 0 && item.property;
827
+ })
828
+ .map((item, index) => {
829
+ return item.property;
830
+ });
831
+ this.$refs.resGrid.exportData({
832
+ filename: fileName,
833
+ mode: "all",
834
+ type: "csv",
835
+ columns: fields,
836
+ });
837
+ }
838
+ },
839
+ createImportTimer() {
840
+ this.excTime = 0;
841
+ let beginTime = new Date().getTime();
842
+ this.importTimer = setInterval(() => {
843
+ let nowTime = new Date().getTime();
844
+ let diffTime = (nowTime - beginTime) / 1000;
845
+ this.$set(this, "excTime", this.$baseLodash.round(diffTime, 2));
846
+ }, 100);
847
+ },
848
+ clearImportTimer() {
849
+ if (this.importTimer) clearInterval(this.importTimer);
850
+ this.importTimer = null;
851
+ this.loadingObj && this.loadingObj.close();
852
+ this.loadingObj = null;
853
+ },
854
+ async dialogPrimary3() {
855
+ if (!this.fileRaw) {
856
+ this.$baseAlert(
857
+ this.$t2("请上传附件", "components.excelImport.warmMsg1")
858
+ );
859
+ return false;
860
+ }
861
+ let that = this;
862
+ let option = this.option;
863
+ let done = () => {
864
+ that.showImportDialog = false;
865
+ };
866
+ if (!option.excel) {
867
+ if (
868
+ option.callback
869
+ && option.callback(null, this.fileRaw, done) !== false
870
+ ) {
871
+ that.showImportDialog = false;
872
+ }
873
+ return;
874
+ }
875
+ this.loadingObj = this.$baseLoading({
876
+ target: document.body,
877
+ background: "unset",
878
+ });
879
+ this.readExcel(this.fileRaw, function (resultData) {
880
+ try {
881
+ if (
882
+ option.callback
883
+ && option.callback(resultData, that.fileRaw, done) !== false
884
+ ) {
885
+ that.showImportDialog = false;
886
+ }
887
+ } catch (et) {
888
+ console.error(et);
889
+ }
890
+ setTimeout(function () {
891
+ that.loadingObj && that.loadingObj.close();
892
+ that.loadingObj = null;
893
+ }, 200);
894
+ });
895
+ },
896
+ },
897
+ };
898
+ export const mixins = tmixins;