index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. <template>
  2. <div class="panorama con">
  3. <div class="top">
  4. <crumbs
  5. v-if="!lastestUsedSearchKey"
  6. :list="folderPath"
  7. :rootName="$i18n.t('gather.pano')"
  8. @click-path="onClickPath"
  9. />
  10. <div v-if="lastestUsedSearchKey" class="">
  11. {{ $i18n.t("gather.pano") }}
  12. </div>
  13. </div>
  14. <div class="second-line" :class="{ disabled: searchKey }">
  15. <template>
  16. <div class="btn">
  17. <button
  18. @mouseover.stop="showList = true"
  19. @click="onUploadFile"
  20. class="ui-button submit"
  21. >
  22. <span>{{ upload_material }}</span>
  23. <i class="iconfont icon-help_i" v-tooltip="pano_size" />
  24. <upload
  25. ref="uploadFile"
  26. :failString="pano_fail"
  27. :limitFailStr="pano_limit"
  28. accept-type=".jpg"
  29. media-type="image"
  30. :limit="120"
  31. @file-change="onFileChange"
  32. ></upload>
  33. </button>
  34. </div>
  35. <button class="ui-button submit" @click="isShowNewFolder = true">
  36. {{ $i18n.t(`gather.new_folder`) }}
  37. </button>
  38. <button
  39. class="ui-button cancel"
  40. :class="{ disable: selectedList.length === 0 }"
  41. @click="onClickMoveFolder"
  42. >
  43. {{ $i18n.t(`gather.move_folder`) }}
  44. </button>
  45. </template>
  46. <div class="filter">
  47. <div
  48. :class="{ active: isFilterFocus }"
  49. @focusin="onFilterFocus"
  50. @focusout="onFilterBlur"
  51. >
  52. <i class="iconfont icon-works_search search"></i>
  53. <input
  54. type="text"
  55. v-model="searchKey"
  56. :placeholder="search_material"
  57. />
  58. <i
  59. v-if="searchKey"
  60. @click="searchKey = ''"
  61. class="iconfont icon-toast_red del"
  62. ></i>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="list">
  67. <tableList
  68. @selection-change="
  69. (data) => {
  70. selectedList = data;
  71. }
  72. "
  73. @request-more-data="getMoreMaterialItem"
  74. :canRequestMoreData="hasMoreData && !isRequestingMoreData"
  75. :header="tabHeader"
  76. :showLine="true"
  77. :selection="lastestUsedSearchKey ? false : true"
  78. :data="tableListData"
  79. class="table-list"
  80. ref="table-list"
  81. >
  82. <!-- 插到tableList组件各个header插槽,并通过插槽的headerItem作用域拿到表头各项 -->
  83. <div slot-scope="{ headerItem }" slot="header">
  84. {{ headerItem.name && $i18n.t(`table.${headerItem.name}`) }}
  85. </div>
  86. <!-- 内容各单元格 -->
  87. <div
  88. slot-scope="{ itemData, lineData, headerItem }"
  89. slot="tableItem"
  90. style="width: 100%"
  91. >
  92. <!-- 操作型单元格 -->
  93. <div class="handle" v-if="headerItem.canclick">
  94. <i
  95. v-if="lineData.type !== 'dir'"
  96. class="iconfont icon-material_operation_image hover-tips"
  97. @click="(showCover = true), (popupItem = lineData)"
  98. >
  99. <div>
  100. <div class="remark">{{ edit_cover }}</div>
  101. </div>
  102. </i>
  103. <i
  104. class="iconfont icon-material_operation_editor hover-tips"
  105. @click="onClickRename(lineData)"
  106. >
  107. <div>
  108. <div class="remark">{{ rename }}</div>
  109. </div>
  110. </i>
  111. <i
  112. class="iconfont icon-material_operation_delete hover-tips-warn"
  113. @click="del(lineData)"
  114. >
  115. <div>
  116. <div class="remark">{{ deltips }}</div>
  117. </div>
  118. </i>
  119. </div>
  120. <!-- 图片型单元格 -->
  121. <div
  122. v-else-if="headerItem.type == 'image' && lineData.type !== 'dir'"
  123. class="img"
  124. @click="previewImage(lineData)"
  125. >
  126. <template v-if="Number(lineData.status) == 3">
  127. <img :src="itemData + $imgsuffix" alt="" />
  128. </template>
  129. <template v-if="Number(lineData.status) < 3">
  130. <img src="@/assets/img/list_placeholder.png" alt="" />
  131. </template>
  132. </div>
  133. <div
  134. v-else-if="headerItem.type == 'image' && lineData.type === 'dir'"
  135. class="img dirIcon"
  136. >
  137. <img
  138. :src="require('@/assets/images/icons/folder-blue.png')"
  139. alt=""
  140. @click="onClickFolder(lineData)"
  141. />
  142. </div>
  143. <!-- 文字型单元格 -->
  144. <div v-else class="textItem">
  145. <!-- 名称 -->
  146. <div v-if="headerItem.key === 'name'" class="name">
  147. <!-- 不是搜索出来的 -->
  148. <div v-if="!lastestUsedSearchKey" class="not-search-res">
  149. <!-- 文件夹名称 -->
  150. <div
  151. v-if="lineData.type === 'dir'"
  152. class="dirName"
  153. @click="onClickFolder(lineData)"
  154. >
  155. {{ itemData || "-" }}
  156. </div>
  157. <!-- 素材名称 -->
  158. <div v-else class="not-dir">
  159. {{ itemData || "-" }}
  160. </div>
  161. </div>
  162. <!-- end of 不是搜索出来的 -->
  163. <!-- 搜索出来的 -->
  164. <div v-if="lastestUsedSearchKey" class="search-res">
  165. <!-- 文件夹名称 -->
  166. <div v-if="lineData.type === 'dir'" class="dirName">
  167. <div class="self-name" @click="onClickFolder(lineData)">
  168. {{ itemData || "-" }}
  169. </div>
  170. <div class="parent-name-wrap">
  171. {{ $i18n.t("gather.dir") }}
  172. <span
  173. class="parent-name"
  174. @click="onClickParentFolder(lineData)"
  175. >{{
  176. lineData.dirId === 1
  177. ? $i18n.t("gather.root_dir")
  178. : lineData.dirName
  179. }}</span
  180. >
  181. </div>
  182. </div>
  183. <!-- 素材名称 -->
  184. <div v-else class="not-dir">
  185. <div class="self-name">
  186. {{ itemData || "-" }}
  187. </div>
  188. <div class="parent-name-wrap">
  189. {{ $i18n.t("gather.dir") }}
  190. <span
  191. class="parent-name"
  192. @click="onClickParentFolder(lineData)"
  193. >{{
  194. lineData.dirId === 1
  195. ? $i18n.t("gather.root_dir")
  196. : lineData.dirName
  197. }}</span
  198. >
  199. </div>
  200. </div>
  201. </div>
  202. <!-- end of 搜索出来的 -->
  203. </div>
  204. <!-- end of 名称 -->
  205. <!-- 不是名称 -->
  206. <div v-else class="not-name">
  207. {{ itemData || "-" }}
  208. </div>
  209. <!-- end of 不是名称 -->
  210. </div>
  211. <!-- end of 文字型单元格 -->
  212. </div>
  213. </tableList>
  214. <UploadTaskList
  215. class="upload-task-list"
  216. fileType="IMAGE"
  217. :taskList="uploadListForUI"
  218. :targetFolderId="lastestUsedSearchKey ? -1 : currentFolderId"
  219. @cancel-task="onCancelTask"
  220. />
  221. <div class="total-number" v-if="list.length !== 0 || hasMoreData">
  222. {{ had_load }}
  223. </div>
  224. <div
  225. class="nodata"
  226. v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey"
  227. >
  228. <img :src="$noresult" alt="" />
  229. <span>{{ no_search_result }}</span>
  230. </div>
  231. <div
  232. class="nodata"
  233. v-if="list.length == 0 && !hasMoreData && !lastestUsedSearchKey"
  234. >
  235. <img :src="config.empty" alt="" />
  236. <span>{{ no_material_result }}</span>
  237. <button @click="$refs.uploadFile.click()" class="upload-btn-in-table">
  238. {{ upload_material }}
  239. </button>
  240. </div>
  241. </div>
  242. <CreateFolder
  243. v-if="isShowNewFolder"
  244. :validate="validateNewFolderName"
  245. @close="isShowNewFolder = false"
  246. @submit="onSubmitNewFolder"
  247. />
  248. <RenameFolder
  249. v-if="isShowRenameFolder"
  250. :oldName="popupItem.name"
  251. :validate="validateRenameFolderName"
  252. @close="isShowRenameFolder = false"
  253. @submit="onSubmitRenameFolder"
  254. />
  255. <MoveFolder
  256. v-if="isShowMoveFolder"
  257. :folderTree="folderTree"
  258. :selectedList="selectedList"
  259. @close="isShowMoveFolder = false"
  260. @submit="onSubmitMoveFolder"
  261. />
  262. <rename
  263. v-if="showRename"
  264. :item="popupItem"
  265. @rename="handleRename"
  266. @close="showRename = false"
  267. />
  268. <preview
  269. ref="image-previewer"
  270. :sceneCodeList="list.map((item) => item.sceneCode)"
  271. :imageTitleList="list.map((item) => item.name)"
  272. @click-delete="onClickDeleteInPreview"
  273. />
  274. <cover
  275. @panocover="handlePanoCover"
  276. :item="popupItem"
  277. v-if="showCover"
  278. @close="showCover = false"
  279. />
  280. </div>
  281. </template>
  282. <script>
  283. import config from "@/config";
  284. import tableList from "@/components/table/index.vue";
  285. import crumbs from "@/components/crumbs/index.vue";
  286. import { data } from "./pano";
  287. import rename from "../popup/rename";
  288. import preview from "../popup/panoImagePreviewer.vue";
  289. import cover from "../popup/cover";
  290. import Upload from "@/components/shared/uploads/UploadMultiple";
  291. import { getImgWH, changeByteUnit } from "@/utils/file";
  292. import UploadTaskList from "../components/uploadList1.1.0.vue";
  293. import { debounce } from "@/utils/other.js";
  294. import { mapState } from "vuex";
  295. import { i18n } from "@/lang";
  296. import folderMixinFactory from "../folderMixinFactory.js";
  297. import {
  298. getMaterialList,
  299. uploadMaterial,
  300. editMaterial,
  301. delMaterial,
  302. uploadCover,
  303. checkMStatus,
  304. checkUserSize,
  305. } from "@/api";
  306. const TYPE = "pano";
  307. const LONG_POLLING_INTERVAL = 5;
  308. const folderMixin = folderMixinFactory(TYPE);
  309. export default {
  310. mixins: [folderMixin],
  311. name: "Pano",
  312. components: {
  313. tableList,
  314. crumbs,
  315. rename,
  316. cover,
  317. preview,
  318. Upload,
  319. UploadTaskList,
  320. },
  321. data() {
  322. return {
  323. upload_material: i18n.t("gather.upload_material"),
  324. search_material: i18n.t("gather.search_material"),
  325. no_search_result: i18n.t("gather.no_search_result"),
  326. no_material_result: i18n.t("gather.no_material_result"),
  327. pano_size: i18n.t("gather.pano_size"),
  328. pano_fail: i18n.t("gather.pano_fail"),
  329. pano_limit: i18n.t("gather.pano_limit"),
  330. edit_cover: i18n.t("gather.edit_cover"),
  331. rename: i18n.t("gather.rename"),
  332. deltips: i18n.t("gather.delete"),
  333. config,
  334. showRename: false,
  335. showCover: false,
  336. showList: false,
  337. popupItem: null,
  338. tabHeader: data,
  339. // 因为searchKey的变化经过debounce、异步请求的延时,才会反映到数据列表的变化上,所以是否显示、显示哪种无数据提示,也要等到数据列表变化后,根据数据列表是否为空,以及引发本次变化的那个searchKey瞬时值来决定。本变量就是用来保存那个瞬时值。
  340. lastestUsedSearchKey: "",
  341. isFilterFocus: false,
  342. searchKey: "",
  343. list: [],
  344. hasMoreData: true,
  345. isRequestingMoreData: false,
  346. uploadListForUI: [],
  347. };
  348. },
  349. computed: {
  350. ...mapState({
  351. // uploadListForUI: "uploadStatusListPano",
  352. }),
  353. needLongPolling() {
  354. return this.uploadListForUI.some((item) => {
  355. return item.status === "LOADING" && item.ifKnowProgress === false;
  356. });
  357. },
  358. had_load() {
  359. return i18n.t("gather.had_load", { msg: this.tableListData.length });
  360. },
  361. getSubstrName() {
  362. return (name) => {
  363. return name.length > 10 ? String(name).substring(0, 10) + "..." : name;
  364. };
  365. },
  366. tableListData() {
  367. return this.list.filter((i) => {
  368. if (i.type !== "dir" && i.status < 3) {
  369. return false;
  370. } else {
  371. return true;
  372. }
  373. });
  374. },
  375. },
  376. mounted() {},
  377. watch: {
  378. needLongPolling: {
  379. handler: function (newVal) {
  380. if (!newVal) {
  381. this.clearinter();
  382. } else {
  383. this.clearinter();
  384. this.interval = setInterval(() => {
  385. this._checkMStatus();
  386. }, LONG_POLLING_INTERVAL * 1000);
  387. }
  388. },
  389. immediate: true,
  390. },
  391. searchKey: {
  392. handler: function (val) {
  393. if (val.length > 0) {
  394. this.selectedList = [];
  395. }
  396. this.refreshListDebounced();
  397. },
  398. immediate: false,
  399. },
  400. list: {
  401. handler(val) {
  402. const uploadList = val.filter((i) => i.status < 3 && i.type !== "dir");
  403. const uploadMark = uploadList.map((item) => {
  404. return {
  405. title: item.name,
  406. ifKnowProgress: false,
  407. progress: 0,
  408. status: "LOADING",
  409. statusText: i18n.t("gather.cutting"),
  410. uid: `u_${this.$randomWord(true, 8, 8)}`,
  411. abortHandler: null,
  412. backendId: item.id,
  413. parentFolderId: item.dirId,
  414. };
  415. // eslint-disable-next-line no-unreachable
  416. });
  417. const res = new Map();
  418. const allList = this.uploadListForUI
  419. .concat(uploadMark)
  420. .filter((a) => !res.has(a.backendId) && res.set(a.backendId, 1));
  421. console.log("allList", uploadMark);
  422. if (allList.length > 0) {
  423. this.uploadListForUI = allList;
  424. this._checkMStatus();
  425. }
  426. },
  427. },
  428. },
  429. methods: {
  430. async onUploadFile() {
  431. const res = await checkUserSize();
  432. if (res)
  433. if (Number(res.useSpace) > Number(res.totalSpace)) {
  434. this.$alert({ content: i18n.t("tips_code.FAILURE_3024") });
  435. } else {
  436. this.$refs.uploadFile.click();
  437. }
  438. },
  439. onFilterFocus() {
  440. this.isFilterFocus = true;
  441. },
  442. onFilterBlur() {
  443. this.isFilterFocus = false;
  444. },
  445. refreshListDebounced: debounce(
  446. function () {
  447. this.list = [];
  448. this.isRequestingMoreData = false;
  449. this.hasMoreData = true;
  450. this.$refs["table-list"].requestMoreData();
  451. },
  452. 500,
  453. false
  454. ),
  455. clearinter() {
  456. this.interval && clearInterval(this.interval);
  457. this.interval = null;
  458. },
  459. handleRename(newName) {
  460. editMaterial(
  461. {
  462. id: this.popupItem.id,
  463. name: newName,
  464. },
  465. () => {
  466. this.$msg.success(i18n.t("gather.edit_success"));
  467. const index = this.list.findIndex((eachItem) => {
  468. return eachItem.id === this.popupItem.id;
  469. });
  470. if (index >= 0) {
  471. this.list[index].name = newName;
  472. } else {
  473. console.error("在素材列表里没找到要重命名的那一项!");
  474. }
  475. this.showRename = false;
  476. this.popupItem = null;
  477. }
  478. );
  479. },
  480. handlePanoCover(data) {
  481. if (data.indexOf("http") > -1) {
  482. this.showCover = false;
  483. this.popupItem = "";
  484. return;
  485. }
  486. uploadCover({ file: data, filename: "cover.jpg" }, (res) => {
  487. if (res.code == 0) {
  488. editMaterial(
  489. {
  490. id: this.popupItem.id,
  491. icon: res.data,
  492. },
  493. () => {
  494. this.$msg.success(i18n.t("gather.setting_success"));
  495. const index = this.list.findIndex((eachItem) => {
  496. return eachItem.id === this.popupItem.id;
  497. });
  498. if (index >= 0) {
  499. this.isRequestingMoreData = true;
  500. const lastestUsedSearchKey = this.searchKey;
  501. getMaterialList(
  502. {
  503. dirId: this.currentFolderId,
  504. pageNum: index + 1,
  505. pageSize: 1,
  506. type: TYPE,
  507. },
  508. (data) => {
  509. const newData = data.data.list.map((i) => {
  510. i.fileSize = changeByteUnit(Number(i.fileSize));
  511. return i;
  512. });
  513. this.list.splice(index, 1, newData[0]);
  514. this.showCover = false;
  515. this.popupItem = "";
  516. this.isRequestingMoreData = false;
  517. this.lastestUsedSearchKey = lastestUsedSearchKey;
  518. },
  519. () => {
  520. this.isRequestingMoreData = false;
  521. this.lastestUsedSearchKey = lastestUsedSearchKey;
  522. this.showCover = false;
  523. this.popupItem = "";
  524. }
  525. );
  526. } else {
  527. console.error("在素材列表里没找到要编辑封面的那一项!");
  528. this.showCover = false;
  529. this.popupItem = "";
  530. }
  531. }
  532. );
  533. }
  534. });
  535. },
  536. _checkMStatus() {
  537. let needPollingTaskList = this.uploadListForUI.filter(
  538. (item) => item.status === "LOADING" && item.ifKnowProgress === false
  539. );
  540. if (needPollingTaskList.length > 0) {
  541. checkMStatus(
  542. {
  543. ids: needPollingTaskList.map((item) => item.backendId),
  544. islongpolling: true,
  545. },
  546. (res) => {
  547. // 1切图中,2失败,3成功
  548. res.data.forEach((eachRes) => {
  549. if (eachRes.status === 2) {
  550. const index = this.uploadListForUI.findIndex(
  551. (eachTask) => eachTask.backendId === eachRes.id
  552. );
  553. index >= 0 && (this.uploadListForUI[index].status = "FAIL");
  554. index >= 0 &&
  555. (this.uploadListForUI[index].statusText = this.$msg.success(
  556. i18n.t("gather.material_cutting_fail")
  557. ));
  558. } else if (eachRes.status === 3) {
  559. const index = this.uploadListForUI.findIndex(
  560. (eachTask) => eachTask.backendId === eachRes.id
  561. );
  562. index >= 0 && this.uploadListForUI.splice(index, 1);
  563. index >= 0 && this.refreshListDebounced();
  564. }
  565. });
  566. }
  567. );
  568. }
  569. },
  570. onClickRename(lineData) {
  571. this.popupItem = lineData;
  572. if (lineData.type !== "dir") {
  573. this.showRename = true;
  574. } else {
  575. this.isShowRenameFolder = true;
  576. }
  577. },
  578. del(item) {
  579. if (item.type === "dir") {
  580. this.delFolder(
  581. item.id,
  582. (lastestUsedSearchKey) => {
  583. getMaterialList(
  584. {
  585. dirId: this.currentFolderId,
  586. pageNum: this.list.length,
  587. pageSize: 1,
  588. searchKey: this.searchKey,
  589. type: TYPE,
  590. },
  591. (data) => {
  592. const index = this.list.findIndex((eachItem) => {
  593. return eachItem.id === item.id;
  594. });
  595. //去掉已存在移动的id
  596. const alreadySelectIndex = this.selectedList.findIndex(
  597. (i) => i.id === item.id
  598. );
  599. if (alreadySelectIndex > -1) {
  600. this.selectedList.splice(alreadySelectIndex, 1);
  601. }
  602. if (index >= 0) {
  603. this.list.splice(index, 1);
  604. const newData = data.data.list.map((i) => {
  605. i.fileSize = changeByteUnit(Number(i.fileSize));
  606. return i;
  607. });
  608. this.list = this.list.concat(newData);
  609. if (this.list.length === data.data.total) {
  610. this.hasMoreData = false;
  611. }
  612. if (this.list.length === 0) {
  613. this.$refs["image-previewer"].onClickClose();
  614. }
  615. } else {
  616. console.error("在素材列表里没找到要删除的那一项!");
  617. }
  618. this.isRequestingMoreData = false;
  619. this.lastestUsedSearchKey = lastestUsedSearchKey;
  620. },
  621. () => {
  622. this.isRequestingMoreData = false;
  623. this.lastestUsedSearchKey = lastestUsedSearchKey;
  624. }
  625. );
  626. },
  627. () => {
  628. console.error("gemer");
  629. }
  630. );
  631. } else {
  632. this.$confirm({
  633. title: i18n.t("gather.delete_material"),
  634. content: i18n.t("gather.comfirm_delete_material"),
  635. okText: i18n.t("gather.delete"),
  636. ok: () => {
  637. delMaterial(item.id, () => {
  638. this.$msg.success(i18n.t("gather.delete_success"));
  639. this.isRequestingMoreData = true;
  640. const lastestUsedSearchKey = this.searchKey;
  641. getMaterialList(
  642. {
  643. dirId: this.currentFolderId,
  644. pageNum: this.list.length,
  645. pageSize: 1,
  646. searchKey: this.searchKey,
  647. type: TYPE,
  648. },
  649. (data) => {
  650. const index = this.list.findIndex((eachItem) => {
  651. return eachItem.id === item.id;
  652. });
  653. //去掉已存在移动的id
  654. const alreadySelectIndex = this.selectedList.findIndex(
  655. (i) => i.id === item.id
  656. );
  657. if (alreadySelectIndex > -1) {
  658. this.selectedList.splice(alreadySelectIndex, 1);
  659. }
  660. if (index >= 0) {
  661. this.list.splice(index, 1);
  662. const newData = data.data.list.map((i) => {
  663. i.fileSize = changeByteUnit(Number(i.fileSize));
  664. return i;
  665. });
  666. this.list = this.list.concat(newData);
  667. if (this.list.length === data.data.total) {
  668. this.hasMoreData = false;
  669. }
  670. if (this.list.length === 0) {
  671. this.$refs["image-previewer"].onClickClose();
  672. }
  673. } else {
  674. console.error("在素材列表里没找到要删除的那一项!");
  675. }
  676. this.isRequestingMoreData = false;
  677. this.lastestUsedSearchKey = lastestUsedSearchKey;
  678. },
  679. () => {
  680. this.isRequestingMoreData = false;
  681. this.lastestUsedSearchKey = lastestUsedSearchKey;
  682. }
  683. );
  684. });
  685. },
  686. });
  687. }
  688. },
  689. previewImage(targetItem) {
  690. const index = this.list.findIndex((eachItem) => {
  691. return eachItem.id === targetItem.id;
  692. });
  693. this.$refs["image-previewer"].show(index);
  694. },
  695. onFileChange(e) {
  696. e.files.forEach(async (eachFile, i) => {
  697. if (eachFile.type.indexOf("jpeg") <= -1) {
  698. setTimeout(() => {
  699. this.$msg({
  700. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  701. type: "warning",
  702. });
  703. }, i * 100);
  704. return;
  705. }
  706. if (
  707. eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50
  708. ) {
  709. setTimeout(() => {
  710. this.$msg({
  711. message: `“${
  712. eachFile.name.substring(0, 50) +
  713. "..." +
  714. eachFile.name.split(".")[1]
  715. }”${i18n.t("gather.too_long_word")}`,
  716. type: "warning",
  717. });
  718. }, i * 100);
  719. return;
  720. }
  721. let WHRate = null;
  722. try {
  723. const { width, height } = await getImgWH(eachFile);
  724. WHRate = width / height;
  725. } catch (e) {
  726. console.error("获取图像宽高失败:", e);
  727. setTimeout(() => {
  728. this.$msg({
  729. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  730. type: "warning",
  731. });
  732. }, i * 100);
  733. return;
  734. }
  735. if (WHRate !== 2) {
  736. setTimeout(() => {
  737. this.$msg({
  738. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  739. type: "warning",
  740. });
  741. }, i * 100);
  742. return;
  743. }
  744. let itemInUploadList = {
  745. title: eachFile.name,
  746. ifKnowProgress: true,
  747. progress: 0,
  748. status: "LOADING",
  749. statusText: i18n.t("gather.uploading_material"),
  750. uid: `u_${this.$randomWord(true, 8, 8)}`,
  751. abortHandler: null,
  752. backendId: "",
  753. parentFolderId: this.currentFolderId,
  754. };
  755. itemInUploadList.abortHandler = uploadMaterial(
  756. {
  757. dirId: this.currentFolderId,
  758. file: eachFile,
  759. tempId: itemInUploadList.uid,
  760. type: TYPE,
  761. },
  762. (response) => {
  763. // 上传成功
  764. itemInUploadList.statusText = i18n.t("gather.cutting");
  765. itemInUploadList.ifKnowProgress = false;
  766. itemInUploadList.backendId = response.data.id;
  767. },
  768. (err) => {
  769. if (err.statusText === "abort") {
  770. // 用户取消了上传任务。
  771. const index = this.uploadListForUI.findIndex((eachItem) => {
  772. return eachItem.uid === itemInUploadList.uid;
  773. });
  774. this.uploadListForUI.splice(index, 1);
  775. } else {
  776. itemInUploadList.status = "FAIL";
  777. itemInUploadList.statusText = i18n.t(
  778. "gather.material_upload_fail"
  779. );
  780. }
  781. },
  782. (progress) => {
  783. itemInUploadList.progress = progress;
  784. }
  785. );
  786. this.uploadListForUI.push(itemInUploadList);
  787. });
  788. },
  789. onCancelTask(uid) {
  790. const index = this.uploadListForUI.findIndex((eachItem) => {
  791. return eachItem.uid === uid;
  792. });
  793. if (this.uploadListForUI[index].status === "LOADING") {
  794. this.uploadListForUI[index].abortHandler.abort();
  795. } else {
  796. this.uploadListForUI.splice(index, 1);
  797. }
  798. },
  799. getMoreMaterialItem(islongpolling = null) {
  800. this.isRequestingMoreData = true;
  801. const lastestUsedSearchKey = this.searchKey;
  802. getMaterialList(
  803. {
  804. dirId: this.currentFolderId,
  805. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  806. pageSize: config.PAGE_SIZE,
  807. searchKey: this.searchKey,
  808. type: TYPE,
  809. islongpolling,
  810. },
  811. (data) => {
  812. const newData = data.data.list.map((i) => {
  813. if (i.type !== "dir") {
  814. i.fileSize = changeByteUnit(Number(i.fileSize));
  815. }
  816. return i;
  817. });
  818. this.list = this.list.concat(newData);
  819. if (this.list.length === data.data.total) {
  820. this.hasMoreData = false;
  821. }
  822. this.isRequestingMoreData = false;
  823. this.lastestUsedSearchKey = lastestUsedSearchKey;
  824. },
  825. () => {
  826. this.isRequestingMoreData = false;
  827. this.lastestUsedSearchKey = lastestUsedSearchKey;
  828. }
  829. );
  830. },
  831. onClickDeleteInPreview(index) {
  832. this.del(this.list[index]);
  833. },
  834. },
  835. };
  836. </script>
  837. <style lang="less" scoped></style>
  838. <style lang="less" scoped>
  839. @import "../style.less";
  840. </style>