|
11 | 11 | <meta name="description" content="{{description}}"/> |
12 | 12 | <meta name="keywords" content="{{keywords}}"/> |
13 | 13 | <meta name="generator" content="FileCodeBox"/> |
14 | | - <meta name="template" content="V1.6 Beta"/> |
| 14 | + <meta name="template" content="V1.7 Beta"/> |
15 | 15 | <style> |
16 | 16 | body { |
17 | 17 | background: #f5f5f5; |
@@ -288,6 +288,7 @@ <h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: poin |
288 | 288 | }, |
289 | 289 | quFiles: [], |
290 | 290 | jiFiles: [], |
| 291 | + uploadGroup: [], |
291 | 292 | pageNum: 0, |
292 | 293 | inputDisable: false, |
293 | 294 | fileSizeLimit: '{{fileSizeLimit}}', |
@@ -386,7 +387,11 @@ <h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: poin |
386 | 387 | formData.append('file_key', file_key); |
387 | 388 | formData.append('chunk_index', chunk_index); |
388 | 389 | formData.append('total_chunks', total_chunks); |
389 | | - await this.http('post', `/file/upload/${file_key}/`, formData) |
| 390 | + this.http('post', `/file/upload/${file_key}/`, formData).then((res) => { |
| 391 | + this.upload_groups[chunk_index - 1] = 1; |
| 392 | + }).catch((res) => { |
| 393 | + this.upload_groups[chunk_index - 1] = 2; |
| 394 | + }) |
390 | 395 | }, |
391 | 396 | copyText: function (value, style = 1) { |
392 | 397 | if (style === 0) { |
@@ -475,36 +480,56 @@ <h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: poin |
475 | 480 | const shardSize = 1024 * 1024 * 5; |
476 | 481 | const {name, size, type} = file; |
477 | 482 | const total_chunks = Math.ceil(size / shardSize); |
| 483 | + this.upload_groups = []; |
| 484 | + for (let i = 0; i < total_chunks; i++) { |
| 485 | + this.upload_groups.push(0); |
| 486 | + } |
478 | 487 | while (chunk_index < total_chunks) { |
479 | 488 | const start = chunk_index * shardSize |
480 | 489 | const end = Math.min(start + shardSize, size) |
481 | 490 | chunk_index += 1; |
482 | | - await this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks); |
| 491 | + this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks); |
483 | 492 | } |
484 | | - this.http('get', `/file/merge/${res.data}/?file_name=${name}&total_chunks=${total_chunks}`).then(text => { |
485 | | - this.http('post', '/share/file/', { |
486 | | - text: text.data, |
487 | | - size: size, |
488 | | - exp_style: this.uploadData.exp_style, |
489 | | - exp_value: this.uploadData.exp_value, |
490 | | - type: type, |
491 | | - name: name, |
492 | | - key: res.data, |
493 | | - }, { |
494 | | - headers: { |
495 | | - 'pwd': this.pwd |
| 493 | + const interval = setInterval(() => { |
| 494 | + let flag = true; |
| 495 | + for (let i = 0; i < total_chunks; i++) { |
| 496 | + if (this.upload_groups[i] === 0) { |
| 497 | + flag = false; |
| 498 | + } else if (this.upload_groups[i] === 2) { |
| 499 | + flag = false; |
| 500 | + start = chunk_index * shardSize; |
| 501 | + const end = Math.min(start + shardSize, size) |
| 502 | + this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks); |
496 | 503 | } |
497 | | - }).then(res => { |
498 | | - this.jiFiles.unshift(res.data); |
499 | | - this.jiDrawer = true; |
500 | | - this.uploadData.text = ''; |
501 | | - this.uploadData.file = null; |
502 | | - this.$message({ |
503 | | - message: '上传成功', |
504 | | - type: 'success' |
505 | | - }); |
506 | | - }) |
507 | | - }) |
| 504 | + } |
| 505 | + if (flag) { |
| 506 | + clearInterval(interval); |
| 507 | + this.http('get', `/file/merge/${res.data}/?file_name=${name}&total_chunks=${total_chunks}`).then(text => { |
| 508 | + this.http('post', '/share/file/', { |
| 509 | + text: text.data, |
| 510 | + size: size, |
| 511 | + exp_style: this.uploadData.exp_style, |
| 512 | + exp_value: this.uploadData.exp_value, |
| 513 | + type: type, |
| 514 | + name: name, |
| 515 | + key: res.data, |
| 516 | + }, { |
| 517 | + headers: { |
| 518 | + 'pwd': this.pwd |
| 519 | + } |
| 520 | + }).then(res => { |
| 521 | + this.jiFiles.unshift(res.data); |
| 522 | + this.jiDrawer = true; |
| 523 | + this.uploadData.text = ''; |
| 524 | + this.uploadData.file = null; |
| 525 | + this.$message({ |
| 526 | + message: '上传成功', |
| 527 | + type: 'success' |
| 528 | + }); |
| 529 | + }) |
| 530 | + }) |
| 531 | + } |
| 532 | + }, 100); |
508 | 533 | }); |
509 | 534 | } |
510 | 535 | }, |
|
0 commit comments