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.

modelmanage-local-create-2.vue 26 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <template>
  2. <div>
  3. <div class="header">
  4. <span class="title">{{ type == '1' ? $t('modelManage.addModelFiles') : $t('modelManage.uploadModelFiles')
  5. }}</span>
  6. </div>
  7. <div class="content ui form">
  8. <div class="guide-c" v-if="type != '1'">
  9. <div class="step">
  10. <div class="num">1</div>
  11. <div class="txt">{{ $t('modelManage.createModel') }}</div>
  12. </div>
  13. <div class="line"></div>
  14. <div class="step focused">
  15. <div class="num">2</div>
  16. <div class="txt">{{ $t('modelManage.uploadModelFiles') }}</div>
  17. </div>
  18. </div>
  19. <div class="row-c">
  20. <div class="row">
  21. <div class="r-title"><label class="required">{{ $t('modelManage.modelName') }}</label></div>
  22. <div class="r-content">
  23. <el-input size="medium" class="input-disabled" v-model="state.name"
  24. :placeholder="$t('modelManage.pleaseInputModelName')" readonly>
  25. </el-input>
  26. </div>
  27. </div>
  28. <div class="row" style="align-items:flex-start;">
  29. <div class="r-title"><label class="required">{{ $t('modelManage.fileUpload') }}</label></div>
  30. <div class="r-content">
  31. <div style="position:relative">
  32. <form class="dropzone" ref="dropzoneRef">
  33. <div class="dropzon-err-tips ui red message" v-show="showUploadErr" style="display:none;margin:2.5rem">
  34. {{ uploadErrTxt }}</div>
  35. </form>
  36. <div class="not-allowed-placeholder" v-show="uploading"></div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="row" style="margin-top:10px">
  41. <div class="r-title"><label></label></div>
  42. <div class="r-content">
  43. <el-button size="medium" class="green" @click="submit" :disabled="uploading">{{ $t('modelManage.upload') }}
  44. </el-button>
  45. <el-button size="medium" @click="cancel">{{ $t('modelManage.cancel') }}</el-button>
  46. </div>
  47. </div>
  48. <div class="row" style="align-items:flex-start;">
  49. <div class="r-title"><label>{{ $t('modelManage.uploadStatus') }}:</label></div>
  50. <div class="r-content">
  51. <div v-for="(item, index) in uploadFiles" :key="item.upload.uuid" class="datast-upload-progress">
  52. <span class="dataset-name nowrap" :title="item.name">{{ item.name }}</span>
  53. <div class="dataset-progress">
  54. <el-progress :text-inside="true" :stroke-width="14" :percentage="uploadStatusList[index].progress">
  55. </el-progress>
  56. </div>
  57. <div class="dataset-status nowrap">
  58. <div class="status-flex">
  59. <i v-if="uploadStatusList[index].infoCode === 1 || uploadStatusList[index].infoCode === 2"
  60. class="ri-close-circle-line failed"></i>
  61. <i v-if="uploadStatusList[index].infoCode === 0" class="ri-checkbox-circle-line success"></i>
  62. <span>{{ uploadStatusList[index].status }}</span>
  63. <el-tooltip v-if="uploadStatusList[index].infoCode === 1" class="item" effect="dark" placement="top">
  64. <div slot="content"> {{ uploadStatusList[index].failedInfo }} </div>
  65. <i style="font-size: 16px; margin-left: 0.5rem; cursor: pointer" class="ri-question-fill"></i>
  66. </el-tooltip>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import 'dropzone/dist/dropzone.css';
  78. import Dropzone from 'dropzone';
  79. import SparkMD5 from "spark-md5";
  80. import { getModelInfoByName, getChunks, getNewMultipart, getMultipartUrl, setCompleteMultipart } from '~/apis/modules/modelmanage';
  81. import { getUrlSearchParams } from '~/utils';
  82. Dropzone.autoDiscover = false;
  83. const uploadChunkSize = 1024 * 1024 * 64;
  84. const md5ChunkSize = 1024 * 1024 * 64;
  85. const maxFileSize = 10;
  86. const maxModelFilesSize = window.MAX_MODEL_SIZE || 200 * 1024 * 1024 * 1024; // 200 GB
  87. export default {
  88. data() {
  89. return {
  90. dropzoneHandler: null,
  91. type: '0', // 1-修改,其它-新增
  92. state: {
  93. type: '',
  94. id: '',
  95. name: '',
  96. version: '',
  97. engine: '',
  98. label: '',
  99. description: '',
  100. size: 0,
  101. },
  102. originData: null,
  103. showUploadErr: false,
  104. uploadErrTxt: '',
  105. uploadFiles: [],
  106. uploadLength: 0,
  107. uploadSuccessLength: 0,
  108. uploadStatusList: [],
  109. uploading: false,
  110. };
  111. },
  112. components: {},
  113. methods: {
  114. initModelData() {
  115. const urlParams = getUrlSearchParams();
  116. if (urlParams.name && urlParams.id) {
  117. this.type = urlParams.type || '0';
  118. this.state.name = urlParams.name;
  119. this.state.id = urlParams.id;
  120. this.loading = true;
  121. getModelInfoByName({
  122. repo: location.pathname.split('/').slice(0, 3).join('/'),
  123. name: urlParams.name,
  124. id: urlParams.id
  125. }).then(res => {
  126. this.loading = false;
  127. const list = res.data;
  128. if (list && list.length) {
  129. const data = list[0];
  130. this.state.type = data.type;
  131. this.state.id = data.id;
  132. this.state.name = data.name;
  133. this.state.version = data.version;
  134. this.state.engine = data.engine.toString();
  135. this.state.label = data.label;
  136. this.state.description = data.description;
  137. this.state.size = data.size || 0;
  138. this.originData = data;
  139. } else {
  140. this.cancel();
  141. }
  142. }).catch(err => {
  143. this.loading = false;
  144. console.log(err);
  145. this.cancel();
  146. });
  147. } else {
  148. this.cancel();
  149. }
  150. },
  151. initDropZone() {
  152. this.dropzoneHandler = new Dropzone(this.$refs.dropzoneRef, {
  153. url: '/',
  154. maxFiles: 10,
  155. parallelUploads: 20,
  156. uploadMultiple: true,
  157. maxFilesize: maxModelFilesSize,
  158. timeout: 0,
  159. addRemoveLinks: true,
  160. autoProcessQueue: false,
  161. dictDefaultMessage: this.$t('modelManage.modelFileUploadDefaultTips'),
  162. dictFileTooBig: this.$t('modelManage.fileIstoBig'),
  163. dictRemoveFile: this.$t('modelManage.removeFile'),
  164. dictMaxFilesExceeded: this.getDefaultErrTxt(),
  165. });
  166. this.dropzoneHandler.on("addedfile", file => {
  167. this.checkFiles(file);
  168. });
  169. this.dropzoneHandler.on("removedfile", file => {
  170. this.checkFiles();
  171. });
  172. },
  173. getDefaultErrTxt() {
  174. return this.$t('modelManage.modelFileUploadErrTips', { size: (maxModelFilesSize / (1024 * 1024 * 1024)).toFixed(2) });
  175. },
  176. showUploadErrInfo(state, info) {
  177. if (state) {
  178. this.uploadErrTxt = info;
  179. this.showUploadErr = true;
  180. } else {
  181. this.uploadErrTxt = '';
  182. this.showUploadErr = false;
  183. }
  184. },
  185. checkFiles(file, countStay) {
  186. const fileList = this.dropzoneHandler.getAcceptedFiles();
  187. const filesSize = fileList.reduce((acc, item, index) => acc + item.size, 0) + (file && !countStay ? file.size : 0);
  188. const filesCount = fileList.length + (file && !countStay ? 1 : 0);
  189. const allfilesSize = filesSize + this.state.size;
  190. if (file && filesCount > maxFileSize) {
  191. this.dropzoneHandler.removeFile(file);
  192. this.showUploadErrInfo(true, this.getDefaultErrTxt());
  193. return false;
  194. }
  195. if (filesCount > maxFileSize || allfilesSize > maxModelFilesSize) {
  196. this.showUploadErrInfo(true, this.getDefaultErrTxt());
  197. return false;
  198. }
  199. if (file && file.name.length > 128) {
  200. this.showUploadErrInfo(true, this.$t('modelManage.modelFileNameTips'));
  201. this.uploadError(file, this.$t('modelManage.modelFileNameTips'));
  202. return false;
  203. }
  204. this.showUploadErrInfo(false);
  205. return true;
  206. },
  207. resetFileStatus() {
  208. this.uploadFiles = [];
  209. this.uploadLength = 0;
  210. this.uploadSuccessLength = 0;
  211. this.uploadStatusList = [];
  212. },
  213. updateFileStatus(file, status, progress, infoCode, failedInfo = "") {
  214. this.uploadStatusList.forEach((item, index) => {
  215. if (item.uploadUuid === file.upload.uuid) {
  216. this.uploadStatusList[index].status = status;
  217. this.uploadStatusList[index].progress = progress;
  218. this.uploadStatusList[index].infoCode = infoCode;
  219. this.uploadStatusList[index].failedInfo = failedInfo;
  220. }
  221. });
  222. },
  223. calcFileMd5(file) {
  224. const blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
  225. const chunkSize = md5ChunkSize;
  226. const chunks = Math.ceil(file.size / chunkSize);
  227. const spark = new SparkMD5.ArrayBuffer();
  228. const fileReader = new FileReader();
  229. file.totalChunkCounts = chunks;
  230. if (file.size == 0) {
  231. file.totalChunkCounts = 1;
  232. }
  233. let currentChunk = 0;
  234. this.uploadStatusList.push({
  235. uploadUuid: file.upload.uuid,
  236. name: file.name,
  237. status: this.$t('modelManage.calcFileMd5'),
  238. progress: 0,
  239. infoCode: 3,
  240. });
  241. return new Promise((resolve, reject) => {
  242. fileReader.onload = function (e) {
  243. spark.append(e.target.result);
  244. currentChunk++;
  245. if (currentChunk < chunks) {
  246. loadNext();
  247. } else {
  248. const md5 = spark.end();
  249. spark.destroy();
  250. file.uniqueIdentifier = md5;
  251. resolve(md5);
  252. }
  253. };
  254. fileReader.onerror = function (e) {
  255. console.warn(file.name + ': calcFileMd5 went wrong.');
  256. reject(e);
  257. };
  258. function loadNext() {
  259. const start = currentChunk * chunkSize;
  260. const end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
  261. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  262. }
  263. loadNext();
  264. });
  265. },
  266. getChunksInfo(file) {
  267. return getChunks({
  268. md5: file.uniqueIdentifier,
  269. type: this.state.type,
  270. modeluuid: this.state.id,
  271. file_name: file.name,
  272. scene: 'model',
  273. }).then(res => {
  274. const data = res.data;
  275. file.uploadID = data.uploadID;
  276. file.uuid = data.uuid;
  277. file.uploaded = data.uploaded;
  278. file.chunks = data.chunks;
  279. file.attachID = data.attachID;
  280. file._modelUuid = data.modeluuid;
  281. file._modelName = data.modelName;
  282. file.realName = data.fileName;
  283. return file;
  284. }).catch(err => {
  285. console.info('getChunksInfo', err);
  286. return err;
  287. });
  288. },
  289. newUpload(file) {
  290. return getNewMultipart({
  291. totalChunkCounts: file.totalChunkCounts,
  292. md5: file.uniqueIdentifier,
  293. size: file.size,
  294. fileType: file.type,
  295. type: this.state.type,
  296. file_name: file.name,
  297. scene: 'model',
  298. modeluuid: file.modelUuid,
  299. }).then(res => {
  300. const data = res.data;
  301. file.uploadID = data.uploadID;
  302. file.uuid = data.uuid;
  303. if (file.uploadID && file.uuid) {
  304. file.chunks = '';
  305. this.breakpointUpload(file);
  306. } else {
  307. this.uploadError(file, info);
  308. this.updateFileStatus(file, this.$t('modelManage.uploadFailed'), 0, 2);
  309. }
  310. return file;
  311. }).catch(err => {
  312. console.log('getNewMultipart', err);
  313. this.uploadError(file, info);
  314. this.updateFileStatus(file, this.$t('modelManage.uploadFailed'), 0, 2);
  315. return err;
  316. });
  317. },
  318. breakpointUpload(file) {
  319. const blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
  320. const fileReader = new FileReader();
  321. const time = new Date().getTime();
  322. const chunkSize = uploadChunkSize;
  323. const chunks = Math.ceil(file.size / chunkSize);
  324. const _this = this;
  325. let currentChunk = 0;
  326. const successChunks = [];
  327. const successParts = file.chunks.split(",");
  328. for (let i = 0; i < successParts.length; i++) {
  329. successChunks[i] = successParts[i].split("-")[0];
  330. }
  331. const urls = [];
  332. const etags = [];
  333. const checkSuccessChunks = () => {
  334. const index = successChunks.indexOf((currentChunk + 1).toString());
  335. if (index == -1) {
  336. return false;
  337. }
  338. return true;
  339. }
  340. const getUploadChunkUrl = async (currentChunk, partSize) => {
  341. const res = await getMultipartUrl({
  342. uuid: file.uuid,
  343. uploadID: file.uploadID,
  344. size: partSize,
  345. chunkNumber: currentChunk + 1,
  346. type: _this.state.type,
  347. file_name: file.name,
  348. scene: 'model',
  349. });
  350. urls[currentChunk] = res.data.url;
  351. };
  352. const uploadMinioNewMethod = async (url, e) => {
  353. const xhr = new XMLHttpRequest();
  354. xhr.open("PUT", url, false);
  355. if (_this.state.type == 0) {
  356. xhr.setRequestHeader("Content-Type", "text/plain");
  357. xhr.send(e.target.result);
  358. const etagValue = xhr.getResponseHeader("etag");
  359. etags[currentChunk] = etagValue;
  360. } else if (_this.state.type == 1) {
  361. xhr.setRequestHeader("Content-Type", "");
  362. xhr.send(e.target.result);
  363. const etagValue = xhr.getResponseHeader("ETag");
  364. etags[currentChunk] = etagValue;
  365. }
  366. }
  367. const uploadChunk = async (e) => {
  368. try {
  369. if (!checkSuccessChunks()) {
  370. const start = currentChunk * chunkSize;
  371. const partSize = start + chunkSize >= file.size ? file.size - start : chunkSize;
  372. // 获取分片上传url
  373. await getUploadChunkUrl(currentChunk, partSize);
  374. if (urls[currentChunk] != '') {
  375. await uploadMinioNewMethod(urls[currentChunk], e);
  376. if (etags[currentChunk] != '') {
  377. } else {
  378. console.log("上传到minio uploadChunk etags[currentChunk] == ''"); // TODO
  379. }
  380. } else {
  381. console.log("uploadChunk urls[currentChunk] != ''"); // TODO
  382. }
  383. }
  384. } catch (error) {
  385. console.log(error);
  386. }
  387. }
  388. const completeUpload = async () => {
  389. return await setCompleteMultipart({
  390. uuid: file.uuid,
  391. uploadID: file.uploadID,
  392. file_name: file.name,
  393. size: file.size,
  394. type: _this.state.type,
  395. scene: 'model',
  396. modeluuid: file.modelUuid,
  397. });
  398. }
  399. function loadNext() {
  400. const start = currentChunk * chunkSize;
  401. const end = start + chunkSize >= file.size ? file.size : start + chunkSize;
  402. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  403. }
  404. fileReader.onload = async (e) => {
  405. try {
  406. await uploadChunk(e);
  407. fileReader.abort();
  408. currentChunk++;
  409. if (currentChunk < chunks) {
  410. console.log(`第${currentChunk}个分片上传完成, 开始第${currentChunk + 1}/${chunks}个分片上传`);
  411. this.updateFileStatus(file, this.$t('modelManage.uploading'), Number(((currentChunk / chunks) * 100).toFixed(2)), 3);
  412. loadNext();
  413. } else {
  414. try {
  415. await completeUpload();
  416. console.log(`文件上传完成:${file.name} \n分片:${chunks} 大小:${file.size} 用时:${(new Date().getTime() - time) / 1000} s`);
  417. this.uploadLength++;
  418. this.uploadSuccessLength++;
  419. this.updateFileStatus(file, this.$t('modelManage.uploadSuccess'), 100, 0);
  420. this.uploadSuccess(file);
  421. } catch (err) {
  422. const info = this.$t('modelManage.uploadFailed');
  423. console.log(info, file)
  424. this.uploadLength++;
  425. this.uploadError(file, info);
  426. this.updateFileStatus(file, info, Number(((currentChunk / chunks) * 100).toFixed(2)) - 1, 2);
  427. }
  428. }
  429. } catch (err) {
  430. console.log(err);
  431. const info = this.$t('modelManage.uploadFailed');
  432. console.log(info, file)
  433. this.uploadLength++;
  434. this.uploadError(file, info);
  435. this.updateFileStatus(file, info, Number(((currentChunk / chunks) * 100).toFixed(2)) - 1, 2);
  436. }
  437. };
  438. console.log("上传分片...");
  439. loadNext();
  440. },
  441. uploadError(file, info) {
  442. file.previewTemplate.querySelector('.dz-success-mark').style.opacity = 0;
  443. file.previewTemplate.querySelector('.dz-error-mark').style.opacity = 1;
  444. file.previewTemplate.querySelector('.dz-error-message span').innerHTML = info;
  445. file.previewTemplate.querySelector(".dz-error-message").style.display = 'block';
  446. file.previewTemplate.querySelector(".dz-details").onmouseover = () => {
  447. file.previewTemplate.querySelector('.dz-error-message').style.opacity = 1;
  448. };
  449. file.previewTemplate.querySelector(".dz-details").onmouseout = () => {
  450. file.previewTemplate.querySelector('.dz-error-message').style.opacity = 0;
  451. };
  452. this.uploadFinishCheck(file);
  453. },
  454. uploadSuccess(file) {
  455. file.previewTemplate.querySelector('.dz-error-mark').style.opacity = 0;
  456. file.previewTemplate.querySelector('.dz-error-message span').innerHTML = '';
  457. file.previewTemplate.querySelector('.dz-success-mark').style.opacity = 1;
  458. file.previewTemplate.querySelector(".dz-error-message").style.display = 'none';
  459. file.previewTemplate.querySelector(".dz-details").onmouseover = null;
  460. file.previewTemplate.querySelector(".dz-details").onmouseout = null;
  461. this.uploadFinishCheck(file);
  462. },
  463. uploadFinishCheck(file) {
  464. console.log('uploadFinishCheck', file, this.uploadLength, '/', this.uploadFiles.length);
  465. if (this.uploadLength === this.uploadFiles.length && this.uploadFiles.length != 0) {
  466. console.log('All file has finish, success ' + this.uploadSuccessLength);
  467. this.uploading = false;
  468. if (this.uploadSuccessLength == this.uploadLength) {
  469. window.setTimeout(() => {
  470. this.goDetail();
  471. }, 1000);
  472. } else {
  473. if (this.uploadSuccessLength > 0) {
  474. this.initModelData();
  475. }
  476. }
  477. }
  478. },
  479. submit() {
  480. const fileList = this.dropzoneHandler.getAcceptedFiles();
  481. if (!fileList.length) return;
  482. for (let i = 0, iLen = fileList.length; i < iLen; i++) {
  483. if (!this.checkFiles(fileList[i], true)) return;
  484. }
  485. this.resetFileStatus();
  486. this.uploadFiles = fileList;
  487. this.uploading = true;
  488. for (let i = 0, iLen = fileList.length; i < iLen; i++) {
  489. const file = fileList[i];
  490. file.modelUuid = this.state.id;
  491. file.modelName = this.state.name;
  492. this.calcFileMd5(file).then(res => { // 计算MD5
  493. this.getChunksInfo(file).then(res => { // 获取Chunk信息
  494. if (file.uploadID == '' || file.uuid == '') { // 未上传过
  495. this.newUpload(file);
  496. } else if (file.uploaded == '1') { // 已上传成功
  497. if (file.attachID == '0') { // 删除数据集记录,未删除文件
  498. // await addAttachment(file);
  499. console.log(`file.attachID == '0'`);
  500. }
  501. this.uploadLength++;
  502. // 同一模型上传同一个文件
  503. if (file._modelUuid) {
  504. const info = `${this.$t('modelManage.fileHasAlreadyInTheModel')} ${file._modelName}`;
  505. this.uploadError(file, info);
  506. this.updateFileStatus(file, this.$t('modelManage.uploadFailed'), 0, 1, info);
  507. } else { // 秒传
  508. this.uploadSuccessLength++;
  509. this.updateFileStatus(file, this.$t('modelManage.uploadSuccess'), 100, 0);
  510. this.uploadSuccess(file);
  511. }
  512. console.log(file.name, '文件处理完成');
  513. } else { // 断点续传
  514. this.breakpointUpload(file);
  515. }
  516. }).catch(err => {
  517. console.info('getChunksInfo', err);
  518. this.uploadLength++;
  519. this.uploadError(file, this.$t('modelManage.uploadFailed'));
  520. this.updateFileStatus(file, this.$t('modelManage.uploadFailed'), 0, 2);
  521. });
  522. }).catch(err => {
  523. console.info('calcFileMd5', err);
  524. this.uploadLength++;
  525. this.uploadError(file, this.$t('modelManage.uploadFailed'));
  526. this.updateFileStatus(file, this.$t('modelManage.uploadFailed'), 0, 2);
  527. });
  528. }
  529. },
  530. cancel() {
  531. if (this.type == '1') {
  532. this.goDetail();
  533. return;
  534. }
  535. const list = window.location.href.split('/');
  536. list.pop();
  537. list.push('show_model');
  538. window.location.href = list.join('/');
  539. },
  540. goDetail() {
  541. const list = window.location.href.split('/');
  542. list.pop();
  543. list.push('show_model_info');
  544. window.location.href = list.join('/') + '?name=' + this.state.name;
  545. }
  546. },
  547. mounted() {
  548. this.initModelData();
  549. this.initDropZone();
  550. },
  551. beforeDestroy() {
  552. },
  553. };
  554. </script>
  555. <style scoped lang="less">
  556. .header {
  557. height: 45px;
  558. border-color: rgb(212, 212, 213);
  559. border-width: 1px;
  560. border-style: solid;
  561. border-radius: 5px 5px 0px 0px;
  562. font-size: 14px;
  563. background: rgb(240, 240, 240);
  564. display: flex;
  565. align-items: center;
  566. .title {
  567. font-weight: 600;
  568. font-size: 16px;
  569. color: rgb(16, 16, 16);
  570. margin-left: 10px;
  571. }
  572. }
  573. .content {
  574. margin-top: -1px;
  575. border-color: rgb(212, 212, 213);
  576. border-width: 1px;
  577. border-style: solid;
  578. padding: 30px 0;
  579. border-top: none;
  580. .guide-c {
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. margin-bottom: 20px;
  585. .step {
  586. display: flex;
  587. align-items: center;
  588. color: rgb(136, 136, 136);
  589. .num {
  590. border: 1px solid rgb(136, 136, 136);
  591. width: 34px;
  592. height: 34px;
  593. font-size: 24px;
  594. text-align: center;
  595. line-height: 34px;
  596. border-radius: 17px;
  597. margin-right: 8px;
  598. }
  599. .txt {
  600. font-weight: 600;
  601. }
  602. &.focused {
  603. color: rgb(22, 132, 252);
  604. .num {
  605. border-color: rgb(22, 132, 252);
  606. }
  607. }
  608. }
  609. .line {
  610. height: 2px;
  611. width: 50px;
  612. background-color: rgb(187, 187, 187);
  613. margin: 0 10px;
  614. }
  615. }
  616. .row-c {
  617. display: flex;
  618. align-items: center;
  619. justify-content: center;
  620. flex-direction: column;
  621. margin: 0 auto;
  622. .row {
  623. width: 100%;
  624. display: flex;
  625. align-items: center;
  626. margin: 8px 0;
  627. margin-left: -190px;
  628. .r-title {
  629. text-align: right;
  630. font-size: .92857143em;
  631. font-weight: 700;
  632. color: rgba(0, 0, 0, .87);
  633. width: 200px;
  634. margin-right: 28px;
  635. position: relative;
  636. .required {
  637. &::after {
  638. position: absolute;
  639. margin: -0.2em 0 0 0.2em;
  640. content: '*';
  641. color: #db2828;
  642. }
  643. }
  644. }
  645. .r-content {
  646. flex: 1;
  647. .cluster-type-btn {
  648. display: flex;
  649. align-items: center;
  650. justify-content: center;
  651. border: 1px solid #DCDFE6;
  652. height: 36px;
  653. padding: 10px;
  654. cursor: pointer;
  655. border-radius: 4px;
  656. .icon {
  657. margin-right: 5px;
  658. }
  659. &.focused {
  660. border-color: rgb(50, 145, 248);
  661. color: rgb(50, 145, 248);
  662. cursor: default;
  663. .icon {
  664. :not([stroke]) {
  665. fill: rgb(50, 145, 248);
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. .not-allowed-placeholder {
  675. position: absolute;
  676. width: 100%;
  677. height: 100%;
  678. z-index: 20;
  679. cursor: no-drop;
  680. top: 0;
  681. }
  682. .dropzone {
  683. min-height: 186px !important;
  684. /deep/ .dz-default.dz-message {
  685. margin: 76px 0 !important;
  686. }
  687. /deep/ .dz-remove {
  688. margin-top: 10px !important;
  689. }
  690. }
  691. .input-disabled {
  692. /deep/ .el-input__inner {
  693. background-color: #f5f5f6 !important;
  694. color: #888888 !important;
  695. }
  696. }
  697. /deep/ .dz-progress {
  698. display: none;
  699. }
  700. .success {
  701. color: #21ba45;
  702. font-size: 16px;
  703. margin-right: 0.5rem;
  704. }
  705. .failed {
  706. color: red;
  707. font-size: 16px;
  708. margin-right: 0.5rem;
  709. }
  710. .datast-upload-progress {
  711. display: flex;
  712. align-items: center;
  713. }
  714. .datast-upload-progress .dataset-name {
  715. text-align: right;
  716. width: 200px;
  717. margin-right: 1rem;
  718. }
  719. .datast-upload-progress .dataset-progress {
  720. flex: 1;
  721. }
  722. .datast-upload-progress .dataset-status {
  723. width: 140px;
  724. margin-left: 1rem;
  725. }
  726. .datast-upload-progress .dataset-status .status-flex {
  727. display: flex;
  728. align-items: center;
  729. }
  730. /deep/ .el-progress-bar__inner {
  731. background-color: #21ba45;
  732. }
  733. .el-select-dropdown__item.selected {
  734. color: #85b7d9;
  735. }
  736. /deep/ .el-button {
  737. background-color: #e0e1e2;
  738. color: rgba(0, 0, 0, .6);
  739. border-color: transparent;
  740. transition: opacity .1s ease, background-color .1s ease, color .1s ease, box-shadow .1s ease, background .1s ease, -webkit-box-shadow .1s ease;
  741. will-change: auto;
  742. -webkit-tap-highlight-color: transparent;
  743. &:hover {
  744. border-color: transparent;
  745. background-color: #cacbcd;
  746. color: rgba(0, 0, 0, .8);
  747. }
  748. &:focus {
  749. background-color: #cacbcd;
  750. color: rgba(0, 0, 0, .8);
  751. border-color: transparent;
  752. }
  753. &:active {
  754. background-color: #babbbc;
  755. color: rgba(0, 0, 0, .9);
  756. border-color: transparent;
  757. }
  758. &.green {
  759. background-color: #5bb973;
  760. color: #fff;
  761. &:hover {
  762. background-color: #16ab39;
  763. border-color: transparent;
  764. }
  765. &:focus {
  766. background-color: #0ea432;
  767. border-color: transparent;
  768. }
  769. &:active {
  770. background-color: #198f35;
  771. border-color: transparent;
  772. }
  773. }
  774. }
  775. /deep/ .el-select {
  776. .is-focus {
  777. .el-input__inner {
  778. border-color: #85b7d9;
  779. }
  780. }
  781. }
  782. /deep/ .el-input__inner {
  783. &:focus {
  784. border-color: #85b7d9;
  785. }
  786. }
  787. /deep/ .el-textarea__inner {
  788. &:focus {
  789. border-color: #85b7d9;
  790. }
  791. }
  792. </style>