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