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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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. dropzoneUploader.removeFile(file)
  125. $('.maxfilesize.ui.red.message').text("单次最多上传10个文件,单个文件不超过200G")
  126. $('.maxfilesize.ui.red.message').css('display','block')
  127. });
  128. this.dropzoneUploader = dropzoneUploader;
  129. },
  130. watch:{
  131. allUploadLength(len){
  132. if(len===this.uploadFiles.length){
  133. setTimeout(() => {
  134. this.dropzoneUploader.removeAllFiles(true)
  135. this.btnFlag = false
  136. this.$emit('setcluster',this.btnFlag)
  137. }, 2000);
  138. }
  139. }
  140. },
  141. methods: {
  142. startUpload(){
  143. this.uploadFiles = this.dropzoneUploader.getQueuedFiles()
  144. if(this.uploadFiles.length===0){
  145. return
  146. }
  147. this.resetStatus()
  148. $('.dz-remove').remove()
  149. $('.maxfilesize.ui.red.message').css('display','none')
  150. this.btnFlag = true
  151. this.$emit('setcluster',this.btnFlag)
  152. this.uploadFiles.forEach(element => {
  153. element.datasetId = document.getElementById('datasetId').getAttribute('datasetId')
  154. this.computeMD5(element)
  155. });
  156. },
  157. cancelDataset(){
  158. location.href = this.repoPath
  159. this.dropzoneUploader.removeAllFiles(true)
  160. },
  161. resetStatus() {
  162. this.uploadLength = 0
  163. this.allUploadLength = 0
  164. this.allUploadFiles = []
  165. },
  166. updateProgress(file, progress) {
  167. file.previewTemplate.querySelector(
  168. '.dz-upload'
  169. ).style.width = `${progress}%`
  170. file.previewTemplate.querySelector(
  171. '.dz-upload'
  172. ).style.background = '#409eff';
  173. },
  174. uploadError(file,info){
  175. file.previewTemplate.querySelector(
  176. '.dz-error-mark'
  177. ).style.opacity = 1
  178. file.previewTemplate.querySelector(
  179. '.dz-progress'
  180. ).style.opacity = 0
  181. file.previewTemplate.querySelector(
  182. '.dz-error-message span'
  183. ).innerHTML = info
  184. file.previewTemplate.querySelector(
  185. '.dz-error-message'
  186. ).style.display = 'block'
  187. file.previewTemplate.querySelector(
  188. '.dz-details'
  189. ).onmouseover = function(){file.previewTemplate.querySelector('.dz-error-message').style.opacity = 1 }
  190. file.previewTemplate.querySelector(
  191. '.dz-details'
  192. ).onmouseout = function(){file.previewTemplate.querySelector('.dz-error-message').style.opacity = 0 }
  193. },
  194. emitDropzoneSuccess(file) {
  195. file.status = 'success';
  196. this.dropzoneUploader.emit('success', file);
  197. this.dropzoneUploader.emit('complete', file);
  198. },
  199. emitDropzoneFailed(file) {
  200. this.status = this.dropzoneParams.data('falied');
  201. file.status = 'error';
  202. this.dropzoneUploader.emit('error', file);
  203. // this.dropzoneUploader.emit('complete', file);
  204. },
  205. finishUpload(file) {
  206. file.previewTemplate.querySelector(
  207. '.dz-success-mark'
  208. ).style.opacity = 1
  209. file.previewTemplate.querySelector(
  210. '.dz-progress'
  211. ).style.opacity = 0
  212. if(this.uploadLength === this.uploadFiles.length){
  213. setTimeout(() => {
  214. window.location.href = this.repoPath
  215. }, 1000);
  216. }
  217. },
  218. computeMD5(file) {
  219. const blobSlice =
  220. File.prototype.slice ||
  221. File.prototype.mozSlice ||
  222. File.prototype.webkitSlice,
  223. chunks = Math.ceil(file.size / chunkSize),
  224. spark = new SparkMD5.ArrayBuffer(),
  225. fileReader = new FileReader();
  226. let currentChunk = 0;
  227. console.log("computeMD5-chunks:",chunks)
  228. const time = new Date().getTime();
  229. this.status = this.dropzoneParams.data('md5-computing');
  230. file.totalChunkCounts = chunks;
  231. if (file.size==0) {
  232. file.totalChunkCounts = 1
  233. }
  234. loadMd5Next();
  235. fileReader.onload = (e) => {
  236. fileLoaded.call(this, e);
  237. };
  238. fileReader.onerror = (err) => {
  239. console.warn('oops, something went wrong.', err);
  240. file.cancel();
  241. };
  242. function fileLoaded(e) {
  243. spark.append(e.target.result); // Append array buffer
  244. currentChunk++;
  245. if (currentChunk < chunks) {
  246. this.status = `${this.dropzoneParams.data('loading-file')} ${(
  247. (currentChunk / chunks) *
  248. 100
  249. ).toFixed(2)}% (${currentChunk}/${chunks})`;
  250. this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
  251. loadMd5Next();
  252. return;
  253. }
  254. const md5 = spark.end();
  255. console.log(
  256. `MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${
  257. file.size
  258. } 用时:${(new Date().getTime() - time) / 1000} s`
  259. );
  260. this.updateProgress(file,100)
  261. spark.destroy(); // 释放缓存
  262. file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识
  263. file.cmd5 = false; // 取消计算md5状态
  264. this.computeMD5Success(file);
  265. }
  266. function loadNext() {
  267. const start = currentChunk * chunkSize;
  268. const end =
  269. start + chunkSize >= file.size ? file.size : start + chunkSize;
  270. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  271. }
  272. function loadMd5Next() {
  273. const start = currentChunk * chunkSize;
  274. const end =
  275. start + md5ChunkSize >= file.size ? file.size : start + md5ChunkSize;
  276. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  277. }
  278. },
  279. async computeMD5Success(md5edFile) {
  280. const file = await this.getSuccessChunks(md5edFile);
  281. try {
  282. if (file.uploadID == '' || file.uuid == '') {
  283. // 未上传过
  284. await this.newMultiUpload(file);
  285. if (file.uploadID != '' && file.uuid != '') {
  286. file.chunks = '';
  287. this.multipartUpload(file);
  288. } else {
  289. // 失败如何处理
  290. let info = "上传失败"
  291. this.allUploadLength++
  292. this.uploadError(file,info)
  293. this.allUploadFiles.push({name:file.name,status:2,info:info})
  294. return;
  295. }
  296. return;
  297. }
  298. if (file.uploaded == '1') {
  299. // 已上传成功
  300. // 秒传
  301. if (file.attachID == '0') {
  302. // 删除数据集记录,未删除文件
  303. await addAttachment(file);
  304. }
  305. //不同数据集上传同一个文件
  306. if (file.datasetID != '') {
  307. if (file.datasetName != "" && file.realName != "") {
  308. // var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")";
  309. // window.location.reload();
  310. let info = `该文件已上传在数据集: ${file.datasetName}`
  311. this.uploadError(file,info)
  312. this.allUploadLength++
  313. this.allUploadFiles.push({name:file.name,status:1,info:info})
  314. }
  315. }
  316. console.log('文件已上传完成');
  317. this.progress = 100;
  318. this.status = this.dropzoneParams.data('upload-complete');
  319. // this.finishUpload(file);
  320. } else {
  321. // 断点续传
  322. this.multipartUpload(file);
  323. }
  324. } catch (error) {
  325. this.emitDropzoneFailed(file);
  326. console.log(error);
  327. }
  328. async function addAttachment(file) {
  329. return await axios.post(
  330. '/attachments/add',
  331. qs.stringify({
  332. uuid: file.uuid,
  333. file_name: file.name,
  334. size: file.size,
  335. dataset_id: file.datasetId,
  336. type: this.uploadtype,
  337. _csrf: csrf
  338. })
  339. );
  340. }
  341. },
  342. async getSuccessChunks(file) {
  343. const params = {
  344. params: {
  345. md5: file.uniqueIdentifier,
  346. type: this.uploadtype,
  347. file_name: file.name,
  348. _csrf: csrf
  349. }
  350. };
  351. try {
  352. const response = await axios.get('/attachments/get_chunks', params);
  353. file.uploadID = response.data.uploadID;
  354. file.uuid = response.data.uuid;
  355. file.uploaded = response.data.uploaded;
  356. file.chunks = response.data.chunks;
  357. file.attachID = response.data.attachID;
  358. file.datasetID = response.data.datasetID;
  359. file.datasetName = response.data.datasetName;
  360. file.realName = response.data.fileName;
  361. return file;
  362. } catch (error) {
  363. this.emitDropzoneFailed(file);
  364. console.log('getSuccessChunks catch: ', error);
  365. return null;
  366. }
  367. },
  368. async newMultiUpload(file) {
  369. const res = await axios.get('/attachments/new_multipart', {
  370. params: {
  371. totalChunkCounts: file.totalChunkCounts,
  372. md5: file.uniqueIdentifier,
  373. size: file.size,
  374. fileType: file.type,
  375. type: this.uploadtype,
  376. file_name: file.name,
  377. _csrf: csrf
  378. }
  379. });
  380. file.uploadID = res.data.uploadID;
  381. file.uuid = res.data.uuid;
  382. },
  383. multipartUpload(file) {
  384. const blobSlice =
  385. File.prototype.slice ||
  386. File.prototype.mozSlice ||
  387. File.prototype.webkitSlice,
  388. chunks = Math.ceil(file.size / chunkSize),
  389. fileReader = new FileReader(),
  390. time = new Date().getTime();
  391. let currentChunk = 0;
  392. let _this = this
  393. function loadNext() {
  394. const start = currentChunk * chunkSize;
  395. const end =
  396. start + chunkSize >= file.size ? file.size : start + chunkSize;
  397. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  398. }
  399. function checkSuccessChunks() {
  400. const index = successChunks.indexOf((currentChunk + 1).toString());
  401. if (index == -1) {
  402. return false;
  403. }
  404. return true;
  405. }
  406. async function getUploadChunkUrl(currentChunk, partSize) {
  407. const res = await axios.get('/attachments/get_multipart_url', {
  408. params: {
  409. uuid: file.uuid,
  410. uploadID: file.uploadID,
  411. size: partSize,
  412. chunkNumber: currentChunk + 1,
  413. type: _this.uploadtype,
  414. file_name: file.name,
  415. _csrf: csrf
  416. }
  417. });
  418. urls[currentChunk] = res.data.url;
  419. }
  420. async function uploadMinio(url, e) {
  421. const res = await axios.put(url, e.target.result);
  422. delete e.target.result
  423. etags[currentChunk] = res.headers.etag;
  424. }
  425. async function uploadMinioNewMethod(url,e){
  426. var xhr = new XMLHttpRequest();
  427. xhr.open('PUT', url, false);
  428. if(_this.uploadtype===0){
  429. xhr.setRequestHeader('Content-Type', 'text/plain')
  430. xhr.send(e.target.result);
  431. var etagValue = xhr.getResponseHeader('etag');
  432. etags[currentChunk] = etagValue;
  433. }
  434. else if(_this.uploadtype===1){
  435. xhr.setRequestHeader('Content-Type', '')
  436. xhr.send(e.target.result);
  437. var etagValue = xhr.getResponseHeader('ETag');
  438. //console.log(etagValue);
  439. etags[currentChunk] = etagValue;
  440. }
  441. }
  442. async function updateChunk(currentChunk) {
  443. await axios.post(
  444. '/attachments/update_chunk',
  445. qs.stringify({
  446. uuid: file.uuid,
  447. chunkNumber: currentChunk + 1,
  448. etag: etags[currentChunk],
  449. _csrf: csrf
  450. })
  451. );
  452. }
  453. async function uploadChunk(e) {
  454. try {
  455. if (!checkSuccessChunks()) {
  456. const start = currentChunk * chunkSize;
  457. const partSize =
  458. start + chunkSize >= file.size ? file.size - start : chunkSize;
  459. // 获取分片上传url
  460. await getUploadChunkUrl(currentChunk, partSize);
  461. if (urls[currentChunk] != '') {
  462. // 上传到minio
  463. //await uploadMinio(urls[currentChunk], e);
  464. await uploadMinioNewMethod(urls[currentChunk], e);
  465. if (etags[currentChunk] != '') {
  466. // 更新数据库:分片上传结果
  467. //await updateChunk(currentChunk);
  468. } else {
  469. console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO
  470. }
  471. } else {
  472. console.log("uploadChunk urls[currentChunk] != ''");// TODO
  473. }
  474. }
  475. } catch (error) {
  476. console.log(error);
  477. //this.emitDropzoneFailed(file);
  478. //console.log(error);
  479. }
  480. }
  481. async function completeUpload() {
  482. return await axios.post(
  483. '/attachments/complete_multipart',
  484. qs.stringify({
  485. uuid: file.uuid,
  486. uploadID: file.uploadID,
  487. file_name: file.name,
  488. size: file.size,
  489. dataset_id: file.datasetId,
  490. type: _this.uploadtype,
  491. _csrf: csrf,
  492. description:_this.desc
  493. })
  494. );
  495. }
  496. const successChunks = [];
  497. let successParts = [];
  498. successParts = file.chunks.split(',');
  499. for (let i = 0; i < successParts.length; i++) {
  500. successChunks[i] = successParts[i].split('-')[0];
  501. }
  502. const urls = []; // TODO const ?
  503. const etags = [];
  504. console.log('上传分片...');
  505. this.status = this.dropzoneParams.data('uploading');
  506. loadNext();
  507. fileReader.onload = async (e) => {
  508. try{
  509. await uploadChunk(e);
  510. }catch(err){
  511. console.log(err)
  512. }
  513. fileReader.abort();
  514. currentChunk++;
  515. if (currentChunk < chunks) {
  516. console.log(
  517. `第${currentChunk}个分片上传完成, 开始第${currentChunk +
  518. 1}/${chunks}个分片上传`
  519. );
  520. this.progress = Math.ceil((currentChunk / chunks) * 100);
  521. this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
  522. this.status = `${this.dropzoneParams.data('uploading')} ${(
  523. (currentChunk / chunks) *
  524. 100
  525. ).toFixed(2)}%`;
  526. await loadNext();
  527. } else {
  528. try{
  529. await completeUpload();
  530. }catch(err){
  531. let info = "上传失败"
  532. this.allUploadLength++
  533. this.uploadError(file,info)
  534. this.allUploadFiles.push({name:file.name,status:2,info:info})
  535. if(err){
  536. return
  537. }
  538. }
  539. console.log(
  540. `文件上传完成:${file.name} \n分片:${chunks} 大小:${
  541. file.size
  542. } 用时:${(new Date().getTime() - time) / 1000} s`
  543. );
  544. this.uploadLength++
  545. this.allUploadLength++
  546. this.allUploadFiles.push({name:file.name,status:0,info:'上传成功'})
  547. this.updateProgress(file, 100);
  548. this.progress = 100;
  549. this.status = this.dropzoneParams.data('upload-complete');
  550. this.finishUpload(file);
  551. }
  552. };
  553. }
  554. }
  555. };
  556. </script>
  557. <style>
  558. .dropzone-wrapper {
  559. margin: 0;
  560. }
  561. .ui .dropzone {
  562. border: 2px dashed #0087f5;
  563. box-shadow: none !important;
  564. padding: 0;
  565. min-height: 5rem;
  566. border-radius: 4px;
  567. }
  568. .dataset .dataset-files #dataset .dz-preview.dz-file-preview,
  569. .dataset .dataset-files #dataset .dz-preview.dz-processing {
  570. display: flex;
  571. align-items: center;
  572. }
  573. .dataset .dataset-files #dataset .dz-preview {
  574. border-bottom: 1px solid #dadce0;
  575. min-height: 0;
  576. }
  577. .upload-info{
  578. margin-top: 1em;
  579. margin-bottom: 3em;
  580. }
  581. .success{
  582. color: #21ba45;
  583. }
  584. .failed{
  585. color: red;
  586. }
  587. </style>