cloud-web-corejs 1.0.54-dev.781 → 1.0.54-dev.783

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 (33) hide show
  1. package/package.json +1 -1
  2. package/src/components/VabUpload/index.vue +242 -242
  3. package/src/components/VabUpload/mixins.js +1971 -1971
  4. package/src/components/VabUpload/privateProfileDialog.vue +2 -2
  5. package/src/components/hiprint/view/design/index.vue +7 -2
  6. package/src/components/obsUpload/index.vue +234 -234
  7. package/src/components/obsUpload/mixins.js +1542 -1542
  8. package/src/components/vb-tabs/x-tabs.vue +7 -3
  9. package/src/components/xform/docs//346/240/221/350/241/250rowField/346/224/266/346/225/233-/350/220/275/345/234/260/346/226/207/346/241/243.md +1427 -0
  10. package/src/components/xform/form-designer/form-widget/dialog/formDialog.vue +2 -2
  11. package/src/components/xform/form-designer/form-widget/dialog/formDrawer.vue +2 -2
  12. package/src/components/xform/form-designer/form-widget/dialog/searchFormDialog.vue +2 -2
  13. package/src/components/xform/form-designer/form-widget/field-widget/copy_button-widget.vue +11 -2
  14. package/src/components/xform/form-designer/form-widget/field-widget/vabUpload-widget.vue +369 -369
  15. package/src/components/xform/form-designer/setting-panel/property-editor/fileTypesSelect.vue +69 -23
  16. package/src/components/xform/form-render/container-item/data-table-item.vue +1 -1
  17. package/src/components/xform/form-render/container-item/data-table-mixin.js +1469 -428
  18. package/src/components/xform/form-render/indexMixin.js +379 -263
  19. package/src/components/xform/mixins/defaultHandle.js +234 -28
  20. package/src/components/xform/mixins/scriptHttp.js +4 -4
  21. package/src/components/xform/utils/treeTableUtil.js +1265 -0
  22. package/src/components/xform/utils/util.js +29 -14
  23. package/src/microRouter/index.js +3 -0
  24. package/src/mixins/tableTree/index.js +77 -14
  25. package/src/store/config/index.js +28 -28
  26. package/src/utils/menuAdapter.js +277 -277
  27. package/src/utils/resolveViewComponent.js +203 -203
  28. package/src/utils/vab.js +6 -3
  29. package/src/views/bd/setting/formVersion/ftHistoryDialog.vue +9 -2
  30. package/src/views/user/common_attribute/list.vue +1 -1
  31. package/src/views/user/form/vform/render.vue +17 -2
  32. package/src/views/user/form/view/list.vue +11 -10
  33. package/src/views/user/wf/wfReport/index.vue +625 -625
@@ -1,1971 +1,1971 @@
1
- /**version-1.0*/
2
- let tmixins, tViewMixins, pmixins;
3
- import axios from "axios";
4
- import SparkMD5 from "spark-md5";
5
- import settingConfig from "@/settings.js";
6
-
7
- let imFun = {
8
- axios,
9
- SparkMD5,
10
- };
11
-
12
- tmixins = {
13
- name: "VabUpload",
14
- props: {
15
- auto: {
16
- type: Boolean,
17
- default: true,
18
- },
19
- url: {
20
- type: String,
21
- default: "/upload",
22
- },
23
- name: {
24
- type: String,
25
- default: "file",
26
- },
27
- limit: {
28
- type: Number,
29
- default: () => 100000,
30
- },
31
- /* 单个文件大小限制(MB),0 表示不限制 */
32
- size: {
33
- type: Number,
34
- default: () => {
35
- return settingConfig.uploadFileSize ?? 200;
36
- },
37
- },
38
- accept: {
39
- type: String,
40
- default: "file",
41
- },
42
- /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
43
- fileTypes: {
44
- type: [Array, String],
45
- default: () => [],
46
- },
47
- chunkSize: {
48
- type: Number,
49
- default: 5, //5MB
50
- },
51
- confirmUpload: {
52
- type: Function,
53
- },
54
- pickPrivateProfile: {
55
- type: Boolean,
56
- default: true,
57
- },
58
- multi: {
59
- type: [String, Boolean],
60
- default: true,
61
- },
62
- uploadingLimit: {
63
- type: Number,
64
- default: 5, //5MB
65
- },
66
- isPartUpload: {
67
- type: Boolean,
68
- default: () => {
69
- return settingConfig.isPartUpload ?? true;
70
- },
71
- },
72
- autoConfirmAfterUpload: {
73
- type: Boolean,
74
- default: false,
75
- },
76
- showFileLibraryButton: Boolean,
77
- storeAreaPrefix: String,
78
- storeAreaCode: String,
79
- },
80
- data() {
81
- return {
82
- fileLibraryName: null,
83
- show: false,
84
- loading: false,
85
- dialogVisible: false,
86
- dialogImageUrl: "",
87
- action: "",
88
- headers: {},
89
- fileList: [],
90
- picture: "picture",
91
- allImgNum: 0,
92
- imgNum: 0,
93
- imgSuccessNum: 0,
94
- imgErrorNum: 0,
95
- typeList: null,
96
- title: this.$t2("上传", "components.VabUpload.title"),
97
- dialogFormVisible: false,
98
- data: {},
99
- fileViewDialogVisible: false,
100
- fileViewInfo: {},
101
- total: 0,
102
- video: null,
103
- btn: false,
104
- filePartMap: {},
105
- uploading: false,
106
- hasReadyFile: false,
107
- showLocalUploadBtn: false,
108
- showPrivateUploadBtn: false,
109
- showPrivateProfileDialog: false,
110
- pasteList: [],
111
- pasteAreaStatus: false,
112
- option: {},
113
- editFileIndex: -1,
114
- showFileNameDialog: false,
115
- editFileName: null,
116
- editFileSuffix: null,
117
- beforeUploadFlag: false,
118
- uploadUrl: null,
119
- };
120
- },
121
- beforeDestroy() {
122
- this.removePasteEvent();
123
- },
124
- filters: {
125
- btnText(btn) {
126
- return btn
127
- ? this.$t2("继续", "components.VabUpload.continue")
128
- : this.$t2("暂停", "components.VabUpload.pause");
129
- },
130
- totalText(total) {
131
- return total > 100 ? 100 : total;
132
- },
133
- },
134
- computed: {
135
- percentage() {
136
- if (this.allImgNum == 0) return 0;
137
- return ((this.imgNum / this.allImgNum, 2) * 100).toFixed(0);
138
- },
139
- fileMaxSize() {
140
- return this.formatFileSize(this.size * 1024 * 1024);
141
- },
142
- errorQuantity() {
143
- return this.fileList.filter((file) => file.status == "fail").length;
144
- },
145
- totalQuantity() {
146
- return this.fileList.length;
147
- },
148
- successQuantity() {
149
- return this.fileList.filter((file) => file.status == "success").length;
150
- },
151
- isMulti: function () {
152
- let isMulti = true;
153
- if (this.multi === "false" || this.multi === false || this.limit === 1) {
154
- isMulti = false;
155
- }
156
- return isMulti;
157
- },
158
- /* 允许上传的文件后缀(小写、去掉点号),为空数组表示不限制 */
159
- allowedFileTypes() {
160
- let types = this.fileTypes;
161
- if (typeof types === "string") {
162
- types = types.split(",");
163
- }
164
- if (!Array.isArray(types)) {
165
- return [];
166
- }
167
- return types
168
- .map((type) => String(type).trim().replace(/^\./, "").toLowerCase())
169
- .filter((type) => !!type);
170
- },
171
- /* 限制了上传格式时用后缀列表覆盖 accept,未限制则沿用外部传入的 accept */
172
- uploadAccept() {
173
- let types = this.allowedFileTypes;
174
- if (!types.length) {
175
- return this.accept;
176
- }
177
- return types.map((type) => "." + type).join(",");
178
- },
179
- allowedFileTypesText() {
180
- return this.allowedFileTypes.join("、");
181
- },
182
- },
183
- methods: {
184
- /* 校验文件后缀是否在允许的上传格式内,未配置格式时一律通过 */
185
- checkFileType(file) {
186
- let types = this.allowedFileTypes;
187
- if (!types.length) {
188
- return true;
189
- }
190
- let suffix = this.$commonFileUtil.getFileSuffix(file.name || "");
191
- return types.indexOf(suffix) > -1;
192
- },
193
- showFileTypeError(fileName) {
194
- this.$message({
195
- message: this.$t2(
196
- "文件[" + fileName + "]格式不支持,仅允许" + this.allowedFileTypesText,
197
- "components.VabUpload.warnMsg4",
198
- {
199
- fileName: fileName,
200
- fileTypes: this.allowedFileTypesText,
201
- }
202
- ),
203
- type: "error",
204
- duration: 3 * 1000,
205
- });
206
- },
207
- openFileLibraryDialog() {
208
- this.$openFileLibraryDialog({
209
- prefix: this.storeAreaPrefix,
210
- storeAreaCode: this.storeAreaCode,
211
- callback: ({ rows, fileRows }) => {
212
- this.addFileLibraryFiles(rows);
213
- },
214
- });
215
- },
216
- initFileLibraryTitle() {
217
- this.fileLibraryName = null;
218
- this.$http({
219
- method: "post",
220
- url: USER_PREFIX + "/file_store_area/getByCode",
221
- data: {
222
- stringOne: this.storeAreaCode,
223
- },
224
- isLoading: true,
225
- success: (res) => {
226
- let fileStoreArea = res.objx;
227
- if (fileStoreArea) {
228
- this.fileLibraryName = fileStoreArea.storeAreaName;
229
- }
230
- },
231
- });
232
- },
233
- updateUploadingStatus() {
234
- var target = this.$refs.upload;
235
- let uploading, hasReadyFile;
236
- if (target) {
237
- var fileList = target.uploadFiles;
238
- let n = fileList.find((item) => {
239
- // return item.percentage != 100;
240
- return item.status == "uploading" || item.status == "preUpload";
241
- });
242
- uploading = n == null ? false : true;
243
-
244
- let readyFiles = fileList.filter((file) => file.status == "ready");
245
- hasReadyFile = readyFiles.length > 0;
246
- } else {
247
- uploading = false;
248
- hasReadyFile = false;
249
- }
250
-
251
- this.uploading = uploading;
252
- this.hasReadyFile = hasReadyFile;
253
- this.checkPreUploadList();
254
- return uploading;
255
- },
256
- submitUpload() {
257
- let successDone = () => {
258
- this.$refs.upload.submit();
259
- };
260
- var files = this.$refs.upload.uploadFiles;
261
- let readyFiles = files.filter((file) => file.status == "ready");
262
- if (this.confirmUpload) {
263
- if (readyFiles.length) {
264
- this.confirmUpload({
265
- files: files,
266
- done: successDone,
267
- });
268
- }
269
- } else {
270
- successDone();
271
- }
272
- },
273
- handleProgress(event, file, fileList) {
274
- // this.loading = true
275
- // this.show = true
276
- },
277
- handleChange(file, fileList) {
278
- /* 格式校验只针对仍在列表中的文件,removeFile 移除后也会回调本方法,不能重复报错 */
279
- if (fileList.indexOf(file) > -1 && !this.checkFileType(file)) {
280
- fileList.splice(fileList.indexOf(file), 1);
281
- this.fileList = fileList;
282
- this.showFileTypeError(file.name);
283
- if (file.raw) {
284
- file.raw.status = "fail";
285
- }
286
- return false;
287
- }
288
- /* size 为 0(或未配置限制)时不做大小校验 */
289
- let maxSize = this.size * 1024 * 1024;
290
- if (maxSize > 0 && file.size > maxSize) {
291
- fileList.map((item, index) => {
292
- if (item === file) {
293
- fileList.splice(index, 1);
294
- }
295
- });
296
- this.fileList = fileList;
297
- let errorText =
298
- "文件[" + file.name + "]大小超出限制" + this.fileMaxSize;
299
- this.$message({
300
- message: this.$t2(errorText, "components.VabUpload.warnMsg1", {
301
- fileName: file.name,
302
- fileMaxSize: this.fileMaxSize,
303
- }),
304
- type: "error",
305
- duration: 3 * 1000,
306
- });
307
- file.raw.status = "fail";
308
- return false;
309
- } else {
310
- this.fileList = fileList;
311
- this.allImgNum = fileList.length;
312
- }
313
- this.updateUploadingStatus();
314
- },
315
- handleSuccess(response, file, fileList) {
316
- if (file.percentage == 100) {
317
- this.imgNum = this.imgNum + 1;
318
- this.imgSuccessNum = this.imgSuccessNum + 1;
319
- }
320
- if (fileList.length === this.imgNum) {
321
- this.fileList = fileList;
322
-
323
- // 添加自动确认功能
324
- // 当所有文件上传完成且 autoConfirmAfterUpload 为 true 时,自动调用 submitImage 方法
325
- if (this.autoConfirmAfterUpload) {
326
- // 使用 nextTick 确保所有文件状态已更新
327
- this.$nextTick(() => {
328
- this.submitImage();
329
- });
330
- return; // 自动确认后直接返回,不执行后续的 setTimeout
331
- }
332
- }
333
-
334
- setTimeout(() => {
335
- this.loading = false;
336
- this.show = false;
337
- }, 1000);
338
- this.updateUploadingStatus();
339
- },
340
- handleError(err, file, fileList) {
341
- this.imgNum = this.imgNum + 1;
342
- this.imgErrorNum = this.imgErrorNum + 1;
343
- setTimeout(() => {
344
- this.loading = false;
345
- this.show = false;
346
- }, 1000);
347
- this.updateUploadingStatus();
348
- },
349
- handleRemove(file, fileList) {
350
- this.imgNum = this.imgNum - 1;
351
- this.allNum = this.allNum - 1;
352
- this.updateUploadingStatus();
353
- },
354
- handlePreview(file) {
355
- this.dialogImageUrl = file.url;
356
- this.dialogVisible = true;
357
- },
358
- handleExceed(files, fileList) {
359
- let errorMsg = `当前限制选择 ${this.limit} 个文件,本次选择了
360
- ${files.length}
361
- 个文件`;
362
- this.$message({
363
- message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
364
- limit: this.limit,
365
- size: files.length,
366
- }),
367
- type: "error",
368
- duration: 5 * 1000,
369
- });
370
- },
371
- handleShow(option) {
372
- this.title = this.$t2("上传", "components.VabUpload.title");
373
- // this.data = data;
374
- this.option = option;
375
- this.clearFileInfo();
376
- this.initPickUploadMode();
377
- this.pasteAreaStatus = false;
378
- this.dialogFormVisible = true;
379
- /*document.removeEventListener('paste', this.pasteEvent);
380
- document.addEventListener('paste', this.pasteEvent);*/
381
-
382
- this.removePasteEvent();
383
- this.addPasteEvent();
384
- this.initFileLibraryTitle();
385
- if (!option.files?.length) {
386
- this.initUploadUrl();
387
- } else {
388
- this.initUploadUrl(() => {
389
- this.handleUpload(option.files);
390
- });
391
- }
392
- },
393
- handleUpload(fileRawList) {
394
- let target = this.$refs.upload;
395
- let innerTarget = target.$refs["upload-inner"];
396
- if (fileRawList.length) {
397
- innerTarget.uploadFiles(fileRawList);
398
- }
399
- },
400
- addPasteEvent() {
401
- document.addEventListener("click", this.blurPasteEvent);
402
- document.addEventListener("paste", this.pasteEvent);
403
- /* if(this.option.copy){
404
-
405
- } */
406
- },
407
- removePasteEvent() {
408
- document.removeEventListener("click", this.blurPasteEvent);
409
- document.removeEventListener("paste", this.pasteEvent);
410
- },
411
- blurPasteEvent() {
412
- this.pasteAreaStatus = false;
413
- },
414
- handleClose() {
415
- let target = this.$refs.upload;
416
- (target.uploadFiles || []).forEach((uploadFile) => {
417
- if (uploadFile.status == "uploading" || uploadFile.status == "ready") {
418
- uploadFile.raw.abort &&
419
- uploadFile.raw.abort(
420
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
421
- );
422
- }
423
- });
424
- this.picture = "picture";
425
- this.clearFileInfo();
426
- this.dialogFormVisible = false;
427
- },
428
- clearFileInfo() {
429
- this.fileList = [];
430
- this.allImgNum = 0;
431
- this.imgNum = 0;
432
- this.imgSuccessNum = 0;
433
- this.imgErrorNum = 0;
434
- },
435
- initUploadUrl(callback) {
436
- let mineUploadUrl = window.BASE_FILEURL;
437
- return this.$http({
438
- url: mineUploadUrl,
439
- method: "post",
440
- data: {
441
- isAuth: false,
442
- },
443
- success: (res) => {
444
- this.uploadUrl = res.objx;
445
- callback && callback();
446
- },
447
- });
448
- },
449
- handleBeforeUpload(file, checkFile, callback) {
450
- /*if (checkFile !== false) {
451
- let target = this.$refs.upload;
452
- let nFile = target.getFile(file);
453
- if (!nFile) {
454
- return false;
455
- }
456
- }
457
- let mineUploadUrl = window.BASE_FILEURL;
458
- return await this.$http({
459
- url: mineUploadUrl,
460
- method: 'post',
461
- data: {
462
- isAuth: false
463
- },
464
- success: res => {
465
- this.uploadUrl = res.objx;
466
- callback && callback()
467
- }
468
- });*/
469
- callback && callback();
470
- },
471
- formatFileSize(fileSize) {
472
- return formatFileSize(fileSize);
473
- },
474
- //自定义上传
475
- async uploadSectionFile(param, isCustom, uploadConfig) {
476
- if (!this.uploadUrl) {
477
- await this.initUploadUrl();
478
- }
479
- let that = this;
480
- var fileObj = param.file;
481
-
482
- let source;
483
-
484
- var form = new FormData();
485
- // 文件对象
486
- form.append("file", fileObj);
487
-
488
- let target = that.$refs.upload;
489
- let file = target ? target.getFile(fileObj) : null;
490
- if (file) {
491
- file.status = "uploading";
492
- }
493
-
494
- let isLoading = uploadConfig?.isLoading === true;
495
- var uploadUrl = this.uploadUrl;
496
- if (uploadUrl) {
497
- var abort;
498
- let config = {
499
- isLoading: isLoading,
500
- headers: {
501
- "Content-Type": "multipart/form-data",
502
- },
503
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
504
- if (!isCustom) {
505
- abort = c;
506
- if (file) file.abort = c;
507
- }
508
- }),
509
- onUploadProgress: (progressEvent) => {
510
- if (isCustom || file) {
511
- // progressEvent.loaded:已上传文件大小
512
- // progressEvent.total:被上传文件的总大小
513
- progressEvent.percent = Math.floor(
514
- (progressEvent.loaded * 100) / progressEvent.total
515
- );
516
- if (!isCustom) {
517
- param.onProgress(progressEvent, fileObj);
518
- }
519
- uploadConfig &&
520
- uploadConfig.onProgress &&
521
- uploadConfig.onProgress(progressEvent, fileObj);
522
- }
523
- },
524
- failMsg: false,
525
- }; //添加请求头
526
-
527
- let req = this.$http
528
- .post(uploadUrl, form, config)
529
- .then((res1) => {
530
- uploadConfig &&
531
- uploadConfig.callback &&
532
- uploadConfig.callback(res1, fileObj);
533
- if (!isCustom) {
534
- if (res1.type == "success") {
535
- param.onSuccess(res1, fileObj);
536
- } else {
537
- // param.onError(new Error(res1.content || '上传异常'));
538
- this.handleFileError(
539
- new Error(
540
- res1.content ||
541
- this.$t2(
542
- "上传异常",
543
- "components.VabUpload.uploadException"
544
- )
545
- ),
546
- fileObj
547
- );
548
- }
549
- }
550
- })
551
- .catch((error, a, b, c) => {
552
- // let {err} = error;
553
- try {
554
- // param.onError(err, fileObj);
555
- if (!isCustom) {
556
- this.handleFileError(error, fileObj);
557
- }
558
- uploadConfig &&
559
- uploadConfig.error &&
560
- uploadConfig.error(error, fileObj);
561
- } catch (tt) {}
562
- });
563
- req.abort = () => {
564
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
565
- };
566
- //return req;
567
- }
568
- },
569
- singerUpload(uploadConfig) {
570
- let onUploadProgress = uploadConfig.onUploadProgress;
571
- let success = uploadConfig.success;
572
- let file = uploadConfig.file;
573
- this.handleBeforeUpload(file, false, () => {
574
- this.uploadSectionFile(
575
- {
576
- file: file,
577
- },
578
- true,
579
- uploadConfig
580
- );
581
- });
582
- },
583
- //begin
584
- fileParse(file, type = "base64", callback) {
585
- /*return new Promise(resolve => {
586
-
587
- });*/
588
- let fileRead = new FileReader();
589
- if (type === "base64") {
590
- fileRead.readAsDataURL(file);
591
- } else if (type === "buffer") {
592
- fileRead.readAsArrayBuffer(file);
593
- }
594
- fileRead.onload = (ev) => {
595
- callback(ev.target.result);
596
- // resolve(ev.target.result);
597
- };
598
- },
599
- getFileMd5(file, callback) {
600
- // 判断是否为大文件(例如大于10MB)
601
- const isLargeFile = file.size > 20 * 1024 * 1024;
602
-
603
- if (!isLargeFile) {
604
- this.fileParse(file, "buffer", (buffer) => {
605
- let spark = new imFun.SparkMD5.ArrayBuffer();
606
- spark.append(buffer);
607
- let hash = spark.end();
608
- callback(hash);
609
- });
610
- } else {
611
- this.calculateFileMD5(file, callback);
612
- }
613
- },
614
- calculateFileMD5(file, callback) {
615
- const chunkSize = 16 * 1024 * 1024; // 2MB一块
616
- const chunks = Math.ceil(file.size / chunkSize);
617
- let currentChunk = 0;
618
- const spark = new imFun.SparkMD5.ArrayBuffer();
619
- const fileReader = new FileReader();
620
-
621
- // 处理读取错误
622
- fileReader.onerror = function () {
623
- console.error("文件读取错误");
624
- callback(null);
625
- };
626
-
627
- // 处理进度回调(可选)
628
- const onProgress = (progress) => {
629
- // 可以在这里更新进度条
630
- console.log("MD5计算进度: " + Math.round(progress * 100) + "%");
631
- };
632
-
633
- // 递归读取下一块
634
- const loadNext = () => {
635
- const start = currentChunk * chunkSize;
636
- const end = Math.min(start + chunkSize, file.size);
637
-
638
- fileReader.readAsArrayBuffer(file.slice(start, end));
639
- };
640
-
641
- // 每块读取完成后的处理
642
- fileReader.onload = function (e) {
643
- spark.append(e.target.result);
644
- currentChunk++;
645
-
646
- // 更新进度
647
- // onProgress(currentChunk / chunks);
648
-
649
- // 继续读取下一块或完成
650
- if (currentChunk < chunks) {
651
- loadNext();
652
- } else {
653
- // 所有块读取完成,计算最终MD5
654
- const md5 = spark.end();
655
- callback(md5);
656
- }
657
- };
658
-
659
- // 开始处理
660
- loadNext();
661
- },
662
- changeFile(param) {
663
- if (!param.file || param.file.status == "fail") return;
664
- let target = this.$refs.upload;
665
- if (!target) return;
666
- let fileObj = target.getFile(param.file);
667
- fileObj.status = "preUpload";
668
- fileObj.param = {
669
- file: param.file,
670
- onSuccess: param.onSuccess,
671
- onProgress: param.onProgress,
672
- onError: param.onError,
673
- };
674
- this.checkPreUploadList();
675
- },
676
- checkPreUploadList() {
677
- let uploadingLimit = this.option.uploadingLimit || this.uploadingLimit;
678
- let target = this.$refs.upload;
679
- let fileList1 = (target.uploadFiles || []).filter((item) => {
680
- return item.status == "preUpload";
681
- });
682
- let fileList2 = (target.uploadFiles || []).filter((item) => {
683
- return item.status == "uploading";
684
- });
685
- if (fileList2.length < uploadingLimit && fileList1.length > 0) {
686
- let num = uploadingLimit - fileList2.length;
687
- if (num) {
688
- let toNum = Math.min(fileList1.length, num);
689
- for (let i = 0; i < toNum; i++) {
690
- let fileRaw = fileList1[i].raw;
691
- this.uploadFile(fileRaw);
692
- }
693
- }
694
- }
695
- },
696
- async uploadFile(file) {
697
- if (!file || file.status == "fail") return;
698
- let target = this.$refs.upload;
699
- if (!target) return;
700
- let fileObj = target.getFile(file);
701
- if (fileObj.status != "preUpload") return;
702
- if (!this.isPartUpload) {
703
- this.uploadSectionFile(fileObj.param);
704
- return;
705
- }
706
-
707
- if (!this.uploadUrl) {
708
- await this.initUploadUrl();
709
- }
710
- this.total = 0;
711
- target.handleProgress({ percent: 0 }, file);
712
-
713
- // 解析为BUFFER数据
714
- // 我们会把文件切片处理:把一个文件分割成为好几个部分(固定数量/固定大小)
715
- // 每一个切片有自己的部分数据和自己的名字
716
- // HASH_1.mp4
717
- // HASH_2.mp4
718
- // ...
719
-
720
- this.getFileMd5(file, (md5) => {
721
- /* let spark = new imFun.SparkMD5.ArrayBuffer(),
722
- chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
723
- chunks = Math.ceil(file.size / chunkSize),
724
- hash,
725
- suffix;
726
- spark.append(buffer);
727
- hash = spark.end(); */
728
-
729
- let chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
730
- chunks = Math.ceil(file.size / chunkSize),
731
- hash = md5,
732
- suffix;
733
-
734
- let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
735
-
736
- suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
737
-
738
- let checkUrl = this.uploadUrl.replace(
739
- "/docfile/upload",
740
- "/docfile/check"
741
- );
742
- let checkData = {
743
- name: file.name,
744
- md5: hash,
745
- };
746
- let abort;
747
- let checkReq = this.$http({
748
- url: checkUrl,
749
- method: "post",
750
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
751
- abort = c;
752
- file.abort = c;
753
- }),
754
- data: checkData,
755
- failMsg: false,
756
- modal: false,
757
- callback: (res) => {
758
- if (res.type == "success") {
759
- let resData = res.objx || {};
760
- let chunkParam = {
761
- fullFile: file,
762
- chunkSize: chunkSize,
763
- chunks: chunks,
764
- chunkIndex: 0,
765
- md5: hash,
766
- uuid: resData.uuid,
767
- };
768
- file.chunkParam = chunkParam;
769
-
770
- this.sendRequest(file);
771
- } else {
772
- this.handleFileError(
773
- new Error(
774
- res.content ||
775
- this.$t2("上传异常", "components.VabUpload.uploadException")
776
- ),
777
- file
778
- );
779
- }
780
- },
781
- error: (e) => {
782
- this.handleFileError(e, file);
783
- },
784
- });
785
- checkReq.abort = () => {
786
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
787
- };
788
- });
789
- },
790
- async sendRequest(fullFile) {
791
- let that = this;
792
- let uploadUrl = this.uploadUrl;
793
- let chunkParam = fullFile.chunkParam;
794
- let target = that.$refs.upload;
795
- let abort;
796
- let config = {
797
- headers: {
798
- "Content-Type": "multipart/form-data",
799
- },
800
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
801
- /* let target = that.$refs.upload;
802
- let filem = target.getFile(file);
803
- abort = c;
804
- filem.abort = c; */
805
- abort = c;
806
- fullFile.abort = c;
807
- }),
808
- onUploadProgress: (progressEvent) => {
809
- if (!target || !fullFile) return;
810
- let file = target.getFile(fullFile);
811
- if (file) {
812
- // progressEvent.loaded:已上传文件大小
813
- // progressEvent.total:被上传文件的总大小
814
- let start = chunkParam.start;
815
- let uploadedSize =
816
- start +
817
- Math.floor(
818
- (chunkParam.currentSize * progressEvent.loaded) /
819
- progressEvent.total
820
- );
821
- let percent = Math.floor((uploadedSize * 100) / fullFile.size);
822
- if (percent == 100) {
823
- percent = 99;
824
- }
825
- progressEvent.percent = percent;
826
- target.handleProgress(progressEvent, fullFile);
827
- }
828
- },
829
- failMsg: false,
830
- modal: false,
831
- }; //添加请求头
832
-
833
- let chunkIndex = chunkParam.chunkIndex;
834
- let chunkSize = chunkParam.chunkSize;
835
- var start = chunkIndex * chunkSize,
836
- end =
837
- start + chunkSize >= fullFile.size
838
- ? fullFile.size
839
- : start + chunkParam.chunkSize;
840
- chunkParam.currentSize = end - start;
841
- chunkParam.start = start;
842
- chunkParam.end = end;
843
-
844
- let preFormData = {
845
- file: fullFile.slice(start, end),
846
- name: fullFile.name,
847
- chunks: chunkParam.chunks,
848
- chunk: chunkIndex,
849
- md5: chunkParam.md5,
850
- uuid: chunkParam.uuid,
851
- fileSize: fullFile.size,
852
- };
853
-
854
- let formData = new FormData();
855
- Object.keys(preFormData).forEach((key) => {
856
- formData.append(key, preFormData[key]);
857
- });
858
-
859
- let req = this.$http
860
- .post(uploadUrl, formData, config)
861
- .then((res1) => {
862
- if (res1.type == "success") {
863
- if (preFormData.chunk + 1 >= preFormData.chunks) {
864
- let mergeData = {};
865
- Object.keys(preFormData).forEach((key) => {
866
- if (key != "file" && key != "chunk") {
867
- mergeData[key] = preFormData[key];
868
- }
869
- });
870
- let _param = {
871
- mergeData: mergeData,
872
- chunkParam: chunkParam,
873
- };
874
- this.mergeFile(_param);
875
- } else {
876
- chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
877
- this.sendRequest(fullFile);
878
- }
879
- } else {
880
- this.handleFileError(
881
- new Error(
882
- res1.content ||
883
- this.$t2("上传异常", "components.VabUpload.uploadException")
884
- ),
885
- fullFile
886
- );
887
- }
888
- return res1;
889
- })
890
- .catch((err) => {
891
- try {
892
- if (!abort) {
893
- this.handleFileError(err, fullFile);
894
- }
895
- } catch (tt) {}
896
- });
897
- req.abort = () => {
898
- abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
899
- };
900
- },
901
- mergeFile(param) {
902
- let mergeData = param.mergeData;
903
- let chunkParam = param.chunkParam;
904
- let fullFile = chunkParam.fullFile;
905
- let mergeUrl = this.uploadUrl.replace(
906
- "/docfile/upload",
907
- "/docfile/merge"
908
- );
909
- let target = this.$refs.upload;
910
- this.$http({
911
- url: mergeUrl,
912
- method: "post",
913
- data: mergeData,
914
- failMsg: false,
915
- modal: false,
916
- cancelToken: new imFun.axios.CancelToken(function executor(c) {
917
- if (fullFile) fullFile.abort = c;
918
- }),
919
- callback: (res) => {
920
- if (!target || !fullFile) return;
921
- if (res.type == "success") {
922
- let file = target.getFile(fullFile);
923
- if (file) {
924
- target.handleProgress(
925
- {
926
- percent: 100,
927
- },
928
- fullFile
929
- );
930
- target.handleSuccess(res, fullFile);
931
- }
932
- } else {
933
- this.handleFileError(
934
- new Error(
935
- res.content ||
936
- this.$t2("上传异常", "components.VabUpload.uploadException")
937
- ),
938
- fullFile
939
- );
940
- }
941
- },
942
- error: (e) => {
943
- if (!target || !fullFile) return;
944
- if (fullFile) {
945
- let file = target.getFile(fullFile);
946
- if (file) {
947
- this.handleFileError(e, fullFile);
948
- }
949
- }
950
- },
951
- });
952
- },
953
- handleBtn() {
954
- let target = this.$refs.upload;
955
- let fileList = (target.uploadFiles || []).filter((item) => {
956
- return item.status == "uploading" || item.status == "ready";
957
- });
958
- if (this.btn) {
959
- //断点续传
960
- this.abort = false;
961
- this.btn = false;
962
- fileList.forEach((uploadFile) => {
963
- let nextChunk = uploadFile.raw.nextChunk;
964
- this.sendRequest(uploadFile.raw.partList, nextChunk);
965
- });
966
- } else {
967
- //暂停上传
968
- fileList.forEach((uploadFile) => {
969
- uploadFile.raw.abort(
970
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
971
- );
972
- });
973
- this.btn = true;
974
- this.abort = true;
975
- }
976
- },
977
- //end
978
- getShowImage(file, fileName) {
979
- fileName = fileName || file.name;
980
- if (this.$commonFileUtil.isPictureFile(fileName)) {
981
- return file.showUrl || file.url;
982
- } else {
983
- return this.$commonFileUtil.getFileIconRequire(fileName);
984
- }
985
- },
986
- removeFile(sfile) {
987
- var target = this.$refs.upload;
988
- var index;
989
- var fileList = target.uploadFiles;
990
- for (let i = 0; i < fileList.length; i++) {
991
- let file = fileList[i];
992
- if (sfile.uid == file.uid) {
993
- index = i;
994
- if (sfile.status == "uploading") {
995
- // file.status == 'delete'
996
- //target.abort(file);
997
- file.raw.abort &&
998
- file.raw.abort(
999
- this.$t2("取消上传", "components.VabUpload.cancelUpload")
1000
- );
1001
- }
1002
- break;
1003
- }
1004
- }
1005
-
1006
- target.uploadFiles.splice(index, 1);
1007
- this.handleChange(sfile, target.uploadFiles);
1008
- },
1009
- submitImage() {
1010
- var target = this.$refs.upload;
1011
- var fileList = target.uploadFiles;
1012
- let fileInfos = [];
1013
- let fileDatas = [];
1014
- for (let i = 0; i < fileList.length; i++) {
1015
- let file = fileList[i];
1016
- if (file.status == "uploading") {
1017
- this.$message({
1018
- message: this.$t2(
1019
- "文件上传中",
1020
- "components.VabUpload.fileUploading"
1021
- ),
1022
- type: "error",
1023
- duration: 2000,
1024
- });
1025
- return;
1026
- }
1027
- if (file.status == "success") {
1028
- let fileData = file.response.objx;
1029
- fileData.name = file.name;
1030
- let fileInfo = {
1031
- name: file.name,
1032
- fileData: fileData,
1033
- file: file.raw,
1034
- };
1035
- fileInfos.push(fileInfo);
1036
- fileDatas.push(fileData);
1037
- }
1038
- }
1039
- this.handleClose();
1040
- this.$emit("callback", fileInfos, fileDatas);
1041
- this.callback && this.callback(fileDatas, fileInfos);
1042
- },
1043
- showViewDialog(lineData) {
1044
- var data = lineData.fileData ? lineData.fileData : lineData;
1045
-
1046
- let thumbnail = data ? data.thumbnail || "" : "";
1047
-
1048
- var realUrl = data.domain + data.url;
1049
- var showUrl = "";
1050
- let fileName = lineData ? lineData.name || "" : "";
1051
- if (!this.$commonFileUtil.isPictureFile(fileName)) {
1052
- showUrl = this.$commonFileUtil.getFileIconRequire(fileName);
1053
- } else if (thumbnail) {
1054
- showUrl = data.domain + thumbnail;
1055
- } else {
1056
- showUrl = data.domain + data.url;
1057
- }
1058
-
1059
- var preName = "";
1060
- var suffix = "";
1061
- var i = fileName.lastIndexOf(".");
1062
- if (i >= 0) {
1063
- suffix = fileName.substring(i + 1, fileName.length).toLowerCase();
1064
- }
1065
- this.fileViewInfo = {
1066
- realUrl: realUrl,
1067
- showUrl: showUrl,
1068
- fileName: fileName,
1069
- suffix: suffix,
1070
- data: data,
1071
- };
1072
- this.fileViewDialogVisible = true;
1073
- },
1074
- getShowUrl(attachment, field) {
1075
- let showUrl = null;
1076
- let typeStr = Object.prototype.toString.call(attachment);
1077
- if (typeStr == "[object Object]") {
1078
- let showField = field ? field : "medium";
1079
- let fullUrl =
1080
- attachment.domain +
1081
- (attachment[showField] ? attachment[showField] : attachment.url);
1082
- showUrl = this.$commonFileUtil.getShowUrl(fullUrl);
1083
- } else {
1084
- showUrl = this.$commonFileUtil.getShowUrl(attachment);
1085
- }
1086
- return showUrl;
1087
- },
1088
- addFileLibraryFiles(rows) {
1089
- var target = this.$refs.upload;
1090
- let uploadFiles = target.uploadFiles;
1091
- let sourceSns = uploadFiles
1092
- .filter((row) => {
1093
- return !!(
1094
- row.response &&
1095
- row.response.objx &&
1096
- row.response.objx.sourceSn
1097
- );
1098
- })
1099
- .map((row) => row.response.objx.sourceSn);
1100
-
1101
- let newFiles = rows
1102
- .filter((row) => !row.dirs && !sourceSns.includes(row.sn))
1103
- .filter((row) => {
1104
- /* 文件库/个人文档选来的文件不走 el-upload,需在此处补做格式校验 */
1105
- if (this.checkFileType({ name: row.fileName })) {
1106
- return true;
1107
- }
1108
- this.showFileTypeError(row.fileName);
1109
- return false;
1110
- })
1111
- .map((row) => {
1112
- let item = {
1113
- status: "success",
1114
- name: row.fileName,
1115
- size: row.fileSize,
1116
- percentage: 100,
1117
- uid: row.fileSn,
1118
- raw: {
1119
- lastModified: "",
1120
- lastModifiedDate: new Date(),
1121
- name: row.fileName,
1122
- size: row.fileSize,
1123
- type: "",
1124
- uid: row.fileSn,
1125
- webkitRelativePath: "",
1126
- },
1127
- response: {
1128
- time: "",
1129
- type: "success",
1130
- objx: {
1131
- thumbnail: row.thumbnail,
1132
- extension: row.extension,
1133
- large: row.large,
1134
- fileSize: row.fileSize,
1135
- domain: row.domain,
1136
- source: row.source,
1137
- medium: row.medium,
1138
- url: row.url,
1139
- sourceSn: row.sn,
1140
-
1141
- attachCode: row.attachCode,
1142
- docCategory: row.docCategory,
1143
- drawingCode: row.drawingCode,
1144
- version: row.version,
1145
- rev: row.rev,
1146
- },
1147
- content: "success",
1148
- rmid: null,
1149
- },
1150
- url: row.domain + row.url,
1151
- showUrl: this.getShowUrl(row),
1152
- };
1153
- return item;
1154
- });
1155
- uploadFiles.push(...newFiles);
1156
- },
1157
- confirmPrivateProfileDialog(rows) {
1158
- this.addFileLibraryFiles(rows);
1159
- },
1160
- initPrivateUploadBt() {
1161
- if (settingConfig.privateProfileCode && this.pickPrivateProfile) {
1162
- this.$http({
1163
- url: USER_PREFIX + "/file_store_area/getByCode",
1164
- method: "post",
1165
- data: { stringOne: settingConfig.privateProfileCode },
1166
- failMsg: false,
1167
- errorMsg: false,
1168
- success: (res) => {
1169
- this.showPrivateUploadBtn = res.objx ? true : false;
1170
- },
1171
- });
1172
- } else {
1173
- this.showPrivateUploadBtn = false;
1174
- }
1175
- },
1176
- initPickUploadMode() {
1177
- this.showLocalUploadBtn = false;
1178
- this.showPrivateUploadBtn = false;
1179
- this.$http({
1180
- url: USER_PREFIX + "/system_parameter/getByCode",
1181
- method: "post",
1182
- data: { code: "pickUploadMode" },
1183
- success: (res) => {
1184
- let value = !res.objx || !res.objx.value ? "2" : res.objx.value;
1185
- if (value == "0") {
1186
- //启用本地上传,个人文档上传
1187
- if (this.option.showLocalUploadBtn !== false)
1188
- this.showLocalUploadBtn = true;
1189
- this.initPrivateUploadBt();
1190
- } else if (value == "1") {
1191
- //启用个人文档上传
1192
- this.initPrivateUploadBt();
1193
- } else if (value == "2") {
1194
- //启用本地上传
1195
- if (this.option.showLocalUploadBtn !== false)
1196
- this.showLocalUploadBtn = true;
1197
- }
1198
- },
1199
- });
1200
- },
1201
- pasteEvent(e) {
1202
- // e.preventDefault();
1203
- e.stopPropagation();
1204
- if (!this.pasteAreaStatus) {
1205
- return;
1206
- }
1207
- if (!(e.clipboardData && e.clipboardData.items)) {
1208
- return;
1209
- }
1210
- let files = Array.from(e.clipboardData.files);
1211
- let getFileSuffix = this.$commonFileUtil.getFileSuffix;
1212
- if (files.length) {
1213
- let fileList = files.map((rawFile) => {
1214
- let name = rawFile.name;
1215
- let index = name.lastIndexOf(".");
1216
- let fileSuffix = getFileSuffix(name);
1217
- let fileName =
1218
- index >= 0 ? name.substring(0, index).toString() : name.toString();
1219
- let file = {
1220
- name: rawFile.name,
1221
- size: rawFile.size,
1222
- raw: rawFile,
1223
- showUrl: URL.createObjectURL(rawFile),
1224
- fileName: fileName,
1225
- fileSuffix: fileSuffix,
1226
- };
1227
- return file;
1228
- });
1229
- this.pasteList.push(...fileList);
1230
- }
1231
- },
1232
- deletePasteFile(index) {
1233
- this.pasteList.splice(index, 1);
1234
- },
1235
- confirmPasteFile() {
1236
- let target = this.$refs.upload;
1237
- let innerTarget = target.$refs["upload-inner"];
1238
- let pasteList = this.$baseLodash.cloneDeep(this.pasteList);
1239
- let files = pasteList.map((item) => {
1240
- let name = item.name;
1241
- let fileRaw = item.raw;
1242
- fileRaw.fileName = name;
1243
- return fileRaw;
1244
- });
1245
- innerTarget.uploadFiles(files);
1246
- this.$nextTick(() => {
1247
- target.uploadFiles.forEach((uploadFile) => {
1248
- let fileRaw = uploadFile.raw;
1249
- if (fileRaw.fileName) {
1250
- uploadFile.name = fileRaw.fileName;
1251
- delete fileRaw.fileName;
1252
- }
1253
- });
1254
- });
1255
- this.pasteList = [];
1256
- },
1257
- changeFileName(file) {
1258
- if (file.fileSuffix) {
1259
- file.name = (file.fileName + "." + file.fileSuffix).toString();
1260
- } else {
1261
- file.name = file.fileName.toString();
1262
- }
1263
- },
1264
- handleFileError(err, rawFile) {
1265
- let target = this.$refs.upload;
1266
- if (!target) return;
1267
- const file = target.getFile(rawFile);
1268
- const fileList = target.uploadFiles;
1269
-
1270
- file.status = "fail";
1271
- file.failMsg = err && err.message ? err.message : null;
1272
-
1273
- // fileList.splice(fileList.indexOf(file), 1);
1274
-
1275
- target.onError(err, file, target.uploadFiles);
1276
- target.onChange(file, target.uploadFiles);
1277
- this.updateUploadingStatus();
1278
- },
1279
- choosePasteArea(e) {
1280
- e.stopPropagation();
1281
- this.pasteAreaStatus = true;
1282
- },
1283
- openFileNameDialog(row, index) {
1284
- this.editFileName = row.fileName?.toString();
1285
- this.editFileSuffix = row.fileSuffix?.toString();
1286
- this.editFileIndex = index;
1287
- this.showFileNameDialog = true;
1288
- },
1289
- confirmFileNameDialog() {
1290
- if (!this.editFileName) {
1291
- this.$message({
1292
- message: this.$t2("文件名不能为空", "components.VabUpload.warnMsg3"),
1293
- type: "error",
1294
- showClose: true,
1295
- duration: 3000,
1296
- });
1297
- return;
1298
- }
1299
- let editFileIndex = this.editFileIndex;
1300
- let file = this.pasteList[editFileIndex];
1301
- file.fileName = this.editFileName.toString();
1302
- file.name = (file.fileName + "." + file.fileSuffix).toString();
1303
- this.showFileNameDialog = false;
1304
- },
1305
- },
1306
- };
1307
-
1308
- tViewMixins = {
1309
- props: {
1310
- resultType: String,
1311
- dataType: String,
1312
- callback: Function,
1313
- file: {
1314
- type: [Array, Object, String],
1315
- },
1316
- multi: {
1317
- type: [String, Boolean],
1318
- default: true,
1319
- },
1320
- auto: {
1321
- type: Boolean,
1322
- default: true,
1323
- },
1324
- limit: {
1325
- type: Number,
1326
- default: 100000,
1327
- },
1328
- /* 单个文件大小限制(MB),0 表示不限制 */
1329
- size: {
1330
- type: Number,
1331
- default: () => {
1332
- return settingConfig.uploadFileSize ?? 200;
1333
- },
1334
- },
1335
- accept: {
1336
- type: String,
1337
- default: "file",
1338
- },
1339
- /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
1340
- fileTypes: {
1341
- type: [Array, String],
1342
- default: () => [],
1343
- },
1344
- chunkSize: {
1345
- type: Number,
1346
- default: 5, //5MB
1347
- },
1348
- confirmUpload: {
1349
- type: Function,
1350
- },
1351
- pickPrivateProfile: {
1352
- type: Boolean,
1353
- default: true,
1354
- },
1355
- uploadingLimit: {
1356
- type: Number,
1357
- default: 5, //5MB
1358
- },
1359
- isPartUpload: {
1360
- type: Boolean,
1361
- default: () => {
1362
- return settingConfig.isPartUpload ?? true;
1363
- },
1364
- },
1365
- autoConfirmAfterPasteUpload: {
1366
- type: Boolean,
1367
- default: false,
1368
- },
1369
- },
1370
- data() {
1371
- return {
1372
- attachments: [],
1373
- pictureList: [],
1374
- pictureDtoList: [],
1375
- showPropertiesDialog: false,
1376
- editAttachment: null,
1377
- showViewer: false,
1378
- chooseIndex: 0,
1379
- fileServerInfo: {},
1380
- model: null,
1381
- };
1382
- },
1383
- computed: {
1384
- fileServerPreviewEnabled() {
1385
- return this.getFileServerPreviewEnabled();
1386
- },
1387
- fileShowImageEnabled() {
1388
- return this.getFileShowImageEnabled();
1389
- },
1390
- fileMaxSize() {
1391
- return this.size;
1392
- },
1393
- showUploadBtn: function () {
1394
- if (!this.isMulti) {
1395
- return this.attachments.length == 0;
1396
- } else {
1397
- return this.limit ? this.limit > this.attachments.length : true;
1398
- }
1399
- },
1400
- isMulti: function () {
1401
- let isMulti = true;
1402
- if (this.multi === "false" || this.multi === false || this.limit === 1) {
1403
- isMulti = false;
1404
- }
1405
- return isMulti;
1406
- },
1407
- },
1408
- watch: {
1409
- file(val) {
1410
- this.initFile();
1411
- },
1412
- attachments(val) {
1413
- let that = this;
1414
- let pictureList = [];
1415
- let pictureDtoList = [];
1416
- if (val) {
1417
- val.forEach((item) => {
1418
- if (item) {
1419
- let typeStr = Object.prototype.toString.call(item);
1420
- if (
1421
- typeStr == "[object Object]" &&
1422
- Object.keys(this.file).length > 0
1423
- ) {
1424
- if (that.$commonFileUtil.isPictureFile(item.url)) {
1425
- pictureList.push(item.domain + item.url);
1426
- pictureDtoList.push(item);
1427
- }
1428
- } else {
1429
- if (that.$commonFileUtil.isPictureFile(item)) {
1430
- pictureList.push(item);
1431
- pictureDtoList.push(item);
1432
- }
1433
- }
1434
- }
1435
- });
1436
- }
1437
- this.pictureList = pictureList;
1438
- this.pictureDtoList = pictureDtoList;
1439
- },
1440
- },
1441
- created() {
1442
- this.initFileServerInfo();
1443
- this.initFile();
1444
- },
1445
- methods: {
1446
- pasteEvent(e) {
1447
- e.stopPropagation();
1448
- if (!(e.clipboardData && e.clipboardData.items)) {
1449
- return;
1450
- }
1451
- let files = Array.from(e.clipboardData.files);
1452
- if (files.length) {
1453
- this.openUploadDialog(files, this.autoConfirmAfterPasteUpload);
1454
- }
1455
- },
1456
- uploadEnterOver() {
1457
- // if (this.isLoading) return;
1458
- document.addEventListener("paste", this.pasteEvent);
1459
- },
1460
- uploadEnterLeave() {
1461
- document.removeEventListener("paste", this.pasteEvent);
1462
- },
1463
- getFileServerPreviewEnabled() {
1464
- let value =
1465
- window.$vueRoot.$store.getters.fileServerInfo
1466
- ?.fileServerPreviewEnabled ??
1467
- settingConfig.fileServerPreviewEnabled ??
1468
- true;
1469
- if (
1470
- this.$attrs.fileServerPreviewEnabled !== null &&
1471
- this.$attrs.fileServerPreviewEnabled !== undefined
1472
- ) {
1473
- value = this.$attrs.fileServerPreviewEnabled;
1474
- }
1475
- return value;
1476
- },
1477
- getFileShowImageEnabled() {
1478
- let value =
1479
- window.$vueRoot.$store.getters.fileServerInfo?.fileShowImageEnabled ??
1480
- settingConfig.fileShowImageEnabled ??
1481
- true;
1482
- if (
1483
- this.$attrs.fileShowImageEnabled !== null &&
1484
- this.$attrs.fileShowImageEnabled !== undefined
1485
- ) {
1486
- value = this.$attrs.fileShowImageEnabled;
1487
- }
1488
- return value;
1489
- },
1490
- openUploadDialog(files, autoConfirmAfterUpload) {
1491
- this.$baseUpload.open({
1492
- files,
1493
- autoConfirmAfterUpload,
1494
- ...this.fileServerInfo,
1495
- ...this._props,
1496
- ...this.$attrs,
1497
- limit: this.limit,
1498
- multi: this.multi,
1499
- accept: this.accept ? this.accept : "file",
1500
- fileTypes: this.fileTypes,
1501
- auto: this.auto,
1502
- size: this.fileMaxSize,
1503
- chunkSize: this.chunkSize,
1504
- callback: this.fileConfirm,
1505
- pickPrivateProfile: this.pickPrivateProfile,
1506
- confirmUpload: this.confirmUpload,
1507
- otherParams: this.$attrs,
1508
- });
1509
- },
1510
- initFileServerInfo() {
1511
- if (this.$attrs.model) {
1512
- this.model = this.$attrs.model;
1513
- // this.fileServerInfo = this.$attrs.fileServerInfo;
1514
- } else {
1515
- this.model =
1516
- window.$vueRoot.$store.getters.fileServerInfo?.model ?? null;
1517
- /* getFileServerInfo(this, (res) => {
1518
- if (res) {
1519
- let fileServerInfo = res;
1520
- this.model = fileServerInfo.model
1521
- this.fileServerInfo = fileServerInfo;
1522
- }else{
1523
- this.model = null;
1524
- this.fileServerInfo = null;
1525
- }
1526
- }) */
1527
- }
1528
- },
1529
- initFile() {
1530
- if (this.file) {
1531
- let typeStr = Object.prototype.toString.call(this.file);
1532
- if (!this.dataType) {
1533
- if (typeStr == "[object Array]") {
1534
- this.attachments = this.file;
1535
- } else if (
1536
- typeStr == "[object Object]" &&
1537
- Object.keys(this.file).length > 0
1538
- ) {
1539
- this.attachments = [this.file];
1540
- } else {
1541
- this.attachments = [];
1542
- }
1543
- } else {
1544
- this.attachments = [this.file];
1545
- }
1546
- } else {
1547
- this.attachments = [];
1548
- }
1549
- },
1550
- deleteFile(index) {
1551
- if (!this.$listeners.delete || this.$listeners.delete(index) !== false) {
1552
- this.attachments.splice(index, 1);
1553
- this.updatePropFile();
1554
- this.$emit("afterDelete", this.attachments);
1555
- }
1556
- },
1557
- fileConfirm(rows, fileInfos) {
1558
- if (rows.length > 0) {
1559
- if (this.isMulti) {
1560
- let limit = this.limit;
1561
- if (limit) {
1562
- let oSize = this.file?.length ?? 0;
1563
- let vailSize = limit - oSize;
1564
- if (vailSize > 0) {
1565
- rows = rows.length < vailSize ? rows : rows.slice(0, vailSize);
1566
- } else {
1567
- rows = [];
1568
- }
1569
- }
1570
- } else {
1571
- rows = [rows[0]];
1572
- }
1573
-
1574
- let attachments = this.attachments;
1575
- let dataType = this.dataType;
1576
- let eRows = [];
1577
- if (dataType != null) {
1578
- eRows = rows.map((row) => {
1579
- return row.domain + (row[dataType] || row["url"]);
1580
- });
1581
- } else {
1582
- eRows = rows;
1583
- }
1584
-
1585
- if (
1586
- !this.$listeners.confirm ||
1587
- this.$listeners.confirm(eRows, fileInfos) !== false
1588
- ) {
1589
- if (this.isMulti) {
1590
- this.attachments = attachments.concat(eRows);
1591
- } else {
1592
- this.attachments = eRows;
1593
- }
1594
- this.updatePropFile();
1595
- this.$emit("callback", eRows, fileInfos);
1596
- }
1597
- }
1598
- },
1599
- updatePropFile() {
1600
- if (this.isMulti) {
1601
- this.$emit("update:file", this.attachments);
1602
- } else {
1603
- let result =
1604
- this.attachments && this.attachments.length
1605
- ? this.attachments[0]
1606
- : null;
1607
- if (
1608
- this.resultType == "Array" ||
1609
- (this.multi !== "false" && this.multi !== false)
1610
- ) {
1611
- result = result ? [result] : [];
1612
- }
1613
- this.$emit("update:file", result);
1614
- }
1615
- this.handleChange();
1616
- },
1617
- handleChange() {
1618
- this.$emit("change", this.attachments);
1619
- },
1620
- getRealPictureList(index) {
1621
- let pictureIndex = -1;
1622
- this.attachments.find((item, i) => {
1623
- let typeStr = Object.prototype.toString.call(item);
1624
- if (typeStr == "[object Object]") {
1625
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1626
- pictureIndex++;
1627
- }
1628
- } else {
1629
- if (this.$commonFileUtil.isPictureFile(item)) {
1630
- pictureIndex++;
1631
- }
1632
- }
1633
- return index == i;
1634
- });
1635
- return this.pictureList
1636
- .slice(pictureIndex)
1637
- .concat(this.pictureList.slice(0, pictureIndex));
1638
- },
1639
- getRealPictureDTOList() {
1640
- let index = this.chooseIndex || 0;
1641
- let pictureIndex = -1;
1642
- this.attachments.find((item, i) => {
1643
- let typeStr = Object.prototype.toString.call(item);
1644
- if (typeStr == "[object Object]") {
1645
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1646
- pictureIndex++;
1647
- }
1648
- } else {
1649
- if (this.$commonFileUtil.isPictureFile(item)) {
1650
- pictureIndex++;
1651
- }
1652
- }
1653
- return index == i;
1654
- });
1655
- let res = this.pictureDtoList
1656
- .slice(pictureIndex)
1657
- .concat(this.pictureDtoList.slice(0, pictureIndex));
1658
- return res;
1659
- },
1660
- openImagePreView(index) {
1661
- // this.chooseIndex = index;
1662
- let pictureIndex = -1;
1663
- this.attachments.find((item, i) => {
1664
- let typeStr = Object.prototype.toString.call(item);
1665
- if (typeStr == "[object Object]") {
1666
- if (this.$commonFileUtil.isPictureFile(item.url)) {
1667
- pictureIndex++;
1668
- }
1669
- } else {
1670
- if (this.$commonFileUtil.isPictureFile(item)) {
1671
- pictureIndex++;
1672
- }
1673
- }
1674
- return index == i;
1675
- });
1676
- this.chooseIndex = pictureIndex;
1677
- this.showViewer = true;
1678
- },
1679
- openPropertiesDialog(attachment) {
1680
- this.editAttachment = attachment;
1681
- this.showPropertiesDialog = true;
1682
- },
1683
- closeViewer() {
1684
- this.showViewer = false;
1685
- },
1686
- hasPreview(attachment) {
1687
- let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1688
- let typeStr = Object.prototype.toString.call(attachment);
1689
- let url =
1690
- typeStr == "[object Object]"
1691
- ? attachment.domain + attachment.url
1692
- : attachment;
1693
- if (fileServerPreviewEnabled) {
1694
- return (
1695
- this.$commonFileUtil.isPictureFile(url) ||
1696
- this.$commonFileUtil.isPreviewFile(url)
1697
- );
1698
- } else {
1699
- return this.$commonFileUtil.isPictureFile(url);
1700
- }
1701
- },
1702
- openPreview(attachment, index) {
1703
- let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1704
- let typeStr = Object.prototype.toString.call(attachment);
1705
- let url =
1706
- typeStr == "[object Object]"
1707
- ? attachment.domain + attachment.url
1708
- : attachment;
1709
- if (this.$commonFileUtil.isPictureFile(url)) {
1710
- this.openImagePreView(index);
1711
- } else if (
1712
- fileServerPreviewEnabled &&
1713
- this.$commonFileUtil.isPreviewFile(url)
1714
- ) {
1715
- this.$openFilePreview(url);
1716
- }
1717
- },
1718
- getAttachmentName(attachment) {
1719
- let name = null;
1720
- let typeStr = Object.prototype.toString.call(attachment);
1721
- if (typeStr == "[object Object]") {
1722
- name = attachment.name;
1723
- } else {
1724
- let url = attachment;
1725
- if (url) {
1726
- var i = url.lastIndexOf("/");
1727
- if (i >= 0) {
1728
- name = url.substring(i + 1, url.length);
1729
- }
1730
- }
1731
- }
1732
- return name;
1733
- },
1734
- getShowUrl(attachment, field) {
1735
- let showUrl = null;
1736
- let showImagePreview = this.getFileShowImageEnabled();
1737
- let typeStr = Object.prototype.toString.call(attachment);
1738
- if (typeStr == "[object Object]") {
1739
- let showField = field ? field : "medium";
1740
- let fullUrl =
1741
- attachment.domain +
1742
- (showImagePreview && attachment[showField]
1743
- ? attachment[showField]
1744
- : attachment.url);
1745
- showUrl = this.$commonFileUtil.getShowUrl(fullUrl, showImagePreview);
1746
- } else {
1747
- showUrl = this.$commonFileUtil.getShowUrl(attachment, showImagePreview);
1748
- }
1749
- return showUrl;
1750
- },
1751
- downloadFile(attachment) {
1752
- let typeStr = Object.prototype.toString.call(attachment);
1753
- if (typeStr == "[object Object]") {
1754
- this.$commonFileUtil.downloadFile(
1755
- attachment.domain + attachment.url,
1756
- attachment.name
1757
- );
1758
- } else {
1759
- this.$commonFileUtil.downloadFile(attachment);
1760
- }
1761
- },
1762
- formatFileSize(fileSize) {
1763
- return formatFileSize(fileSize);
1764
- },
1765
- },
1766
- };
1767
-
1768
- pmixins = {
1769
- name: "propertiesDialog",
1770
- components: {},
1771
- created() {
1772
- this.attachmentDTO = this.$attrs.editAttachment;
1773
- this.current_prefix =
1774
- this.attachmentDTO && this.attachmentDTO.serverName
1775
- ? "/" + this.attachmentDTO.serverName
1776
- : "";
1777
- },
1778
- mounted() {
1779
- this.initTableM1();
1780
- },
1781
- data() {
1782
- return {
1783
- showDialog: true,
1784
- falseValue: false,
1785
- vxeOption: {},
1786
- showContent: true,
1787
- attachmentDTO: {},
1788
- current_prefix: "",
1789
- };
1790
- },
1791
- methods: {
1792
- saveData() {
1793
- this.$refs.editForm.validate((valid) => {
1794
- if (valid) {
1795
- this.$baseConfirm(
1796
- this.$t2("您确定要保存吗?", "components.VabUpload.saveTip")
1797
- ).then(() => {
1798
- let formData = commonDataUtil.handleForm(this.attachmentDTO);
1799
-
1800
- var url = this.current_prefix + "/attachment/attribute/save";
1801
- this.$http({
1802
- url: url,
1803
- method: "post",
1804
- data: formData,
1805
- isLoading: true,
1806
- success: (res) => {
1807
- this.$message({
1808
- message: res.content,
1809
- type: "success",
1810
- duration: 500,
1811
- onClose: (t) => {
1812
- this.reloadContent();
1813
- },
1814
- });
1815
- },
1816
- });
1817
- });
1818
- }
1819
- });
1820
- },
1821
- dialogClose() {
1822
- this.$emit("update:visiable", false);
1823
- },
1824
- reloadContent() {
1825
- this.getData();
1826
- },
1827
- getData() {
1828
- this.$http({
1829
- url: this.current_prefix + "/attachment/attribute/list",
1830
- method: "post",
1831
- data: {
1832
- id: this.attachmentDTO.id,
1833
- },
1834
- isLoading: true,
1835
- // modalStrictly: true,
1836
- success: (res) => {
1837
- this.$set(
1838
- this.attachmentDTO,
1839
- "attachmentAttributeDTOs",
1840
- res.objx || []
1841
- );
1842
- },
1843
- });
1844
- this.getUserBasicInfos();
1845
- },
1846
- getUserBasicInfos() {
1847
- let createBy = this.attachmentDTO.createBy;
1848
- if (!!this.attachmentDTO._createBy || !createBy) return;
1849
- this.$http({
1850
- url: USER_PREFIX + `/userb/getUserBasicInfos`,
1851
- method: "post",
1852
- data: [createBy],
1853
- isLoading: true,
1854
- // modalStrictly: true,
1855
- success: (res) => {
1856
- let _createBy = createBy;
1857
- if (res.objx?.length) {
1858
- let nickName = res.objx[0].nickName;
1859
- let queryCreateInfo =
1860
- window.$vueRoot.$store.getters.queryCreateInfo || "0";
1861
- if (nickName) {
1862
- if (queryCreateInfo == "1") {
1863
- _createBy = createBy + "(" + nickName + ")";
1864
- } else if (queryCreateInfo == "2") {
1865
- _createBy = nickName;
1866
- }
1867
- }
1868
- }
1869
- this.$set(this.attachmentDTO, "_createBy", _createBy);
1870
- },
1871
- });
1872
- },
1873
- initTableM1() {
1874
- //明细
1875
- var that = this;
1876
- const tableRef = "table-m1";
1877
- const tableOption = {
1878
- vue: this,
1879
- tableRef: tableRef,
1880
- tableName: "components_vabUpload_propertiesDialog_list-m1",
1881
- columns: [
1882
- {
1883
- type: "checkbox",
1884
- fixed: "left",
1885
- width: 48,
1886
- resizable: false,
1887
- },
1888
- {
1889
- title: this.$t2("属性名称", "components.VabUpload.attributeName"),
1890
- field: "attributeName",
1891
- width: 200,
1892
- slots: {
1893
- default: "attributeName",
1894
- },
1895
- },
1896
- {
1897
- title: this.$t2("属性值", "components.VabUpload.attributeValue"),
1898
- field: "attributeValue",
1899
- width: 200,
1900
- slots: {
1901
- default: "attributeValue",
1902
- },
1903
- },
1904
- {
1905
- width: 50,
1906
- fixed: "right",
1907
- title: "",
1908
- sortable: false,
1909
- slots: {
1910
- default: "operate",
1911
- },
1912
- },
1913
- ],
1914
- };
1915
- this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
1916
- this.vxeOption = opts;
1917
- });
1918
- this.getData();
1919
- },
1920
- addItem() {
1921
- this.attachmentDTO.attachmentAttributeDTOs.push({});
1922
- },
1923
- formatFileSize(fileSize) {
1924
- return formatFileSize(fileSize);
1925
- },
1926
- },
1927
- };
1928
-
1929
- function getFileServerInfo(that, callback) {
1930
- that.$http({
1931
- url: USER_PREFIX + "/logic_param/getFileServerInfo",
1932
- method: "post",
1933
- data: {},
1934
- failMsg: false,
1935
- errorMsg: false,
1936
- modal: false,
1937
- success: (res) => {
1938
- if (res.objx) {
1939
- callback && callback(res.objx);
1940
- } else {
1941
- callback && callback();
1942
- }
1943
- },
1944
- error: (err) => {
1945
- callback && callback();
1946
- },
1947
- });
1948
- }
1949
-
1950
- function formatFileSize(fileSize) {
1951
- fileSize = fileSize || 0;
1952
- if (fileSize < 1024) {
1953
- return fileSize + "B";
1954
- } else if (fileSize < 1024 * 1024) {
1955
- var temp = fileSize / 1024;
1956
- temp = temp.toFixed(2);
1957
- return temp + "KB";
1958
- } else if (fileSize < 1024 * 1024 * 1024) {
1959
- var temp = fileSize / (1024 * 1024);
1960
- temp = temp.toFixed(2);
1961
- return temp + "MB";
1962
- } else {
1963
- var temp = fileSize / (1024 * 1024 * 1024);
1964
- temp = temp.toFixed(2);
1965
- return temp + "GB";
1966
- }
1967
- }
1968
-
1969
- export const mixins = tmixins;
1970
- export const viewMixins = tViewMixins;
1971
- export const propertiesMixins = pmixins;
1
+ /**version-1.0*/
2
+ let tmixins, tViewMixins, pmixins;
3
+ import axios from "axios";
4
+ import SparkMD5 from "spark-md5";
5
+ import settingConfig from "@/settings.js";
6
+
7
+ let imFun = {
8
+ axios,
9
+ SparkMD5,
10
+ };
11
+
12
+ tmixins = {
13
+ name: "VabUpload",
14
+ props: {
15
+ auto: {
16
+ type: Boolean,
17
+ default: true,
18
+ },
19
+ url: {
20
+ type: String,
21
+ default: "/upload",
22
+ },
23
+ name: {
24
+ type: String,
25
+ default: "file",
26
+ },
27
+ limit: {
28
+ type: Number,
29
+ default: () => 100000,
30
+ },
31
+ /* 单个文件大小限制(MB),0 表示不限制 */
32
+ size: {
33
+ type: Number,
34
+ default: () => {
35
+ return settingConfig.uploadFileSize ?? 200;
36
+ },
37
+ },
38
+ accept: {
39
+ type: String,
40
+ default: "file",
41
+ },
42
+ /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
43
+ fileTypes: {
44
+ type: [Array, String],
45
+ default: () => [],
46
+ },
47
+ chunkSize: {
48
+ type: Number,
49
+ default: 5, //5MB
50
+ },
51
+ confirmUpload: {
52
+ type: Function,
53
+ },
54
+ pickPrivateProfile: {
55
+ type: Boolean,
56
+ default: true,
57
+ },
58
+ multi: {
59
+ type: [String, Boolean],
60
+ default: true,
61
+ },
62
+ uploadingLimit: {
63
+ type: Number,
64
+ default: 5, //5MB
65
+ },
66
+ isPartUpload: {
67
+ type: Boolean,
68
+ default: () => {
69
+ return settingConfig.isPartUpload ?? true;
70
+ },
71
+ },
72
+ autoConfirmAfterUpload: {
73
+ type: Boolean,
74
+ default: false,
75
+ },
76
+ showFileLibraryButton: Boolean,
77
+ storeAreaPrefix: String,
78
+ storeAreaCode: String,
79
+ },
80
+ data() {
81
+ return {
82
+ fileLibraryName: null,
83
+ show: false,
84
+ loading: false,
85
+ dialogVisible: false,
86
+ dialogImageUrl: "",
87
+ action: "",
88
+ headers: {},
89
+ fileList: [],
90
+ picture: "picture",
91
+ allImgNum: 0,
92
+ imgNum: 0,
93
+ imgSuccessNum: 0,
94
+ imgErrorNum: 0,
95
+ typeList: null,
96
+ title: this.$t2("上传", "components.VabUpload.title"),
97
+ dialogFormVisible: false,
98
+ data: {},
99
+ fileViewDialogVisible: false,
100
+ fileViewInfo: {},
101
+ total: 0,
102
+ video: null,
103
+ btn: false,
104
+ filePartMap: {},
105
+ uploading: false,
106
+ hasReadyFile: false,
107
+ showLocalUploadBtn: false,
108
+ showPrivateUploadBtn: false,
109
+ showPrivateProfileDialog: false,
110
+ pasteList: [],
111
+ pasteAreaStatus: false,
112
+ option: {},
113
+ editFileIndex: -1,
114
+ showFileNameDialog: false,
115
+ editFileName: null,
116
+ editFileSuffix: null,
117
+ beforeUploadFlag: false,
118
+ uploadUrl: null,
119
+ };
120
+ },
121
+ beforeDestroy() {
122
+ this.removePasteEvent();
123
+ },
124
+ filters: {
125
+ btnText(btn) {
126
+ return btn
127
+ ? this.$t2("继续", "components.VabUpload.continue")
128
+ : this.$t2("暂停", "components.VabUpload.pause");
129
+ },
130
+ totalText(total) {
131
+ return total > 100 ? 100 : total;
132
+ },
133
+ },
134
+ computed: {
135
+ percentage() {
136
+ if (this.allImgNum == 0) return 0;
137
+ return ((this.imgNum / this.allImgNum, 2) * 100).toFixed(0);
138
+ },
139
+ fileMaxSize() {
140
+ return this.formatFileSize(this.size * 1024 * 1024);
141
+ },
142
+ errorQuantity() {
143
+ return this.fileList.filter((file) => file.status == "fail").length;
144
+ },
145
+ totalQuantity() {
146
+ return this.fileList.length;
147
+ },
148
+ successQuantity() {
149
+ return this.fileList.filter((file) => file.status == "success").length;
150
+ },
151
+ isMulti: function () {
152
+ let isMulti = true;
153
+ if (this.multi === "false" || this.multi === false || this.limit === 1) {
154
+ isMulti = false;
155
+ }
156
+ return isMulti;
157
+ },
158
+ /* 允许上传的文件后缀(小写、去掉点号),为空数组表示不限制 */
159
+ allowedFileTypes() {
160
+ let types = this.fileTypes;
161
+ if (typeof types === "string") {
162
+ types = types.split(",");
163
+ }
164
+ if (!Array.isArray(types)) {
165
+ return [];
166
+ }
167
+ return types
168
+ .map((type) => String(type).trim().replace(/^\./, "").toLowerCase())
169
+ .filter((type) => !!type);
170
+ },
171
+ /* 限制了上传格式时用后缀列表覆盖 accept,未限制则沿用外部传入的 accept */
172
+ uploadAccept() {
173
+ let types = this.allowedFileTypes;
174
+ if (!types.length) {
175
+ return this.accept;
176
+ }
177
+ return types.map((type) => "." + type).join(",");
178
+ },
179
+ allowedFileTypesText() {
180
+ return this.allowedFileTypes.join("、");
181
+ },
182
+ },
183
+ methods: {
184
+ /* 校验文件后缀是否在允许的上传格式内,未配置格式时一律通过 */
185
+ checkFileType(file) {
186
+ let types = this.allowedFileTypes;
187
+ if (!types.length) {
188
+ return true;
189
+ }
190
+ let suffix = this.$commonFileUtil.getFileSuffix(file.name || "");
191
+ return types.indexOf(suffix) > -1;
192
+ },
193
+ showFileTypeError(fileName) {
194
+ this.$message({
195
+ message: this.$t2(
196
+ "文件[" + fileName + "]格式不支持,仅允许" + this.allowedFileTypesText,
197
+ "components.VabUpload.warnMsg4",
198
+ {
199
+ fileName: fileName,
200
+ fileTypes: this.allowedFileTypesText,
201
+ }
202
+ ),
203
+ type: "error",
204
+ duration: 3 * 1000,
205
+ });
206
+ },
207
+ openFileLibraryDialog() {
208
+ this.$openFileLibraryDialog({
209
+ prefix: this.storeAreaPrefix,
210
+ storeAreaCode: this.storeAreaCode,
211
+ callback: ({ rows, fileRows }) => {
212
+ this.addFileLibraryFiles(rows);
213
+ },
214
+ });
215
+ },
216
+ initFileLibraryTitle() {
217
+ this.fileLibraryName = null;
218
+ this.$http({
219
+ method: "post",
220
+ url: USER_PREFIX + "/file_store_area/getByCode",
221
+ data: {
222
+ stringOne: this.storeAreaCode,
223
+ },
224
+ isLoading: true,
225
+ success: (res) => {
226
+ let fileStoreArea = res.objx;
227
+ if (fileStoreArea) {
228
+ this.fileLibraryName = fileStoreArea.storeAreaName;
229
+ }
230
+ },
231
+ });
232
+ },
233
+ updateUploadingStatus() {
234
+ var target = this.$refs.upload;
235
+ let uploading, hasReadyFile;
236
+ if (target) {
237
+ var fileList = target.uploadFiles;
238
+ let n = fileList.find((item) => {
239
+ // return item.percentage != 100;
240
+ return item.status == "uploading" || item.status == "preUpload";
241
+ });
242
+ uploading = n == null ? false : true;
243
+
244
+ let readyFiles = fileList.filter((file) => file.status == "ready");
245
+ hasReadyFile = readyFiles.length > 0;
246
+ } else {
247
+ uploading = false;
248
+ hasReadyFile = false;
249
+ }
250
+
251
+ this.uploading = uploading;
252
+ this.hasReadyFile = hasReadyFile;
253
+ this.checkPreUploadList();
254
+ return uploading;
255
+ },
256
+ submitUpload() {
257
+ let successDone = () => {
258
+ this.$refs.upload.submit();
259
+ };
260
+ var files = this.$refs.upload.uploadFiles;
261
+ let readyFiles = files.filter((file) => file.status == "ready");
262
+ if (this.confirmUpload) {
263
+ if (readyFiles.length) {
264
+ this.confirmUpload({
265
+ files: files,
266
+ done: successDone,
267
+ });
268
+ }
269
+ } else {
270
+ successDone();
271
+ }
272
+ },
273
+ handleProgress(event, file, fileList) {
274
+ // this.loading = true
275
+ // this.show = true
276
+ },
277
+ handleChange(file, fileList) {
278
+ /* 格式校验只针对仍在列表中的文件,removeFile 移除后也会回调本方法,不能重复报错 */
279
+ if (fileList.indexOf(file) > -1 && !this.checkFileType(file)) {
280
+ fileList.splice(fileList.indexOf(file), 1);
281
+ this.fileList = fileList;
282
+ this.showFileTypeError(file.name);
283
+ if (file.raw) {
284
+ file.raw.status = "fail";
285
+ }
286
+ return false;
287
+ }
288
+ /* size 为 0(或未配置限制)时不做大小校验 */
289
+ let maxSize = this.size * 1024 * 1024;
290
+ if (maxSize > 0 && file.size > maxSize) {
291
+ fileList.map((item, index) => {
292
+ if (item === file) {
293
+ fileList.splice(index, 1);
294
+ }
295
+ });
296
+ this.fileList = fileList;
297
+ let errorText =
298
+ "文件[" + file.name + "]大小超出限制" + this.fileMaxSize;
299
+ this.$message({
300
+ message: this.$t2(errorText, "components.VabUpload.warnMsg1", {
301
+ fileName: file.name,
302
+ fileMaxSize: this.fileMaxSize,
303
+ }),
304
+ type: "error",
305
+ duration: 3 * 1000,
306
+ });
307
+ file.raw.status = "fail";
308
+ return false;
309
+ } else {
310
+ this.fileList = fileList;
311
+ this.allImgNum = fileList.length;
312
+ }
313
+ this.updateUploadingStatus();
314
+ },
315
+ handleSuccess(response, file, fileList) {
316
+ if (file.percentage == 100) {
317
+ this.imgNum = this.imgNum + 1;
318
+ this.imgSuccessNum = this.imgSuccessNum + 1;
319
+ }
320
+ if (fileList.length === this.imgNum) {
321
+ this.fileList = fileList;
322
+
323
+ // 添加自动确认功能
324
+ // 当所有文件上传完成且 autoConfirmAfterUpload 为 true 时,自动调用 submitImage 方法
325
+ if (this.autoConfirmAfterUpload) {
326
+ // 使用 nextTick 确保所有文件状态已更新
327
+ this.$nextTick(() => {
328
+ this.submitImage();
329
+ });
330
+ return; // 自动确认后直接返回,不执行后续的 setTimeout
331
+ }
332
+ }
333
+
334
+ setTimeout(() => {
335
+ this.loading = false;
336
+ this.show = false;
337
+ }, 1000);
338
+ this.updateUploadingStatus();
339
+ },
340
+ handleError(err, file, fileList) {
341
+ this.imgNum = this.imgNum + 1;
342
+ this.imgErrorNum = this.imgErrorNum + 1;
343
+ setTimeout(() => {
344
+ this.loading = false;
345
+ this.show = false;
346
+ }, 1000);
347
+ this.updateUploadingStatus();
348
+ },
349
+ handleRemove(file, fileList) {
350
+ this.imgNum = this.imgNum - 1;
351
+ this.allNum = this.allNum - 1;
352
+ this.updateUploadingStatus();
353
+ },
354
+ handlePreview(file) {
355
+ this.dialogImageUrl = file.url;
356
+ this.dialogVisible = true;
357
+ },
358
+ handleExceed(files, fileList) {
359
+ let errorMsg = `当前限制选择 ${this.limit} 个文件,本次选择了
360
+ ${files.length}
361
+ 个文件`;
362
+ this.$message({
363
+ message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
364
+ limit: this.limit,
365
+ size: files.length,
366
+ }),
367
+ type: "error",
368
+ duration: 5 * 1000,
369
+ });
370
+ },
371
+ handleShow(option) {
372
+ this.title = this.$t2("上传", "components.VabUpload.title");
373
+ // this.data = data;
374
+ this.option = option;
375
+ this.clearFileInfo();
376
+ this.initPickUploadMode();
377
+ this.pasteAreaStatus = false;
378
+ this.dialogFormVisible = true;
379
+ /*document.removeEventListener('paste', this.pasteEvent);
380
+ document.addEventListener('paste', this.pasteEvent);*/
381
+
382
+ this.removePasteEvent();
383
+ this.addPasteEvent();
384
+ this.initFileLibraryTitle();
385
+ if (!option.files?.length) {
386
+ this.initUploadUrl();
387
+ } else {
388
+ this.initUploadUrl(() => {
389
+ this.handleUpload(option.files);
390
+ });
391
+ }
392
+ },
393
+ handleUpload(fileRawList) {
394
+ let target = this.$refs.upload;
395
+ let innerTarget = target.$refs["upload-inner"];
396
+ if (fileRawList.length) {
397
+ innerTarget.uploadFiles(fileRawList);
398
+ }
399
+ },
400
+ addPasteEvent() {
401
+ document.addEventListener("click", this.blurPasteEvent);
402
+ document.addEventListener("paste", this.pasteEvent);
403
+ /* if(this.option.copy){
404
+
405
+ } */
406
+ },
407
+ removePasteEvent() {
408
+ document.removeEventListener("click", this.blurPasteEvent);
409
+ document.removeEventListener("paste", this.pasteEvent);
410
+ },
411
+ blurPasteEvent() {
412
+ this.pasteAreaStatus = false;
413
+ },
414
+ handleClose() {
415
+ let target = this.$refs.upload;
416
+ (target.uploadFiles || []).forEach((uploadFile) => {
417
+ if (uploadFile.status == "uploading" || uploadFile.status == "ready") {
418
+ uploadFile.raw.abort &&
419
+ uploadFile.raw.abort(
420
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
421
+ );
422
+ }
423
+ });
424
+ this.picture = "picture";
425
+ this.clearFileInfo();
426
+ this.dialogFormVisible = false;
427
+ },
428
+ clearFileInfo() {
429
+ this.fileList = [];
430
+ this.allImgNum = 0;
431
+ this.imgNum = 0;
432
+ this.imgSuccessNum = 0;
433
+ this.imgErrorNum = 0;
434
+ },
435
+ initUploadUrl(callback) {
436
+ let mineUploadUrl = window.BASE_FILEURL;
437
+ return this.$http({
438
+ url: mineUploadUrl,
439
+ method: "post",
440
+ data: {
441
+ isAuth: false,
442
+ },
443
+ success: (res) => {
444
+ this.uploadUrl = res.objx;
445
+ callback && callback();
446
+ },
447
+ });
448
+ },
449
+ handleBeforeUpload(file, checkFile, callback) {
450
+ /*if (checkFile !== false) {
451
+ let target = this.$refs.upload;
452
+ let nFile = target.getFile(file);
453
+ if (!nFile) {
454
+ return false;
455
+ }
456
+ }
457
+ let mineUploadUrl = window.BASE_FILEURL;
458
+ return await this.$http({
459
+ url: mineUploadUrl,
460
+ method: 'post',
461
+ data: {
462
+ isAuth: false
463
+ },
464
+ success: res => {
465
+ this.uploadUrl = res.objx;
466
+ callback && callback()
467
+ }
468
+ });*/
469
+ callback && callback();
470
+ },
471
+ formatFileSize(fileSize) {
472
+ return formatFileSize(fileSize);
473
+ },
474
+ //自定义上传
475
+ async uploadSectionFile(param, isCustom, uploadConfig) {
476
+ if (!this.uploadUrl) {
477
+ await this.initUploadUrl();
478
+ }
479
+ let that = this;
480
+ var fileObj = param.file;
481
+
482
+ let source;
483
+
484
+ var form = new FormData();
485
+ // 文件对象
486
+ form.append("file", fileObj);
487
+
488
+ let target = that.$refs.upload;
489
+ let file = target ? target.getFile(fileObj) : null;
490
+ if (file) {
491
+ file.status = "uploading";
492
+ }
493
+
494
+ let isLoading = uploadConfig?.isLoading === true;
495
+ var uploadUrl = this.uploadUrl;
496
+ if (uploadUrl) {
497
+ var abort;
498
+ let config = {
499
+ isLoading: isLoading,
500
+ headers: {
501
+ "Content-Type": "multipart/form-data",
502
+ },
503
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
504
+ if (!isCustom) {
505
+ abort = c;
506
+ if (file) file.abort = c;
507
+ }
508
+ }),
509
+ onUploadProgress: (progressEvent) => {
510
+ if (isCustom || file) {
511
+ // progressEvent.loaded:已上传文件大小
512
+ // progressEvent.total:被上传文件的总大小
513
+ progressEvent.percent = Math.floor(
514
+ (progressEvent.loaded * 100) / progressEvent.total
515
+ );
516
+ if (!isCustom) {
517
+ param.onProgress(progressEvent, fileObj);
518
+ }
519
+ uploadConfig &&
520
+ uploadConfig.onProgress &&
521
+ uploadConfig.onProgress(progressEvent, fileObj);
522
+ }
523
+ },
524
+ failMsg: false,
525
+ }; //添加请求头
526
+
527
+ let req = this.$http
528
+ .post(uploadUrl, form, config)
529
+ .then((res1) => {
530
+ uploadConfig &&
531
+ uploadConfig.callback &&
532
+ uploadConfig.callback(res1, fileObj);
533
+ if (!isCustom) {
534
+ if (res1.type == "success") {
535
+ param.onSuccess(res1, fileObj);
536
+ } else {
537
+ // param.onError(new Error(res1.content || '上传异常'));
538
+ this.handleFileError(
539
+ new Error(
540
+ res1.content ||
541
+ this.$t2(
542
+ "上传异常",
543
+ "components.VabUpload.uploadException"
544
+ )
545
+ ),
546
+ fileObj
547
+ );
548
+ }
549
+ }
550
+ })
551
+ .catch((error, a, b, c) => {
552
+ // let {err} = error;
553
+ try {
554
+ // param.onError(err, fileObj);
555
+ if (!isCustom) {
556
+ this.handleFileError(error, fileObj);
557
+ }
558
+ uploadConfig &&
559
+ uploadConfig.error &&
560
+ uploadConfig.error(error, fileObj);
561
+ } catch (tt) {}
562
+ });
563
+ req.abort = () => {
564
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
565
+ };
566
+ //return req;
567
+ }
568
+ },
569
+ singerUpload(uploadConfig) {
570
+ let onUploadProgress = uploadConfig.onUploadProgress;
571
+ let success = uploadConfig.success;
572
+ let file = uploadConfig.file;
573
+ this.handleBeforeUpload(file, false, () => {
574
+ this.uploadSectionFile(
575
+ {
576
+ file: file,
577
+ },
578
+ true,
579
+ uploadConfig
580
+ );
581
+ });
582
+ },
583
+ //begin
584
+ fileParse(file, type = "base64", callback) {
585
+ /*return new Promise(resolve => {
586
+
587
+ });*/
588
+ let fileRead = new FileReader();
589
+ if (type === "base64") {
590
+ fileRead.readAsDataURL(file);
591
+ } else if (type === "buffer") {
592
+ fileRead.readAsArrayBuffer(file);
593
+ }
594
+ fileRead.onload = (ev) => {
595
+ callback(ev.target.result);
596
+ // resolve(ev.target.result);
597
+ };
598
+ },
599
+ getFileMd5(file, callback) {
600
+ // 判断是否为大文件(例如大于10MB)
601
+ const isLargeFile = file.size > 20 * 1024 * 1024;
602
+
603
+ if (!isLargeFile) {
604
+ this.fileParse(file, "buffer", (buffer) => {
605
+ let spark = new imFun.SparkMD5.ArrayBuffer();
606
+ spark.append(buffer);
607
+ let hash = spark.end();
608
+ callback(hash);
609
+ });
610
+ } else {
611
+ this.calculateFileMD5(file, callback);
612
+ }
613
+ },
614
+ calculateFileMD5(file, callback) {
615
+ const chunkSize = 16 * 1024 * 1024; // 2MB一块
616
+ const chunks = Math.ceil(file.size / chunkSize);
617
+ let currentChunk = 0;
618
+ const spark = new imFun.SparkMD5.ArrayBuffer();
619
+ const fileReader = new FileReader();
620
+
621
+ // 处理读取错误
622
+ fileReader.onerror = function () {
623
+ console.error("文件读取错误");
624
+ callback(null);
625
+ };
626
+
627
+ // 处理进度回调(可选)
628
+ const onProgress = (progress) => {
629
+ // 可以在这里更新进度条
630
+ console.log("MD5计算进度: " + Math.round(progress * 100) + "%");
631
+ };
632
+
633
+ // 递归读取下一块
634
+ const loadNext = () => {
635
+ const start = currentChunk * chunkSize;
636
+ const end = Math.min(start + chunkSize, file.size);
637
+
638
+ fileReader.readAsArrayBuffer(file.slice(start, end));
639
+ };
640
+
641
+ // 每块读取完成后的处理
642
+ fileReader.onload = function (e) {
643
+ spark.append(e.target.result);
644
+ currentChunk++;
645
+
646
+ // 更新进度
647
+ // onProgress(currentChunk / chunks);
648
+
649
+ // 继续读取下一块或完成
650
+ if (currentChunk < chunks) {
651
+ loadNext();
652
+ } else {
653
+ // 所有块读取完成,计算最终MD5
654
+ const md5 = spark.end();
655
+ callback(md5);
656
+ }
657
+ };
658
+
659
+ // 开始处理
660
+ loadNext();
661
+ },
662
+ changeFile(param) {
663
+ if (!param.file || param.file.status == "fail") return;
664
+ let target = this.$refs.upload;
665
+ if (!target) return;
666
+ let fileObj = target.getFile(param.file);
667
+ fileObj.status = "preUpload";
668
+ fileObj.param = {
669
+ file: param.file,
670
+ onSuccess: param.onSuccess,
671
+ onProgress: param.onProgress,
672
+ onError: param.onError,
673
+ };
674
+ this.checkPreUploadList();
675
+ },
676
+ checkPreUploadList() {
677
+ let uploadingLimit = this.option.uploadingLimit || this.uploadingLimit;
678
+ let target = this.$refs.upload;
679
+ let fileList1 = (target.uploadFiles || []).filter((item) => {
680
+ return item.status == "preUpload";
681
+ });
682
+ let fileList2 = (target.uploadFiles || []).filter((item) => {
683
+ return item.status == "uploading";
684
+ });
685
+ if (fileList2.length < uploadingLimit && fileList1.length > 0) {
686
+ let num = uploadingLimit - fileList2.length;
687
+ if (num) {
688
+ let toNum = Math.min(fileList1.length, num);
689
+ for (let i = 0; i < toNum; i++) {
690
+ let fileRaw = fileList1[i].raw;
691
+ this.uploadFile(fileRaw);
692
+ }
693
+ }
694
+ }
695
+ },
696
+ async uploadFile(file) {
697
+ if (!file || file.status == "fail") return;
698
+ let target = this.$refs.upload;
699
+ if (!target) return;
700
+ let fileObj = target.getFile(file);
701
+ if (fileObj.status != "preUpload") return;
702
+ if (!this.isPartUpload) {
703
+ this.uploadSectionFile(fileObj.param);
704
+ return;
705
+ }
706
+
707
+ if (!this.uploadUrl) {
708
+ await this.initUploadUrl();
709
+ }
710
+ this.total = 0;
711
+ target.handleProgress({ percent: 0 }, file);
712
+
713
+ // 解析为BUFFER数据
714
+ // 我们会把文件切片处理:把一个文件分割成为好几个部分(固定数量/固定大小)
715
+ // 每一个切片有自己的部分数据和自己的名字
716
+ // HASH_1.mp4
717
+ // HASH_2.mp4
718
+ // ...
719
+
720
+ this.getFileMd5(file, (md5) => {
721
+ /* let spark = new imFun.SparkMD5.ArrayBuffer(),
722
+ chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
723
+ chunks = Math.ceil(file.size / chunkSize),
724
+ hash,
725
+ suffix;
726
+ spark.append(buffer);
727
+ hash = spark.end(); */
728
+
729
+ let chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
730
+ chunks = Math.ceil(file.size / chunkSize),
731
+ hash = md5,
732
+ suffix;
733
+
734
+ let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
735
+
736
+ suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
737
+
738
+ let checkUrl = this.uploadUrl.replace(
739
+ "/docfile/upload",
740
+ "/docfile/check"
741
+ );
742
+ let checkData = {
743
+ name: file.name,
744
+ md5: hash,
745
+ };
746
+ let abort;
747
+ let checkReq = this.$http({
748
+ url: checkUrl,
749
+ method: "post",
750
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
751
+ abort = c;
752
+ file.abort = c;
753
+ }),
754
+ data: checkData,
755
+ failMsg: false,
756
+ modal: false,
757
+ callback: (res) => {
758
+ if (res.type == "success") {
759
+ let resData = res.objx || {};
760
+ let chunkParam = {
761
+ fullFile: file,
762
+ chunkSize: chunkSize,
763
+ chunks: chunks,
764
+ chunkIndex: 0,
765
+ md5: hash,
766
+ uuid: resData.uuid,
767
+ };
768
+ file.chunkParam = chunkParam;
769
+
770
+ this.sendRequest(file);
771
+ } else {
772
+ this.handleFileError(
773
+ new Error(
774
+ res.content ||
775
+ this.$t2("上传异常", "components.VabUpload.uploadException")
776
+ ),
777
+ file
778
+ );
779
+ }
780
+ },
781
+ error: (e) => {
782
+ this.handleFileError(e, file);
783
+ },
784
+ });
785
+ checkReq.abort = () => {
786
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
787
+ };
788
+ });
789
+ },
790
+ async sendRequest(fullFile) {
791
+ let that = this;
792
+ let uploadUrl = this.uploadUrl;
793
+ let chunkParam = fullFile.chunkParam;
794
+ let target = that.$refs.upload;
795
+ let abort;
796
+ let config = {
797
+ headers: {
798
+ "Content-Type": "multipart/form-data",
799
+ },
800
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
801
+ /* let target = that.$refs.upload;
802
+ let filem = target.getFile(file);
803
+ abort = c;
804
+ filem.abort = c; */
805
+ abort = c;
806
+ fullFile.abort = c;
807
+ }),
808
+ onUploadProgress: (progressEvent) => {
809
+ if (!target || !fullFile) return;
810
+ let file = target.getFile(fullFile);
811
+ if (file) {
812
+ // progressEvent.loaded:已上传文件大小
813
+ // progressEvent.total:被上传文件的总大小
814
+ let start = chunkParam.start;
815
+ let uploadedSize =
816
+ start +
817
+ Math.floor(
818
+ (chunkParam.currentSize * progressEvent.loaded) /
819
+ progressEvent.total
820
+ );
821
+ let percent = Math.floor((uploadedSize * 100) / fullFile.size);
822
+ if (percent == 100) {
823
+ percent = 99;
824
+ }
825
+ progressEvent.percent = percent;
826
+ target.handleProgress(progressEvent, fullFile);
827
+ }
828
+ },
829
+ failMsg: false,
830
+ modal: false,
831
+ }; //添加请求头
832
+
833
+ let chunkIndex = chunkParam.chunkIndex;
834
+ let chunkSize = chunkParam.chunkSize;
835
+ var start = chunkIndex * chunkSize,
836
+ end =
837
+ start + chunkSize >= fullFile.size
838
+ ? fullFile.size
839
+ : start + chunkParam.chunkSize;
840
+ chunkParam.currentSize = end - start;
841
+ chunkParam.start = start;
842
+ chunkParam.end = end;
843
+
844
+ let preFormData = {
845
+ file: fullFile.slice(start, end),
846
+ name: fullFile.name,
847
+ chunks: chunkParam.chunks,
848
+ chunk: chunkIndex,
849
+ md5: chunkParam.md5,
850
+ uuid: chunkParam.uuid,
851
+ fileSize: fullFile.size,
852
+ };
853
+
854
+ let formData = new FormData();
855
+ Object.keys(preFormData).forEach((key) => {
856
+ formData.append(key, preFormData[key]);
857
+ });
858
+
859
+ let req = this.$http
860
+ .post(uploadUrl, formData, config)
861
+ .then((res1) => {
862
+ if (res1.type == "success") {
863
+ if (preFormData.chunk + 1 >= preFormData.chunks) {
864
+ let mergeData = {};
865
+ Object.keys(preFormData).forEach((key) => {
866
+ if (key != "file" && key != "chunk") {
867
+ mergeData[key] = preFormData[key];
868
+ }
869
+ });
870
+ let _param = {
871
+ mergeData: mergeData,
872
+ chunkParam: chunkParam,
873
+ };
874
+ this.mergeFile(_param);
875
+ } else {
876
+ chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
877
+ this.sendRequest(fullFile);
878
+ }
879
+ } else {
880
+ this.handleFileError(
881
+ new Error(
882
+ res1.content ||
883
+ this.$t2("上传异常", "components.VabUpload.uploadException")
884
+ ),
885
+ fullFile
886
+ );
887
+ }
888
+ return res1;
889
+ })
890
+ .catch((err) => {
891
+ try {
892
+ if (!abort) {
893
+ this.handleFileError(err, fullFile);
894
+ }
895
+ } catch (tt) {}
896
+ });
897
+ req.abort = () => {
898
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
899
+ };
900
+ },
901
+ mergeFile(param) {
902
+ let mergeData = param.mergeData;
903
+ let chunkParam = param.chunkParam;
904
+ let fullFile = chunkParam.fullFile;
905
+ let mergeUrl = this.uploadUrl.replace(
906
+ "/docfile/upload",
907
+ "/docfile/merge"
908
+ );
909
+ let target = this.$refs.upload;
910
+ this.$http({
911
+ url: mergeUrl,
912
+ method: "post",
913
+ data: mergeData,
914
+ failMsg: false,
915
+ modal: false,
916
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
917
+ if (fullFile) fullFile.abort = c;
918
+ }),
919
+ callback: (res) => {
920
+ if (!target || !fullFile) return;
921
+ if (res.type == "success") {
922
+ let file = target.getFile(fullFile);
923
+ if (file) {
924
+ target.handleProgress(
925
+ {
926
+ percent: 100,
927
+ },
928
+ fullFile
929
+ );
930
+ target.handleSuccess(res, fullFile);
931
+ }
932
+ } else {
933
+ this.handleFileError(
934
+ new Error(
935
+ res.content ||
936
+ this.$t2("上传异常", "components.VabUpload.uploadException")
937
+ ),
938
+ fullFile
939
+ );
940
+ }
941
+ },
942
+ error: (e) => {
943
+ if (!target || !fullFile) return;
944
+ if (fullFile) {
945
+ let file = target.getFile(fullFile);
946
+ if (file) {
947
+ this.handleFileError(e, fullFile);
948
+ }
949
+ }
950
+ },
951
+ });
952
+ },
953
+ handleBtn() {
954
+ let target = this.$refs.upload;
955
+ let fileList = (target.uploadFiles || []).filter((item) => {
956
+ return item.status == "uploading" || item.status == "ready";
957
+ });
958
+ if (this.btn) {
959
+ //断点续传
960
+ this.abort = false;
961
+ this.btn = false;
962
+ fileList.forEach((uploadFile) => {
963
+ let nextChunk = uploadFile.raw.nextChunk;
964
+ this.sendRequest(uploadFile.raw.partList, nextChunk);
965
+ });
966
+ } else {
967
+ //暂停上传
968
+ fileList.forEach((uploadFile) => {
969
+ uploadFile.raw.abort(
970
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
971
+ );
972
+ });
973
+ this.btn = true;
974
+ this.abort = true;
975
+ }
976
+ },
977
+ //end
978
+ getShowImage(file, fileName) {
979
+ fileName = fileName || file.name;
980
+ if (this.$commonFileUtil.isPictureFile(fileName)) {
981
+ return file.showUrl || file.url;
982
+ } else {
983
+ return this.$commonFileUtil.getFileIconRequire(fileName);
984
+ }
985
+ },
986
+ removeFile(sfile) {
987
+ var target = this.$refs.upload;
988
+ var index;
989
+ var fileList = target.uploadFiles;
990
+ for (let i = 0; i < fileList.length; i++) {
991
+ let file = fileList[i];
992
+ if (sfile.uid == file.uid) {
993
+ index = i;
994
+ if (sfile.status == "uploading") {
995
+ // file.status == 'delete'
996
+ //target.abort(file);
997
+ file.raw.abort &&
998
+ file.raw.abort(
999
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
1000
+ );
1001
+ }
1002
+ break;
1003
+ }
1004
+ }
1005
+
1006
+ target.uploadFiles.splice(index, 1);
1007
+ this.handleChange(sfile, target.uploadFiles);
1008
+ },
1009
+ submitImage() {
1010
+ var target = this.$refs.upload;
1011
+ var fileList = target.uploadFiles;
1012
+ let fileInfos = [];
1013
+ let fileDatas = [];
1014
+ for (let i = 0; i < fileList.length; i++) {
1015
+ let file = fileList[i];
1016
+ if (file.status == "uploading") {
1017
+ this.$message({
1018
+ message: this.$t2(
1019
+ "文件上传中",
1020
+ "components.VabUpload.fileUploading"
1021
+ ),
1022
+ type: "error",
1023
+ duration: 2000,
1024
+ });
1025
+ return;
1026
+ }
1027
+ if (file.status == "success") {
1028
+ let fileData = file.response.objx;
1029
+ fileData.name = file.name;
1030
+ let fileInfo = {
1031
+ name: file.name,
1032
+ fileData: fileData,
1033
+ file: file.raw,
1034
+ };
1035
+ fileInfos.push(fileInfo);
1036
+ fileDatas.push(fileData);
1037
+ }
1038
+ }
1039
+ this.handleClose();
1040
+ this.$emit("callback", fileInfos, fileDatas);
1041
+ this.callback && this.callback(fileDatas, fileInfos);
1042
+ },
1043
+ showViewDialog(lineData) {
1044
+ var data = lineData.fileData ? lineData.fileData : lineData;
1045
+
1046
+ let thumbnail = data ? data.thumbnail || "" : "";
1047
+
1048
+ var realUrl = data.domain + data.url;
1049
+ var showUrl = "";
1050
+ let fileName = lineData ? lineData.name || "" : "";
1051
+ if (!this.$commonFileUtil.isPictureFile(fileName)) {
1052
+ showUrl = this.$commonFileUtil.getFileIconRequire(fileName);
1053
+ } else if (thumbnail) {
1054
+ showUrl = data.domain + thumbnail;
1055
+ } else {
1056
+ showUrl = data.domain + data.url;
1057
+ }
1058
+
1059
+ var preName = "";
1060
+ var suffix = "";
1061
+ var i = fileName.lastIndexOf(".");
1062
+ if (i >= 0) {
1063
+ suffix = fileName.substring(i + 1, fileName.length).toLowerCase();
1064
+ }
1065
+ this.fileViewInfo = {
1066
+ realUrl: realUrl,
1067
+ showUrl: showUrl,
1068
+ fileName: fileName,
1069
+ suffix: suffix,
1070
+ data: data,
1071
+ };
1072
+ this.fileViewDialogVisible = true;
1073
+ },
1074
+ getShowUrl(attachment, field) {
1075
+ let showUrl = null;
1076
+ let typeStr = Object.prototype.toString.call(attachment);
1077
+ if (typeStr == "[object Object]") {
1078
+ let showField = field ? field : "medium";
1079
+ let fullUrl =
1080
+ attachment.domain +
1081
+ (attachment[showField] ? attachment[showField] : attachment.url);
1082
+ showUrl = this.$commonFileUtil.getShowUrl(fullUrl);
1083
+ } else {
1084
+ showUrl = this.$commonFileUtil.getShowUrl(attachment);
1085
+ }
1086
+ return showUrl;
1087
+ },
1088
+ addFileLibraryFiles(rows) {
1089
+ var target = this.$refs.upload;
1090
+ let uploadFiles = target.uploadFiles;
1091
+ let sourceSns = uploadFiles
1092
+ .filter((row) => {
1093
+ return !!(
1094
+ row.response &&
1095
+ row.response.objx &&
1096
+ row.response.objx.sourceSn
1097
+ );
1098
+ })
1099
+ .map((row) => row.response.objx.sourceSn);
1100
+
1101
+ let newFiles = rows
1102
+ .filter((row) => !row.dirs && !sourceSns.includes(row.sn))
1103
+ .filter((row) => {
1104
+ /* 文件库/个人文档选来的文件不走 el-upload,需在此处补做格式校验 */
1105
+ if (this.checkFileType({ name: row.fileName })) {
1106
+ return true;
1107
+ }
1108
+ this.showFileTypeError(row.fileName);
1109
+ return false;
1110
+ })
1111
+ .map((row) => {
1112
+ let item = {
1113
+ status: "success",
1114
+ name: row.fileName,
1115
+ size: row.fileSize,
1116
+ percentage: 100,
1117
+ uid: row.fileSn,
1118
+ raw: {
1119
+ lastModified: "",
1120
+ lastModifiedDate: new Date(),
1121
+ name: row.fileName,
1122
+ size: row.fileSize,
1123
+ type: "",
1124
+ uid: row.fileSn,
1125
+ webkitRelativePath: "",
1126
+ },
1127
+ response: {
1128
+ time: "",
1129
+ type: "success",
1130
+ objx: {
1131
+ thumbnail: row.thumbnail,
1132
+ extension: row.extension,
1133
+ large: row.large,
1134
+ fileSize: row.fileSize,
1135
+ domain: row.domain,
1136
+ source: row.source,
1137
+ medium: row.medium,
1138
+ url: row.url,
1139
+ sourceSn: row.sn,
1140
+
1141
+ attachCode: row.attachCode,
1142
+ docCategory: row.docCategory,
1143
+ drawingCode: row.drawingCode,
1144
+ version: row.version,
1145
+ rev: row.rev,
1146
+ },
1147
+ content: "success",
1148
+ rmid: null,
1149
+ },
1150
+ url: row.domain + row.url,
1151
+ showUrl: this.getShowUrl(row),
1152
+ };
1153
+ return item;
1154
+ });
1155
+ uploadFiles.push(...newFiles);
1156
+ },
1157
+ confirmPrivateProfileDialog(rows) {
1158
+ this.addFileLibraryFiles(rows);
1159
+ },
1160
+ initPrivateUploadBt() {
1161
+ if (settingConfig.privateProfileCode && this.pickPrivateProfile) {
1162
+ this.$http({
1163
+ url: USER_PREFIX + "/file_store_area/getByCode",
1164
+ method: "post",
1165
+ data: { stringOne: settingConfig.privateProfileCode },
1166
+ failMsg: false,
1167
+ errorMsg: false,
1168
+ success: (res) => {
1169
+ this.showPrivateUploadBtn = res.objx ? true : false;
1170
+ },
1171
+ });
1172
+ } else {
1173
+ this.showPrivateUploadBtn = false;
1174
+ }
1175
+ },
1176
+ initPickUploadMode() {
1177
+ this.showLocalUploadBtn = false;
1178
+ this.showPrivateUploadBtn = false;
1179
+ this.$http({
1180
+ url: USER_PREFIX + "/system_parameter/getByCode",
1181
+ method: "post",
1182
+ data: { code: "pickUploadMode" },
1183
+ success: (res) => {
1184
+ let value = !res.objx || !res.objx.value ? "2" : res.objx.value;
1185
+ if (value == "0") {
1186
+ //启用本地上传,个人文档上传
1187
+ if (this.option.showLocalUploadBtn !== false)
1188
+ this.showLocalUploadBtn = true;
1189
+ this.initPrivateUploadBt();
1190
+ } else if (value == "1") {
1191
+ //启用个人文档上传
1192
+ this.initPrivateUploadBt();
1193
+ } else if (value == "2") {
1194
+ //启用本地上传
1195
+ if (this.option.showLocalUploadBtn !== false)
1196
+ this.showLocalUploadBtn = true;
1197
+ }
1198
+ },
1199
+ });
1200
+ },
1201
+ pasteEvent(e) {
1202
+ // e.preventDefault();
1203
+ e.stopPropagation();
1204
+ if (!this.pasteAreaStatus) {
1205
+ return;
1206
+ }
1207
+ if (!(e.clipboardData && e.clipboardData.items)) {
1208
+ return;
1209
+ }
1210
+ let files = Array.from(e.clipboardData.files);
1211
+ let getFileSuffix = this.$commonFileUtil.getFileSuffix;
1212
+ if (files.length) {
1213
+ let fileList = files.map((rawFile) => {
1214
+ let name = rawFile.name;
1215
+ let index = name.lastIndexOf(".");
1216
+ let fileSuffix = getFileSuffix(name);
1217
+ let fileName =
1218
+ index >= 0 ? name.substring(0, index).toString() : name.toString();
1219
+ let file = {
1220
+ name: rawFile.name,
1221
+ size: rawFile.size,
1222
+ raw: rawFile,
1223
+ showUrl: URL.createObjectURL(rawFile),
1224
+ fileName: fileName,
1225
+ fileSuffix: fileSuffix,
1226
+ };
1227
+ return file;
1228
+ });
1229
+ this.pasteList.push(...fileList);
1230
+ }
1231
+ },
1232
+ deletePasteFile(index) {
1233
+ this.pasteList.splice(index, 1);
1234
+ },
1235
+ confirmPasteFile() {
1236
+ let target = this.$refs.upload;
1237
+ let innerTarget = target.$refs["upload-inner"];
1238
+ let pasteList = this.$baseLodash.cloneDeep(this.pasteList);
1239
+ let files = pasteList.map((item) => {
1240
+ let name = item.name;
1241
+ let fileRaw = item.raw;
1242
+ fileRaw.fileName = name;
1243
+ return fileRaw;
1244
+ });
1245
+ innerTarget.uploadFiles(files);
1246
+ this.$nextTick(() => {
1247
+ target.uploadFiles.forEach((uploadFile) => {
1248
+ let fileRaw = uploadFile.raw;
1249
+ if (fileRaw.fileName) {
1250
+ uploadFile.name = fileRaw.fileName;
1251
+ delete fileRaw.fileName;
1252
+ }
1253
+ });
1254
+ });
1255
+ this.pasteList = [];
1256
+ },
1257
+ changeFileName(file) {
1258
+ if (file.fileSuffix) {
1259
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1260
+ } else {
1261
+ file.name = file.fileName.toString();
1262
+ }
1263
+ },
1264
+ handleFileError(err, rawFile) {
1265
+ let target = this.$refs.upload;
1266
+ if (!target) return;
1267
+ const file = target.getFile(rawFile);
1268
+ const fileList = target.uploadFiles;
1269
+
1270
+ file.status = "fail";
1271
+ file.failMsg = err && err.message ? err.message : null;
1272
+
1273
+ // fileList.splice(fileList.indexOf(file), 1);
1274
+
1275
+ target.onError(err, file, target.uploadFiles);
1276
+ target.onChange(file, target.uploadFiles);
1277
+ this.updateUploadingStatus();
1278
+ },
1279
+ choosePasteArea(e) {
1280
+ e.stopPropagation();
1281
+ this.pasteAreaStatus = true;
1282
+ },
1283
+ openFileNameDialog(row, index) {
1284
+ this.editFileName = row.fileName?.toString();
1285
+ this.editFileSuffix = row.fileSuffix?.toString();
1286
+ this.editFileIndex = index;
1287
+ this.showFileNameDialog = true;
1288
+ },
1289
+ confirmFileNameDialog() {
1290
+ if (!this.editFileName) {
1291
+ this.$message({
1292
+ message: this.$t2("文件名不能为空", "components.VabUpload.warnMsg3"),
1293
+ type: "error",
1294
+ showClose: true,
1295
+ duration: 3000,
1296
+ });
1297
+ return;
1298
+ }
1299
+ let editFileIndex = this.editFileIndex;
1300
+ let file = this.pasteList[editFileIndex];
1301
+ file.fileName = this.editFileName.toString();
1302
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1303
+ this.showFileNameDialog = false;
1304
+ },
1305
+ },
1306
+ };
1307
+
1308
+ tViewMixins = {
1309
+ props: {
1310
+ resultType: String,
1311
+ dataType: String,
1312
+ callback: Function,
1313
+ file: {
1314
+ type: [Array, Object, String],
1315
+ },
1316
+ multi: {
1317
+ type: [String, Boolean],
1318
+ default: true,
1319
+ },
1320
+ auto: {
1321
+ type: Boolean,
1322
+ default: true,
1323
+ },
1324
+ limit: {
1325
+ type: Number,
1326
+ default: 100000,
1327
+ },
1328
+ /* 单个文件大小限制(MB),0 表示不限制 */
1329
+ size: {
1330
+ type: Number,
1331
+ default: () => {
1332
+ return settingConfig.uploadFileSize ?? 200;
1333
+ },
1334
+ },
1335
+ accept: {
1336
+ type: String,
1337
+ default: "file",
1338
+ },
1339
+ /* 允许上传的文件格式,数组或逗号分隔字符串,如 ['doc','xlsx'] / 'doc,xlsx';为空表示不限制 */
1340
+ fileTypes: {
1341
+ type: [Array, String],
1342
+ default: () => [],
1343
+ },
1344
+ chunkSize: {
1345
+ type: Number,
1346
+ default: 5, //5MB
1347
+ },
1348
+ confirmUpload: {
1349
+ type: Function,
1350
+ },
1351
+ pickPrivateProfile: {
1352
+ type: Boolean,
1353
+ default: true,
1354
+ },
1355
+ uploadingLimit: {
1356
+ type: Number,
1357
+ default: 5, //5MB
1358
+ },
1359
+ isPartUpload: {
1360
+ type: Boolean,
1361
+ default: () => {
1362
+ return settingConfig.isPartUpload ?? true;
1363
+ },
1364
+ },
1365
+ autoConfirmAfterPasteUpload: {
1366
+ type: Boolean,
1367
+ default: false,
1368
+ },
1369
+ },
1370
+ data() {
1371
+ return {
1372
+ attachments: [],
1373
+ pictureList: [],
1374
+ pictureDtoList: [],
1375
+ showPropertiesDialog: false,
1376
+ editAttachment: null,
1377
+ showViewer: false,
1378
+ chooseIndex: 0,
1379
+ fileServerInfo: {},
1380
+ model: null,
1381
+ };
1382
+ },
1383
+ computed: {
1384
+ fileServerPreviewEnabled() {
1385
+ return this.getFileServerPreviewEnabled();
1386
+ },
1387
+ fileShowImageEnabled() {
1388
+ return this.getFileShowImageEnabled();
1389
+ },
1390
+ fileMaxSize() {
1391
+ return this.size;
1392
+ },
1393
+ showUploadBtn: function () {
1394
+ if (!this.isMulti) {
1395
+ return this.attachments.length == 0;
1396
+ } else {
1397
+ return this.limit ? this.limit > this.attachments.length : true;
1398
+ }
1399
+ },
1400
+ isMulti: function () {
1401
+ let isMulti = true;
1402
+ if (this.multi === "false" || this.multi === false || this.limit === 1) {
1403
+ isMulti = false;
1404
+ }
1405
+ return isMulti;
1406
+ },
1407
+ },
1408
+ watch: {
1409
+ file(val) {
1410
+ this.initFile();
1411
+ },
1412
+ attachments(val) {
1413
+ let that = this;
1414
+ let pictureList = [];
1415
+ let pictureDtoList = [];
1416
+ if (val) {
1417
+ val.forEach((item) => {
1418
+ if (item) {
1419
+ let typeStr = Object.prototype.toString.call(item);
1420
+ if (
1421
+ typeStr == "[object Object]" &&
1422
+ Object.keys(this.file).length > 0
1423
+ ) {
1424
+ if (that.$commonFileUtil.isPictureFile(item.url)) {
1425
+ pictureList.push(item.domain + item.url);
1426
+ pictureDtoList.push(item);
1427
+ }
1428
+ } else {
1429
+ if (that.$commonFileUtil.isPictureFile(item)) {
1430
+ pictureList.push(item);
1431
+ pictureDtoList.push(item);
1432
+ }
1433
+ }
1434
+ }
1435
+ });
1436
+ }
1437
+ this.pictureList = pictureList;
1438
+ this.pictureDtoList = pictureDtoList;
1439
+ },
1440
+ },
1441
+ created() {
1442
+ this.initFileServerInfo();
1443
+ this.initFile();
1444
+ },
1445
+ methods: {
1446
+ pasteEvent(e) {
1447
+ e.stopPropagation();
1448
+ if (!(e.clipboardData && e.clipboardData.items)) {
1449
+ return;
1450
+ }
1451
+ let files = Array.from(e.clipboardData.files);
1452
+ if (files.length) {
1453
+ this.openUploadDialog(files, this.autoConfirmAfterPasteUpload);
1454
+ }
1455
+ },
1456
+ uploadEnterOver() {
1457
+ // if (this.isLoading) return;
1458
+ document.addEventListener("paste", this.pasteEvent);
1459
+ },
1460
+ uploadEnterLeave() {
1461
+ document.removeEventListener("paste", this.pasteEvent);
1462
+ },
1463
+ getFileServerPreviewEnabled() {
1464
+ let value =
1465
+ window.$vueRoot.$store.getters.fileServerInfo
1466
+ ?.fileServerPreviewEnabled ??
1467
+ settingConfig.fileServerPreviewEnabled ??
1468
+ true;
1469
+ if (
1470
+ this.$attrs.fileServerPreviewEnabled !== null &&
1471
+ this.$attrs.fileServerPreviewEnabled !== undefined
1472
+ ) {
1473
+ value = this.$attrs.fileServerPreviewEnabled;
1474
+ }
1475
+ return value;
1476
+ },
1477
+ getFileShowImageEnabled() {
1478
+ let value =
1479
+ window.$vueRoot.$store.getters.fileServerInfo?.fileShowImageEnabled ??
1480
+ settingConfig.fileShowImageEnabled ??
1481
+ true;
1482
+ if (
1483
+ this.$attrs.fileShowImageEnabled !== null &&
1484
+ this.$attrs.fileShowImageEnabled !== undefined
1485
+ ) {
1486
+ value = this.$attrs.fileShowImageEnabled;
1487
+ }
1488
+ return value;
1489
+ },
1490
+ openUploadDialog(files, autoConfirmAfterUpload) {
1491
+ this.$baseUpload.open({
1492
+ files,
1493
+ autoConfirmAfterUpload,
1494
+ ...this.fileServerInfo,
1495
+ ...this._props,
1496
+ ...this.$attrs,
1497
+ limit: this.limit,
1498
+ multi: this.multi,
1499
+ accept: this.accept ? this.accept : "file",
1500
+ fileTypes: this.fileTypes,
1501
+ auto: this.auto,
1502
+ size: this.fileMaxSize,
1503
+ chunkSize: this.chunkSize,
1504
+ callback: this.fileConfirm,
1505
+ pickPrivateProfile: this.pickPrivateProfile,
1506
+ confirmUpload: this.confirmUpload,
1507
+ otherParams: this.$attrs,
1508
+ });
1509
+ },
1510
+ initFileServerInfo() {
1511
+ if (this.$attrs.model) {
1512
+ this.model = this.$attrs.model;
1513
+ // this.fileServerInfo = this.$attrs.fileServerInfo;
1514
+ } else {
1515
+ this.model =
1516
+ window.$vueRoot.$store.getters.fileServerInfo?.model ?? null;
1517
+ /* getFileServerInfo(this, (res) => {
1518
+ if (res) {
1519
+ let fileServerInfo = res;
1520
+ this.model = fileServerInfo.model
1521
+ this.fileServerInfo = fileServerInfo;
1522
+ }else{
1523
+ this.model = null;
1524
+ this.fileServerInfo = null;
1525
+ }
1526
+ }) */
1527
+ }
1528
+ },
1529
+ initFile() {
1530
+ if (this.file) {
1531
+ let typeStr = Object.prototype.toString.call(this.file);
1532
+ if (!this.dataType) {
1533
+ if (typeStr == "[object Array]") {
1534
+ this.attachments = this.file;
1535
+ } else if (
1536
+ typeStr == "[object Object]" &&
1537
+ Object.keys(this.file).length > 0
1538
+ ) {
1539
+ this.attachments = [this.file];
1540
+ } else {
1541
+ this.attachments = [];
1542
+ }
1543
+ } else {
1544
+ this.attachments = [this.file];
1545
+ }
1546
+ } else {
1547
+ this.attachments = [];
1548
+ }
1549
+ },
1550
+ deleteFile(index) {
1551
+ if (!this.$listeners.delete || this.$listeners.delete(index) !== false) {
1552
+ this.attachments.splice(index, 1);
1553
+ this.updatePropFile();
1554
+ this.$emit("afterDelete", this.attachments);
1555
+ }
1556
+ },
1557
+ fileConfirm(rows, fileInfos) {
1558
+ if (rows.length > 0) {
1559
+ if (this.isMulti) {
1560
+ let limit = this.limit;
1561
+ if (limit) {
1562
+ let oSize = this.file?.length ?? 0;
1563
+ let vailSize = limit - oSize;
1564
+ if (vailSize > 0) {
1565
+ rows = rows.length < vailSize ? rows : rows.slice(0, vailSize);
1566
+ } else {
1567
+ rows = [];
1568
+ }
1569
+ }
1570
+ } else {
1571
+ rows = [rows[0]];
1572
+ }
1573
+
1574
+ let attachments = this.attachments;
1575
+ let dataType = this.dataType;
1576
+ let eRows = [];
1577
+ if (dataType != null) {
1578
+ eRows = rows.map((row) => {
1579
+ return row.domain + (row[dataType] || row["url"]);
1580
+ });
1581
+ } else {
1582
+ eRows = rows;
1583
+ }
1584
+
1585
+ if (
1586
+ !this.$listeners.confirm ||
1587
+ this.$listeners.confirm(eRows, fileInfos) !== false
1588
+ ) {
1589
+ if (this.isMulti) {
1590
+ this.attachments = attachments.concat(eRows);
1591
+ } else {
1592
+ this.attachments = eRows;
1593
+ }
1594
+ this.updatePropFile();
1595
+ this.$emit("callback", eRows, fileInfos);
1596
+ }
1597
+ }
1598
+ },
1599
+ updatePropFile() {
1600
+ if (this.isMulti) {
1601
+ this.$emit("update:file", this.attachments);
1602
+ } else {
1603
+ let result =
1604
+ this.attachments && this.attachments.length
1605
+ ? this.attachments[0]
1606
+ : null;
1607
+ if (
1608
+ this.resultType == "Array" ||
1609
+ (this.multi !== "false" && this.multi !== false)
1610
+ ) {
1611
+ result = result ? [result] : [];
1612
+ }
1613
+ this.$emit("update:file", result);
1614
+ }
1615
+ this.handleChange();
1616
+ },
1617
+ handleChange() {
1618
+ this.$emit("change", this.attachments);
1619
+ },
1620
+ getRealPictureList(index) {
1621
+ let pictureIndex = -1;
1622
+ this.attachments.find((item, i) => {
1623
+ let typeStr = Object.prototype.toString.call(item);
1624
+ if (typeStr == "[object Object]") {
1625
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1626
+ pictureIndex++;
1627
+ }
1628
+ } else {
1629
+ if (this.$commonFileUtil.isPictureFile(item)) {
1630
+ pictureIndex++;
1631
+ }
1632
+ }
1633
+ return index == i;
1634
+ });
1635
+ return this.pictureList
1636
+ .slice(pictureIndex)
1637
+ .concat(this.pictureList.slice(0, pictureIndex));
1638
+ },
1639
+ getRealPictureDTOList() {
1640
+ let index = this.chooseIndex || 0;
1641
+ let pictureIndex = -1;
1642
+ this.attachments.find((item, i) => {
1643
+ let typeStr = Object.prototype.toString.call(item);
1644
+ if (typeStr == "[object Object]") {
1645
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1646
+ pictureIndex++;
1647
+ }
1648
+ } else {
1649
+ if (this.$commonFileUtil.isPictureFile(item)) {
1650
+ pictureIndex++;
1651
+ }
1652
+ }
1653
+ return index == i;
1654
+ });
1655
+ let res = this.pictureDtoList
1656
+ .slice(pictureIndex)
1657
+ .concat(this.pictureDtoList.slice(0, pictureIndex));
1658
+ return res;
1659
+ },
1660
+ openImagePreView(index) {
1661
+ // this.chooseIndex = index;
1662
+ let pictureIndex = -1;
1663
+ this.attachments.find((item, i) => {
1664
+ let typeStr = Object.prototype.toString.call(item);
1665
+ if (typeStr == "[object Object]") {
1666
+ if (this.$commonFileUtil.isPictureFile(item.url)) {
1667
+ pictureIndex++;
1668
+ }
1669
+ } else {
1670
+ if (this.$commonFileUtil.isPictureFile(item)) {
1671
+ pictureIndex++;
1672
+ }
1673
+ }
1674
+ return index == i;
1675
+ });
1676
+ this.chooseIndex = pictureIndex;
1677
+ this.showViewer = true;
1678
+ },
1679
+ openPropertiesDialog(attachment) {
1680
+ this.editAttachment = attachment;
1681
+ this.showPropertiesDialog = true;
1682
+ },
1683
+ closeViewer() {
1684
+ this.showViewer = false;
1685
+ },
1686
+ hasPreview(attachment) {
1687
+ let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1688
+ let typeStr = Object.prototype.toString.call(attachment);
1689
+ let url =
1690
+ typeStr == "[object Object]"
1691
+ ? attachment.domain + attachment.url
1692
+ : attachment;
1693
+ if (fileServerPreviewEnabled) {
1694
+ return (
1695
+ this.$commonFileUtil.isPictureFile(url) ||
1696
+ this.$commonFileUtil.isPreviewFile(url)
1697
+ );
1698
+ } else {
1699
+ return this.$commonFileUtil.isPictureFile(url);
1700
+ }
1701
+ },
1702
+ openPreview(attachment, index) {
1703
+ let fileServerPreviewEnabled = this.getFileServerPreviewEnabled();
1704
+ let typeStr = Object.prototype.toString.call(attachment);
1705
+ let url =
1706
+ typeStr == "[object Object]"
1707
+ ? attachment.domain + attachment.url
1708
+ : attachment;
1709
+ if (this.$commonFileUtil.isPictureFile(url)) {
1710
+ this.openImagePreView(index);
1711
+ } else if (
1712
+ fileServerPreviewEnabled &&
1713
+ this.$commonFileUtil.isPreviewFile(url)
1714
+ ) {
1715
+ this.$openFilePreview(url);
1716
+ }
1717
+ },
1718
+ getAttachmentName(attachment) {
1719
+ let name = null;
1720
+ let typeStr = Object.prototype.toString.call(attachment);
1721
+ if (typeStr == "[object Object]") {
1722
+ name = attachment.name;
1723
+ } else {
1724
+ let url = attachment;
1725
+ if (url) {
1726
+ var i = url.lastIndexOf("/");
1727
+ if (i >= 0) {
1728
+ name = url.substring(i + 1, url.length);
1729
+ }
1730
+ }
1731
+ }
1732
+ return name;
1733
+ },
1734
+ getShowUrl(attachment, field) {
1735
+ let showUrl = null;
1736
+ let showImagePreview = this.getFileShowImageEnabled();
1737
+ let typeStr = Object.prototype.toString.call(attachment);
1738
+ if (typeStr == "[object Object]") {
1739
+ let showField = field ? field : "medium";
1740
+ let fullUrl =
1741
+ attachment.domain +
1742
+ (showImagePreview && attachment[showField]
1743
+ ? attachment[showField]
1744
+ : attachment.url);
1745
+ showUrl = this.$commonFileUtil.getShowUrl(fullUrl, showImagePreview);
1746
+ } else {
1747
+ showUrl = this.$commonFileUtil.getShowUrl(attachment, showImagePreview);
1748
+ }
1749
+ return showUrl;
1750
+ },
1751
+ downloadFile(attachment) {
1752
+ let typeStr = Object.prototype.toString.call(attachment);
1753
+ if (typeStr == "[object Object]") {
1754
+ this.$commonFileUtil.downloadFile(
1755
+ attachment.domain + attachment.url,
1756
+ attachment.name
1757
+ );
1758
+ } else {
1759
+ this.$commonFileUtil.downloadFile(attachment);
1760
+ }
1761
+ },
1762
+ formatFileSize(fileSize) {
1763
+ return formatFileSize(fileSize);
1764
+ },
1765
+ },
1766
+ };
1767
+
1768
+ pmixins = {
1769
+ name: "propertiesDialog",
1770
+ components: {},
1771
+ created() {
1772
+ this.attachmentDTO = this.$attrs.editAttachment;
1773
+ this.current_prefix =
1774
+ this.attachmentDTO && this.attachmentDTO.serverName
1775
+ ? "/" + this.attachmentDTO.serverName
1776
+ : "";
1777
+ },
1778
+ mounted() {
1779
+ this.initTableM1();
1780
+ },
1781
+ data() {
1782
+ return {
1783
+ showDialog: true,
1784
+ falseValue: false,
1785
+ vxeOption: {},
1786
+ showContent: true,
1787
+ attachmentDTO: {},
1788
+ current_prefix: "",
1789
+ };
1790
+ },
1791
+ methods: {
1792
+ saveData() {
1793
+ this.$refs.editForm.validate((valid) => {
1794
+ if (valid) {
1795
+ this.$baseConfirm(
1796
+ this.$t2("您确定要保存吗?", "components.VabUpload.saveTip")
1797
+ ).then(() => {
1798
+ let formData = commonDataUtil.handleForm(this.attachmentDTO);
1799
+
1800
+ var url = this.current_prefix + "/attachment/attribute/save";
1801
+ this.$http({
1802
+ url: url,
1803
+ method: "post",
1804
+ data: formData,
1805
+ isLoading: true,
1806
+ success: (res) => {
1807
+ this.$message({
1808
+ message: res.content,
1809
+ type: "success",
1810
+ duration: 500,
1811
+ onClose: (t) => {
1812
+ this.reloadContent();
1813
+ },
1814
+ });
1815
+ },
1816
+ });
1817
+ });
1818
+ }
1819
+ });
1820
+ },
1821
+ dialogClose() {
1822
+ this.$emit("update:visiable", false);
1823
+ },
1824
+ reloadContent() {
1825
+ this.getData();
1826
+ },
1827
+ getData() {
1828
+ this.$http({
1829
+ url: this.current_prefix + "/attachment/attribute/list",
1830
+ method: "post",
1831
+ data: {
1832
+ id: this.attachmentDTO.id,
1833
+ },
1834
+ isLoading: true,
1835
+ // modalStrictly: true,
1836
+ success: (res) => {
1837
+ this.$set(
1838
+ this.attachmentDTO,
1839
+ "attachmentAttributeDTOs",
1840
+ res.objx || []
1841
+ );
1842
+ },
1843
+ });
1844
+ this.getUserBasicInfos();
1845
+ },
1846
+ getUserBasicInfos() {
1847
+ let createBy = this.attachmentDTO.createBy;
1848
+ if (!!this.attachmentDTO._createBy || !createBy) return;
1849
+ this.$http({
1850
+ url: USER_PREFIX + `/userb/getUserBasicInfos`,
1851
+ method: "post",
1852
+ data: [createBy],
1853
+ isLoading: true,
1854
+ // modalStrictly: true,
1855
+ success: (res) => {
1856
+ let _createBy = createBy;
1857
+ if (res.objx?.length) {
1858
+ let nickName = res.objx[0].nickName;
1859
+ let queryCreateInfo =
1860
+ window.$vueRoot.$store.getters.queryCreateInfo || "0";
1861
+ if (nickName) {
1862
+ if (queryCreateInfo == "1") {
1863
+ _createBy = createBy + "(" + nickName + ")";
1864
+ } else if (queryCreateInfo == "2") {
1865
+ _createBy = nickName;
1866
+ }
1867
+ }
1868
+ }
1869
+ this.$set(this.attachmentDTO, "_createBy", _createBy);
1870
+ },
1871
+ });
1872
+ },
1873
+ initTableM1() {
1874
+ //明细
1875
+ var that = this;
1876
+ const tableRef = "table-m1";
1877
+ const tableOption = {
1878
+ vue: this,
1879
+ tableRef: tableRef,
1880
+ tableName: "components_vabUpload_propertiesDialog_list-m1",
1881
+ columns: [
1882
+ {
1883
+ type: "checkbox",
1884
+ fixed: "left",
1885
+ width: 48,
1886
+ resizable: false,
1887
+ },
1888
+ {
1889
+ title: this.$t2("属性名称", "components.VabUpload.attributeName"),
1890
+ field: "attributeName",
1891
+ width: 200,
1892
+ slots: {
1893
+ default: "attributeName",
1894
+ },
1895
+ },
1896
+ {
1897
+ title: this.$t2("属性值", "components.VabUpload.attributeValue"),
1898
+ field: "attributeValue",
1899
+ width: 200,
1900
+ slots: {
1901
+ default: "attributeValue",
1902
+ },
1903
+ },
1904
+ {
1905
+ width: 50,
1906
+ fixed: "right",
1907
+ title: "",
1908
+ sortable: false,
1909
+ slots: {
1910
+ default: "operate",
1911
+ },
1912
+ },
1913
+ ],
1914
+ };
1915
+ this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
1916
+ this.vxeOption = opts;
1917
+ });
1918
+ this.getData();
1919
+ },
1920
+ addItem() {
1921
+ this.attachmentDTO.attachmentAttributeDTOs.push({});
1922
+ },
1923
+ formatFileSize(fileSize) {
1924
+ return formatFileSize(fileSize);
1925
+ },
1926
+ },
1927
+ };
1928
+
1929
+ function getFileServerInfo(that, callback) {
1930
+ that.$http({
1931
+ url: USER_PREFIX + "/logic_param/getFileServerInfo",
1932
+ method: "post",
1933
+ data: {},
1934
+ failMsg: false,
1935
+ errorMsg: false,
1936
+ modal: false,
1937
+ success: (res) => {
1938
+ if (res.objx) {
1939
+ callback && callback(res.objx);
1940
+ } else {
1941
+ callback && callback();
1942
+ }
1943
+ },
1944
+ error: (err) => {
1945
+ callback && callback();
1946
+ },
1947
+ });
1948
+ }
1949
+
1950
+ function formatFileSize(fileSize) {
1951
+ fileSize = fileSize || 0;
1952
+ if (fileSize < 1024) {
1953
+ return fileSize + "B";
1954
+ } else if (fileSize < 1024 * 1024) {
1955
+ var temp = fileSize / 1024;
1956
+ temp = temp.toFixed(2);
1957
+ return temp + "KB";
1958
+ } else if (fileSize < 1024 * 1024 * 1024) {
1959
+ var temp = fileSize / (1024 * 1024);
1960
+ temp = temp.toFixed(2);
1961
+ return temp + "MB";
1962
+ } else {
1963
+ var temp = fileSize / (1024 * 1024 * 1024);
1964
+ temp = temp.toFixed(2);
1965
+ return temp + "GB";
1966
+ }
1967
+ }
1968
+
1969
+ export const mixins = tmixins;
1970
+ export const viewMixins = tViewMixins;
1971
+ export const propertiesMixins = pmixins;