materialListInMaterialSelector.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. <template>
  2. <div
  3. class="material-list"
  4. :class="{
  5. dark: isDarkTheme,
  6. }"
  7. >
  8. <crumbs
  9. class="crumbs"
  10. v-if="!searchKey"
  11. :isDarkTheme="isDarkTheme"
  12. :list="uniqueFolderList(folderPath)"
  13. :rootName="$i18n.t(`gather.${materialTypeAlias}`)"
  14. @click-path="onClickPath"
  15. />
  16. <div v-if="searchKey" class="crumbs">
  17. {{ $i18n.t(`gather.${materialTypeAlias}`) }}
  18. </div>
  19. <div class="table">
  20. <!-- <div class="table-head-row">
  21. <span
  22. class="table-head"
  23. :style="{
  24. width: '50px',
  25. }"
  26. >
  27. 1
  28. </span>
  29. <span
  30. class="table-head"
  31. v-for="(item, idx) in tableHeaders"
  32. :key="idx"
  33. :style="{
  34. width: columnWidthList[idx],
  35. }"
  36. >
  37. </span>
  38. </div> -->
  39. <div
  40. v-show="listLocalLength !== 0 || hasMoreData"
  41. class="table-body"
  42. v-infinite-scroll="requestMoreData"
  43. :infinite-scroll-disabled="!hasMoreData || isRequestingMoreData"
  44. >
  45. <!-- vuex中的上传中数据 -->
  46. <div v-for="(item, i) in uploadStatusList" :key="item.uid">
  47. <div
  48. class="table-body-row"
  49. v-if="item.parentFolderId === currentFolderId && !searchKey"
  50. @click="onClickRow"
  51. >
  52. <!-- 如果已经上传成功 -->
  53. <template v-if="item.status === 'SUCCESS'">
  54. <span class="table-data">
  55. <RadioOrCheckbox
  56. class="checkbox"
  57. :isLightTheme="!isDarkTheme"
  58. :isMultiSelection="isMultiSelection"
  59. :isCheckedInitial="
  60. select.some((i) => i.id === item.successInfo.id)
  61. "
  62. @change="(v) => selectItem(item.successInfo, v)"
  63. />
  64. </span>
  65. <span
  66. class="table-data"
  67. :style="{
  68. width: columnWidthList[idx] || '',
  69. }"
  70. v-for="(tableItemStructure, idx) in tableHeaders"
  71. :key="idx"
  72. >
  73. <div v-if="tableItemStructure.type" class="list-img">
  74. <slot
  75. name="materialUploadSuccessIcon"
  76. :uploadInfo="item"
  77. :tableItemStructure="tableItemStructure"
  78. >
  79. </slot>
  80. </div>
  81. <span
  82. v-else-if="tableItemStructure.key === 'name'"
  83. class="name"
  84. >
  85. <div
  86. class="name-inner ellipsis"
  87. v-title="item.successInfo[tableItemStructure.key]"
  88. >
  89. {{ item.successInfo[tableItemStructure.key] }}
  90. </div>
  91. </span>
  92. <span v-else class="ellipsis">
  93. {{ item.successInfo[tableItemStructure.key] }}
  94. </span>
  95. </span>
  96. </template>
  97. <!-- 如果还在上传或切图处理中 -->
  98. <template v-else-if="item.status === 'LOADING'">
  99. <span class="table-data">
  100. <RadioOrCheckbox
  101. class="checkbox"
  102. :isLightTheme="!isDarkTheme"
  103. :isMultiSelection="isMultiSelection"
  104. :isDisabled="true"
  105. />
  106. </span>
  107. <span
  108. class="table-data"
  109. :style="{
  110. width: columnWidthList[idx],
  111. }"
  112. v-for="(tableItemStructure, idx) in tableHeaders"
  113. :key="idx"
  114. >
  115. <div v-if="tableItemStructure.type" class="list-img">
  116. <slot name="materialUploadingIcon"> </slot>
  117. </div>
  118. <span
  119. v-if="tableItemStructure.key === 'name'"
  120. class="name upload-status-wrap"
  121. >
  122. <div class="name-inner ellipsis" v-title="item.title">
  123. {{ item.title }}
  124. </div>
  125. <div v-if="item.ifKnowProgress" class="upload-status">
  126. {{ $i18n.t(`gather.upload_material`) }}
  127. {{ Math.round(item.progress * 100) }}%
  128. </div>
  129. <div v-else class="upload-status">
  130. {{ item.statusText }}
  131. </div>
  132. </span>
  133. <span v-else></span>
  134. </span>
  135. </template>
  136. <!-- 如果上传失败了 -->
  137. <template v-else-if="item.status === 'FAIL'">
  138. <span class="table-data">
  139. <RadioOrCheckbox
  140. class="checkbox"
  141. :isLightTheme="!isDarkTheme"
  142. :isMultiSelection="isMultiSelection"
  143. :isDisabled="true"
  144. />
  145. </span>
  146. <span
  147. class="table-data"
  148. :style="{
  149. width: columnWidthList[idx],
  150. }"
  151. v-for="(tableItemStructure, idx) in tableHeaders"
  152. :key="idx"
  153. >
  154. <div v-if="tableItemStructure.type" class="list-img">
  155. <slot name="materialUploadFailIcon"> </slot>
  156. </div>
  157. <span
  158. v-if="tableItemStructure.key === 'name'"
  159. class="name upload-status-wrap"
  160. >
  161. <div class="name-inner ellipsis" v-title="item.title">
  162. {{ item.title }}
  163. </div>
  164. <div class="upload-status">
  165. {{ item.statusText }}
  166. </div>
  167. </span>
  168. <span v-if="tableItemStructure.key === 'fileSize'">{{
  169. $i18n.t(`tips_code.FAILURE_3025`)
  170. }}</span>
  171. <span
  172. v-if="
  173. tableItemStructure.key !== 'name' &&
  174. tableItemStructure.key !== 'fileSize'
  175. "
  176. ></span>
  177. </span>
  178. </template>
  179. </div>
  180. </div>
  181. <!-- 本组件内的列表数据 -->
  182. <div
  183. class="table-body-row"
  184. v-for="(item, i) in showList"
  185. :key="i"
  186. @click="
  187. (e) => {
  188. if (item.type === 'dir') {
  189. onClickFolder(item);
  190. } else {
  191. onClickRow(e);
  192. }
  193. }
  194. "
  195. >
  196. <span class="table-data">
  197. <RadioOrCheckbox
  198. class="checkbox"
  199. :isLightTheme="!isDarkTheme"
  200. :isDisabled="item.type === 'dir'"
  201. :isMultiSelection="isMultiSelection"
  202. :isCheckedInitial="select.some((i) => i.id === item.id)"
  203. @change="(v) => selectItem(item, v)"
  204. />
  205. </span>
  206. <span
  207. class="table-data"
  208. v-for="(tableItemStructure, idx) in tableHeaders"
  209. :style="{
  210. width: columnWidthList[idx],
  211. }"
  212. :key="idx"
  213. >
  214. <div v-if="tableItemStructure.type" class="list-img">
  215. <img
  216. v-if="item.type === 'dir'"
  217. class="folderIcon"
  218. src="@/assets/images/icons/folder-blue.png"
  219. alt=""
  220. />
  221. <slot
  222. v-else
  223. name="materialIcon"
  224. :materialInfo="item"
  225. :tableItemStructure="tableItemStructure"
  226. >
  227. </slot>
  228. </div>
  229. <span
  230. v-else-if="tableItemStructure.key === 'name'"
  231. class="name"
  232. :class="{
  233. searchRes: latestUsedSearchKey,
  234. }"
  235. >
  236. <div
  237. class="name-inner ellipsis"
  238. v-title="item[tableItemStructure.key]"
  239. >
  240. {{ item[tableItemStructure.key] }}
  241. </div>
  242. <div v-if="latestUsedSearchKey" class="parent-info">
  243. {{ $i18n.t("gather.dir") }}
  244. <span
  245. class="parent-name"
  246. @click.stop="onClickParentFolder(item)"
  247. >{{
  248. item.dirId === 1 ? $i18n.t("gather.root_dir") : item.dirName
  249. }}</span
  250. >
  251. </div>
  252. </span>
  253. <span v-else class="ellipsis">
  254. {{ item[tableItemStructure.key] }}
  255. </span>
  256. </span>
  257. </div>
  258. <LoadingPoints
  259. v-show="isRequestingMoreData"
  260. :isDarkTheme="isDarkTheme"
  261. />
  262. <!-- <div class="no-more-data" v-show="!hasMoreData">
  263. - {{ $i18n.t("gather.no_more_data") }} -
  264. </div> -->
  265. </div>
  266. <!-- 无数据时的提示 -->
  267. <div v-show="!(listLocalLength !== 0 || hasMoreData)" class="no-data">
  268. <div v-if="latestUsedSearchKey">
  269. <img
  270. :src="
  271. require(`@/assets/images/default/empty_search_${
  272. isDarkTheme ? 'dark' : 'bright'
  273. }.png`)
  274. "
  275. alt=""
  276. />
  277. <span>{{ $i18n.t("gather.no_search_result") }}</span>
  278. </div>
  279. <div v-if="!latestUsedSearchKey">
  280. <img
  281. :src="
  282. require(`@/assets/images/default/empty_${
  283. isDarkTheme ? 'dark' : 'bright'
  284. }.png`)
  285. "
  286. alt=""
  287. />
  288. <span>{{ $i18n.t("gather.no_material_result") }}</span>
  289. <a v-if="!canUpload" href="/#/">
  290. <button class="ui-button">
  291. {{ $i18n.t("gather.how_to_shoot") }}
  292. </button>
  293. </a>
  294. </div>
  295. </div>
  296. </div>
  297. <div class="btns">
  298. <button
  299. v-if="canUpload && !searchKey"
  300. class="ui-button upload-btn"
  301. @click="onClickUpload"
  302. >
  303. <span>{{ $i18n.t("gather.upload_material") }}</span>
  304. <i
  305. class="iconfont icon-help_i tool-tip-for-editor"
  306. v-tooltip="fileInputBtnTip"
  307. />
  308. <FileInput
  309. ref="file-input"
  310. :failString="fileInputFailString"
  311. :limitFailStr="fileInputLimitFailStr"
  312. :acceptType="fileInputAcceptType"
  313. :mediaType="fileInputMediaType"
  314. :limit="fileInputLimit"
  315. @file-change="onFileInputChange"
  316. />
  317. </button>
  318. </div>
  319. </div>
  320. </template>
  321. <script>
  322. import {
  323. getMaterialList,
  324. get3DSceneList,
  325. searchInAll3DScenes,
  326. uploadMaterial,
  327. checkUserSize,
  328. } from "@/api";
  329. import { changeByteUnit } from "@/utils/file";
  330. import { debounce, capitalize } from "@/utils/other.js";
  331. import config from "@/config";
  332. import FileInput from "@/components/shared/uploads/UploadMultiple.vue";
  333. import RadioOrCheckbox from "@/components/shared/RadioOrCheckbox.vue";
  334. import LoadingPoints from "@/components/shared/LoadingPoints.vue";
  335. import folderMixin from "./materialSelectorFolderMixin.js";
  336. export default {
  337. components: {
  338. FileInput,
  339. RadioOrCheckbox,
  340. LoadingPoints,
  341. },
  342. mixins: [folderMixin],
  343. props: {
  344. isDarkTheme: {
  345. type: Boolean,
  346. default: true,
  347. },
  348. currentMaterialType: {
  349. type: String,
  350. required: true,
  351. },
  352. materialType: {
  353. type: String,
  354. required: true,
  355. },
  356. materialItemCustomProcess: {
  357. type: Function,
  358. default: (item) => {
  359. return;
  360. },
  361. },
  362. tableHeaderKeyList: {
  363. type: Array,
  364. default: () => {
  365. return [];
  366. },
  367. },
  368. columnWidthList: {
  369. type: Array,
  370. default: () => {
  371. return [];
  372. },
  373. },
  374. isMultiSelection: {
  375. type: Boolean,
  376. default: false,
  377. },
  378. select: {
  379. type: Array,
  380. required: true,
  381. },
  382. searchKey: {
  383. type: String,
  384. default: "",
  385. },
  386. canUpload: {
  387. type: Boolean,
  388. defaut: false,
  389. },
  390. fileInputBtnTip: {
  391. type: String,
  392. },
  393. fileInputCustomCheck: {
  394. type: Function,
  395. default: async () => {
  396. return true;
  397. },
  398. },
  399. fileUploadLongPollingCb: {
  400. type: Function || null,
  401. default: null,
  402. },
  403. fileUploadLongPollingStatusText: {
  404. type: String,
  405. default: "",
  406. },
  407. fileInputFailString: {
  408. type: String,
  409. },
  410. fileInputLimitFailStr: {
  411. type: String,
  412. },
  413. fileInputAcceptType: {
  414. type: String,
  415. },
  416. fileInputMediaType: {
  417. type: String,
  418. },
  419. fileInputLimit: {
  420. type: Number,
  421. },
  422. },
  423. data() {
  424. return {
  425. list: [],
  426. latestUsedSearchKey: "",
  427. isRequestingMoreData: false,
  428. hasMoreData: true,
  429. longPollingIntervalId: null,
  430. };
  431. },
  432. computed: {
  433. uniqueFolderList() {
  434. return (arr) => {
  435. const tem = new Map();
  436. let res = arr.filter(
  437. (item) => !tem.has(item.id) && tem.set(item.id, 1)
  438. );
  439. return res;
  440. };
  441. },
  442. showList() {
  443. if (this.materialTypeAlias === "pano") {
  444. return this.list.filter((i) => {
  445. if (i.type !== "dir" && i.status < 3) {
  446. return false;
  447. } else {
  448. return true;
  449. }
  450. });
  451. }
  452. return this.list;
  453. },
  454. materialTypeAlias() {
  455. if (this.materialType === "3D") {
  456. return "scene";
  457. } else {
  458. return this.materialType;
  459. }
  460. },
  461. tableHeaders() {
  462. /*
  463. [
  464. {
  465. en: "素材", // 暂时没用到
  466. key: "icon",
  467. name: "素材",
  468. type: "image",
  469. width: 150, // 暂时没用到
  470. },
  471. {
  472. en: "名称",
  473. key: "name",
  474. name: "名称",
  475. width: 240,
  476. },
  477. {
  478. en: "大小",
  479. key: "fileSize",
  480. name: "大小",
  481. width: 80,
  482. }
  483. ]
  484. */
  485. return this.$MAPTABLEHEADER[this.materialTypeAlias].filter((item) => {
  486. return this.tableHeaderKeyList.includes(item.key);
  487. });
  488. },
  489. uploadStatusList() {
  490. if (this.canUpload) {
  491. return this.$store.state[
  492. `uploadStatusList${capitalize(this.materialType)}`
  493. ];
  494. } else {
  495. return [];
  496. }
  497. },
  498. listRealLength() {
  499. return (
  500. this.list.length +
  501. this.uploadStatusList.filter((item) => {
  502. return item.status === "SUCCESS";
  503. }).length
  504. );
  505. },
  506. listLocalLength() {
  507. return this.list.length + this.uploadStatusList.length;
  508. },
  509. needLongPolling() {
  510. return this.uploadStatusList.some((item) => {
  511. return item.status === "LOADING" && item.ifKnowProgress === false;
  512. });
  513. },
  514. },
  515. watch: {
  516. searchKey: {
  517. handler: function () {
  518. if (this.currentMaterialType === this.materialType) {
  519. this.refreshMaterialList();
  520. }
  521. },
  522. immediate: false,
  523. },
  524. currentMaterialType: {
  525. handler: function (newVal) {
  526. if (newVal === this.materialType && this.list.length === 0) {
  527. this.refreshMaterialList();
  528. }
  529. },
  530. immediate: false,
  531. },
  532. needLongPolling: {
  533. handler: function (newVal, oldValue) {
  534. if (!newVal) {
  535. clearInterval(this.longPollingIntervalId);
  536. this.longPollingIntervalId = null;
  537. // 最后上传成功能状态
  538. if (!newVal && oldValue) {
  539. // debugger;
  540. this.refreshMaterialList();
  541. }
  542. } else {
  543. clearInterval(this.longPollingIntervalId);
  544. this.longPollingIntervalId = null;
  545. this.longPollingIntervalId = setInterval(() => {
  546. this.fileUploadLongPollingCb(this.uploadStatusList);
  547. }, 3000);
  548. }
  549. },
  550. immediate: true,
  551. },
  552. },
  553. methods: {
  554. selectItem(item, v) {
  555. item.materialType = this.materialType; // 三维场景数据没有type字段来表明自己是三维场景。所以统一加一个字段。
  556. if (this.isMultiSelection) {
  557. if (v) {
  558. // eslint-disable-next-line vue/no-mutating-props
  559. this.select.push(item);
  560. } else {
  561. const toDeleteIdx = this.select.findIndex((eachSelect) => {
  562. return eachSelect.id === item.id;
  563. });
  564. if (toDeleteIdx >= 0) {
  565. // eslint-disable-next-line vue/no-mutating-props
  566. this.select.splice(toDeleteIdx, 1);
  567. }
  568. }
  569. } else {
  570. // eslint-disable-next-line vue/no-mutating-props
  571. this.select.splice(0, this.select.length);
  572. if (v) {
  573. // eslint-disable-next-line vue/no-mutating-props
  574. this.select.push(item);
  575. }
  576. }
  577. },
  578. requestMoreData() {
  579. this.isRequestingMoreData = true;
  580. const latestUsedSearchKey = this.searchKey;
  581. let getListFn = null;
  582. let params = null;
  583. if (this.materialType === "3D") {
  584. if (!this.searchKey) {
  585. getListFn = get3DSceneList;
  586. params = {
  587. pathLevel2Id: this.folderPath[1]?.id,
  588. folderId: this.currentFolderId,
  589. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  590. pageSize: config.PAGE_SIZE,
  591. searchKey: this.searchKey,
  592. };
  593. } else {
  594. getListFn = searchInAll3DScenes;
  595. params = {
  596. searchKey: this.searchKey,
  597. };
  598. }
  599. } else {
  600. getListFn = getMaterialList;
  601. params = {
  602. dirId: this.currentFolderId,
  603. pageNum: Math.floor(this.listRealLength / config.PAGE_SIZE) + 1,
  604. pageSize: config.PAGE_SIZE,
  605. searchKey: this.searchKey,
  606. type: this.materialType,
  607. };
  608. }
  609. getListFn(
  610. params,
  611. (data) => {
  612. const newData = data.data.list.map((i) => {
  613. if (i.fileSize) {
  614. i.fileSize = changeByteUnit(Number(i.fileSize));
  615. } else {
  616. i.fileSize = "";
  617. }
  618. this.materialItemCustomProcess(i);
  619. return i;
  620. });
  621. this.preProessData(newData);
  622. if (this.listRealLength === data.data.total) {
  623. this.hasMoreData = false;
  624. }
  625. this.isRequestingMoreData = false;
  626. this.latestUsedSearchKey = latestUsedSearchKey;
  627. },
  628. () => {
  629. this.isRequestingMoreData = false;
  630. this.latestUsedSearchKey = latestUsedSearchKey;
  631. }
  632. );
  633. },
  634. preProessData(newData) {
  635. this.list = this.list.concat(newData);
  636. //全景图
  637. if (this.materialTypeAlias === "pano") {
  638. const uploadlist = this.list
  639. .filter((i) => i.status < 3 && i.type !== "dir")
  640. .map((item) => {
  641. let itemInUploadList = {
  642. title: item.name,
  643. ifKnowProgress: false,
  644. progress: 0,
  645. status: "LOADING",
  646. statusText: this.$i18n.t(`gather.cutting`),
  647. uid: `u_${this.$randomWord(true, 8, 8)}`,
  648. abortHandler: null,
  649. backendId: item.id, // 只用于全景图上传
  650. parentFolderId: item.dirId,
  651. };
  652. return itemInUploadList;
  653. });
  654. const res = new Map();
  655. const latestUploadlist = this.uploadStatusList
  656. .concat(uploadlist)
  657. .filter((a) => !res.has(a.backendId) && res.set(a.backendId, 1));
  658. console.log("latestUploadlist", latestUploadlist);
  659. // console.log("origin-list", this.list);
  660. const capitalizedMaterialType = capitalize(this.materialType);
  661. this.$store.commit(
  662. `setUploadStatusList${capitalizedMaterialType}`,
  663. latestUploadlist
  664. );
  665. }
  666. },
  667. refreshMaterialList: debounce(
  668. function (type) {
  669. this.isRequestingMoreData = false;
  670. this.hasMoreData = true;
  671. this.list = [];
  672. if (this.canUpload) {
  673. let filterResult = this.uploadStatusList.filter((item) => {
  674. return item.status === "LOADING";
  675. });
  676. const capitalizedMaterialType = capitalize(this.materialType);
  677. this.$store.commit(
  678. `setUploadStatusList${capitalizedMaterialType}`,
  679. filterResult
  680. );
  681. }
  682. this.requestMoreData();
  683. },
  684. 500,
  685. false
  686. ),
  687. onFileInputChange(e) {
  688. e.files.forEach(async (eachFile, i) => {
  689. const extension = eachFile.name.split(".").pop();
  690. console.log("extension", extension, this.fileInputAcceptType);
  691. if (
  692. this.fileInputAcceptType.indexOf(
  693. String(extension).toLocaleLowerCase()
  694. ) <= -1
  695. ) {
  696. console.log("格式不对!");
  697. setTimeout(() => {
  698. this.$msg({
  699. message: `“${eachFile.name}”${this.fileInputFailString}`,
  700. type: "warning",
  701. });
  702. }, i * 100);
  703. return;
  704. }
  705. if (
  706. eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50
  707. ) {
  708. setTimeout(() => {
  709. this.$msg({
  710. message: `“${eachFile.name}”${this.$i18n.t(
  711. `gather.too_long_word`
  712. )}`,
  713. type: "warning",
  714. });
  715. }, i * 100);
  716. return;
  717. }
  718. const customCheckRes = await this.fileInputCustomCheck(eachFile, i);
  719. if (!customCheckRes) {
  720. return;
  721. }
  722. let itemInUploadList = {
  723. title: eachFile.name,
  724. ifKnowProgress: true,
  725. progress: 0,
  726. status: "LOADING",
  727. statusText: this.$i18n.t(`gather.uploading_material`),
  728. uid: `u_${this.$randomWord(true, 8, 8)}`,
  729. abortHandler: null,
  730. backendId: "", // 只用于全景图上传
  731. parentFolderId: this.currentFolderId,
  732. };
  733. itemInUploadList.abortHandler = uploadMaterial(
  734. {
  735. dirId: this.currentFolderId,
  736. file: eachFile,
  737. tempId: itemInUploadList.uid,
  738. type: this.materialType,
  739. },
  740. (response) => {
  741. // 上传成功
  742. if (response.code !== 0) {
  743. console.error("上传接口响应异常:", response);
  744. return;
  745. }
  746. console.log("上传成功1");
  747. if (this.fileUploadLongPollingCb) {
  748. itemInUploadList.statusText =
  749. this.fileUploadLongPollingStatusText;
  750. itemInUploadList.ifKnowProgress = false;
  751. itemInUploadList.backendId = response.data.id;
  752. } else {
  753. itemInUploadList.status = "SUCCESS";
  754. if (response.data.fileSize) {
  755. response.data.fileSize = changeByteUnit(
  756. Number(response.fileSize)
  757. );
  758. } else {
  759. response.data.fileSize = "";
  760. }
  761. itemInUploadList.successInfo = response.data;
  762. // 非pano上传refresh
  763. this.refreshMaterialList();
  764. }
  765. },
  766. (err) => {
  767. if (err.statusText === "abort") {
  768. // 用户取消了上传任务。
  769. console.log("用户取消了任务!");
  770. const index = this.uploadStatusList.findIndex((eachItem) => {
  771. return eachItem.uid === itemInUploadList.uid;
  772. });
  773. this.uploadStatusList.splice(index, 1);
  774. } else {
  775. console.log("上传失败!");
  776. itemInUploadList.status = "FAIL";
  777. itemInUploadList.statusText = this.$i18n.t(
  778. `gather.material_upload_fail`
  779. );
  780. }
  781. },
  782. (progress) => {
  783. console.log("进度:", progress);
  784. itemInUploadList.progress = progress;
  785. }
  786. );
  787. this.uploadStatusList.unshift(itemInUploadList);
  788. });
  789. },
  790. onClickRow(e) {
  791. const checkboxNodeList = e.currentTarget.getElementsByClassName(
  792. "selection-click-target"
  793. );
  794. if (checkboxNodeList && checkboxNodeList[0]) {
  795. checkboxNodeList[0].click();
  796. }
  797. },
  798. async onClickUpload() {
  799. const res = await checkUserSize();
  800. if (res)
  801. if (Number(res.useSpace) > Number(res.totalSpace)) {
  802. this.$alert({ content: this.$i18n.t("tips_code.FAILURE_3024") });
  803. } else {
  804. this.$refs["file-input"].click();
  805. }
  806. },
  807. // onClickUpload() {
  808. // checkUserSize({}, ({ useSpace, totalSpace }) => {
  809. // //判断已用是否大于3G
  810. // if (Number(useSpace) > Number(totalSpace)) {
  811. // this.$alert({ content: this.$i18n.t("tips_code.FAILURE_3024") });
  812. // } else {
  813. // de
  814. // this.$refs["file-input"].click();
  815. // }
  816. // });
  817. // },
  818. // 1.3.0插入排序
  819. insertListBySort(newData) {
  820. const firstNotDirItem = this.uploadStatusList.slice
  821. .filter((i) => i.dir !== "dir")
  822. .shift();
  823. console.log("firstNotDirItem", firstNotDirItem);
  824. const firstNotDirItemIndex = this.uploadStatusList.findIndex(
  825. (i) => i.id === firstNotDirItem.id
  826. );
  827. console.log("firstNotDirItemIndex", firstNotDirItemIndex);
  828. this.uploadStatusList.unshift(newData);
  829. },
  830. },
  831. mounted() {},
  832. beforeDestroy() {
  833. if (this.canUpload) {
  834. const capitalizedMaterialType = capitalize(this.materialType);
  835. this.$store.commit(
  836. `setUploadStatusList${capitalizedMaterialType}`,
  837. this.uploadStatusList.filter((item) => {
  838. return item.status === "LOADING";
  839. })
  840. );
  841. }
  842. },
  843. };
  844. </script>
  845. <style lang="less" scoped>
  846. .material-list {
  847. position: relative;
  848. .ellipsis {
  849. text-overflow: ellipsis;
  850. overflow: hidden;
  851. white-space: nowrap;
  852. width: 100%;
  853. display: inline-block;
  854. }
  855. .crumbs {
  856. margin-top: 10px;
  857. }
  858. // @table-height: 420px;
  859. // @table-head-row-height: 40px;
  860. // @table-border-size: 1px;
  861. @table-height: 420px;
  862. @table-head-row-height: 0px;
  863. @table-border-size: 0px;
  864. .table {
  865. margin-top: 10px;
  866. // border: @table-border-size solid #EBEDF0;
  867. width: 100%;
  868. height: @table-height;
  869. // >.table-head-row {
  870. // width: 100%;
  871. // height: @table-head-row-height;
  872. // background: #F5F7FA;
  873. // color: #646566;
  874. // .table-head {
  875. // font-size: 16px;
  876. // line-height: @table-head-row-height;
  877. // height: 100%;
  878. // display: inline-block;
  879. // &:nth-of-type(1) {
  880. // color: transparent;
  881. // }
  882. // }
  883. // }
  884. > .table-body {
  885. height: calc(
  886. @table-height - @table-head-row-height - @table-border-size -
  887. @table-border-size
  888. );
  889. overflow: auto;
  890. display: inline-block;
  891. width: 100%;
  892. .table-body-row {
  893. height: 50px;
  894. // border-bottom: 1px solid #EBEDF0;
  895. display: flex;
  896. align-items: center;
  897. border-radius: 4px;
  898. cursor: pointer;
  899. &:hover {
  900. background: #f7f8fa;
  901. }
  902. > .table-data {
  903. font-size: 14px;
  904. line-height: 50px;
  905. height: 100%;
  906. color: #323233;
  907. &:nth-of-type(1) {
  908. width: 50px;
  909. }
  910. &:nth-of-type(2) {
  911. width: 96px;
  912. }
  913. &:nth-of-type(3) {
  914. width: calc(100% - 50px - 96px);
  915. }
  916. &:last-of-type {
  917. padding-right: 10px;
  918. }
  919. > .list-img {
  920. position: relative;
  921. height: 100%;
  922. display: inline-block;
  923. width: 100%;
  924. > img,
  925. .audio-player {
  926. position: absolute;
  927. top: 50%;
  928. transform: translateY(-50%);
  929. width: 40px;
  930. height: 40px;
  931. object-fit: cover;
  932. &.folderIcon {
  933. object-fit: contain;
  934. }
  935. }
  936. }
  937. > .name:not(.searchRes) {
  938. display: inline-block;
  939. height: 100%;
  940. width: 100%;
  941. display: flex;
  942. align-items: center;
  943. > .name-inner {
  944. flex: 0 0 auto;
  945. display: inline-block;
  946. height: 100%;
  947. width: 50%;
  948. }
  949. > .upload-status {
  950. flex: 0 0 auto;
  951. display: inline-block;
  952. height: 100%;
  953. margin-left: 20px;
  954. }
  955. }
  956. > .name.searchRes {
  957. height: 100%;
  958. width: 100%;
  959. display: flex;
  960. flex-direction: column;
  961. justify-content: center;
  962. align-items: flex-start;
  963. line-height: initial;
  964. > .name-inner {
  965. flex: 0 0 auto;
  966. display: inline-block;
  967. width: 100%;
  968. }
  969. > .parent-info {
  970. > .parent-name {
  971. color: @color;
  972. }
  973. }
  974. }
  975. > .name:not(.upload-status-wrap):hover {
  976. > .name-inner {
  977. width: 100%;
  978. }
  979. }
  980. }
  981. }
  982. .no-more-data {
  983. margin-top: 16px;
  984. margin-bottom: 16px;
  985. text-align: center;
  986. font-size: 12px;
  987. color: #969799;
  988. }
  989. }
  990. > .no-data {
  991. height: calc(
  992. @table-height - @table-head-row-height - @table-border-size -
  993. @table-border-size
  994. );
  995. width: 100%;
  996. position: relative;
  997. > div {
  998. position: absolute;
  999. top: 50%;
  1000. left: 50%;
  1001. transform: translate(-50%, -50%);
  1002. text-align: center;
  1003. > img {
  1004. width: 116px;
  1005. }
  1006. > span {
  1007. margin-top: 20px;
  1008. display: block;
  1009. font-size: 14px;
  1010. color: #646566;
  1011. }
  1012. > a {
  1013. > button {
  1014. margin-top: 20px;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. .checkbox {
  1021. width: 100%;
  1022. height: 100%;
  1023. }
  1024. .btns {
  1025. left: 0;
  1026. margin-top: 29px;
  1027. .upload-btn {
  1028. display: flex;
  1029. align-items: center;
  1030. > span {
  1031. display: inline-block;
  1032. margin-right: 4px;
  1033. }
  1034. i.tool-tip-for-editor {
  1035. font-size: 12px;
  1036. transform: scale(0.923) translateY(1px);
  1037. cursor: default;
  1038. }
  1039. }
  1040. }
  1041. }
  1042. .material-list.dark {
  1043. .ellipsis {
  1044. }
  1045. .crumbs {
  1046. ul > li .name {
  1047. max-width: 80px;
  1048. display: block;
  1049. }
  1050. }
  1051. .table {
  1052. // border: @table-border-size solid #EBEDF0;
  1053. // >.table-head-row {
  1054. // background: #F5F7FA;
  1055. // color: #646566;
  1056. // .table-head {
  1057. // &:nth-of-type(1) {
  1058. // color: transparent;
  1059. // }
  1060. // }
  1061. // }
  1062. > .table-body {
  1063. .table-body-row {
  1064. // border-bottom: 1px solid #EBEDF0;
  1065. &:hover {
  1066. background: #252526;
  1067. }
  1068. > .table-data {
  1069. color: #fff;
  1070. > .list-img {
  1071. > img,
  1072. .audio-player {
  1073. &.folderIcon {
  1074. }
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. > .no-data {
  1081. > div {
  1082. > img {
  1083. }
  1084. > span {
  1085. color: rgba(255, 255, 255, 0.6);
  1086. }
  1087. > a {
  1088. > button {
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. .checkbox {
  1095. }
  1096. .btns {
  1097. .upload-btn {
  1098. > span {
  1099. }
  1100. i.tool-tip-for-editor {
  1101. }
  1102. }
  1103. }
  1104. }
  1105. </style>
  1106. <style lang="less">
  1107. .material-list,
  1108. .material-list.dark {
  1109. .crumbs {
  1110. // display: none;
  1111. ul > li {
  1112. display: flex;
  1113. justify-content: center;
  1114. align-items: center;
  1115. .name {
  1116. max-width: 180px;
  1117. display: block;
  1118. }
  1119. }
  1120. }
  1121. }
  1122. </style>