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