cloud-web-corejs 1.0.163 → 1.0.164
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/package.json +2 -1
- package/src/components/vb-tabs/x-tabs.vue +30 -13
- package/src/components/xform/form-designer/designer.js +1 -1
- package/src/components/xform/form-designer/form-widget/components/gantt/index.vue +419 -0
- package/src/components/xform/form-designer/form-widget/container-widget/data-table-mixin.js +1 -1
- package/src/components/xform/form-designer/form-widget/dialog/baseFormulaDialog copy.vue +971 -0
- package/src/components/xform/form-designer/form-widget/dialog/baseFormulaDialog.vue +971 -0
- package/src/components/xform/form-designer/form-widget/dialog/formDialog.vue +71 -50
- package/src/components/xform/form-designer/form-widget/dialog/formulaDialog.vue +799 -0
- package/src/components/xform/form-designer/form-widget/dialog/importDialogMixin - /345/211/257/346/234/254.js" +1639 -0
- package/src/components/xform/form-designer/form-widget/dialog/searchFormDialog.vue +102 -73
- package/src/components/xform/form-designer/form-widget/field-widget/cascader-widget.vue +19 -1
- package/src/components/xform/form-designer/form-widget/field-widget/census-widget.vue +41 -27
- package/src/components/xform/form-designer/form-widget/field-widget/checkbox-widget.vue +4 -1
- package/src/components/xform/form-designer/form-widget/field-widget/color-widget.vue +4 -1
- package/src/components/xform/form-designer/form-widget/field-widget/date-range-widget.vue +13 -2
- package/src/components/xform/form-designer/form-widget/field-widget/date-widget.vue +9 -2
- package/src/components/xform/form-designer/form-widget/field-widget/download-button-widget.vue +133 -0
- package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +2 -1
- package/src/components/xform/form-designer/form-widget/field-widget/gantt-widget.vue +962 -0
- package/src/components/xform/form-designer/form-widget/field-widget/input-widget.vue +7 -2
- package/src/components/xform/form-designer/form-widget/field-widget/multiSearch-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/number-widget.vue +7 -0
- package/src/components/xform/form-designer/form-widget/field-widget/oplog-widget.vue +1 -0
- package/src/components/xform/form-designer/form-widget/field-widget/print-button-widget.vue +44 -27
- package/src/components/xform/form-designer/form-widget/field-widget/print-detail-button-widget.vue +19 -11
- package/src/components/xform/form-designer/form-widget/field-widget/project-tag-widget.vue +19 -1
- package/src/components/xform/form-designer/form-widget/field-widget/radio-widget.vue +11 -7
- package/src/components/xform/form-designer/form-widget/field-widget/select-widget.vue +11 -8
- package/src/components/xform/form-designer/form-widget/field-widget/singerSearch-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/table-export-button-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/vabSearch-widget.vue +1 -1
- package/src/components/xform/form-designer/setting-panel/form-setting.vue +106 -76
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/data-table-editor.vue +13 -263
- package/src/components/xform/form-designer/setting-panel/property-editor/container-data-table/table-column-dialog.vue +47 -81
- package/src/components/xform/form-designer/setting-panel/property-editor/downloadButtonFlag-editor.vue +32 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/event-handler/onClick-editor.vue +14 -7
- package/src/components/xform/form-designer/setting-panel/property-editor/field-gantt/gantt-editor.vue +36 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-print-button/print-button-editor.vue +37 -16
- package/src/components/xform/form-designer/setting-panel/property-editor/field-print-button/print-detail-button-editor.vue +42 -18
- package/src/components/xform/form-designer/setting-panel/property-editor/field-vabUpload/field-vabUpload-editor.vue +2 -2
- package/src/components/xform/form-designer/setting-panel/property-editor/formScriptEnabled-editor.vue +57 -34
- package/src/components/xform/form-designer/setting-panel/property-editor/project-tag-editor.vue +84 -53
- package/src/components/xform/form-designer/setting-panel/property-editor/wfFlag-editor.vue +35 -44
- package/src/components/xform/form-designer/setting-panel/propertyRegister.js +2 -0
- package/src/components/xform/form-designer/widget-panel/widgetsConfig.js +68 -3
- package/src/components/xform/form-render/container-item/containerItemMixin.js +2 -2
- package/src/components/xform/form-render/container-item/data-table-mixin.js +1 -1
- package/src/components/xform/form-render/container-item/tab-item.vue +64 -32
- package/src/components/xform/form-render/index.vue +69 -23
- package/src/components/xform/form-render/indexMixin.js +18 -17
- package/src/components/xform/lang/zh-CN.js +8 -2
- package/src/components/xform/utils/formula-util.js +306 -5
- package/src/components/xform/utils/util.js +1 -1
- package/src/components/xform/utils/vue2js-generator.js +2 -2
- package/src/utils/request.js +1 -1
- package/src/utils/vab.js +1 -1
- package/src/views/user/form/vform/render.vue +54 -36
- package/src/views/user/form/view/list.vue +103 -10
- package/src/views/user/menu/list.vue +24 -1
- package/src/views/user/role/authConfig.vue +89 -0
- package/src/views/user/role/dialog.vue +70 -48
- package/src/views/user/role/edit.vue +114 -4
|
@@ -0,0 +1,1639 @@
|
|
|
1
|
+
/**version-1.0*/
|
|
2
|
+
import { read, utils } from "xlsx";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import SparkMD5 from "spark-md5";
|
|
5
|
+
|
|
6
|
+
let tmixins = {};
|
|
7
|
+
var XLSX = window.XLSX || { read, utils };
|
|
8
|
+
import { getToken } from "../../../../../utils/auth";
|
|
9
|
+
import XEUtils from "xe-utils";
|
|
10
|
+
import { getErrorMsg } from "@base/utils/index.js";
|
|
11
|
+
|
|
12
|
+
let configUtil = {
|
|
13
|
+
baseUrl: process.env.VUE_APP_BASE_API,
|
|
14
|
+
XLSX,
|
|
15
|
+
getToken,
|
|
16
|
+
};
|
|
17
|
+
let importTimer = null;
|
|
18
|
+
let loadingObj = null;
|
|
19
|
+
tmixins = {
|
|
20
|
+
name: "excelImport",
|
|
21
|
+
props: ["param", "parentTarget"],
|
|
22
|
+
inject: ["getReportTemplate", "formHttp"],
|
|
23
|
+
data() {
|
|
24
|
+
return {
|
|
25
|
+
excTime: 0,
|
|
26
|
+
showImportDialog: false,
|
|
27
|
+
showImportDialog2: false,
|
|
28
|
+
falseValue: false,
|
|
29
|
+
fileRaw: false,
|
|
30
|
+
isEnd: false,
|
|
31
|
+
currentIndex: 0,
|
|
32
|
+
excelTemplate: "",
|
|
33
|
+
prefix: "/user",
|
|
34
|
+
dataSize: 0,
|
|
35
|
+
totalSuccessNum: 0,
|
|
36
|
+
totalErrorNum: 0,
|
|
37
|
+
percentageNum: 0,
|
|
38
|
+
successRows: [],
|
|
39
|
+
failRows: [],
|
|
40
|
+
oriCols: [],
|
|
41
|
+
showImportResult: false,
|
|
42
|
+
resultType: "",
|
|
43
|
+
option: {},
|
|
44
|
+
showContent: false,
|
|
45
|
+
resOption: {},
|
|
46
|
+
fileCellFields: [],
|
|
47
|
+
importLoading: false,
|
|
48
|
+
loadingTitle: null,
|
|
49
|
+
|
|
50
|
+
percent1: 0,
|
|
51
|
+
percent2: 0,
|
|
52
|
+
percent3: 0,
|
|
53
|
+
|
|
54
|
+
loadingPercent: 0,
|
|
55
|
+
handleRowSize: 1,
|
|
56
|
+
|
|
57
|
+
headerRows: 3,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
computed: {
|
|
61
|
+
importFileLimitSize() {
|
|
62
|
+
return Math.min(
|
|
63
|
+
this.param?.importOption?.importFileLimitSize || 200,
|
|
64
|
+
200
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
created() {
|
|
69
|
+
this.exc();
|
|
70
|
+
},
|
|
71
|
+
beforeDestroy() {
|
|
72
|
+
this.clearImportTimer();
|
|
73
|
+
},
|
|
74
|
+
methods: {
|
|
75
|
+
initResGird() {
|
|
76
|
+
var that = this;
|
|
77
|
+
let tableRef = "resGrid";
|
|
78
|
+
let columns = [
|
|
79
|
+
{
|
|
80
|
+
type: "checkbox",
|
|
81
|
+
fixed: "left",
|
|
82
|
+
width: 48,
|
|
83
|
+
resizable: false,
|
|
84
|
+
headerClassName: "vxe-hcs",
|
|
85
|
+
className: "vxe-hcs",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
field: "impNumber",
|
|
89
|
+
title: this.$t2("行号", "components.excelImport.impNumber"),
|
|
90
|
+
width: 100,
|
|
91
|
+
fixed: "left",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
field: "_resultContent",
|
|
95
|
+
title: this.$t2("结果", "components.excelImport.resultContent"),
|
|
96
|
+
width: 250,
|
|
97
|
+
fixed: "left",
|
|
98
|
+
slots: {
|
|
99
|
+
default: ({ row, $rowIndex, $table }) => {
|
|
100
|
+
return that.handleRes(row._resultContent);
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
let cCols = this.oriCols.map((oriCol, index) => {
|
|
106
|
+
let col = {
|
|
107
|
+
field: oriCol.field,
|
|
108
|
+
title: oriCol.title,
|
|
109
|
+
width: 150,
|
|
110
|
+
...oriCol.otherConfig,
|
|
111
|
+
};
|
|
112
|
+
if (index == 0) {
|
|
113
|
+
col.fixed = "left";
|
|
114
|
+
}
|
|
115
|
+
return col;
|
|
116
|
+
});
|
|
117
|
+
columns = columns.concat(cCols);
|
|
118
|
+
|
|
119
|
+
let tableOption = {
|
|
120
|
+
vue: this,
|
|
121
|
+
tableRef: tableRef,
|
|
122
|
+
tableNameRequired: false,
|
|
123
|
+
columns: columns,
|
|
124
|
+
config: {
|
|
125
|
+
toolbarConfig: {
|
|
126
|
+
custom: false,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
|
|
132
|
+
this.resOption = opts;
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
exc() {
|
|
136
|
+
this.option = this.param;
|
|
137
|
+
this.showContent = true;
|
|
138
|
+
this.showImportDialog = true;
|
|
139
|
+
this.showImportDialog2 = false;
|
|
140
|
+
},
|
|
141
|
+
showSuccessResult() {
|
|
142
|
+
this.showImportResult = true;
|
|
143
|
+
this.resultType = 1;
|
|
144
|
+
this.$nextTick(() => {
|
|
145
|
+
this.initResGird();
|
|
146
|
+
this.$nextTick(() => {
|
|
147
|
+
let tDatas = this.successRows.map((item, index) => {
|
|
148
|
+
item.id = index;
|
|
149
|
+
return item;
|
|
150
|
+
});
|
|
151
|
+
this.$refs.resGrid.loadData(tDatas);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
showErrorResult() {
|
|
156
|
+
this.showImportResult = true;
|
|
157
|
+
this.resultType = 0;
|
|
158
|
+
this.$nextTick(() => {
|
|
159
|
+
this.initResGird();
|
|
160
|
+
this.$nextTick(() => {
|
|
161
|
+
let tDatas = this.failRows.map((item, index) => {
|
|
162
|
+
item.id = index;
|
|
163
|
+
return item;
|
|
164
|
+
});
|
|
165
|
+
this.$refs.resGrid.loadData(tDatas);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
fileChange(file) {
|
|
170
|
+
if (file) {
|
|
171
|
+
this.fileRaw = file.raw;
|
|
172
|
+
} else {
|
|
173
|
+
this.fileRaw = false;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
dialogClose1() {
|
|
177
|
+
this.importLoading = false;
|
|
178
|
+
if (!this.showImportDialog2) {
|
|
179
|
+
this.$emit("update:visiable", false);
|
|
180
|
+
this.showContent = false;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
async dialogPrimary1() {
|
|
184
|
+
let that = this;
|
|
185
|
+
let option = this.option;
|
|
186
|
+
|
|
187
|
+
let fileRaw = this.fileRaw;
|
|
188
|
+
if (!fileRaw) {
|
|
189
|
+
this.$baseAlert(
|
|
190
|
+
this.$t2("请上传附件", "components.excelImport.warmMsg1")
|
|
191
|
+
);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
let importFileLimitSize = this.importFileLimitSize;
|
|
195
|
+
let fileSize = fileRaw.size;
|
|
196
|
+
let limitSize = importFileLimitSize * 1024 * 1024;
|
|
197
|
+
if (fileSize > limitSize) {
|
|
198
|
+
this.$baseAlert(
|
|
199
|
+
this.$t1("导入文件不允许超过{fileSize}MB", {
|
|
200
|
+
fileSize: importFileLimitSize,
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (option.importFrontOnly) {
|
|
207
|
+
this.dialogPrimary3();
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.createImportTimer();
|
|
212
|
+
this.showImportDialog = false;
|
|
213
|
+
if (!option.onConfirm) {
|
|
214
|
+
this.showImportDialog2 = true;
|
|
215
|
+
}
|
|
216
|
+
this.$nextTick(() => {
|
|
217
|
+
try {
|
|
218
|
+
this.readExcel(this.fileRaw, function (resultData) {
|
|
219
|
+
if (option.onConfirm) {
|
|
220
|
+
option.onConfirm(resultData.data, that.fileRaw);
|
|
221
|
+
} else {
|
|
222
|
+
that.handleBeforeImport0(that.fileRaw, resultData, () => {
|
|
223
|
+
that.syncDataForImport({
|
|
224
|
+
multi: false,
|
|
225
|
+
data: resultData,
|
|
226
|
+
// saveUrl: saveUrl
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
} catch (et) {
|
|
232
|
+
that.clearImportTimer();
|
|
233
|
+
console.error(et);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
handleBeforeImport(file, resultData, callback) {
|
|
238
|
+
let importOption = this.option.importOption;
|
|
239
|
+
let that = this;
|
|
240
|
+
if (importOption.onBeforeImport) {
|
|
241
|
+
const toDo = (res) => {
|
|
242
|
+
let rows = res?.objx || [];
|
|
243
|
+
rows.forEach((row, rowIndex) => {
|
|
244
|
+
let item = resultData[rowIndex];
|
|
245
|
+
Object.keys(row).forEach((key) => {
|
|
246
|
+
item[key] = row[key];
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
callback && callback();
|
|
250
|
+
};
|
|
251
|
+
this.getFieldTarget().handleCustomEvent(
|
|
252
|
+
importOption.onBeforeImport,
|
|
253
|
+
["file", "resultData", "done"],
|
|
254
|
+
[file, resultData, toDo]
|
|
255
|
+
);
|
|
256
|
+
} else {
|
|
257
|
+
callback && callback();
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
handleBeforeImport0(file, resultData, callback) {
|
|
261
|
+
if (!this.showImportDialog2) return;
|
|
262
|
+
let importOption = this.option.importOption;
|
|
263
|
+
if (!importOption.enabledImportPreHandle) {
|
|
264
|
+
this.handleBeforeImport(file, resultData, () => {
|
|
265
|
+
callback && callback();
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
this.uploadFile(() => {
|
|
271
|
+
this.importLoading = false;
|
|
272
|
+
this.handleBeforeImport(file, resultData, () => {
|
|
273
|
+
callback && callback();
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
},
|
|
278
|
+
handleBeforeClose(hide) {
|
|
279
|
+
this.option.onCancel &&
|
|
280
|
+
this.option.onCancel(this.getCallbackData(), this.fileRaw);
|
|
281
|
+
let importOption = this.option.importOption;
|
|
282
|
+
this.getFieldTarget().handleCustomEvent(
|
|
283
|
+
importOption.onSuccessImport,
|
|
284
|
+
["resultData", "file"],
|
|
285
|
+
[this.getCallbackData(), this.fileRaw]
|
|
286
|
+
);
|
|
287
|
+
this.handleTableCallback();
|
|
288
|
+
hide();
|
|
289
|
+
},
|
|
290
|
+
dialogClose2() {
|
|
291
|
+
this.showImportDialog2 = false;
|
|
292
|
+
this.option.onBeforeCancel &&
|
|
293
|
+
this.option.onBeforeCancel(this.getCallbackData(), this.fileRaw);
|
|
294
|
+
let importOption = this.option.importOption;
|
|
295
|
+
this.getFieldTarget().handleCustomEvent(
|
|
296
|
+
importOption.onSuccessImport,
|
|
297
|
+
["resultData", "file"],
|
|
298
|
+
[this.getCallbackData(), this.fileRaw]
|
|
299
|
+
);
|
|
300
|
+
this.handleTableCallback();
|
|
301
|
+
},
|
|
302
|
+
handleClose2() {
|
|
303
|
+
this.clearImportTimer();
|
|
304
|
+
this.showImportDialog2 = false;
|
|
305
|
+
this.showContent = false;
|
|
306
|
+
this.option.onClose &&
|
|
307
|
+
this.option.onClose(this.getCallbackData(), this.fileRaw);
|
|
308
|
+
this.option.callback &&
|
|
309
|
+
this.option.callback(this.getCallbackData(), this.fileRaw);
|
|
310
|
+
this.dialogClose1();
|
|
311
|
+
},
|
|
312
|
+
dialogPrimary2() {
|
|
313
|
+
let importOption = this.option.importOption;
|
|
314
|
+
this.showImportDialog2 = false;
|
|
315
|
+
this.option.onBeforeConfirm &&
|
|
316
|
+
this.option.onBeforeConfirm(this.getCallbackData(), this.fileRaw);
|
|
317
|
+
this.getFieldTarget().handleCustomEvent(
|
|
318
|
+
importOption.onSuccessImport,
|
|
319
|
+
["resultData", "file"],
|
|
320
|
+
[this.getCallbackData(), this.fileRaw]
|
|
321
|
+
);
|
|
322
|
+
this.handleTableCallback();
|
|
323
|
+
},
|
|
324
|
+
getCallbackData() {
|
|
325
|
+
return {
|
|
326
|
+
...this.resultData,
|
|
327
|
+
successRows: this.successRows,
|
|
328
|
+
failRows: this.failRows,
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
/*dialogClose2(flag) {
|
|
333
|
+
let importOption = this.option.importOption;
|
|
334
|
+
this.clearImportTimer();
|
|
335
|
+
this.showImportDialog2 = false;
|
|
336
|
+
this.dialogClose1();
|
|
337
|
+
this.handleTableCallback(flag);
|
|
338
|
+
this.parentTarget.handleCustomEvent(importOption.onSuccessImport, ['resultData', 'file'], [this.resultData, this.fileRaw])
|
|
339
|
+
this.option.callback && this.option.callback(this.resultData, this.fileRaw);
|
|
340
|
+
},
|
|
341
|
+
dialogPrimary2() {
|
|
342
|
+
let importOption = this.option.importOption;
|
|
343
|
+
this.clearImportTimer();
|
|
344
|
+
this.showImportDialog2 = false;
|
|
345
|
+
this.dialogClose1()
|
|
346
|
+
this.handleTableCallback();
|
|
347
|
+
let fileRaw = this.fileRaw;
|
|
348
|
+
this.parentTarget.handleCustomEvent(importOption.onSuccessImport, ['resultData', 'file'], [this.resultData, this.fileRaw])
|
|
349
|
+
this.option.callback && this.option.callback(this.resultData, this.fileRaw);
|
|
350
|
+
},*/
|
|
351
|
+
handleTableCallback(flag) {
|
|
352
|
+
if (flag === 0) return;
|
|
353
|
+
let importOption = this.option.importOption;
|
|
354
|
+
let tableTarget;
|
|
355
|
+
if (importOption.tableRef)
|
|
356
|
+
tableTarget = this.getFieldTarget().getWidgetRef(importOption.tableRef);
|
|
357
|
+
if (tableTarget) {
|
|
358
|
+
let isQueryTable = tableTarget.widget.options.isQueryTable;
|
|
359
|
+
if (isQueryTable) {
|
|
360
|
+
tableTarget.searchEvent();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
async readExcel(file, callback) {
|
|
365
|
+
let that = this;
|
|
366
|
+
let option = this.option;
|
|
367
|
+
|
|
368
|
+
const fileReader = new FileReader();
|
|
369
|
+
fileReader.onload = async (ev) => {
|
|
370
|
+
var resultData;
|
|
371
|
+
try {
|
|
372
|
+
const data = ev.target.result;
|
|
373
|
+
const workbook = configUtil.XLSX.read(data, {
|
|
374
|
+
type: "binary",
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
var sheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
378
|
+
if (sheet["!ref"] == undefined) {
|
|
379
|
+
/*that.showImportDialog2 = false;
|
|
380
|
+
that.showContent = false;
|
|
381
|
+
that.clearImportTimer();*/
|
|
382
|
+
that.$baseAlert(
|
|
383
|
+
this.$t2(
|
|
384
|
+
"请使用正确的导入模版!",
|
|
385
|
+
"components.excelImport.warmMsg2"
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
that.handleClose2();
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
var range = configUtil.XLSX.utils.decode_range(sheet["!ref"]);
|
|
392
|
+
var dataSize = range.e.r + 1; //行数
|
|
393
|
+
that.dataSize = dataSize - 3 >= 0 ? dataSize - 3 : 0;
|
|
394
|
+
var titles = [];
|
|
395
|
+
var fields = [];
|
|
396
|
+
|
|
397
|
+
const ws = workbook.Sheets[sheet];
|
|
398
|
+
|
|
399
|
+
let prefix = option.prefix;
|
|
400
|
+
let excelUrl = option.excel;
|
|
401
|
+
|
|
402
|
+
var excelRows = [];
|
|
403
|
+
var row;
|
|
404
|
+
var rowNum;
|
|
405
|
+
var colNum;
|
|
406
|
+
for (rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
|
|
407
|
+
row = [];
|
|
408
|
+
for (colNum = range.s.c; colNum <= range.e.c; colNum++) {
|
|
409
|
+
var nextCell =
|
|
410
|
+
sheet[
|
|
411
|
+
configUtil.XLSX.utils.encode_cell({
|
|
412
|
+
r: rowNum,
|
|
413
|
+
c: colNum,
|
|
414
|
+
})
|
|
415
|
+
];
|
|
416
|
+
if (typeof nextCell === "undefined") {
|
|
417
|
+
row.push(void 0);
|
|
418
|
+
} else {
|
|
419
|
+
row.push(nextCell.w.trim());
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (rowNum == 1) {
|
|
423
|
+
titles = row;
|
|
424
|
+
}
|
|
425
|
+
if (rowNum == 2) {
|
|
426
|
+
fields = row;
|
|
427
|
+
let checkResult = true;
|
|
428
|
+
/*await that.checkExcelForImport(titles, fields, excelUrl, prefix).then(
|
|
429
|
+
res => {
|
|
430
|
+
if (res.type != "success") {
|
|
431
|
+
checkResult = false;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
if (!checkResult) {
|
|
435
|
+
that.showContent = false;
|
|
436
|
+
that.clearImportTimer();
|
|
437
|
+
return false;
|
|
438
|
+
}*/
|
|
439
|
+
}
|
|
440
|
+
if (rowNum > 2) {
|
|
441
|
+
let item = {};
|
|
442
|
+
for (let i = 0; i < fields.length; i++) {
|
|
443
|
+
let field = fields[i];
|
|
444
|
+
if (field) {
|
|
445
|
+
item[field] = row[i] ?? null;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
excelRows.push(item);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (
|
|
452
|
+
!titles.length ||
|
|
453
|
+
!fields.length ||
|
|
454
|
+
titles.length != fields.length
|
|
455
|
+
) {
|
|
456
|
+
// that.showContent = false;
|
|
457
|
+
// that.clearImportTimer();
|
|
458
|
+
that.$baseAlert(
|
|
459
|
+
this.$t2(
|
|
460
|
+
"请使用正确的导入模版!",
|
|
461
|
+
"components.excelImport.warmMsg2"
|
|
462
|
+
)
|
|
463
|
+
);
|
|
464
|
+
that.handleClose2();
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
var columns = [];
|
|
469
|
+
var cols = [];
|
|
470
|
+
let uniqueFields = [];
|
|
471
|
+
for (let i = 0; i < titles.length; i++) {
|
|
472
|
+
let title = titles[i];
|
|
473
|
+
if (title) {
|
|
474
|
+
let field = fields[i];
|
|
475
|
+
if (field == null) {
|
|
476
|
+
// that.showContent = false;
|
|
477
|
+
// that.clearImportTimer();
|
|
478
|
+
that.$baseAlert(
|
|
479
|
+
this.$t2(
|
|
480
|
+
"请使用正确的导入模版!",
|
|
481
|
+
"components.excelImport.warmMsg2"
|
|
482
|
+
)
|
|
483
|
+
);
|
|
484
|
+
that.handleClose2();
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
let t = title.substr(-1);
|
|
488
|
+
let u = title.length >= 2 ? title.substr(-2) : title;
|
|
489
|
+
let isNeed = false;
|
|
490
|
+
if (t === "*") {
|
|
491
|
+
isNeed = true;
|
|
492
|
+
}
|
|
493
|
+
let isUnique = false;
|
|
494
|
+
if (u === "**") {
|
|
495
|
+
uniqueFields.push(field);
|
|
496
|
+
isUnique = true;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
let otherConfig = {};
|
|
500
|
+
let isFile = false;
|
|
501
|
+
if (field.startsWith("attachments_")) {
|
|
502
|
+
that.fileCellFields.push(field);
|
|
503
|
+
isFile = true;
|
|
504
|
+
otherConfig = {
|
|
505
|
+
slots: {
|
|
506
|
+
default: "attachment",
|
|
507
|
+
},
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
let col = {
|
|
512
|
+
field: field,
|
|
513
|
+
title: title,
|
|
514
|
+
width: 100,
|
|
515
|
+
isNeed: isNeed,
|
|
516
|
+
isUnique: isUnique,
|
|
517
|
+
isFile,
|
|
518
|
+
otherConfig,
|
|
519
|
+
};
|
|
520
|
+
cols.push(col);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
var oriCols = JSON.parse(JSON.stringify(cols)); //列信息
|
|
525
|
+
if (uniqueFields.length) {
|
|
526
|
+
//分组唯一字段为空时,全部不发包。
|
|
527
|
+
for (let i = 0; i < oriCols.length; i++) {
|
|
528
|
+
let oriCol = oriCols[i];
|
|
529
|
+
if (oriCol.isNeed) {
|
|
530
|
+
for (let j = 0; j < excelRows.length; j++) {
|
|
531
|
+
let data = excelRows[j];
|
|
532
|
+
let value = data[oriCol.field];
|
|
533
|
+
if (value == null || value == "") {
|
|
534
|
+
that.clearImportTimer();
|
|
535
|
+
that.$baseAlert(
|
|
536
|
+
this.$t2(
|
|
537
|
+
"第" + (j + 4) + "行[" + oriCol.title + "]不能为空;",
|
|
538
|
+
"components.excelImport.warmMsg3",
|
|
539
|
+
{
|
|
540
|
+
lineNo: j + 4,
|
|
541
|
+
title: oriCol.title,
|
|
542
|
+
}
|
|
543
|
+
)
|
|
544
|
+
);
|
|
545
|
+
that.handleClose2();
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
this.oriCols = oriCols;
|
|
554
|
+
|
|
555
|
+
resultData = {
|
|
556
|
+
data: excelRows,
|
|
557
|
+
titles: titles,
|
|
558
|
+
fields: fields,
|
|
559
|
+
uniqueFields: uniqueFields,
|
|
560
|
+
oriCols: oriCols,
|
|
561
|
+
};
|
|
562
|
+
this.resultData = resultData;
|
|
563
|
+
callback(resultData);
|
|
564
|
+
} catch (et) {
|
|
565
|
+
that.showContent = false;
|
|
566
|
+
that.clearImportTimer();
|
|
567
|
+
console.error(et);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
fileReader.readAsBinaryString(file);
|
|
571
|
+
},
|
|
572
|
+
async checkExcelForImport(titles, fields, turl, prefix) {
|
|
573
|
+
if (!this.showImportDialog2) return;
|
|
574
|
+
let that = this;
|
|
575
|
+
var data = {
|
|
576
|
+
filed_name: fields,
|
|
577
|
+
field_note: titles,
|
|
578
|
+
url: turl,
|
|
579
|
+
};
|
|
580
|
+
var param = JSON.stringify(data);
|
|
581
|
+
return this.$http({
|
|
582
|
+
url: prefix + "/sf_common/compareExcelFields",
|
|
583
|
+
method: "post",
|
|
584
|
+
headers: {
|
|
585
|
+
"Content-Type": "application/json;charset=utf-8",
|
|
586
|
+
},
|
|
587
|
+
// data: param,
|
|
588
|
+
data: data,
|
|
589
|
+
});
|
|
590
|
+
},
|
|
591
|
+
saveImportHandle(data, opt) {
|
|
592
|
+
var multi = this.option.multi;
|
|
593
|
+
let importOption = this.option.importOption;
|
|
594
|
+
|
|
595
|
+
let entity = importOption.importEntity;
|
|
596
|
+
|
|
597
|
+
if (!entity) return;
|
|
598
|
+
|
|
599
|
+
let reportTemplate = this.getReportTemplate();
|
|
600
|
+
let formCode = reportTemplate?.formCode;
|
|
601
|
+
let scriptCode = importOption.importScriptCode || "import";
|
|
602
|
+
// let config = option?.config;
|
|
603
|
+
|
|
604
|
+
// let reqData = this.getReqFormData();
|
|
605
|
+
let fileCellFields = this.fileCellFields;
|
|
606
|
+
let formData = null;
|
|
607
|
+
if (multi) {
|
|
608
|
+
formData = data;
|
|
609
|
+
} else {
|
|
610
|
+
formData = {
|
|
611
|
+
[entity]: { ...data },
|
|
612
|
+
};
|
|
613
|
+
if (fileCellFields.length) {
|
|
614
|
+
fileCellFields.forEach((field) => {
|
|
615
|
+
let attachments = data[field] || [];
|
|
616
|
+
delete formData[entity][field];
|
|
617
|
+
formData[field] = attachments;
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
let reqData = {
|
|
623
|
+
formCode: formCode,
|
|
624
|
+
formVersion: reportTemplate.formVersion,
|
|
625
|
+
taBm: entity,
|
|
626
|
+
data: formData,
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
this.formHttp({
|
|
630
|
+
scriptCode: scriptCode,
|
|
631
|
+
data: reqData,
|
|
632
|
+
modal: false,
|
|
633
|
+
...opt,
|
|
634
|
+
});
|
|
635
|
+
},
|
|
636
|
+
syncDataForImport(opts) {
|
|
637
|
+
let that = this;
|
|
638
|
+
var multi = this.option.multi;
|
|
639
|
+
var resultData = this.resultData;
|
|
640
|
+
var datas = resultData.data;
|
|
641
|
+
var titles = resultData.titles;
|
|
642
|
+
var fields = resultData.fields;
|
|
643
|
+
let uniqueFields = resultData.uniqueFields;
|
|
644
|
+
var saveUrl = opts.saveUrl;
|
|
645
|
+
var size = datas.length;
|
|
646
|
+
var index = 0;
|
|
647
|
+
var successNum = 0;
|
|
648
|
+
var failNum = 0;
|
|
649
|
+
var dialogObj = this.$refs.importDialog.$el;
|
|
650
|
+
var successNumObj = dialogObj.querySelector(".successNum");
|
|
651
|
+
var failNumObj = dialogObj.querySelector(".failNum");
|
|
652
|
+
var percentageObj = dialogObj.querySelector(".percentage");
|
|
653
|
+
var doneNumObj = dialogObj.querySelector(".doneNum");
|
|
654
|
+
dialogObj.querySelector(".dataSize").innerText = size;
|
|
655
|
+
|
|
656
|
+
that.successRows = [];
|
|
657
|
+
that.failRows = [];
|
|
658
|
+
|
|
659
|
+
var multiSize = opts.multiSize || 2;
|
|
660
|
+
|
|
661
|
+
let groupIndex = 0;
|
|
662
|
+
let groupDatas = [];
|
|
663
|
+
if (uniqueFields.length) {
|
|
664
|
+
let d = XEUtils.groupBy(datas, function (item, itemIndex, items) {
|
|
665
|
+
let keyArr = [];
|
|
666
|
+
uniqueFields.forEach((field) => {
|
|
667
|
+
keyArr.push(item[field]);
|
|
668
|
+
});
|
|
669
|
+
return keyArr.join("&_&");
|
|
670
|
+
});
|
|
671
|
+
for (let key in d) {
|
|
672
|
+
groupDatas.push(d[key]);
|
|
673
|
+
}
|
|
674
|
+
datas.forEach((item, itemIndex) => {
|
|
675
|
+
item.impSeq = itemIndex;
|
|
676
|
+
item.impNumber = itemIndex + 4;
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
var compareV = function (property) {
|
|
681
|
+
return function (a, b) {
|
|
682
|
+
var value1 = a[property];
|
|
683
|
+
var value2 = b[property];
|
|
684
|
+
return value1 - value2;
|
|
685
|
+
};
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
var prevHandleData = function (percentageStr, excNum) {
|
|
689
|
+
successNumObj.innerText = successNum;
|
|
690
|
+
failNumObj.innerText = failNum;
|
|
691
|
+
doneNumObj.innerText = successNum + failNum;
|
|
692
|
+
that.percentageNum = percentageStr;
|
|
693
|
+
let isEnd = false;
|
|
694
|
+
if (multi && uniqueFields.length) {
|
|
695
|
+
isEnd = groupIndex + 1 >= groupDatas.length;
|
|
696
|
+
} else {
|
|
697
|
+
isEnd = index + excNum >= size;
|
|
698
|
+
}
|
|
699
|
+
if (!isEnd) {
|
|
700
|
+
index = index + excNum;
|
|
701
|
+
groupIndex = groupIndex + 1;
|
|
702
|
+
setTimeout(function () {
|
|
703
|
+
handleData();
|
|
704
|
+
}, 1);
|
|
705
|
+
} else {
|
|
706
|
+
setTimeout(function () {
|
|
707
|
+
that.clearImportTimer();
|
|
708
|
+
}, 300);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
let getDefaultValue = (row) => {
|
|
713
|
+
let value = null;
|
|
714
|
+
let defaultValue = this.option.defaultValue;
|
|
715
|
+
if (defaultValue) {
|
|
716
|
+
if (typeof defaultValue == "function") {
|
|
717
|
+
value = defaultValue(row) || {};
|
|
718
|
+
} else {
|
|
719
|
+
value = defaultValue || {};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return value;
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
let handleData = () => {
|
|
726
|
+
if (!that.isEnd && index < size) {
|
|
727
|
+
var param;
|
|
728
|
+
var excNum;
|
|
729
|
+
if (multi) {
|
|
730
|
+
if (!uniqueFields.length) {
|
|
731
|
+
if (index + multiSize < size) {
|
|
732
|
+
excNum = multiSize;
|
|
733
|
+
} else {
|
|
734
|
+
excNum = size - index;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
let dataList = [];
|
|
738
|
+
for (let i = 0; i < excNum; i++) {
|
|
739
|
+
var mIndex = index + i;
|
|
740
|
+
let mData = datas[mIndex];
|
|
741
|
+
mData.impSeq = mIndex;
|
|
742
|
+
mData.impNumber = mIndex + 4;
|
|
743
|
+
|
|
744
|
+
let errorInfo = that.vailData(mData, opts);
|
|
745
|
+
if (errorInfo.length > 0) {
|
|
746
|
+
mData._resultType = "error";
|
|
747
|
+
mData._resultContent = errorInfo;
|
|
748
|
+
failNum++;
|
|
749
|
+
that.failRows.push(mData);
|
|
750
|
+
} else {
|
|
751
|
+
let defaultValue = getDefaultValue(mData);
|
|
752
|
+
if (defaultValue) {
|
|
753
|
+
Object.assign(mData, defaultValue);
|
|
754
|
+
}
|
|
755
|
+
dataList.push(mData);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
datas[mIndex] = mData;
|
|
759
|
+
}
|
|
760
|
+
if (dataList.length > 0) {
|
|
761
|
+
param = dataList;
|
|
762
|
+
}
|
|
763
|
+
} else {
|
|
764
|
+
excNum = groupDatas[groupIndex].length;
|
|
765
|
+
param = groupDatas[groupIndex];
|
|
766
|
+
}
|
|
767
|
+
} else {
|
|
768
|
+
var data = that.resultData.data[index];
|
|
769
|
+
data.impSeq = index;
|
|
770
|
+
data.impNumber = index + 4;
|
|
771
|
+
excNum = 1;
|
|
772
|
+
datas[index] = data;
|
|
773
|
+
|
|
774
|
+
let errorInfo = that.vailData(data, opts);
|
|
775
|
+
if (errorInfo.length > 0) {
|
|
776
|
+
data._resultType = "error";
|
|
777
|
+
data._resultContent = errorInfo;
|
|
778
|
+
failNum++;
|
|
779
|
+
that.failRows.push(data);
|
|
780
|
+
} else {
|
|
781
|
+
param = data;
|
|
782
|
+
let defaultValue = getDefaultValue(data);
|
|
783
|
+
if (defaultValue) {
|
|
784
|
+
Object.assign(param, defaultValue);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
var percentageStr = parseInt(((index + excNum) * 100) / size);
|
|
790
|
+
if (param == null || param.length == 0) {
|
|
791
|
+
if (that.showContent) {
|
|
792
|
+
prevHandleData(percentageStr, excNum);
|
|
793
|
+
}
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
that.saveImportHandle(param, {
|
|
798
|
+
failMsg: false,
|
|
799
|
+
callback: (resultMsg) => {
|
|
800
|
+
if (multi) {
|
|
801
|
+
if (resultMsg.type == "success") {
|
|
802
|
+
var multiRows = resultMsg.objx;
|
|
803
|
+
for (let i = 0; i < multiRows.length; i++) {
|
|
804
|
+
var multiRow = multiRows[i];
|
|
805
|
+
var data = datas[multiRow.impSeq];
|
|
806
|
+
data._resultType = multiRow.impReturnType;
|
|
807
|
+
data._resultContent =
|
|
808
|
+
multiRow.impReturnType == "success"
|
|
809
|
+
? this.$t2(
|
|
810
|
+
"导入成功",
|
|
811
|
+
"components.excelImport.importSucess"
|
|
812
|
+
)
|
|
813
|
+
: multiRow.impReturnMsg;
|
|
814
|
+
if (multiRow.impReturnType == "success") {
|
|
815
|
+
successNum++;
|
|
816
|
+
that.successRows.push(data);
|
|
817
|
+
} else {
|
|
818
|
+
failNum++;
|
|
819
|
+
that.failRows.push(data);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
that.failRows = that.failRows.sort(compareV("impSeq"));
|
|
824
|
+
} else {
|
|
825
|
+
// error_win(resultMsg);
|
|
826
|
+
// layer.close(opts.dialogObjIndex);
|
|
827
|
+
|
|
828
|
+
let items = param.map((item) => {
|
|
829
|
+
return {
|
|
830
|
+
...item,
|
|
831
|
+
_resultType: "error",
|
|
832
|
+
_resultContent: resultMsg.content,
|
|
833
|
+
};
|
|
834
|
+
});
|
|
835
|
+
failNum = failNum + items.length;
|
|
836
|
+
that.failRows.push(...items);
|
|
837
|
+
|
|
838
|
+
that.failRows = that.failRows.sort(compareV("impSeq"));
|
|
839
|
+
|
|
840
|
+
/* that.$errorMsg(resultMsg);
|
|
841
|
+
that.showContent = false;
|
|
842
|
+
that.clearImportTimer();
|
|
843
|
+
return; */
|
|
844
|
+
}
|
|
845
|
+
} else {
|
|
846
|
+
var data = that.resultData.data[index];
|
|
847
|
+
data._resultType = resultMsg.type;
|
|
848
|
+
data._resultContent =
|
|
849
|
+
resultMsg.type == "success"
|
|
850
|
+
? this.$t2(
|
|
851
|
+
"导入成功",
|
|
852
|
+
"components.excelImport.importSucess"
|
|
853
|
+
)
|
|
854
|
+
: resultMsg.content;
|
|
855
|
+
|
|
856
|
+
if (resultMsg.type == "success") {
|
|
857
|
+
successNum++;
|
|
858
|
+
that.successRows.push(data);
|
|
859
|
+
} else {
|
|
860
|
+
failNum++;
|
|
861
|
+
that.failRows.push(data);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (that.showContent) {
|
|
865
|
+
prevHandleData(percentageStr, excNum);
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
error: (et) => {
|
|
869
|
+
that.isEnd = true;
|
|
870
|
+
that.clearImportTimer();
|
|
871
|
+
console.error(et);
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
handleData();
|
|
877
|
+
},
|
|
878
|
+
commonLocalDownload() {
|
|
879
|
+
let importOption = this.option.importOption;
|
|
880
|
+
let importAttachCode = importOption.importAttachCode;
|
|
881
|
+
if (!importAttachCode) return;
|
|
882
|
+
this.$http({
|
|
883
|
+
url: USER_PREFIX + "/bd_attach_setting/getByCode",
|
|
884
|
+
method: "post",
|
|
885
|
+
data: {
|
|
886
|
+
stringOne: importAttachCode,
|
|
887
|
+
},
|
|
888
|
+
success: (res) => {
|
|
889
|
+
let url = res.objx?.url;
|
|
890
|
+
if (url) {
|
|
891
|
+
this.$commonFileUtil.downloadFile(url);
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
});
|
|
895
|
+
},
|
|
896
|
+
vailData(data, opts) {
|
|
897
|
+
var oriCols = opts.data.oriCols;
|
|
898
|
+
var errorInfo = [];
|
|
899
|
+
for (let i = 0; i < oriCols.length; i++) {
|
|
900
|
+
let oriCol = oriCols[i];
|
|
901
|
+
if (oriCol.isNeed) {
|
|
902
|
+
let value = data[oriCol.field];
|
|
903
|
+
if (value == null || value == "") {
|
|
904
|
+
errorInfo.push(
|
|
905
|
+
this.$t2(
|
|
906
|
+
"[" + oriCol.title + "]不能为空;",
|
|
907
|
+
"components.excelImport.warmMsg4",
|
|
908
|
+
{ title: oriCol.title }
|
|
909
|
+
)
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return errorInfo.join("");
|
|
915
|
+
},
|
|
916
|
+
handleRes(val) {
|
|
917
|
+
/* var content = val;
|
|
918
|
+
var text = content;
|
|
919
|
+
if (content && content.indexOf("Exception") >= 0) {
|
|
920
|
+
var index0 = content.lastIndexOf("*]");
|
|
921
|
+
if (index0 >= 0) {
|
|
922
|
+
text = content.substr(index0);
|
|
923
|
+
if (text) {
|
|
924
|
+
var index1 = text.indexOf("Exception:");
|
|
925
|
+
if (index1 >= 0) {
|
|
926
|
+
text = text.substr(index1 + 10);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
} */
|
|
931
|
+
let text = getErrorMsg(val);
|
|
932
|
+
return text;
|
|
933
|
+
},
|
|
934
|
+
exportToExcel() {
|
|
935
|
+
let str =
|
|
936
|
+
this.resultType === 1
|
|
937
|
+
? this.$t2("成功", "components.excelImport.success")
|
|
938
|
+
: this.$t2("失败", "components.excelImport.fail");
|
|
939
|
+
let fileName =
|
|
940
|
+
this.$t2("导入结果导出", "components.excelImport.exportFileName") +
|
|
941
|
+
"(" +
|
|
942
|
+
str +
|
|
943
|
+
")";
|
|
944
|
+
let $grid = this.$refs.resGrid;
|
|
945
|
+
let columns = $grid.getColumns();
|
|
946
|
+
if (columns && columns.length) {
|
|
947
|
+
let fields = columns
|
|
948
|
+
.filter((item, index) => {
|
|
949
|
+
return index > 0 && item.property;
|
|
950
|
+
})
|
|
951
|
+
.map((item, index) => {
|
|
952
|
+
return item.property;
|
|
953
|
+
});
|
|
954
|
+
this.$refs.resGrid.exportData({
|
|
955
|
+
filename: fileName,
|
|
956
|
+
mode: "all",
|
|
957
|
+
type: "csv",
|
|
958
|
+
columns: fields,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
createImportTimer() {
|
|
963
|
+
this.excTime = 0;
|
|
964
|
+
let beginTime = new Date().getTime();
|
|
965
|
+
importTimer = setInterval(() => {
|
|
966
|
+
let nowTime = new Date().getTime();
|
|
967
|
+
let diffTime = (nowTime - beginTime) / 1000;
|
|
968
|
+
this.$set(this, "excTime", this.$baseLodash.round(diffTime, 2));
|
|
969
|
+
}, 100);
|
|
970
|
+
},
|
|
971
|
+
clearImportTimer() {
|
|
972
|
+
clearInterval(importTimer);
|
|
973
|
+
loadingObj && loadingObj.close();
|
|
974
|
+
},
|
|
975
|
+
getWidgetTarget() {},
|
|
976
|
+
getFieldTarget() {
|
|
977
|
+
return this.param.target;
|
|
978
|
+
},
|
|
979
|
+
async dialogPrimary3() {
|
|
980
|
+
if (!this.fileRaw) {
|
|
981
|
+
this.$baseAlert(
|
|
982
|
+
this.$t2("请上传附件", "components.excelImport.warmMsg1")
|
|
983
|
+
);
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
let that = this;
|
|
987
|
+
let option = this.option;
|
|
988
|
+
loadingObj = this.$baseLoading({
|
|
989
|
+
target: document.body,
|
|
990
|
+
background: "unset",
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
let importOption = option.importOption;
|
|
994
|
+
this.readExcel(this.fileRaw, function (resultData) {
|
|
995
|
+
let file = that.fileRaw;
|
|
996
|
+
let flag = false;
|
|
997
|
+
let done = () => {
|
|
998
|
+
if (flag) return;
|
|
999
|
+
flag = true;
|
|
1000
|
+
that.showImportDialog = false;
|
|
1001
|
+
return that
|
|
1002
|
+
.getFieldTarget()
|
|
1003
|
+
.handleCustomEvent(
|
|
1004
|
+
importOption.onSuccessImport,
|
|
1005
|
+
["resultData", "file"],
|
|
1006
|
+
[resultData, file]
|
|
1007
|
+
);
|
|
1008
|
+
};
|
|
1009
|
+
try {
|
|
1010
|
+
if (importOption.onConfirmImportEnabled) {
|
|
1011
|
+
if (
|
|
1012
|
+
that
|
|
1013
|
+
.getFieldTarget()
|
|
1014
|
+
.handleCustomEvent(
|
|
1015
|
+
importOption.onConfirmImport,
|
|
1016
|
+
["resultData", "file", "done"],
|
|
1017
|
+
[resultData, file, done]
|
|
1018
|
+
) !== false
|
|
1019
|
+
) {
|
|
1020
|
+
done();
|
|
1021
|
+
}
|
|
1022
|
+
} else if (importOption.tableRef) {
|
|
1023
|
+
let tableRef = that
|
|
1024
|
+
.getFieldTarget()
|
|
1025
|
+
.getWidgetRef(importOption.tableRef);
|
|
1026
|
+
tableRef && tableRef.addTableData(resultData.data);
|
|
1027
|
+
done();
|
|
1028
|
+
}
|
|
1029
|
+
} catch (et) {
|
|
1030
|
+
console.error(et);
|
|
1031
|
+
}
|
|
1032
|
+
setTimeout(function () {
|
|
1033
|
+
loadingObj && loadingObj.close();
|
|
1034
|
+
}, 200);
|
|
1035
|
+
});
|
|
1036
|
+
},
|
|
1037
|
+
|
|
1038
|
+
//begin
|
|
1039
|
+
fileParse(file, type = "base64", callback) {
|
|
1040
|
+
let fileRead = new FileReader();
|
|
1041
|
+
if (type === "base64") {
|
|
1042
|
+
fileRead.readAsDataURL(file);
|
|
1043
|
+
} else if (type === "buffer") {
|
|
1044
|
+
fileRead.readAsArrayBuffer(file);
|
|
1045
|
+
}
|
|
1046
|
+
fileRead.onload = (ev) => {
|
|
1047
|
+
callback(ev.target.result);
|
|
1048
|
+
};
|
|
1049
|
+
},
|
|
1050
|
+
getUploadText(percent) {
|
|
1051
|
+
return this.$t1("上传导入文件 {percent}%", { percent });
|
|
1052
|
+
},
|
|
1053
|
+
changeUploadPercent(percent) {
|
|
1054
|
+
// return this.$t1('上传导入文件 {percent}%', {percent})
|
|
1055
|
+
this.percent1 = percent;
|
|
1056
|
+
this.loadingIndex = 1;
|
|
1057
|
+
},
|
|
1058
|
+
uploadFile(callback) {
|
|
1059
|
+
let that = this;
|
|
1060
|
+
that.loadingPercent = 0;
|
|
1061
|
+
// that.loadingTitle = this.getUploadText(0);
|
|
1062
|
+
that.changeUploadPercent(0);
|
|
1063
|
+
let file = this.fileRaw;
|
|
1064
|
+
let uploadChunkSize = 5;
|
|
1065
|
+
this.importLoading = true;
|
|
1066
|
+
this.fileUploadCallback = callback;
|
|
1067
|
+
this.fileParse(file, "buffer", (buffer) => {
|
|
1068
|
+
let spark = new SparkMD5.ArrayBuffer(),
|
|
1069
|
+
chunkSize = uploadChunkSize * 1024 * 1024, // Read in chunks of 2MB
|
|
1070
|
+
chunks = Math.ceil(file.size / chunkSize),
|
|
1071
|
+
hash,
|
|
1072
|
+
suffix;
|
|
1073
|
+
spark.append(buffer);
|
|
1074
|
+
hash = spark.end();
|
|
1075
|
+
let md5 = hash;
|
|
1076
|
+
let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
|
|
1077
|
+
|
|
1078
|
+
suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
|
|
1079
|
+
|
|
1080
|
+
let chunkParam = {
|
|
1081
|
+
fullFile: file,
|
|
1082
|
+
chunkSize: chunkSize,
|
|
1083
|
+
chunks: chunks,
|
|
1084
|
+
chunkIndex: 0,
|
|
1085
|
+
md5: hash,
|
|
1086
|
+
uuid: "",
|
|
1087
|
+
name: file.name,
|
|
1088
|
+
};
|
|
1089
|
+
file.chunkParam = chunkParam;
|
|
1090
|
+
|
|
1091
|
+
this.sendRequest(file);
|
|
1092
|
+
});
|
|
1093
|
+
},
|
|
1094
|
+
async sendRequest(fullFile) {
|
|
1095
|
+
if (!this.showImportDialog2) return;
|
|
1096
|
+
let that = this;
|
|
1097
|
+
let uploadUrl = USER_PREFIX + "/excel_import/uploadFile";
|
|
1098
|
+
let chunkParam = fullFile.chunkParam;
|
|
1099
|
+
let target = that.$refs.upload;
|
|
1100
|
+
let abort;
|
|
1101
|
+
let config = {
|
|
1102
|
+
headers: {
|
|
1103
|
+
"Content-Type": "multipart/form-data",
|
|
1104
|
+
},
|
|
1105
|
+
cancelToken: new axios.CancelToken(function executor(c) {
|
|
1106
|
+
abort = c;
|
|
1107
|
+
fullFile.abort = c;
|
|
1108
|
+
}),
|
|
1109
|
+
onUploadProgress: (progressEvent) => {
|
|
1110
|
+
let start = chunkParam.start;
|
|
1111
|
+
let uploadedSize =
|
|
1112
|
+
start +
|
|
1113
|
+
Math.floor(
|
|
1114
|
+
(chunkParam.currentSize * progressEvent.loaded) /
|
|
1115
|
+
progressEvent.total
|
|
1116
|
+
);
|
|
1117
|
+
let percent = Math.floor((uploadedSize * 100) / fullFile.size);
|
|
1118
|
+
if (percent == 100) {
|
|
1119
|
+
percent = 99;
|
|
1120
|
+
}
|
|
1121
|
+
that.loadingPercent = percent;
|
|
1122
|
+
|
|
1123
|
+
// that.$set(that, 'loadingTitle', this.getUploadText(percent))
|
|
1124
|
+
that.changeUploadPercent(percent);
|
|
1125
|
+
},
|
|
1126
|
+
// failMsg: false,
|
|
1127
|
+
modal: false,
|
|
1128
|
+
callback: (res1) => {
|
|
1129
|
+
if (res1.type == "success") {
|
|
1130
|
+
let uuid = res1.objx.uuid;
|
|
1131
|
+
chunkParam.uuid = uuid;
|
|
1132
|
+
if (preFormData.chunk + 1 >= preFormData.chunks) {
|
|
1133
|
+
let mergeData = {
|
|
1134
|
+
name: chunkParam.name,
|
|
1135
|
+
md5: chunkParam.md5,
|
|
1136
|
+
uuid: uuid,
|
|
1137
|
+
};
|
|
1138
|
+
let _param = {
|
|
1139
|
+
mergeData: mergeData,
|
|
1140
|
+
chunkParam: chunkParam,
|
|
1141
|
+
};
|
|
1142
|
+
setTimeout(() => {
|
|
1143
|
+
this.mergeFile(_param);
|
|
1144
|
+
}, 100);
|
|
1145
|
+
} else {
|
|
1146
|
+
chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
|
|
1147
|
+
chunkParam.uuid = uuid;
|
|
1148
|
+
setTimeout(() => {
|
|
1149
|
+
this.sendRequest(fullFile);
|
|
1150
|
+
}, 100);
|
|
1151
|
+
}
|
|
1152
|
+
} else {
|
|
1153
|
+
this.dialogClose2(0);
|
|
1154
|
+
}
|
|
1155
|
+
return res1;
|
|
1156
|
+
},
|
|
1157
|
+
error: (err) => {
|
|
1158
|
+
console.log(err);
|
|
1159
|
+
this.dialogClose2(0);
|
|
1160
|
+
},
|
|
1161
|
+
}; //添加请求头
|
|
1162
|
+
|
|
1163
|
+
let chunkIndex = chunkParam.chunkIndex;
|
|
1164
|
+
let chunkSize = chunkParam.chunkSize;
|
|
1165
|
+
var start = chunkIndex * chunkSize,
|
|
1166
|
+
end =
|
|
1167
|
+
start + chunkSize >= fullFile.size
|
|
1168
|
+
? fullFile.size
|
|
1169
|
+
: start + chunkParam.chunkSize;
|
|
1170
|
+
chunkParam.currentSize = end - start;
|
|
1171
|
+
chunkParam.start = start;
|
|
1172
|
+
chunkParam.end = end;
|
|
1173
|
+
|
|
1174
|
+
let preFormData = {
|
|
1175
|
+
file: fullFile.slice(start, end),
|
|
1176
|
+
name: fullFile.name,
|
|
1177
|
+
chunks: chunkParam.chunks,
|
|
1178
|
+
chunk: chunkIndex,
|
|
1179
|
+
md5: chunkParam.md5,
|
|
1180
|
+
uuid: chunkParam.uuid,
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
let formData = new FormData();
|
|
1184
|
+
Object.keys(preFormData).forEach((key) => {
|
|
1185
|
+
formData.append(key, preFormData[key]);
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
let req = this.$http.post(uploadUrl, formData, config);
|
|
1189
|
+
req.abort = () => {
|
|
1190
|
+
abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
|
|
1191
|
+
};
|
|
1192
|
+
},
|
|
1193
|
+
mergeFile(param) {
|
|
1194
|
+
if (!this.showImportDialog2) return;
|
|
1195
|
+
let that = this;
|
|
1196
|
+
let mergeData = param.mergeData;
|
|
1197
|
+
let chunkParam = param.chunkParam;
|
|
1198
|
+
let fullFile = chunkParam.fullFile;
|
|
1199
|
+
let mergeUrl = USER_PREFIX + "/excel_import/mergeChunk";
|
|
1200
|
+
let target = this.$refs.upload;
|
|
1201
|
+
this.$http({
|
|
1202
|
+
url: mergeUrl,
|
|
1203
|
+
method: "post",
|
|
1204
|
+
data: mergeData,
|
|
1205
|
+
// failMsg: false,
|
|
1206
|
+
modal: false,
|
|
1207
|
+
cancelToken: new axios.CancelToken(function executor(c) {
|
|
1208
|
+
if (fullFile) fullFile.abort = c;
|
|
1209
|
+
}),
|
|
1210
|
+
callback: (res) => {
|
|
1211
|
+
if (res.type == "success") {
|
|
1212
|
+
that.loadingPercent = 100;
|
|
1213
|
+
// that.loadingTitle = this.getUploadText(100);
|
|
1214
|
+
this.changeUploadPercent(100);
|
|
1215
|
+
setTimeout(() => {
|
|
1216
|
+
this.checkImportData();
|
|
1217
|
+
}, 100);
|
|
1218
|
+
} else {
|
|
1219
|
+
this.dialogClose2(0);
|
|
1220
|
+
}
|
|
1221
|
+
},
|
|
1222
|
+
error: (e) => {
|
|
1223
|
+
console.log(err);
|
|
1224
|
+
this.dialogClose2(0);
|
|
1225
|
+
},
|
|
1226
|
+
});
|
|
1227
|
+
},
|
|
1228
|
+
getCheckText(percent) {
|
|
1229
|
+
return this.$t1("校验导入文件中的图片数据格式 {percent}%", { percent });
|
|
1230
|
+
},
|
|
1231
|
+
changeCheckTextPercent(percent) {
|
|
1232
|
+
this.percent2 = percent;
|
|
1233
|
+
this.loadingIndex = 2;
|
|
1234
|
+
},
|
|
1235
|
+
checkImportData() {
|
|
1236
|
+
if (!this.showImportDialog2) return;
|
|
1237
|
+
let that = this;
|
|
1238
|
+
that.loadingPercent = 0;
|
|
1239
|
+
// that.loadingTitle = this.getCheckText(0);
|
|
1240
|
+
that.changeCheckTextPercent(0);
|
|
1241
|
+
let fullFile = this.fileRaw;
|
|
1242
|
+
let chunkParam = fullFile.chunkParam;
|
|
1243
|
+
|
|
1244
|
+
this.$http({
|
|
1245
|
+
url: USER_PREFIX + "/excel_import/checkData",
|
|
1246
|
+
method: "post",
|
|
1247
|
+
data: {
|
|
1248
|
+
name: chunkParam.name,
|
|
1249
|
+
md5: chunkParam.md5,
|
|
1250
|
+
uuid: chunkParam.uuid,
|
|
1251
|
+
},
|
|
1252
|
+
// failMsg: false,
|
|
1253
|
+
modal: false,
|
|
1254
|
+
cancelToken: new axios.CancelToken(function executor(c) {
|
|
1255
|
+
if (fullFile) fullFile.abort = c;
|
|
1256
|
+
}),
|
|
1257
|
+
onUploadProgress: (progressEvent) => {
|
|
1258
|
+
let percent = Math.floor(
|
|
1259
|
+
(progressEvent.loaded * 100) / progressEvent.total
|
|
1260
|
+
);
|
|
1261
|
+
if (percent == 100) {
|
|
1262
|
+
percent = 99;
|
|
1263
|
+
}
|
|
1264
|
+
that.loadingPercent = percent;
|
|
1265
|
+
// that.$set(that, 'loadingTitle', this.getCheckText(percent))
|
|
1266
|
+
that.changeCheckTextPercent(percent);
|
|
1267
|
+
},
|
|
1268
|
+
callback: (res) => {
|
|
1269
|
+
if (res.type == "success") {
|
|
1270
|
+
that.loadingPercent = 100;
|
|
1271
|
+
// that.loadingTitle = this.getCheckText(100);
|
|
1272
|
+
that.changeCheckTextPercent(100);
|
|
1273
|
+
this.handleImageData();
|
|
1274
|
+
} else {
|
|
1275
|
+
this.dialogClose2(0);
|
|
1276
|
+
}
|
|
1277
|
+
},
|
|
1278
|
+
error: (e) => {
|
|
1279
|
+
console.log(err);
|
|
1280
|
+
this.dialogClose2(0);
|
|
1281
|
+
},
|
|
1282
|
+
});
|
|
1283
|
+
},
|
|
1284
|
+
getSaveImageText(percent) {
|
|
1285
|
+
return this.$t1("存储导入文件中的图片 {percent}%", { percent });
|
|
1286
|
+
},
|
|
1287
|
+
changeSaveImageTextPercent(percent) {
|
|
1288
|
+
// return this.$t1('存储导入文件中的图片 {percent}%', {percent})
|
|
1289
|
+
this.percent3 = percent;
|
|
1290
|
+
this.loadingIndex = 3;
|
|
1291
|
+
},
|
|
1292
|
+
handleImageData() {
|
|
1293
|
+
let that = this;
|
|
1294
|
+
that.loadingPercent = 0;
|
|
1295
|
+
// that.loadingTitle = this.getSaveImageText(0);
|
|
1296
|
+
that.changeSaveImageTextPercent(0);
|
|
1297
|
+
this.getImportData(0);
|
|
1298
|
+
},
|
|
1299
|
+
getImportData(index) {
|
|
1300
|
+
if (!this.showImportDialog2) return;
|
|
1301
|
+
let that = this;
|
|
1302
|
+
let rowSize = this.handleRowSize;
|
|
1303
|
+
let fullFile = this.fileRaw;
|
|
1304
|
+
let chunkParam = fullFile.chunkParam;
|
|
1305
|
+
let rowDatas = this.resultData.data;
|
|
1306
|
+
let size = rowDatas.length;
|
|
1307
|
+
let currentLineNo = index + 1;
|
|
1308
|
+
let rowNumber = index + 3;
|
|
1309
|
+
let startRow = index + 3;
|
|
1310
|
+
let endRow = index + 3 + rowSize - 1;
|
|
1311
|
+
this.$http({
|
|
1312
|
+
url: USER_PREFIX + "/excel_import/getData",
|
|
1313
|
+
method: "post",
|
|
1314
|
+
data: {
|
|
1315
|
+
name: chunkParam.name,
|
|
1316
|
+
md5: chunkParam.md5,
|
|
1317
|
+
uuid: chunkParam.uuid,
|
|
1318
|
+
startRow: startRow,
|
|
1319
|
+
endRow: endRow,
|
|
1320
|
+
},
|
|
1321
|
+
// failMsg: false,
|
|
1322
|
+
modal: false,
|
|
1323
|
+
cancelToken: new axios.CancelToken(function executor(c) {
|
|
1324
|
+
if (fullFile) fullFile.abort = c;
|
|
1325
|
+
}),
|
|
1326
|
+
callback: (res) => {
|
|
1327
|
+
if (res.type == "success") {
|
|
1328
|
+
let rows = res?.objx?.datas || [];
|
|
1329
|
+
let fileCellFields = this.fileCellFields;
|
|
1330
|
+
rows.forEach((row) => {
|
|
1331
|
+
let rowIndex = row.row - 3;
|
|
1332
|
+
let item = rowDatas[rowIndex];
|
|
1333
|
+
Object.keys(row).forEach((key) => {
|
|
1334
|
+
if (fileCellFields.includes(key)) {
|
|
1335
|
+
let value = row[key] || [];
|
|
1336
|
+
if (!Array.isArray(value)) {
|
|
1337
|
+
value = [value];
|
|
1338
|
+
}
|
|
1339
|
+
item[key] = value;
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
let cIndex = index + rowSize - 1;
|
|
1344
|
+
let percent = Math.floor(((cIndex + 1) * 100) / size);
|
|
1345
|
+
that.loadingPercent = percent;
|
|
1346
|
+
// that.loadingTitle = this.getSaveImageText(percent);
|
|
1347
|
+
that.changeSaveImageTextPercent(percent);
|
|
1348
|
+
if (cIndex + 1 < size) {
|
|
1349
|
+
this.getImportData(cIndex + 1);
|
|
1350
|
+
} else {
|
|
1351
|
+
this.fileUploadCallback();
|
|
1352
|
+
}
|
|
1353
|
+
} else {
|
|
1354
|
+
this.dialogClose2(0);
|
|
1355
|
+
}
|
|
1356
|
+
},
|
|
1357
|
+
error: (e) => {
|
|
1358
|
+
this.dialogClose2(0);
|
|
1359
|
+
},
|
|
1360
|
+
});
|
|
1361
|
+
},
|
|
1362
|
+
async generateNewExcel() {
|
|
1363
|
+
let file = this.fileRaw;
|
|
1364
|
+
try {
|
|
1365
|
+
// 1. 读取原始文件
|
|
1366
|
+
const workbook = XLSX.read(file, { type: "binary" });
|
|
1367
|
+
const sheetName = workbook.SheetNames[0];
|
|
1368
|
+
const rawData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);
|
|
1369
|
+
|
|
1370
|
+
// 2. 提取表头和数据
|
|
1371
|
+
const headers = rawData.slice(0, this.headerRows);
|
|
1372
|
+
const bodyData = rawData.slice(this.headerRows);
|
|
1373
|
+
|
|
1374
|
+
let exporLineNos = [];
|
|
1375
|
+
if (this.resultType) {
|
|
1376
|
+
exporLineNos = this.successRows.map((item) => item.impNumber - 1);
|
|
1377
|
+
} else {
|
|
1378
|
+
exporLineNos = this.failRows.map((item) => item.impNumber - 1);
|
|
1379
|
+
}
|
|
1380
|
+
// 3. 应用筛选规则
|
|
1381
|
+
let selectRule = (row, index) => {
|
|
1382
|
+
return exporLineNos.includes(index);
|
|
1383
|
+
};
|
|
1384
|
+
const filteredData = bodyData.filter(
|
|
1385
|
+
(row, index) => {
|
|
1386
|
+
return selectRule(row, index + this.headerRows);
|
|
1387
|
+
}
|
|
1388
|
+
// this.selectRule(row, index + this.headerRows) // 注意索引转换
|
|
1389
|
+
);
|
|
1390
|
+
|
|
1391
|
+
// 4. 合并数据
|
|
1392
|
+
const newData = [...headers, ...filteredData];
|
|
1393
|
+
|
|
1394
|
+
// 5. 生成新文件
|
|
1395
|
+
const newWorkbook = XLSX.utils.book_new();
|
|
1396
|
+
const newSheet = XLSX.utils.aoa_to_sheet(newData);
|
|
1397
|
+
XLSX.utils.book_append_sheet(newWorkbook, newSheet, "Sheet1");
|
|
1398
|
+
|
|
1399
|
+
// 6. 下载文件
|
|
1400
|
+
const blob = XLSX.write(newWorkbook, {
|
|
1401
|
+
bookType: "xlsx",
|
|
1402
|
+
type: "array",
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
const url = URL.createObjectURL(blob);
|
|
1406
|
+
const a = document.createElement("a");
|
|
1407
|
+
a.href = url;
|
|
1408
|
+
let fileName = null;
|
|
1409
|
+
if (this.resultType) {
|
|
1410
|
+
fileName = `导入结果(成功).xlsx`;
|
|
1411
|
+
} else {
|
|
1412
|
+
fileName = `导入结果(失败).xlsx`;
|
|
1413
|
+
}
|
|
1414
|
+
a.download = fileName;
|
|
1415
|
+
a.click();
|
|
1416
|
+
|
|
1417
|
+
// 7. 更新进度
|
|
1418
|
+
this.progress = 100;
|
|
1419
|
+
setTimeout(() => (this.progress = 0), 1000);
|
|
1420
|
+
} catch (error) {
|
|
1421
|
+
console.error("处理文件时出错:", error);
|
|
1422
|
+
}
|
|
1423
|
+
},
|
|
1424
|
+
//end
|
|
1425
|
+
getLoadingClass(flag, percent) {
|
|
1426
|
+
let classStr = null;
|
|
1427
|
+
let loadingIndex = this.loadingIndex;
|
|
1428
|
+
if (percent >= 100) {
|
|
1429
|
+
classStr = "ok";
|
|
1430
|
+
} else if (flag === loadingIndex) {
|
|
1431
|
+
classStr = "loading";
|
|
1432
|
+
}
|
|
1433
|
+
return classStr;
|
|
1434
|
+
},
|
|
1435
|
+
|
|
1436
|
+
/***sheet1 */
|
|
1437
|
+
async readExcel2(file, callback) {
|
|
1438
|
+
let that = this;
|
|
1439
|
+
let option = this.option;
|
|
1440
|
+
|
|
1441
|
+
const fileReader = new FileReader();
|
|
1442
|
+
fileReader.onload = async (ev) => {
|
|
1443
|
+
var resultData;
|
|
1444
|
+
try {
|
|
1445
|
+
const data = ev.target.result;
|
|
1446
|
+
const workbook = configUtil.XLSX.read(data, {
|
|
1447
|
+
type: "binary",
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
let sheetDatas = []
|
|
1451
|
+
for (let pi = 0; pi < workbook.SheetNames.length; pi++) {
|
|
1452
|
+
let sheetName = workbook.SheetNames[pi];
|
|
1453
|
+
let sheet = workbook.Sheets[sheetName];
|
|
1454
|
+
|
|
1455
|
+
if (sheet["!ref"] == undefined) {
|
|
1456
|
+
that.$baseAlert(
|
|
1457
|
+
this.$t2(
|
|
1458
|
+
"请使用正确的导入模版!",
|
|
1459
|
+
"components.excelImport.warmMsg2"
|
|
1460
|
+
)
|
|
1461
|
+
);
|
|
1462
|
+
that.handleClose2();
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
var range = configUtil.XLSX.utils.decode_range(sheet["!ref"]);
|
|
1466
|
+
var dataSize = range.e.r + 1; //行数
|
|
1467
|
+
that.dataSize = dataSize - 3 >= 0 ? dataSize - 3 : 0;
|
|
1468
|
+
var titles = [];
|
|
1469
|
+
var fields = [];
|
|
1470
|
+
|
|
1471
|
+
const ws = workbook.Sheets[sheet];
|
|
1472
|
+
|
|
1473
|
+
let prefix = option.prefix;
|
|
1474
|
+
let excelUrl = option.excel;
|
|
1475
|
+
|
|
1476
|
+
var excelRows = [];
|
|
1477
|
+
var row;
|
|
1478
|
+
var rowNum;
|
|
1479
|
+
var colNum;
|
|
1480
|
+
for (rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
|
|
1481
|
+
row = [];
|
|
1482
|
+
for (colNum = range.s.c; colNum <= range.e.c; colNum++) {
|
|
1483
|
+
var nextCell =
|
|
1484
|
+
sheet[
|
|
1485
|
+
configUtil.XLSX.utils.encode_cell({
|
|
1486
|
+
r: rowNum,
|
|
1487
|
+
c: colNum,
|
|
1488
|
+
})
|
|
1489
|
+
];
|
|
1490
|
+
if (typeof nextCell === "undefined") {
|
|
1491
|
+
row.push(void 0);
|
|
1492
|
+
} else {
|
|
1493
|
+
row.push(nextCell.w.trim());
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
if (rowNum == 1) {
|
|
1497
|
+
titles = row;
|
|
1498
|
+
}
|
|
1499
|
+
if (rowNum == 2) {
|
|
1500
|
+
fields = row;
|
|
1501
|
+
let checkResult = true;
|
|
1502
|
+
}
|
|
1503
|
+
if (rowNum > 2) {
|
|
1504
|
+
let item = {};
|
|
1505
|
+
for (let i = 0; i < fields.length; i++) {
|
|
1506
|
+
let field = fields[i];
|
|
1507
|
+
if (field) {
|
|
1508
|
+
item[field] = row[i] ?? null;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
excelRows.push(item);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
if (
|
|
1515
|
+
!titles.length ||
|
|
1516
|
+
!fields.length ||
|
|
1517
|
+
titles.length != fields.length
|
|
1518
|
+
) {
|
|
1519
|
+
that.$baseAlert(
|
|
1520
|
+
this.$t2(
|
|
1521
|
+
"请使用正确的导入模版!",
|
|
1522
|
+
"components.excelImport.warmMsg2"
|
|
1523
|
+
)
|
|
1524
|
+
);
|
|
1525
|
+
that.handleClose2();
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
var columns = [];
|
|
1530
|
+
var cols = [];
|
|
1531
|
+
let uniqueFields = [];
|
|
1532
|
+
for (let i = 0; i < titles.length; i++) {
|
|
1533
|
+
let title = titles[i];
|
|
1534
|
+
if (title) {
|
|
1535
|
+
let field = fields[i];
|
|
1536
|
+
if (field == null) {
|
|
1537
|
+
that.$baseAlert(
|
|
1538
|
+
this.$t2(
|
|
1539
|
+
"请使用正确的导入模版!",
|
|
1540
|
+
"components.excelImport.warmMsg2"
|
|
1541
|
+
)
|
|
1542
|
+
);
|
|
1543
|
+
that.handleClose2();
|
|
1544
|
+
return false;
|
|
1545
|
+
}
|
|
1546
|
+
let t = title.substr(-1);
|
|
1547
|
+
let u = title.length >= 2 ? title.substr(-2) : title;
|
|
1548
|
+
let isNeed = false;
|
|
1549
|
+
if (t === "*") {
|
|
1550
|
+
isNeed = true;
|
|
1551
|
+
}
|
|
1552
|
+
let isUnique = false;
|
|
1553
|
+
if (u === "**") {
|
|
1554
|
+
uniqueFields.push(field);
|
|
1555
|
+
isUnique = true;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
let otherConfig = {};
|
|
1559
|
+
let isFile = false;
|
|
1560
|
+
if (field.startsWith("attachments_")) {
|
|
1561
|
+
that.fileCellFields.push(field);
|
|
1562
|
+
isFile = true;
|
|
1563
|
+
otherConfig = {
|
|
1564
|
+
slots: {
|
|
1565
|
+
default: "attachment",
|
|
1566
|
+
},
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
let col = {
|
|
1571
|
+
field: field,
|
|
1572
|
+
title: title,
|
|
1573
|
+
width: 100,
|
|
1574
|
+
isNeed: isNeed,
|
|
1575
|
+
isUnique: isUnique,
|
|
1576
|
+
isFile,
|
|
1577
|
+
otherConfig,
|
|
1578
|
+
};
|
|
1579
|
+
cols.push(col);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
var oriCols = JSON.parse(JSON.stringify(cols)); //列信息
|
|
1584
|
+
if (uniqueFields.length) {
|
|
1585
|
+
//分组唯一字段为空时,全部不发包。
|
|
1586
|
+
for (let i = 0; i < oriCols.length; i++) {
|
|
1587
|
+
let oriCol = oriCols[i];
|
|
1588
|
+
if (oriCol.isNeed) {
|
|
1589
|
+
for (let j = 0; j < excelRows.length; j++) {
|
|
1590
|
+
let data = excelRows[j];
|
|
1591
|
+
let value = data[oriCol.field];
|
|
1592
|
+
if (value == null || value == "") {
|
|
1593
|
+
that.clearImportTimer();
|
|
1594
|
+
that.$baseAlert(
|
|
1595
|
+
`[${sheetName}]`+
|
|
1596
|
+
this.$t2(
|
|
1597
|
+
"第" + (j + 4) + "行[" + oriCol.title + "]不能为空;",
|
|
1598
|
+
"components.excelImport.warmMsg3",
|
|
1599
|
+
{
|
|
1600
|
+
lineNo: j + 4,
|
|
1601
|
+
title: oriCol.title,
|
|
1602
|
+
}
|
|
1603
|
+
)
|
|
1604
|
+
);
|
|
1605
|
+
that.handleClose2();
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
this.oriCols = oriCols;
|
|
1614
|
+
|
|
1615
|
+
let resultData1 = {
|
|
1616
|
+
sheetName: sheetName,
|
|
1617
|
+
data: excelRows,
|
|
1618
|
+
titles: titles,
|
|
1619
|
+
fields: fields,
|
|
1620
|
+
uniqueFields: uniqueFields,
|
|
1621
|
+
oriCols: oriCols,
|
|
1622
|
+
};
|
|
1623
|
+
sheetDatas.push(resultData1);
|
|
1624
|
+
}
|
|
1625
|
+
// var sheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
1626
|
+
// this.resultData = resultData;
|
|
1627
|
+
callback(sheetDatas);
|
|
1628
|
+
} catch (et) {
|
|
1629
|
+
that.showContent = false;
|
|
1630
|
+
that.clearImportTimer();
|
|
1631
|
+
console.error(et);
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
fileReader.readAsBinaryString(file);
|
|
1635
|
+
},
|
|
1636
|
+
/***sheet2 */
|
|
1637
|
+
},
|
|
1638
|
+
};
|
|
1639
|
+
export const mixins = tmixins;
|