cloud-web-corejs 1.0.54-dev.397 → 1.0.54-dev.399

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.
@@ -0,0 +1,1458 @@
1
+ /**version-1.0*/
2
+ let tmixins;
3
+ import axios from "axios";
4
+ import SparkMD5 from "spark-md5";
5
+ import settingConfig from "@/settings.js";
6
+ import ObsClient from "esdk-obs-browserjs/src/obs";
7
+
8
+ let imFun = {
9
+ axios,
10
+ SparkMD5,
11
+ };
12
+
13
+ tmixins = {
14
+ name: "VabUpload",
15
+ props: {
16
+ auto: {
17
+ type: Boolean,
18
+ default: true,
19
+ },
20
+ url: {
21
+ type: String,
22
+ default: "/upload",
23
+ },
24
+ name: {
25
+ type: String,
26
+ default: "file",
27
+ },
28
+ limit: {
29
+ type: Number,
30
+ default: () => 100000,
31
+ },
32
+ size: {
33
+ type: Number,
34
+ default: 200,
35
+ },
36
+ accept: {
37
+ type: String,
38
+ default: "file",
39
+ },
40
+ chunkSize: {
41
+ type: Number,
42
+ default: 5, //5MB
43
+ },
44
+ confirmUpload: {
45
+ type: Function,
46
+ },
47
+ pickPrivateProfile: {
48
+ type: Boolean,
49
+ default: true,
50
+ },
51
+ multi: {
52
+ type: [String, Boolean],
53
+ default: true,
54
+ },
55
+ uploadingLimit: {
56
+ type: Number,
57
+ default: 5, //5MB
58
+ },
59
+ },
60
+ data() {
61
+ return {
62
+ show: false,
63
+ loading: false,
64
+ dialogVisible: false,
65
+ dialogImageUrl: "",
66
+ action: "",
67
+ headers: {},
68
+ fileList: [],
69
+ picture: "picture",
70
+ allImgNum: 0,
71
+ imgNum: 0,
72
+ imgSuccessNum: 0,
73
+ imgErrorNum: 0,
74
+ typeList: null,
75
+ title: this.$t2("上传", "components.VabUpload.title"),
76
+ dialogFormVisible: false,
77
+ data: {},
78
+ fileViewDialogVisible: false,
79
+ fileViewInfo: {},
80
+ total: 0,
81
+ video: null,
82
+ btn: false,
83
+ filePartMap: {},
84
+ uploading: false,
85
+ hasReadyFile: false,
86
+ showLocalUploadBtn: false,
87
+ showPrivateUploadBtn: false,
88
+ showPrivateProfileDialog: false,
89
+ pasteList: [],
90
+ pasteAreaStatus: false,
91
+ option: {},
92
+ editFileIndex: -1,
93
+ showFileNameDialog: false,
94
+ editFileName: null,
95
+ editFileSuffix: null,
96
+ beforeUploadFlag: false,
97
+ uploadUrl: null,
98
+
99
+ access_key_id: "HPUAQ1TAFXWGOKSNKCGW", // 你的ak
100
+ secret_access_key: "Ns1nwPwikK67Acbhj3wlfUambjbdroqpk0TFv7qg", // 你的sk
101
+ server: "https://obs.cn-south-1.myhuaweicloud.com", // 你的endPoint 记得加入https://
102
+ Bucket: "gztw-file01", // 你的桶名
103
+ };
104
+ },
105
+ beforeDestroy() {
106
+ this.removePasteEvent();
107
+ },
108
+ filters: {
109
+ btnText(btn) {
110
+ return btn
111
+ ? this.$t2("继续", "components.VabUpload.continue")
112
+ : this.$t2("暂停", "components.VabUpload.pause");
113
+ },
114
+ totalText(total) {
115
+ return total > 100 ? 100 : total;
116
+ },
117
+ },
118
+ computed: {
119
+ percentage() {
120
+ if (this.allImgNum == 0) return 0;
121
+ return ((this.imgNum / this.allImgNum, 2) * 100).toFixed(0);
122
+ },
123
+ fileMaxSize() {
124
+ return this.formatFileSize(this.size * 1024 * 1024);
125
+ },
126
+ errorQuantity() {
127
+ return this.fileList.filter((file) => file.status == "fail").length;
128
+ },
129
+ totalQuantity() {
130
+ return this.fileList.length;
131
+ },
132
+ successQuantity() {
133
+ return this.fileList.filter((file) => file.status == "success").length;
134
+ },
135
+ isMulti: function () {
136
+ let isMulti = true;
137
+ if (this.multi === "false" || this.multi === false || this.limit === 1) {
138
+ isMulti = false;
139
+ }
140
+ return isMulti;
141
+ },
142
+ },
143
+ methods: {
144
+ updateUploadingStatus() {
145
+ var target = this.$refs.upload;
146
+ let uploading, hasReadyFile;
147
+ if (target) {
148
+ var fileList = target.uploadFiles;
149
+ let n = fileList.find((item) => {
150
+ // return item.percentage != 100;
151
+ return item.status == "uploading" || item.status == "preUpload";
152
+ });
153
+ uploading = n == null ? false : true;
154
+
155
+ let readyFiles = fileList.filter((file) => file.status == "ready");
156
+ hasReadyFile = readyFiles.length > 0;
157
+ } else {
158
+ uploading = false;
159
+ hasReadyFile = false;
160
+ }
161
+
162
+ this.uploading = uploading;
163
+ this.hasReadyFile = hasReadyFile;
164
+ this.checkPreUploadList();
165
+ return uploading;
166
+ },
167
+ submitUpload() {
168
+ let successDone = () => {
169
+ this.$refs.upload.submit();
170
+ };
171
+ var files = this.$refs.upload.uploadFiles;
172
+ let readyFiles = files.filter((file) => file.status == "ready");
173
+ if (this.confirmUpload) {
174
+ if (readyFiles.length) {
175
+ this.confirmUpload({
176
+ files: files,
177
+ done: successDone,
178
+ });
179
+ }
180
+ } else {
181
+ successDone();
182
+ }
183
+ },
184
+ handleProgress(event, file, fileList) {
185
+ // this.loading = true
186
+ // this.show = true
187
+ },
188
+ handleChange(file, fileList) {
189
+ let maxSize = this.size * 1024 * 1024;
190
+ if (file.size > maxSize) {
191
+ fileList.map((item, index) => {
192
+ if (item === file) {
193
+ fileList.splice(index, 1);
194
+ }
195
+ });
196
+ this.fileList = fileList;
197
+ let errorText =
198
+ "文件[" + file.name + "]大小超出限制" + this.fileMaxSize;
199
+ this.$message({
200
+ message: this.$t2(errorText, "components.VabUpload.warnMsg1", {
201
+ fileName: file.name,
202
+ fileMaxSize: this.fileMaxSize,
203
+ }),
204
+ type: "error",
205
+ duration: 3 * 1000,
206
+ });
207
+ file.raw.status = "fail";
208
+ return false;
209
+ } else {
210
+ this.fileList = fileList;
211
+ this.allImgNum = fileList.length;
212
+ }
213
+ this.updateUploadingStatus();
214
+ },
215
+ handleSuccess(response, file, fileList) {
216
+ if (file.percentage == 100) {
217
+ this.imgNum = this.imgNum + 1;
218
+ this.imgSuccessNum = this.imgSuccessNum + 1;
219
+ }
220
+ if (fileList.length === this.imgNum) {
221
+ this.fileList = fileList;
222
+ }
223
+
224
+ setTimeout(() => {
225
+ this.loading = false;
226
+ this.show = false;
227
+ }, 1000);
228
+ this.updateUploadingStatus();
229
+ },
230
+ handleError(err, file, fileList) {
231
+ this.imgNum = this.imgNum + 1;
232
+ this.imgErrorNum = this.imgErrorNum + 1;
233
+ setTimeout(() => {
234
+ this.loading = false;
235
+ this.show = false;
236
+ }, 1000);
237
+ this.updateUploadingStatus();
238
+ },
239
+ handleRemove(file, fileList) {
240
+ this.imgNum = this.imgNum - 1;
241
+ this.allNum = this.allNum - 1;
242
+ this.updateUploadingStatus();
243
+ },
244
+ handlePreview(file) {
245
+ this.dialogImageUrl = file.url;
246
+ this.dialogVisible = true;
247
+ },
248
+ handleExceed(files, fileList) {
249
+ let errorMsg = `当前限制选择 ${this.limit} 个文件,本次选择了
250
+ ${files.length}
251
+ 个文件`;
252
+ this.$message({
253
+ message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
254
+ limit: this.limit,
255
+ size: files.length,
256
+ }),
257
+ type: "error",
258
+ duration: 5 * 1000,
259
+ });
260
+ },
261
+ handleShow(option) {
262
+ this.getFileServerInfo(option,()=>{
263
+ this.title = this.$t2("上传", "components.VabUpload.title");
264
+ // this.data = data;
265
+ this.option = option;
266
+ this.clearFileInfo();
267
+ this.initPickUploadMode();
268
+ this.pasteAreaStatus = false;
269
+ this.dialogFormVisible = true;
270
+
271
+ this.removePasteEvent();
272
+ this.addPasteEvent();
273
+ })
274
+
275
+ },
276
+ addPasteEvent() {
277
+ document.addEventListener("click", this.blurPasteEvent);
278
+ document.addEventListener("paste", this.pasteEvent);
279
+ },
280
+ removePasteEvent() {
281
+ document.removeEventListener("click", this.blurPasteEvent);
282
+ document.removeEventListener("paste", this.pasteEvent);
283
+ },
284
+ blurPasteEvent() {
285
+ this.pasteAreaStatus = false;
286
+ },
287
+ handleClose() {
288
+ let target = this.$refs.upload;
289
+ (target.uploadFiles || []).forEach((uploadFile) => {
290
+ if (uploadFile.status == "uploading" || uploadFile.status == "ready") {
291
+ uploadFile.raw.abort &&
292
+ uploadFile.raw.abort(
293
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
294
+ );
295
+ }
296
+ });
297
+ this.picture = "picture";
298
+ this.clearFileInfo();
299
+ this.dialogFormVisible = false;
300
+ },
301
+ clearFileInfo() {
302
+ this.fileList = [];
303
+ this.allImgNum = 0;
304
+ this.imgNum = 0;
305
+ this.imgSuccessNum = 0;
306
+ this.imgErrorNum = 0;
307
+ },
308
+ initUploadUrl() {
309
+ let mineUploadUrl = window.BASE_FILEURL;
310
+ return this.$http({
311
+ url: mineUploadUrl,
312
+ method: "post",
313
+ data: {
314
+ isAuth: false,
315
+ },
316
+ success: (res) => {
317
+ this.uploadUrl = res.objx;
318
+ },
319
+ });
320
+ },
321
+ handleBeforeUpload(file, checkFile, callback) {
322
+ /*if (checkFile !== false) {
323
+ let target = this.$refs.upload;
324
+ let nFile = target.getFile(file);
325
+ if (!nFile) {
326
+ return false;
327
+ }
328
+ }
329
+ let mineUploadUrl = window.BASE_FILEURL;
330
+ return await this.$http({
331
+ url: mineUploadUrl,
332
+ method: 'post',
333
+ data: {
334
+ isAuth: false
335
+ },
336
+ success: res => {
337
+ this.uploadUrl = res.objx;
338
+ callback && callback()
339
+ }
340
+ });*/
341
+ callback && callback();
342
+ },
343
+ formatFileSize(fileSize) {
344
+ return formatFileSize(fileSize);
345
+ },
346
+ //自定义上传
347
+ async uploadSectionFile(param, isCustom, uploadConfig) {
348
+ if (!this.uploadUrl) {
349
+ await this.initUploadUrl();
350
+ }
351
+ let that = this;
352
+ var fileObj = param.file;
353
+
354
+ let source;
355
+
356
+ var form = new FormData();
357
+ // 文件对象
358
+ form.append("file", fileObj);
359
+
360
+ let target = that.$refs.upload;
361
+ let file = target ? target.getFile(fileObj) : null;
362
+ if (file) {
363
+ file.status = "uploading";
364
+ }
365
+
366
+ let isLoading = uploadConfig?.isLoading === true;
367
+ var uploadUrl = this.uploadUrl;
368
+ if (uploadUrl) {
369
+ var abort;
370
+ let config = {
371
+ isLoading: isLoading,
372
+ headers: {
373
+ "Content-Type": "multipart/form-data",
374
+ },
375
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
376
+ if (!isCustom) {
377
+ abort = c;
378
+ if (file) file.abort = c;
379
+ }
380
+ }),
381
+ onUploadProgress: (progressEvent) => {
382
+ if (isCustom || file) {
383
+ // progressEvent.loaded:已上传文件大小
384
+ // progressEvent.total:被上传文件的总大小
385
+ progressEvent.percent = Math.floor(
386
+ (progressEvent.loaded * 100) / progressEvent.total
387
+ );
388
+ if (!isCustom) {
389
+ param.onProgress(progressEvent, fileObj);
390
+ }
391
+ uploadConfig &&
392
+ uploadConfig.onProgress &&
393
+ uploadConfig.onProgress(progressEvent, fileObj);
394
+ }
395
+ },
396
+ failMsg: false,
397
+ }; //添加请求头
398
+
399
+ let req = this.$http
400
+ .post(uploadUrl, form, config)
401
+ .then((res1) => {
402
+ uploadConfig &&
403
+ uploadConfig.callback &&
404
+ uploadConfig.callback(res1, fileObj);
405
+ if (!isCustom) {
406
+ if (res1.type == "success") {
407
+ param.onSuccess(res1, fileObj);
408
+ } else {
409
+ // param.onError(new Error(res1.content || '上传异常'));
410
+ this.handleFileError(
411
+ new Error(
412
+ res1.content ||
413
+ this.$t2(
414
+ "上传异常",
415
+ "components.VabUpload.uploadException"
416
+ )
417
+ ),
418
+ fileObj
419
+ );
420
+ }
421
+ }
422
+ })
423
+ .catch((error, a, b, c) => {
424
+ // let {err} = error;
425
+ try {
426
+ // param.onError(err, fileObj);
427
+ if (!isCustom) {
428
+ this.handleFileError(error, fileObj);
429
+ }
430
+ uploadConfig &&
431
+ uploadConfig.error &&
432
+ uploadConfig.error(error, fileObj);
433
+ } catch (tt) {}
434
+ });
435
+ req.abort = () => {
436
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
437
+ };
438
+ //return req;
439
+ }
440
+ },
441
+ singerUpload(uploadConfig) {
442
+ let onUploadProgress = uploadConfig.onUploadProgress;
443
+ let success = uploadConfig.success;
444
+ let file = uploadConfig.file;
445
+ this.handleBeforeUpload(file, false, () => {
446
+ this.uploadSectionFile(
447
+ {
448
+ file: file,
449
+ },
450
+ true,
451
+ uploadConfig
452
+ );
453
+ });
454
+ },
455
+ //begin
456
+ fileParse(file, type = "base64", callback) {
457
+ /*return new Promise(resolve => {
458
+
459
+ });*/
460
+ let fileRead = new FileReader();
461
+ if (type === "base64") {
462
+ fileRead.readAsDataURL(file);
463
+ } else if (type === "buffer") {
464
+ fileRead.readAsArrayBuffer(file);
465
+ }
466
+ fileRead.onload = (ev) => {
467
+ callback(ev.target.result);
468
+ // resolve(ev.target.result);
469
+ };
470
+ },
471
+ changeFile(param) {
472
+ if (!param.file || param.file.status == "fail") return;
473
+
474
+ let target = this.$refs.upload;
475
+ if (!target) return;
476
+ let fileObj = target.getFile(param.file);
477
+ fileObj.status = "preUpload";
478
+ this.checkPreUploadList();
479
+ },
480
+ getFileServerInfoData(callback){
481
+ this.$http({
482
+ url: USER_PREFIX + "/logic_param/getFileServerInfo",
483
+ method: "post",
484
+ data: {paramCode: "obs"},
485
+ failMsg: false,
486
+ errorMsg: false,
487
+ modal: false,
488
+ success: (res) => {
489
+ if(res.objx){
490
+ callback && callback(res.objx);
491
+ }else{
492
+ callback && callback();
493
+ }
494
+ },
495
+ error: (err) => {
496
+ callback && callback();
497
+ }
498
+ })
499
+ },
500
+ getFileServerInfo(option,callback){
501
+ if(option.obsConfig){
502
+ let fileServerInfo = option.obsConfig;
503
+ this.initObsClient(fileServerInfo);
504
+ callback && callback();
505
+ }else{
506
+ this.getFileServerInfoData((res)=>{
507
+ if(res?.obsConfig){
508
+ this.initObsClient(res.obsConfig);
509
+ callback && callback();
510
+ }else{
511
+ this.$message.error("上传服务信息未维护")
512
+ }
513
+ })
514
+ }
515
+ },
516
+ //obs begin
517
+ initObsClient(obsConfig) {
518
+ this.obsConfig = obsConfig;
519
+ this.obsClient = new ObsClient({
520
+ access_key_id: obsConfig.access_key_id,
521
+ secret_access_key: obsConfig.secret_access_key,
522
+ server: obsConfig.server,
523
+ // obsClient: ''
524
+ });
525
+ },
526
+ getBucket(){
527
+ return this.obsConfig.Bucket;
528
+ },
529
+ abortMultipartUpload(file, callback) {
530
+ if (file.uploadId && file.status == "uploading") {
531
+ this.obsClient
532
+ .abortMultipartUpload({
533
+ Bucket: this.getBucket(),
534
+ Key: file.obsKey,
535
+ UploadId: file.uploadId,
536
+ })
537
+ .then((result) => {
538
+ if (result.CommonMsg.Status < 300) {
539
+ callback && callback();
540
+ }
541
+ });
542
+ } else {
543
+ callback && callback();
544
+ }
545
+ },
546
+ createUUID() {
547
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
548
+ .replace(/[xy]/g, function (c) {
549
+ var r = (Math.random() * 16) | 0,
550
+ v = c == "x" ? r : (r & 0x3) | 0x8;
551
+ return v.toString(16);
552
+ })
553
+ .replaceAll("-", "");
554
+ },
555
+ handleUpload(file) {
556
+ let target = this.$refs.upload;
557
+ let fileObj = target.getFile(file);
558
+ fileObj.status = "uploading";
559
+ // this.initiateData.option = option;
560
+ this.fileUrl = "";
561
+ var _this = this;
562
+ let fileSuffix = this.$commonFileUtil.getFileSuffix(file.name);
563
+ let uuids = this.createUUID() + Date.now();
564
+ fileObj.obsKey = uuids + "." + fileSuffix;
565
+ const params = {
566
+ Bucket: this.getBucket(),
567
+ Key: fileObj.obsKey,
568
+ };
569
+ // let target = this.$refs.upload;
570
+ // let fileObj = target.getFile(option.file);
571
+ // fileObj.obsKey = uuids;
572
+ setTimeout(() => {
573
+ this.obsClient.initiateMultipartUpload(params).then((result) => {
574
+ if (result.CommonMsg.Status < 300) {
575
+ var uploadId = result.InterfaceResult.UploadId;
576
+ // _this.initiateData.uploadId = uploadId;
577
+ fileObj.uploadId = uploadId;
578
+ /*
579
+ * Step 2: upload a part
580
+ */
581
+ var etag = [];
582
+ var uploadPromise = new Promise((resolve) => {
583
+ var partLen = 5 * 1024 * 1024;
584
+ var count = Math.ceil(file.size / partLen);
585
+ var indexNum = 0;
586
+ this.uploadPartMethod(
587
+ file,
588
+ uploadId,
589
+ indexNum,
590
+ partLen,
591
+ etag,
592
+ count,
593
+ resolve
594
+ );
595
+ });
596
+ uploadPromise.then((result) => {
597
+ const paramsEnd = {
598
+ Bucket: this.getBucket(),
599
+ Key: fileObj.obsKey,
600
+ UploadId: uploadId,
601
+ Parts: etag.sort((a, b) => a.PartNumber - b.PartNumber),
602
+ };
603
+ this.obsClient
604
+ .completeMultipartUpload(paramsEnd)
605
+ .then((result) => {
606
+ if (result.CommonMsg.Status < 300) {
607
+ let fileUrl = _this.getImageUrl(file);
608
+ let fileData = this.parseFileUrl(fileUrl, file);
609
+ target.handleProgress({ percent: 100 }, file);
610
+
611
+ target.handleSuccess(
612
+ {
613
+ type: "success",
614
+ objx: fileData,
615
+ },
616
+ file
617
+ );
618
+ } else {
619
+ this.handleFileError(
620
+ new Error(
621
+ result.CommonMsg.Message ||
622
+ this.$t2(
623
+ "上传异常",
624
+ "components.VabUpload.uploadException"
625
+ )
626
+ ),
627
+ file
628
+ );
629
+ }
630
+ });
631
+ });
632
+ } else {
633
+ this.handleFileError(
634
+ new Error(
635
+ result.CommonMsg.Message ||
636
+ this.$t2("上传异常", "components.VabUpload.uploadException")
637
+ ),
638
+ file
639
+ );
640
+ }
641
+ });
642
+ }, 20);
643
+ },
644
+ parseFileUrl(fileUrl,file) {
645
+ if (!fileUrl) return null;
646
+ let result = null;
647
+
648
+ // 输入校验
649
+ if (typeof fileUrl !== "string") {
650
+ throw new TypeError("输入必须是字符串格式");
651
+ }
652
+ if (!fileUrl.trim()) {
653
+ throw new Error("URL不能为空");
654
+ }
655
+
656
+ // 基本URL格式验证
657
+ const urlRegex =
658
+ /^(https?:\/\/)?([\w.-]+)(:\d+)?(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i;
659
+ if (!urlRegex.test(fileUrl)) {
660
+ throw new Error("无效的URL格式");
661
+ }
662
+
663
+ // 提取域名部分
664
+ const domainRegex = /^(https?:\/\/[^\/]+)/i;
665
+ const domainMatch = fileUrl.match(domainRegex);
666
+ if (!domainMatch) {
667
+ throw new Error("URL缺少协议或域名部分");
668
+ }
669
+ const domain = domainMatch[0];
670
+
671
+ // 提取完整路径
672
+ const url = fileUrl.substring(domain.length);
673
+ if (!url || url === "/") {
674
+ throw new Error("URL缺少文件路径部分");
675
+ }
676
+
677
+ // 提取带扩展名的文件名
678
+ const filenameRegex = /[^\/]+$/;
679
+ const filenameMatch = url.match(filenameRegex);
680
+ if (!filenameMatch) {
681
+ throw new Error("无法从路径中提取文件名");
682
+ }
683
+ const fullFilename = filenameMatch[0];
684
+
685
+ // 验证文件名格式(至少1字符+扩展名)
686
+ const nameFormat = /^.+\..+$/;
687
+ if (!nameFormat.test(fullFilename)) {
688
+ throw new Error(`无效的文件名格式: ${fullFilename}`);
689
+ }
690
+
691
+ // 修复点:更可靠的文件名和扩展名分离
692
+ const lastDotIndex = fullFilename.lastIndexOf(".");
693
+ const filenameBase = fullFilename.substring(0, lastDotIndex); // 点之前部分
694
+ const extension = fullFilename.substring(lastDotIndex + 1).toLowerCase(); // 点之后部分
695
+
696
+ // 扩展名验证
697
+ /* const validExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'];
698
+ if (!validExtensions.includes(extension)) {
699
+ throw new Error(`不支持的扩展名类型: ${extension}`);
700
+ } */
701
+
702
+ let thumbnail = null,
703
+ large = null,
704
+ medium = null,
705
+ source = null;
706
+ if (this.$commonFileUtil.isPicture(extension)) {
707
+ thumbnail = url;
708
+ large = url;
709
+ medium = url;
710
+ source = url;
711
+ }
712
+
713
+ result = {
714
+ extension,
715
+ domain,
716
+ url,
717
+ thumbnail,
718
+ large,
719
+ medium,
720
+ source,
721
+ fileSize: file?file.size:0,
722
+ name: file?file.name:null
723
+ };
724
+
725
+ // 返回结构化对象
726
+ return result;
727
+ },
728
+ uploadPartMethod(file, UploadId, indexNum, partLen, etag, count, resolve) {
729
+ let target = this.$refs.upload;
730
+ let fileObj = target.getFile(file);
731
+ var _this = this;
732
+ this.obsClient
733
+ .uploadPart({
734
+ Bucket: this.getBucket(),
735
+ Key: fileObj.obsKey,
736
+ UploadId,
737
+ PartNumber: indexNum + 1,
738
+ SourceFile: file,
739
+ PartSize: partLen,
740
+ Offset: partLen * indexNum,
741
+ })
742
+ .then((result) => {
743
+ if (fileObj.status !== "uploading") {
744
+ return;
745
+ }
746
+ if (result.CommonMsg.Status < 300) {
747
+ etag.push({
748
+ ETag: result.InterfaceResult.ETag,
749
+ PartNumber: indexNum + 1,
750
+ });
751
+ indexNum++;
752
+ if (indexNum < count) {
753
+ let percentage = Math.ceil((indexNum / count) * 100);
754
+ // _this.percentage = Math.ceil((indexNum / count) * 100);
755
+ fileObj.percentage = percentage;
756
+ // option.file.percent = percentage;
757
+ // option.onProgress(option.file);
758
+
759
+ let progressEvent = document.createEvent("Event");
760
+ progressEvent.percent = percentage;
761
+ target.handleProgress(progressEvent, file);
762
+
763
+ _this.uploadPartMethod(
764
+ file,
765
+ UploadId,
766
+ indexNum,
767
+ partLen,
768
+ etag,
769
+ count,
770
+ resolve
771
+ );
772
+ }
773
+ if (indexNum == count) {
774
+ // _this.percentage = 100;
775
+ let percentage = 100;
776
+ fileObj.percentage = percentage;
777
+ /* option.file.percent = percentage;
778
+ option.onProgress(option.file); */
779
+
780
+ let progressEvent = document.createEvent("Event");
781
+ progressEvent.percent = percentage;
782
+ target.handleProgress(progressEvent, file);
783
+
784
+ resolve("任务完成");
785
+ }
786
+ } else {
787
+ this.handleFileError(
788
+ new Error(
789
+ result.CommonMsg.Message ||
790
+ this.$t2("上传异常", "components.VabUpload.uploadException")
791
+ ),
792
+ file
793
+ );
794
+ }
795
+ })
796
+ .catch((error) => {
797
+ this.handleFileError(error, file);
798
+ });
799
+ },
800
+ getImageUrl(file) {
801
+ let target = this.$refs.upload;
802
+ let fileObj = target.getFile(file);
803
+ let Bucket= this.getBucket();
804
+ let server = this.obsConfig.server
805
+ let arr = server.split("//")
806
+ let url = `${arr[0]}//${Bucket}.${arr[1]}/${fileObj.obsKey}`
807
+ // let url = `https://gztw-file01.obs.cn-south-1.myhuaweicloud.com/${fileObj.obsKey}`;
808
+ return url;
809
+ console.log(url);
810
+ /* let target = this.$refs.upload;
811
+ let fileObj = target.getFile(file);
812
+ const _this = this;
813
+ this.obsClient.getObject(
814
+ {
815
+ Bucket: this.getBucket(),
816
+ Key: fileObj.obsKey,
817
+ SaveByType: "file",
818
+ },
819
+ function (error, response) {
820
+ if (error) {
821
+ } else if (response.CommonMsg.Status < 300) {
822
+ const url = response.InterfaceResult.Content.SignedUrl;
823
+ console.log(url);
824
+ // this.imageUrl = url;
825
+ }
826
+ }
827
+ ); */
828
+ },
829
+ //obs end
830
+
831
+ checkPreUploadList() {
832
+ let uploadingLimit = this.option.uploadingLimit || this.uploadingLimit;
833
+ let target = this.$refs.upload;
834
+ let fileList1 = (target.uploadFiles || []).filter((item) => {
835
+ return item.status == "preUpload";
836
+ });
837
+ let fileList2 = (target.uploadFiles || []).filter((item) => {
838
+ return item.status == "uploading";
839
+ });
840
+ if (fileList2.length < uploadingLimit && fileList1.length > 0) {
841
+ let num = uploadingLimit - fileList2.length;
842
+ if (num) {
843
+ let toNum = Math.min(fileList1.length, num);
844
+ for (let i = 0; i < toNum; i++) {
845
+ let fileRaw = fileList1[i].raw;
846
+ // this.uploadFile(fileRaw);
847
+ this.handleUpload(fileRaw);
848
+ }
849
+ }
850
+ }
851
+ },
852
+ async uploadFile(file) {
853
+ if (!file || file.status == "fail") return;
854
+ let target = this.$refs.upload;
855
+ if (!target) return;
856
+ let fileObj = target.getFile(file);
857
+ if (fileObj.status != "preUpload") return;
858
+ if (!this.uploadUrl) {
859
+ await this.initUploadUrl();
860
+ }
861
+ this.total = 0;
862
+ target.handleProgress({ percent: 0 }, file);
863
+
864
+ // 解析为BUFFER数据
865
+ // 我们会把文件切片处理:把一个文件分割成为好几个部分(固定数量/固定大小)
866
+ // 每一个切片有自己的部分数据和自己的名字
867
+ // HASH_1.mp4
868
+ // HASH_2.mp4
869
+ // ...
870
+
871
+ this.fileParse(file, "buffer", (buffer) => {
872
+ let spark = new imFun.SparkMD5.ArrayBuffer(),
873
+ chunkSize = this.chunkSize * 1024 * 1024, // Read in chunks of 2MB
874
+ chunks = Math.ceil(file.size / chunkSize),
875
+ hash,
876
+ suffix;
877
+ spark.append(buffer);
878
+ hash = spark.end();
879
+ let nameSplit = /\.([0-9a-zA-Z]+)$/i.exec(file.name);
880
+
881
+ suffix = nameSplit && nameSplit.length > 1 ? nameSplit[1] : "";
882
+
883
+ let checkUrl = this.uploadUrl.replace(
884
+ "/docfile/upload",
885
+ "/docfile/check"
886
+ );
887
+ let checkData = {
888
+ name: file.name,
889
+ md5: hash,
890
+ };
891
+ let abort;
892
+ let checkReq = this.$http({
893
+ url: checkUrl,
894
+ method: "post",
895
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
896
+ abort = c;
897
+ file.abort = c;
898
+ }),
899
+ data: checkData,
900
+ failMsg: false,
901
+ modal: false,
902
+ callback: (res) => {
903
+ if (res.type == "success") {
904
+ let resData = res.objx || {};
905
+ let chunkParam = {
906
+ fullFile: file,
907
+ chunkSize: chunkSize,
908
+ chunks: chunks,
909
+ chunkIndex: 0,
910
+ md5: hash,
911
+ uuid: resData.uuid,
912
+ };
913
+ file.chunkParam = chunkParam;
914
+
915
+ this.sendRequest(file);
916
+ } else {
917
+ this.handleFileError(
918
+ new Error(
919
+ res.content ||
920
+ this.$t2("上传异常", "components.VabUpload.uploadException")
921
+ ),
922
+ file
923
+ );
924
+ }
925
+ },
926
+ error: (e) => {
927
+ this.handleFileError(e, file);
928
+ },
929
+ });
930
+ checkReq.abort = () => {
931
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
932
+ };
933
+ });
934
+ },
935
+ async sendRequest(fullFile) {
936
+ let that = this;
937
+ let uploadUrl = this.uploadUrl;
938
+ let chunkParam = fullFile.chunkParam;
939
+ let target = that.$refs.upload;
940
+ let abort;
941
+ let config = {
942
+ headers: {
943
+ "Content-Type": "multipart/form-data",
944
+ },
945
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
946
+ /* let target = that.$refs.upload;
947
+ let filem = target.getFile(file);
948
+ abort = c;
949
+ filem.abort = c; */
950
+ abort = c;
951
+ fullFile.abort = c;
952
+ }),
953
+ onUploadProgress: (progressEvent) => {
954
+ if (!target || !fullFile) return;
955
+ let file = target.getFile(fullFile);
956
+ if (file) {
957
+ // progressEvent.loaded:已上传文件大小
958
+ // progressEvent.total:被上传文件的总大小
959
+ let start = chunkParam.start;
960
+ let uploadedSize =
961
+ start +
962
+ Math.floor(
963
+ (chunkParam.currentSize * progressEvent.loaded) /
964
+ progressEvent.total
965
+ );
966
+ let percent = Math.floor((uploadedSize * 100) / fullFile.size);
967
+ if (percent == 100) {
968
+ percent = 99;
969
+ }
970
+ progressEvent.percent = percent;
971
+ target.handleProgress(progressEvent, fullFile);
972
+ }
973
+ },
974
+ failMsg: false,
975
+ modal: false,
976
+ }; //添加请求头
977
+
978
+ let chunkIndex = chunkParam.chunkIndex;
979
+ let chunkSize = chunkParam.chunkSize;
980
+ var start = chunkIndex * chunkSize,
981
+ end =
982
+ start + chunkSize >= fullFile.size
983
+ ? fullFile.size
984
+ : start + chunkParam.chunkSize;
985
+ chunkParam.currentSize = end - start;
986
+ chunkParam.start = start;
987
+ chunkParam.end = end;
988
+
989
+ let preFormData = {
990
+ file: fullFile.slice(start, end),
991
+ name: fullFile.name,
992
+ chunks: chunkParam.chunks,
993
+ chunk: chunkIndex,
994
+ md5: chunkParam.md5,
995
+ uuid: chunkParam.uuid,
996
+ fileSize: fullFile.size,
997
+ };
998
+
999
+ let formData = new FormData();
1000
+ Object.keys(preFormData).forEach((key) => {
1001
+ formData.append(key, preFormData[key]);
1002
+ });
1003
+
1004
+ let req = this.$http
1005
+ .post(uploadUrl, formData, config)
1006
+ .then((res1) => {
1007
+ if (res1.type == "success") {
1008
+ if (preFormData.chunk + 1 >= preFormData.chunks) {
1009
+ let mergeData = {};
1010
+ Object.keys(preFormData).forEach((key) => {
1011
+ if (key != "file" && key != "chunk") {
1012
+ mergeData[key] = preFormData[key];
1013
+ }
1014
+ });
1015
+ let _param = {
1016
+ mergeData: mergeData,
1017
+ chunkParam: chunkParam,
1018
+ };
1019
+ this.mergeFile(_param);
1020
+ } else {
1021
+ chunkParam.chunkIndex = chunkParam.chunkIndex + 1;
1022
+ this.sendRequest(fullFile);
1023
+ }
1024
+ } else {
1025
+ this.handleFileError(
1026
+ new Error(
1027
+ res1.content ||
1028
+ this.$t2("上传异常", "components.VabUpload.uploadException")
1029
+ ),
1030
+ fullFile
1031
+ );
1032
+ }
1033
+ return res1;
1034
+ })
1035
+ .catch((err) => {
1036
+ try {
1037
+ if (!abort) {
1038
+ this.handleFileError(err, fullFile);
1039
+ }
1040
+ } catch (tt) {}
1041
+ });
1042
+ req.abort = () => {
1043
+ abort(this.$t2("取消上传", "components.VabUpload.cancelUpload"));
1044
+ };
1045
+ },
1046
+ mergeFile(param) {
1047
+ let mergeData = param.mergeData;
1048
+ let chunkParam = param.chunkParam;
1049
+ let fullFile = chunkParam.fullFile;
1050
+ let mergeUrl = this.uploadUrl.replace(
1051
+ "/docfile/upload",
1052
+ "/docfile/merge"
1053
+ );
1054
+ let target = this.$refs.upload;
1055
+ this.$http({
1056
+ url: mergeUrl,
1057
+ method: "post",
1058
+ data: mergeData,
1059
+ failMsg: false,
1060
+ modal: false,
1061
+ cancelToken: new imFun.axios.CancelToken(function executor(c) {
1062
+ if (fullFile) fullFile.abort = c;
1063
+ }),
1064
+ callback: (res) => {
1065
+ if (!target || !fullFile) return;
1066
+ if (res.type == "success") {
1067
+ let file = target.getFile(fullFile);
1068
+ if (file) {
1069
+ target.handleProgress(
1070
+ {
1071
+ percent: 100,
1072
+ },
1073
+ fullFile
1074
+ );
1075
+ target.handleSuccess(res, fullFile);
1076
+ }
1077
+ } else {
1078
+ this.handleFileError(
1079
+ new Error(
1080
+ res.content ||
1081
+ this.$t2("上传异常", "components.VabUpload.uploadException")
1082
+ ),
1083
+ fullFile
1084
+ );
1085
+ }
1086
+ },
1087
+ error: (e) => {
1088
+ if (!target || !fullFile) return;
1089
+ if (fullFile) {
1090
+ let file = target.getFile(fullFile);
1091
+ if (file) {
1092
+ this.handleFileError(e, fullFile);
1093
+ }
1094
+ }
1095
+ },
1096
+ });
1097
+ },
1098
+ handleBtn() {
1099
+ let target = this.$refs.upload;
1100
+ let fileList = (target.uploadFiles || []).filter((item) => {
1101
+ return item.status == "uploading" || item.status == "ready";
1102
+ });
1103
+ if (this.btn) {
1104
+ //断点续传
1105
+ this.abort = false;
1106
+ this.btn = false;
1107
+ fileList.forEach((uploadFile) => {
1108
+ let nextChunk = uploadFile.raw.nextChunk;
1109
+ this.sendRequest(uploadFile.raw.partList, nextChunk);
1110
+ });
1111
+ } else {
1112
+ //暂停上传
1113
+ fileList.forEach((uploadFile) => {
1114
+ uploadFile.raw.abort(
1115
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
1116
+ );
1117
+ });
1118
+ this.btn = true;
1119
+ this.abort = true;
1120
+ }
1121
+ },
1122
+ //end
1123
+ getShowImage(file, fileName) {
1124
+ fileName = fileName || file.name;
1125
+ if (this.$commonFileUtil.isPictureFile(fileName)) {
1126
+ return file.showUrl || file.url;
1127
+ } else {
1128
+ return this.$commonFileUtil.getFileIconRequire(fileName);
1129
+ }
1130
+ },
1131
+ removeFile(sfile) {
1132
+ var target = this.$refs.upload;
1133
+ var index;
1134
+ var fileList = target.uploadFiles;
1135
+ for (let i = 0; i < fileList.length; i++) {
1136
+ let file = fileList[i];
1137
+ if (sfile.uid == file.uid) {
1138
+ index = i;
1139
+ if (sfile.status == "uploading") {
1140
+ // file.status == 'delete'
1141
+ //target.abort(file);
1142
+ this.abortMultipartUpload(file);
1143
+ /* file.raw.abort &&
1144
+ file.raw.abort(
1145
+ this.$t2("取消上传", "components.VabUpload.cancelUpload")
1146
+ ); */
1147
+ }
1148
+ break;
1149
+ }
1150
+ }
1151
+
1152
+ target.uploadFiles.splice(index, 1);
1153
+ this.handleChange(sfile, target.uploadFiles);
1154
+ },
1155
+ submitImage() {
1156
+ var target = this.$refs.upload;
1157
+ var fileList = target.uploadFiles;
1158
+ let fileInfos = [];
1159
+ let fileDatas = [];
1160
+ for (let i = 0; i < fileList.length; i++) {
1161
+ let file = fileList[i];
1162
+ if (file.status == "uploading") {
1163
+ this.$message({
1164
+ message: this.$t2(
1165
+ "文件上传中",
1166
+ "components.VabUpload.fileUploading"
1167
+ ),
1168
+ type: "error",
1169
+ duration: 2000,
1170
+ });
1171
+ return;
1172
+ }
1173
+ if (file.status == "success") {
1174
+ let fileData = file.response.objx;
1175
+ fileData.name = file.name;
1176
+ let fileInfo = {
1177
+ name: file.name,
1178
+ fileData: fileData,
1179
+ file: file.raw,
1180
+ };
1181
+ fileInfos.push(fileInfo);
1182
+ fileDatas.push(fileData);
1183
+ }
1184
+ }
1185
+ this.handleClose();
1186
+ this.$emit("callback", fileInfos, fileDatas);
1187
+ this.callback && this.callback(fileDatas, fileInfos);
1188
+ },
1189
+ showViewDialog(lineData) {
1190
+ var data = lineData.fileData ? lineData.fileData : lineData;
1191
+
1192
+ let thumbnail = data ? data.thumbnail || "" : "";
1193
+
1194
+ var realUrl = data.domain + data.url;
1195
+ var showUrl = "";
1196
+ let fileName = lineData ? lineData.name || "" : "";
1197
+ if (!this.$commonFileUtil.isPictureFile(fileName)) {
1198
+ showUrl = this.$commonFileUtil.getFileIconRequire(fileName);
1199
+ } else if (thumbnail) {
1200
+ showUrl = data.domain + thumbnail;
1201
+ } else {
1202
+ showUrl = data.domain + data.url;
1203
+ }
1204
+
1205
+ var preName = "";
1206
+ var suffix = "";
1207
+ var i = fileName.lastIndexOf(".");
1208
+ if (i >= 0) {
1209
+ suffix = fileName.substring(i + 1, fileName.length).toLowerCase();
1210
+ }
1211
+ this.fileViewInfo = {
1212
+ realUrl: realUrl,
1213
+ showUrl: showUrl,
1214
+ fileName: fileName,
1215
+ suffix: suffix,
1216
+ data: data,
1217
+ };
1218
+ this.fileViewDialogVisible = true;
1219
+ },
1220
+ getShowUrl(attachment, field) {
1221
+ let showUrl = null;
1222
+ let typeStr = Object.prototype.toString.call(attachment);
1223
+ if (typeStr == "[object Object]") {
1224
+ let showField = field ? field : "medium";
1225
+ let fullUrl =
1226
+ attachment.domain +
1227
+ (attachment[showField] ? attachment[showField] : attachment.url);
1228
+ showUrl = this.$commonFileUtil.getShowUrl(fullUrl);
1229
+ } else {
1230
+ showUrl = this.$commonFileUtil.getShowUrl(attachment);
1231
+ }
1232
+ return showUrl;
1233
+ },
1234
+ addPrivateFiles(rows) {
1235
+ var target = this.$refs.upload;
1236
+ let uploadFiles = target.uploadFiles;
1237
+ let sourceSns = uploadFiles
1238
+ .filter((row) => {
1239
+ return !!(
1240
+ row.response &&
1241
+ row.response.objx &&
1242
+ row.response.objx.sourceSn
1243
+ );
1244
+ })
1245
+ .map((row) => row.response.objx.sourceSn);
1246
+
1247
+ let newFiles = rows
1248
+ .filter((row) => !row.dirs && !sourceSns.includes(row.sn))
1249
+ .map((row) => {
1250
+ let item = {
1251
+ status: "success",
1252
+ name: row.fileName,
1253
+ size: row.fileSize,
1254
+ percentage: 100,
1255
+ uid: row.fileSn,
1256
+ raw: {
1257
+ lastModified: "",
1258
+ lastModifiedDate: new Date(),
1259
+ name: row.fileName,
1260
+ size: row.fileSize,
1261
+ type: "",
1262
+ uid: row.fileSn,
1263
+ webkitRelativePath: "",
1264
+ },
1265
+ response: {
1266
+ time: "",
1267
+ type: "success",
1268
+ objx: {
1269
+ thumbnail: row.thumbnail,
1270
+ extension: row.extension,
1271
+ large: row.large,
1272
+ fileSize: row.fileSize,
1273
+ domain: row.domain,
1274
+ source: row.source,
1275
+ medium: row.medium,
1276
+ url: row.url,
1277
+ sourceSn: row.sn,
1278
+ },
1279
+ content: "success",
1280
+ rmid: null,
1281
+ },
1282
+ url: row.domain + row.url,
1283
+ showUrl: this.getShowUrl(row),
1284
+ };
1285
+ return item;
1286
+ });
1287
+ uploadFiles.push(...newFiles);
1288
+ },
1289
+ confirmPrivateProfileDialog(rows) {
1290
+ this.addPrivateFiles(rows);
1291
+ },
1292
+ initPrivateUploadBt() {
1293
+ if (settingConfig.privateProfileCode && this.pickPrivateProfile) {
1294
+ this.$http({
1295
+ url: USER_PREFIX + "/file_store_area/getByCode",
1296
+ method: "post",
1297
+ data: { stringOne: settingConfig.privateProfileCode },
1298
+ failMsg: false,
1299
+ errorMsg: false,
1300
+ success: (res) => {
1301
+ this.showPrivateUploadBtn = res.objx ? true : false;
1302
+ },
1303
+ });
1304
+ } else {
1305
+ this.showPrivateUploadBtn = false;
1306
+ }
1307
+ },
1308
+ initPickUploadMode() {
1309
+ this.showLocalUploadBtn = false;
1310
+ this.showPrivateUploadBtn = false;
1311
+ this.$http({
1312
+ url: USER_PREFIX + "/system_parameter/getByCode",
1313
+ method: "post",
1314
+ data: { code: "pickUploadMode" },
1315
+ success: (res) => {
1316
+ let value = !res.objx || !res.objx.value ? "2" : res.objx.value;
1317
+ if (value == "0") {
1318
+ //启用本地上传,个人文档上传
1319
+ this.showLocalUploadBtn = true;
1320
+ this.initPrivateUploadBt();
1321
+ } else if (value == "1") {
1322
+ //启用个人文档上传
1323
+ this.initPrivateUploadBt();
1324
+ } else if (value == "2") {
1325
+ //启用本地上传
1326
+ this.showLocalUploadBtn = true;
1327
+ }
1328
+ },
1329
+ });
1330
+ },
1331
+ pasteEvent(e) {
1332
+ // e.preventDefault();
1333
+ e.stopPropagation();
1334
+ if (!this.pasteAreaStatus) {
1335
+ return;
1336
+ }
1337
+ if (!(e.clipboardData && e.clipboardData.items)) {
1338
+ return;
1339
+ }
1340
+ let files = Array.from(e.clipboardData.files);
1341
+ let getFileSuffix = this.$commonFileUtil.getFileSuffix;
1342
+ if (files.length) {
1343
+ let fileList = files.map((rawFile) => {
1344
+ let name = rawFile.name;
1345
+ let index = name.lastIndexOf(".");
1346
+ let fileSuffix = getFileSuffix(name);
1347
+ let fileName =
1348
+ index >= 0 ? name.substring(0, index).toString() : name.toString();
1349
+ let file = {
1350
+ name: rawFile.name,
1351
+ size: rawFile.size,
1352
+ raw: rawFile,
1353
+ showUrl: URL.createObjectURL(rawFile),
1354
+ fileName: fileName,
1355
+ fileSuffix: fileSuffix,
1356
+ };
1357
+ return file;
1358
+ });
1359
+ this.pasteList.push(...fileList);
1360
+ }
1361
+ },
1362
+ deletePasteFile(index) {
1363
+ this.pasteList.splice(index, 1);
1364
+ },
1365
+ confirmPasteFile() {
1366
+ let target = this.$refs.upload;
1367
+ let innerTarget = target.$refs["upload-inner"];
1368
+ let pasteList = this.$baseLodash.cloneDeep(this.pasteList);
1369
+ let files = pasteList.map((item) => {
1370
+ let name = item.name;
1371
+ let fileRaw = item.raw;
1372
+ fileRaw.fileName = name;
1373
+ return fileRaw;
1374
+ });
1375
+ innerTarget.uploadFiles(files);
1376
+ this.$nextTick(() => {
1377
+ target.uploadFiles.forEach((uploadFile) => {
1378
+ let fileRaw = uploadFile.raw;
1379
+ if (fileRaw.fileName) {
1380
+ uploadFile.name = fileRaw.fileName;
1381
+ delete fileRaw.fileName;
1382
+ }
1383
+ });
1384
+ });
1385
+ this.pasteList = [];
1386
+ },
1387
+ changeFileName(file) {
1388
+ if (file.fileSuffix) {
1389
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1390
+ } else {
1391
+ file.name = file.fileName.toString();
1392
+ }
1393
+ },
1394
+ handleFileError(err, rawFile) {
1395
+ let target = this.$refs.upload;
1396
+ if (!target) return;
1397
+ const file = target.getFile(rawFile);
1398
+ const fileList = target.uploadFiles;
1399
+
1400
+ file.status = "fail";
1401
+ file.failMsg = err && err.message ? err.message : null;
1402
+
1403
+ // fileList.splice(fileList.indexOf(file), 1);
1404
+
1405
+ target.onError(err, file, target.uploadFiles);
1406
+ target.onChange(file, target.uploadFiles);
1407
+ this.updateUploadingStatus();
1408
+ },
1409
+ choosePasteArea(e) {
1410
+ e.stopPropagation();
1411
+ this.pasteAreaStatus = true;
1412
+ },
1413
+ openFileNameDialog(row, index) {
1414
+ this.editFileName = row.fileName?.toString();
1415
+ this.editFileSuffix = row.fileSuffix?.toString();
1416
+ this.editFileIndex = index;
1417
+ this.showFileNameDialog = true;
1418
+ },
1419
+ confirmFileNameDialog() {
1420
+ if (!this.editFileName) {
1421
+ this.$message({
1422
+ message: this.$t2("文件名不能为空", "components.VabUpload.warnMsg3"),
1423
+ type: "error",
1424
+ showClose: true,
1425
+ duration: 3000,
1426
+ });
1427
+ return;
1428
+ }
1429
+ let editFileIndex = this.editFileIndex;
1430
+ let file = this.pasteList[editFileIndex];
1431
+ file.fileName = this.editFileName.toString();
1432
+ file.name = (file.fileName + "." + file.fileSuffix).toString();
1433
+ this.showFileNameDialog = false;
1434
+ },
1435
+ },
1436
+ };
1437
+
1438
+
1439
+ function formatFileSize(fileSize) {
1440
+ fileSize = fileSize || 0;
1441
+ if (fileSize < 1024) {
1442
+ return fileSize + "B";
1443
+ } else if (fileSize < 1024 * 1024) {
1444
+ var temp = fileSize / 1024;
1445
+ temp = temp.toFixed(2);
1446
+ return temp + "KB";
1447
+ } else if (fileSize < 1024 * 1024 * 1024) {
1448
+ var temp = fileSize / (1024 * 1024);
1449
+ temp = temp.toFixed(2);
1450
+ return temp + "MB";
1451
+ } else {
1452
+ var temp = fileSize / (1024 * 1024 * 1024);
1453
+ temp = temp.toFixed(2);
1454
+ return temp + "GB";
1455
+ }
1456
+ }
1457
+
1458
+ export const mixins = tmixins;