You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MinioUploader.vue 22 kB

5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <div class="dropzone-wrapper dataset-files">
  3. <div id="dataset" class="dropzone">
  4. <div class="maxfilesize ui red message" style="display: none;margin: 2.5rem;"></div>
  5. </div>
  6. <!-- <p class="upload-info">
  7. {{ file_status_text }}
  8. <strong class="success text red">{{ status }}</strong>
  9. </p> -->
  10. <el-button style="background-color: #21ba45;margin-top: 2rem;" type="success" :disabled="btnFlag" @click="startUpload">{{upload}}</el-button>
  11. <el-button type="info" @click="cancelDataset">{{cancel}}</el-button>
  12. <div style="margin-top: 2rem;position: relative;">
  13. <label class="el-form-item__label" style="width: 140px;position: absolute;left: -140px;">上传状态:</label>
  14. <div v-for="item in allUploadFiles" style="display:flex;padding: 0.8rem 0;border-bottom: 1px solid #e8e8e8;line-height: 1;" >
  15. <span style="flex:4 1 0%;display: flex;"><i :class="[item.status===0?'ri-checkbox-circle-line success':'ri-close-circle-line failed']" style="margin-right: 0.5rem;"></i>{{item.name}}</span>
  16. <span style="flex:1" v-if="item.status===0"><span style="color: #21ba45;">上传成功</span></span>
  17. <span style="flex:1" v-else-if="item.status===1">
  18. <el-tooltip class="item" effect="dark" placement="top">
  19. <div slot="content">{{item.info}}</div>
  20. <span style="color: red;cursor: pointer;">上传失败<span>(重复上传)</span></span>
  21. </el-tooltip>
  22. </span>
  23. <span style="flex:1" v-else><span style="color: red;">上传失败</span></span>
  24. </div>
  25. </div>
  26. <!-- <p>说明:<br>
  27. - 只有zip格式的数据集才能发起云脑任务;<br>
  28. - 云脑1提供 <span class="text blue">CPU / GPU</span> 资源,云脑2提供 <span class="text blue">Ascend NPU</span> 资源;调试使用的数据集也需要上传到对应的环境。</p> -->
  29. </div>
  30. </template>
  31. <script>
  32. import SparkMD5 from 'spark-md5';
  33. import axios from 'axios';
  34. import qs from 'qs';
  35. import createDropzone from '../features/dropzone.js';
  36. const {_AppSubUrl, _StaticUrlPrefix, csrf} = window.config;
  37. const chunkSize = 1024 * 1024 * 64;
  38. const md5ChunkSize = 1024 * 1024 * 1;
  39. export default {
  40. props:{
  41. uploadtype:{
  42. type:Number,
  43. required:true
  44. },
  45. desc:{
  46. type:String,
  47. default:''
  48. }
  49. },
  50. data() {
  51. return {
  52. dropzoneUploader: null,
  53. maxFiles: 10,
  54. maxFilesize: 200 ,
  55. acceptedFiles: '*/*',
  56. progress: 0,
  57. status: '',
  58. dropzoneParams: {},
  59. file_status_text: '',
  60. file:{},
  61. repoPath:'',
  62. btnFlag:false,
  63. cancel:'',
  64. upload:'',
  65. uploadFiles:[],
  66. uploadFilesAddId:[],
  67. allUploadFiles:[],
  68. uploadLength:0,
  69. allUploadLength:0,
  70. };
  71. },
  72. async mounted() {
  73. this.dropzoneParams = $('div#minioUploader-params');
  74. this.file_status_text = this.dropzoneParams.data('file-status');
  75. this.status = this.dropzoneParams.data('file-init-status');
  76. this.repoPath = this.dropzoneParams.data('repopath');
  77. this.cancel = this.dropzoneParams.data('cancel');
  78. this.upload = this.dropzoneParams.data('upload');
  79. let previewTemplate = `
  80. <div class="dz-preview dz-file-preview">
  81. <div class="dz-image">
  82. <img data-dz-thumbnail />
  83. </div>
  84. <div class="dz-details">
  85. <div class="dz-size"><span data-dz-size></span></div>
  86. <div class="dz-filename"><span data-dz-name></span></div>
  87. </div>
  88. <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
  89. <div class="dz-error-message" style="line-height: 1.5;"><span data-dz-errormessage></span></div>
  90. <div class="dz-success-mark"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="54" height="54"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm-.997-4L6.76 11.757l1.414-1.414 2.829 2.829 5.656-5.657 1.415 1.414L11.003 16z" fill="rgba(47,204,113,1)"/></svg></div>
  91. <div class="dz-error-mark"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="54" height="54"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-9.414l2.828-2.829 1.415 1.415L13.414 12l2.829 2.828-1.415 1.415L12 13.414l-2.828 2.829-1.415-1.415L10.586 12 7.757 9.172l1.415-1.415L12 10.586z" fill="rgba(231,76,60,1)"/></svg></div>
  92. </div> `
  93. const $dropzone = $('div#dataset');
  94. const dropzoneUploader = await createDropzone($dropzone[0], {
  95. url: '/todouploader',
  96. maxFiles: this.maxFiles,
  97. maxFilesize: 1024*10,
  98. filesizeBase:1024,
  99. parallelUploads: this.maxFiles,
  100. timeout: 0,
  101. addRemoveLinks:true,
  102. // autoQueue: false,
  103. autoProcessQueue: false, //自动上传
  104. dictDefaultMessage: this.dropzoneParams.data('default-message'),
  105. dictInvalidFileType: this.dropzoneParams.data('invalid-input-type'),
  106. dictFileTooBig: this.dropzoneParams.data('file-too-big'),
  107. dictRemoveFile: this.dropzoneParams.data('remove-file'),
  108. previewTemplate:previewTemplate
  109. });
  110. dropzoneUploader.on('addedfile', (file) => {
  111. if(file.size/(1024*1024)>dropzoneUploader.options.maxFilesize){
  112. dropzoneUploader.removeFile(file)
  113. $('.maxfilesize.ui.red.message').text("单次最多上传10个文件,单个文件不超过200G")
  114. $('.maxfilesize.ui.red.message').css('display','block')
  115. }else{
  116. this.file = file
  117. $('.maxfilesize.ui.red.message').css('display','none')
  118. }
  119. });
  120. dropzoneUploader.on("removedfile",(file)=>{
  121. $('.maxfilesize.ui.red.message').css('display','none')
  122. })
  123. dropzoneUploader.on('maxfilesexceeded', function (file) {
  124. console.log("maxfilesexceeded")
  125. // if (this.files[0].status !== 'success') {
  126. // alert(this.dropzoneParams.data('waitting-uploading'));
  127. // this.removeFile(file);
  128. // return;
  129. // }
  130. dropzoneUploader.removeFile(file)
  131. $('.maxfilesize.ui.red.message').text("单次最多上传10个文件,单个文件不超过200G")
  132. $('.maxfilesize.ui.red.message').css('display','block')
  133. // this.removeAllFiles();
  134. // this.addFile(file);
  135. });
  136. this.dropzoneUploader = dropzoneUploader;
  137. console.log(this.dropzoneUploader)
  138. },
  139. watch:{
  140. allUploadLength(len){
  141. console.log(len)
  142. if(len===this.uploadFiles.length){
  143. setTimeout(() => {
  144. this.dropzoneUploader.removeAllFiles(true)
  145. this.btnFlag = false
  146. }, 2000);
  147. }
  148. }
  149. },
  150. methods: {
  151. startUpload(){
  152. this.resetStatus()
  153. $('.dz-remove').remove()
  154. $('.maxfilesize.ui.red.message').css('display','none')
  155. this.btnFlag = true
  156. this.uploadFiles = this.dropzoneUploader.getQueuedFiles()
  157. this.uploadFiles.forEach(element => {
  158. element.datasetId = document.getElementById('datasetId').getAttribute('datasetId')
  159. this.computeMD5(element)
  160. });
  161. },
  162. cancelDataset(){
  163. location.href = this.repoPath
  164. this.dropzoneUploader.removeAllFiles(true)
  165. },
  166. resetStatus() {
  167. this.uploadLength = 0
  168. this.allUploadLength = 0
  169. this.allUploadFiles = []
  170. },
  171. updateProgress(file, progress) {
  172. file.previewTemplate.querySelector(
  173. '.dz-upload'
  174. ).style.width = `${progress}%`
  175. file.previewTemplate.querySelector(
  176. '.dz-upload'
  177. ).style.background = '#409eff';
  178. },
  179. uploadError(file,info){
  180. file.previewTemplate.querySelector(
  181. '.dz-error-mark'
  182. ).style.opacity = 1
  183. file.previewTemplate.querySelector(
  184. '.dz-progress'
  185. ).style.opacity = 0
  186. file.previewTemplate.querySelector(
  187. '.dz-error-message span'
  188. ).innerHTML = info
  189. file.previewTemplate.querySelector(
  190. '.dz-error-message'
  191. ).style.display = 'block'
  192. file.previewTemplate.querySelector(
  193. '.dz-details'
  194. ).onmouseover = function(){file.previewTemplate.querySelector('.dz-error-message').style.opacity = 1 }
  195. file.previewTemplate.querySelector(
  196. '.dz-details'
  197. ).onmouseout = function(){file.previewTemplate.querySelector('.dz-error-message').style.opacity = 0 }
  198. },
  199. emitDropzoneSuccess(file) {
  200. file.status = 'success';
  201. this.dropzoneUploader.emit('success', file);
  202. this.dropzoneUploader.emit('complete', file);
  203. },
  204. emitDropzoneFailed(file) {
  205. this.status = this.dropzoneParams.data('falied');
  206. file.status = 'error';
  207. this.dropzoneUploader.emit('error', file);
  208. // this.dropzoneUploader.emit('complete', file);
  209. },
  210. finishUpload(file) {
  211. file.previewTemplate.querySelector(
  212. '.dz-success-mark'
  213. ).style.opacity = 1
  214. file.previewTemplate.querySelector(
  215. '.dz-progress'
  216. ).style.opacity = 0
  217. console.log()
  218. if(this.uploadLength === this.uploadFiles.length){
  219. setTimeout(() => {
  220. window.location.href = this.repoPath
  221. }, 1000);
  222. }
  223. },
  224. computeMD5(file) {
  225. console.log("computeMD5-file:",file)
  226. const blobSlice =
  227. File.prototype.slice ||
  228. File.prototype.mozSlice ||
  229. File.prototype.webkitSlice,
  230. chunks = Math.ceil(file.size / chunkSize),
  231. spark = new SparkMD5.ArrayBuffer(),
  232. fileReader = new FileReader();
  233. let currentChunk = 0;
  234. console.log("computeMD5-chunks:",chunks)
  235. const time = new Date().getTime();
  236. this.status = this.dropzoneParams.data('md5-computing');
  237. file.totalChunkCounts = chunks;
  238. if (file.size==0) {
  239. file.totalChunkCounts = 1
  240. }
  241. loadMd5Next();
  242. fileReader.onload = (e) => {
  243. fileLoaded.call(this, e);
  244. };
  245. fileReader.onerror = (err) => {
  246. console.warn('oops, something went wrong.', err);
  247. file.cancel();
  248. };
  249. function fileLoaded(e) {
  250. spark.append(e.target.result); // Append array buffer
  251. currentChunk++;
  252. if (currentChunk < chunks) {
  253. this.status = `${this.dropzoneParams.data('loading-file')} ${(
  254. (currentChunk / chunks) *
  255. 100
  256. ).toFixed(2)}% (${currentChunk}/${chunks})`;
  257. console.log("this.status",this.status)
  258. this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
  259. loadMd5Next();
  260. return;
  261. }
  262. const md5 = spark.end();
  263. console.log(
  264. `MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${
  265. file.size
  266. } 用时:${(new Date().getTime() - time) / 1000} s`
  267. );
  268. this.updateProgress(file,100)
  269. spark.destroy(); // 释放缓存
  270. file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识
  271. file.cmd5 = false; // 取消计算md5状态
  272. this.computeMD5Success(file);
  273. }
  274. function loadNext() {
  275. const start = currentChunk * chunkSize;
  276. const end =
  277. start + chunkSize >= file.size ? file.size : start + chunkSize;
  278. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  279. }
  280. function loadMd5Next() {
  281. const start = currentChunk * chunkSize;
  282. const end =
  283. start + md5ChunkSize >= file.size ? file.size : start + md5ChunkSize;
  284. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  285. }
  286. },
  287. async computeMD5Success(md5edFile) {
  288. const file = await this.getSuccessChunks(md5edFile);
  289. try {
  290. if (file.uploadID == '' || file.uuid == '') {
  291. // 未上传过
  292. await this.newMultiUpload(file);
  293. if (file.uploadID != '' && file.uuid != '') {
  294. file.chunks = '';
  295. this.multipartUpload(file);
  296. } else {
  297. // 失败如何处理
  298. let info = "上传失败"
  299. this.allUploadLength++
  300. this.uploadError(file,info)
  301. this.allUploadFiles.push({name:file.name,status:2,info:info})
  302. return;
  303. }
  304. return;
  305. }
  306. if (file.uploaded == '1') {
  307. // 已上传成功
  308. // 秒传
  309. if (file.attachID == '0') {
  310. // 删除数据集记录,未删除文件
  311. await addAttachment(file);
  312. }
  313. //不同数据集上传同一个文件
  314. if (file.datasetID != '') {
  315. if (file.datasetName != "" && file.realName != "") {
  316. // var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")";
  317. // window.location.reload();
  318. let info = `该文件已上传在数据集: ${file.datasetName}`
  319. this.uploadError(file,info)
  320. this.allUploadLength++
  321. this.allUploadFiles.push({name:file.name,status:1,info:info})
  322. }
  323. }
  324. console.log('文件已上传完成');
  325. this.progress = 100;
  326. this.status = this.dropzoneParams.data('upload-complete');
  327. // this.finishUpload(file);
  328. } else {
  329. // 断点续传
  330. this.multipartUpload(file);
  331. }
  332. } catch (error) {
  333. this.emitDropzoneFailed(file);
  334. console.log(error);
  335. }
  336. async function addAttachment(file) {
  337. return await axios.post(
  338. '/attachments/add',
  339. qs.stringify({
  340. uuid: file.uuid,
  341. file_name: file.name,
  342. size: file.size,
  343. dataset_id: file.datasetId,
  344. type: this.uploadtype,
  345. _csrf: csrf
  346. })
  347. );
  348. }
  349. },
  350. async getSuccessChunks(file) {
  351. const params = {
  352. params: {
  353. md5: file.uniqueIdentifier,
  354. type: this.uploadtype,
  355. file_name: file.name,
  356. _csrf: csrf
  357. }
  358. };
  359. try {
  360. const response = await axios.get('/attachments/get_chunks', params);
  361. file.uploadID = response.data.uploadID;
  362. file.uuid = response.data.uuid;
  363. file.uploaded = response.data.uploaded;
  364. file.chunks = response.data.chunks;
  365. file.attachID = response.data.attachID;
  366. file.datasetID = response.data.datasetID;
  367. file.datasetName = response.data.datasetName;
  368. file.realName = response.data.fileName;
  369. return file;
  370. } catch (error) {
  371. this.emitDropzoneFailed(file);
  372. console.log('getSuccessChunks catch: ', error);
  373. return null;
  374. }
  375. },
  376. async newMultiUpload(file) {
  377. const res = await axios.get('/attachments/new_multipart', {
  378. params: {
  379. totalChunkCounts: file.totalChunkCounts,
  380. md5: file.uniqueIdentifier,
  381. size: file.size,
  382. fileType: file.type,
  383. type: this.uploadtype,
  384. file_name: file.name,
  385. _csrf: csrf
  386. }
  387. });
  388. file.uploadID = res.data.uploadID;
  389. file.uuid = res.data.uuid;
  390. },
  391. multipartUpload(file) {
  392. const blobSlice =
  393. File.prototype.slice ||
  394. File.prototype.mozSlice ||
  395. File.prototype.webkitSlice,
  396. chunks = Math.ceil(file.size / chunkSize),
  397. fileReader = new FileReader(),
  398. time = new Date().getTime();
  399. let currentChunk = 0;
  400. let _this = this
  401. function loadNext() {
  402. const start = currentChunk * chunkSize;
  403. const end =
  404. start + chunkSize >= file.size ? file.size : start + chunkSize;
  405. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  406. }
  407. function checkSuccessChunks() {
  408. const index = successChunks.indexOf((currentChunk + 1).toString());
  409. if (index == -1) {
  410. return false;
  411. }
  412. return true;
  413. }
  414. async function getUploadChunkUrl(currentChunk, partSize) {
  415. const res = await axios.get('/attachments/get_multipart_url', {
  416. params: {
  417. uuid: file.uuid,
  418. uploadID: file.uploadID,
  419. size: partSize,
  420. chunkNumber: currentChunk + 1,
  421. type: _this.uploadtype,
  422. file_name: file.name,
  423. _csrf: csrf
  424. }
  425. });
  426. urls[currentChunk] = res.data.url;
  427. }
  428. async function uploadMinio(url, e) {
  429. const res = await axios.put(url, e.target.result);
  430. delete e.target.result
  431. etags[currentChunk] = res.headers.etag;
  432. }
  433. async function uploadMinioNewMethod(url,e){
  434. var xhr = new XMLHttpRequest();
  435. xhr.open('PUT', url, false);
  436. if(_this.uploadtype===0){
  437. xhr.setRequestHeader('Content-Type', 'text/plain')
  438. xhr.send(e.target.result);
  439. var etagValue = xhr.getResponseHeader('etag');
  440. etags[currentChunk] = etagValue;
  441. }
  442. else if(_this.uploadtype===1){
  443. xhr.setRequestHeader('Content-Type', '')
  444. xhr.send(e.target.result);
  445. var etagValue = xhr.getResponseHeader('ETag');
  446. //console.log(etagValue);
  447. etags[currentChunk] = etagValue;
  448. }
  449. }
  450. async function updateChunk(currentChunk) {
  451. await axios.post(
  452. '/attachments/update_chunk',
  453. qs.stringify({
  454. uuid: file.uuid,
  455. chunkNumber: currentChunk + 1,
  456. etag: etags[currentChunk],
  457. _csrf: csrf
  458. })
  459. );
  460. }
  461. async function uploadChunk(e) {
  462. try {
  463. if (!checkSuccessChunks()) {
  464. const start = currentChunk * chunkSize;
  465. const partSize =
  466. start + chunkSize >= file.size ? file.size - start : chunkSize;
  467. // 获取分片上传url
  468. await getUploadChunkUrl(currentChunk, partSize);
  469. if (urls[currentChunk] != '') {
  470. // 上传到minio
  471. //await uploadMinio(urls[currentChunk], e);
  472. await uploadMinioNewMethod(urls[currentChunk], e);
  473. if (etags[currentChunk] != '') {
  474. // 更新数据库:分片上传结果
  475. //await updateChunk(currentChunk);
  476. } else {
  477. console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO
  478. }
  479. } else {
  480. console.log("uploadChunk urls[currentChunk] != ''");// TODO
  481. }
  482. }
  483. } catch (error) {
  484. console.log(error);
  485. //this.emitDropzoneFailed(file);
  486. //console.log(error);
  487. }
  488. }
  489. async function completeUpload() {
  490. return await axios.post(
  491. '/attachments/complete_multipart',
  492. qs.stringify({
  493. uuid: file.uuid,
  494. uploadID: file.uploadID,
  495. file_name: file.name,
  496. size: file.size,
  497. dataset_id: file.datasetId,
  498. type: _this.uploadtype,
  499. _csrf: csrf,
  500. description:_this.desc
  501. })
  502. );
  503. }
  504. const successChunks = [];
  505. let successParts = [];
  506. successParts = file.chunks.split(',');
  507. for (let i = 0; i < successParts.length; i++) {
  508. successChunks[i] = successParts[i].split('-')[0];
  509. }
  510. const urls = []; // TODO const ?
  511. const etags = [];
  512. console.log('上传分片...');
  513. this.status = this.dropzoneParams.data('uploading');
  514. loadNext();
  515. fileReader.onload = async (e) => {
  516. try{
  517. await uploadChunk(e);
  518. }catch(err){
  519. console.log(err)
  520. }
  521. fileReader.abort();
  522. currentChunk++;
  523. if (currentChunk < chunks) {
  524. console.log(
  525. `第${currentChunk}个分片上传完成, 开始第${currentChunk +
  526. 1}/${chunks}个分片上传`
  527. );
  528. this.progress = Math.ceil((currentChunk / chunks) * 100);
  529. this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
  530. this.status = `${this.dropzoneParams.data('uploading')} ${(
  531. (currentChunk / chunks) *
  532. 100
  533. ).toFixed(2)}%`;
  534. await loadNext();
  535. } else {
  536. try{
  537. await completeUpload();
  538. }catch(err){
  539. let info = "上传失败"
  540. this.allUploadLength++
  541. this.uploadError(file,info)
  542. this.allUploadFiles.push({name:file.name,status:2,info:info})
  543. console.log("err",err)
  544. if(err){
  545. return
  546. }
  547. }
  548. console.log(
  549. `文件上传完成:${file.name} \n分片:${chunks} 大小:${
  550. file.size
  551. } 用时:${(new Date().getTime() - time) / 1000} s`
  552. );
  553. this.uploadLength++
  554. this.allUploadLength++
  555. this.allUploadFiles.push({name:file.name,status:0,info:'上传成功'})
  556. this.updateProgress(file, 100);
  557. this.progress = 100;
  558. this.status = this.dropzoneParams.data('upload-complete');
  559. this.finishUpload(file);
  560. }
  561. };
  562. }
  563. }
  564. };
  565. </script>
  566. <style>
  567. .dropzone-wrapper {
  568. margin: 0;
  569. }
  570. .ui .dropzone {
  571. border: 2px dashed #0087f5;
  572. box-shadow: none !important;
  573. padding: 0;
  574. min-height: 5rem;
  575. border-radius: 4px;
  576. }
  577. .dataset .dataset-files #dataset .dz-preview.dz-file-preview,
  578. .dataset .dataset-files #dataset .dz-preview.dz-processing {
  579. display: flex;
  580. align-items: center;
  581. }
  582. .dataset .dataset-files #dataset .dz-preview {
  583. border-bottom: 1px solid #dadce0;
  584. min-height: 0;
  585. }
  586. .upload-info{
  587. margin-top: 1em;
  588. margin-bottom: 3em;
  589. }
  590. .success{
  591. color: #21ba45;
  592. }
  593. .failed{
  594. color: red;
  595. }
  596. </style>