index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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 icontoast_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="list"
  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.list.length });
  360. },
  361. getSubstrName() {
  362. return (name) => {
  363. return name.length > 10 ? String(name).substring(0, 10) + "..." : name;
  364. };
  365. },
  366. },
  367. mounted() {},
  368. watch: {
  369. needLongPolling: {
  370. handler: function (newVal) {
  371. if (!newVal) {
  372. this.clearinter();
  373. } else {
  374. this.clearinter();
  375. this.interval = setInterval(() => {
  376. this._checkMStatus();
  377. }, LONG_POLLING_INTERVAL * 1000);
  378. }
  379. },
  380. immediate: true,
  381. },
  382. searchKey: {
  383. handler: function (val) {
  384. if (val.length > 0) {
  385. this.selectedList = [];
  386. }
  387. this.refreshListDebounced();
  388. },
  389. immediate: false,
  390. },
  391. list: {
  392. handler(val) {
  393. const uploadList = val.filter((i) => i.status < 3);
  394. const uploadMark = uploadList.map((item) => {
  395. return {
  396. title: item.name,
  397. ifKnowProgress: false,
  398. progress: 0,
  399. status: "LOADING",
  400. statusText: i18n.t("gather.cutting"),
  401. uid: `u_${this.$randomWord(true, 8, 8)}`,
  402. abortHandler: null,
  403. backendId: item.id,
  404. parentFolderId: item.dirId,
  405. };
  406. // eslint-disable-next-line no-unreachable
  407. });
  408. const res = new Map();
  409. const allList = this.uploadListForUI.concat(uploadMark).filter((a) => !res.has(a.backendId) && res.set(a.backendId, 1))
  410. console.log("allList", uploadMark);
  411. if (allList.length > 0) {
  412. this.uploadListForUI = allList;
  413. this._checkMStatus();
  414. }
  415. },
  416. },
  417. },
  418. methods: {
  419. async onUploadFile() {
  420. const res = await checkUserSize();
  421. if (res)
  422. if (Number(res.useSpace) > Number(res.totalSpace)) {
  423. this.$alert({ content: i18n.t("tips_code.FAILURE_3024") });
  424. } else {
  425. this.$refs.uploadFile.click();
  426. }
  427. },
  428. onFilterFocus() {
  429. this.isFilterFocus = true;
  430. },
  431. onFilterBlur() {
  432. this.isFilterFocus = false;
  433. },
  434. refreshListDebounced: debounce(
  435. function () {
  436. this.list = [];
  437. this.isRequestingMoreData = false;
  438. this.hasMoreData = true;
  439. this.$refs["table-list"].requestMoreData();
  440. },
  441. 500,
  442. false
  443. ),
  444. clearinter() {
  445. this.interval && clearInterval(this.interval);
  446. this.interval = null;
  447. },
  448. handleRename(newName) {
  449. editMaterial(
  450. {
  451. id: this.popupItem.id,
  452. name: newName,
  453. },
  454. () => {
  455. this.$msg.success(i18n.t("gather.edit_success"));
  456. const index = this.list.findIndex((eachItem) => {
  457. return eachItem.id === this.popupItem.id;
  458. });
  459. if (index >= 0) {
  460. this.list[index].name = newName;
  461. } else {
  462. console.error("在素材列表里没找到要重命名的那一项!");
  463. }
  464. this.showRename = false;
  465. this.popupItem = null;
  466. }
  467. );
  468. },
  469. handlePanoCover(data) {
  470. if (data.indexOf("http") > -1) {
  471. this.showCover = false;
  472. this.popupItem = "";
  473. return;
  474. }
  475. uploadCover({ file: data, filename: "cover.jpg" }, (res) => {
  476. if (res.code == 0) {
  477. editMaterial(
  478. {
  479. id: this.popupItem.id,
  480. icon: res.data,
  481. },
  482. () => {
  483. this.$msg.success(i18n.t("gather.setting_success"));
  484. const index = this.list.findIndex((eachItem) => {
  485. return eachItem.id === this.popupItem.id;
  486. });
  487. if (index >= 0) {
  488. this.isRequestingMoreData = true;
  489. const lastestUsedSearchKey = this.searchKey;
  490. getMaterialList(
  491. {
  492. dirId: this.currentFolderId,
  493. pageNum: index + 1,
  494. pageSize: 1,
  495. type: TYPE,
  496. },
  497. (data) => {
  498. const newData = data.data.list.map((i) => {
  499. i.fileSize = changeByteUnit(Number(i.fileSize));
  500. return i;
  501. });
  502. this.list.splice(index, 1, newData[0]);
  503. this.showCover = false;
  504. this.popupItem = "";
  505. this.isRequestingMoreData = false;
  506. this.lastestUsedSearchKey = lastestUsedSearchKey;
  507. },
  508. () => {
  509. this.isRequestingMoreData = false;
  510. this.lastestUsedSearchKey = lastestUsedSearchKey;
  511. this.showCover = false;
  512. this.popupItem = "";
  513. }
  514. );
  515. } else {
  516. console.error("在素材列表里没找到要编辑封面的那一项!");
  517. this.showCover = false;
  518. this.popupItem = "";
  519. }
  520. }
  521. );
  522. }
  523. });
  524. },
  525. _checkMStatus() {
  526. let needPollingTaskList = this.uploadListForUI.filter(
  527. (item) => item.status === "LOADING" && item.ifKnowProgress === false
  528. );
  529. if (needPollingTaskList.length > 0) {
  530. checkMStatus(
  531. {
  532. ids: needPollingTaskList.map((item) => item.backendId),
  533. islongpolling: true,
  534. },
  535. (res) => {
  536. // 1切图中,2失败,3成功
  537. res.data.forEach((eachRes) => {
  538. if (eachRes.status === 2) {
  539. const index = this.uploadListForUI.findIndex(
  540. (eachTask) => eachTask.backendId === eachRes.id
  541. );
  542. index >= 0 && (this.uploadListForUI[index].status = "FAIL");
  543. index >= 0 &&
  544. (this.uploadListForUI[index].statusText = this.$msg.success(
  545. i18n.t("gather.material_cutting_fail")
  546. ));
  547. } else if (eachRes.status === 3) {
  548. const index = this.uploadListForUI.findIndex(
  549. (eachTask) => eachTask.backendId === eachRes.id
  550. );
  551. index >= 0 && this.uploadListForUI.splice(index, 1);
  552. index >= 0 && this.refreshListDebounced();
  553. }
  554. });
  555. }
  556. );
  557. }
  558. },
  559. onClickRename(lineData) {
  560. this.popupItem = lineData;
  561. if (lineData.type !== "dir") {
  562. this.showRename = true;
  563. } else {
  564. this.isShowRenameFolder = true;
  565. }
  566. },
  567. del(item) {
  568. if (item.type === "dir") {
  569. this.delFolder(
  570. item.id,
  571. (lastestUsedSearchKey) => {
  572. getMaterialList(
  573. {
  574. dirId: this.currentFolderId,
  575. pageNum: this.list.length,
  576. pageSize: 1,
  577. searchKey: this.searchKey,
  578. type: TYPE,
  579. },
  580. (data) => {
  581. const index = this.list.findIndex((eachItem) => {
  582. return eachItem.id === item.id;
  583. });
  584. //去掉已存在移动的id
  585. const alreadySelectIndex = this.selectedList.findIndex(
  586. (i) => i.id === item.id
  587. );
  588. if (alreadySelectIndex > -1) {
  589. this.selectedList.splice(alreadySelectIndex, 1);
  590. }
  591. if (index >= 0) {
  592. this.list.splice(index, 1);
  593. const newData = data.data.list.map((i) => {
  594. i.fileSize = changeByteUnit(Number(i.fileSize));
  595. return i;
  596. });
  597. this.list = this.list.concat(newData);
  598. if (this.list.length === data.data.total) {
  599. this.hasMoreData = false;
  600. }
  601. if (this.list.length === 0) {
  602. this.$refs["image-previewer"].onClickClose();
  603. }
  604. } else {
  605. console.error("在素材列表里没找到要删除的那一项!");
  606. }
  607. this.isRequestingMoreData = false;
  608. this.lastestUsedSearchKey = lastestUsedSearchKey;
  609. },
  610. () => {
  611. this.isRequestingMoreData = false;
  612. this.lastestUsedSearchKey = lastestUsedSearchKey;
  613. }
  614. );
  615. },
  616. () => {
  617. console.error("gemer");
  618. }
  619. );
  620. } else {
  621. this.$confirm({
  622. title: i18n.t("gather.delete_material"),
  623. content: i18n.t("gather.comfirm_delete_material"),
  624. okText: i18n.t("gather.delete"),
  625. ok: () => {
  626. delMaterial(item.id, () => {
  627. this.$msg.success(i18n.t("gather.delete_success"));
  628. this.isRequestingMoreData = true;
  629. const lastestUsedSearchKey = this.searchKey;
  630. getMaterialList(
  631. {
  632. dirId: this.currentFolderId,
  633. pageNum: this.list.length,
  634. pageSize: 1,
  635. searchKey: this.searchKey,
  636. type: TYPE,
  637. },
  638. (data) => {
  639. const index = this.list.findIndex((eachItem) => {
  640. return eachItem.id === item.id;
  641. });
  642. //去掉已存在移动的id
  643. const alreadySelectIndex = this.selectedList.findIndex(
  644. (i) => i.id === item.id
  645. );
  646. if (alreadySelectIndex > -1) {
  647. this.selectedList.splice(alreadySelectIndex, 1);
  648. }
  649. if (index >= 0) {
  650. this.list.splice(index, 1);
  651. const newData = data.data.list.map((i) => {
  652. i.fileSize = changeByteUnit(Number(i.fileSize));
  653. return i;
  654. });
  655. this.list = this.list.concat(newData);
  656. if (this.list.length === data.data.total) {
  657. this.hasMoreData = false;
  658. }
  659. if (this.list.length === 0) {
  660. this.$refs["image-previewer"].onClickClose();
  661. }
  662. } else {
  663. console.error("在素材列表里没找到要删除的那一项!");
  664. }
  665. this.isRequestingMoreData = false;
  666. this.lastestUsedSearchKey = lastestUsedSearchKey;
  667. },
  668. () => {
  669. this.isRequestingMoreData = false;
  670. this.lastestUsedSearchKey = lastestUsedSearchKey;
  671. }
  672. );
  673. });
  674. },
  675. });
  676. }
  677. },
  678. previewImage(targetItem) {
  679. const index = this.list.findIndex((eachItem) => {
  680. return eachItem.id === targetItem.id;
  681. });
  682. this.$refs["image-previewer"].show(index);
  683. },
  684. onFileChange(e) {
  685. e.files.forEach(async (eachFile, i) => {
  686. if (eachFile.type.indexOf("jpeg") <= -1) {
  687. setTimeout(() => {
  688. this.$msg({
  689. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  690. type: "warning",
  691. });
  692. }, i * 100);
  693. return;
  694. }
  695. if (
  696. eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50
  697. ) {
  698. setTimeout(() => {
  699. this.$msg({
  700. message: `“${
  701. eachFile.name.substring(0, 50) +
  702. "..." +
  703. eachFile.name.split(".")[1]
  704. }”${i18n.t("gather.too_long_word")}`,
  705. type: "warning",
  706. });
  707. }, i * 100);
  708. return;
  709. }
  710. let WHRate = null;
  711. try {
  712. const { width, height } = await getImgWH(eachFile);
  713. WHRate = width / height;
  714. } catch (e) {
  715. console.error("获取图像宽高失败:", e);
  716. setTimeout(() => {
  717. this.$msg({
  718. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  719. type: "warning",
  720. });
  721. }, i * 100);
  722. return;
  723. }
  724. if (WHRate !== 2) {
  725. setTimeout(() => {
  726. this.$msg({
  727. message: `“${eachFile.name}”${i18n.t("gather.pano_fail")}`,
  728. type: "warning",
  729. });
  730. }, i * 100);
  731. return;
  732. }
  733. let itemInUploadList = {
  734. title: eachFile.name,
  735. ifKnowProgress: true,
  736. progress: 0,
  737. status: "LOADING",
  738. statusText: i18n.t("gather.uploading_material"),
  739. uid: `u_${this.$randomWord(true, 8, 8)}`,
  740. abortHandler: null,
  741. backendId: "",
  742. parentFolderId: this.currentFolderId,
  743. };
  744. itemInUploadList.abortHandler = uploadMaterial(
  745. {
  746. dirId: this.currentFolderId,
  747. file: eachFile,
  748. tempId: itemInUploadList.uid,
  749. type: TYPE,
  750. },
  751. (response) => {
  752. // 上传成功
  753. itemInUploadList.statusText = i18n.t("gather.cutting");
  754. itemInUploadList.ifKnowProgress = false;
  755. itemInUploadList.backendId = response.data.id;
  756. },
  757. (err) => {
  758. if (err.statusText === "abort") {
  759. // 用户取消了上传任务。
  760. const index = this.uploadListForUI.findIndex((eachItem) => {
  761. return eachItem.uid === itemInUploadList.uid;
  762. });
  763. this.uploadListForUI.splice(index, 1);
  764. } else {
  765. itemInUploadList.status = "FAIL";
  766. itemInUploadList.statusText = i18n.t(
  767. "gather.material_upload_fail"
  768. );
  769. }
  770. },
  771. (progress) => {
  772. itemInUploadList.progress = progress;
  773. }
  774. );
  775. this.uploadListForUI.push(itemInUploadList);
  776. });
  777. },
  778. onCancelTask(uid) {
  779. const index = this.uploadListForUI.findIndex((eachItem) => {
  780. return eachItem.uid === uid;
  781. });
  782. if (this.uploadListForUI[index].status === "LOADING") {
  783. this.uploadListForUI[index].abortHandler.abort();
  784. } else {
  785. this.uploadListForUI.splice(index, 1);
  786. }
  787. },
  788. getMoreMaterialItem(islongpolling = null) {
  789. this.isRequestingMoreData = true;
  790. const lastestUsedSearchKey = this.searchKey;
  791. getMaterialList(
  792. {
  793. dirId: this.currentFolderId,
  794. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  795. pageSize: config.PAGE_SIZE,
  796. searchKey: this.searchKey,
  797. type: TYPE,
  798. islongpolling,
  799. },
  800. (data) => {
  801. const newData = data.data.list.map((i) => {
  802. if (i.type !== "dir") {
  803. i.fileSize = changeByteUnit(Number(i.fileSize));
  804. }
  805. return i;
  806. });
  807. this.list = this.list.concat(newData);
  808. if (this.list.length === data.data.total) {
  809. this.hasMoreData = false;
  810. }
  811. this.isRequestingMoreData = false;
  812. this.lastestUsedSearchKey = lastestUsedSearchKey;
  813. },
  814. () => {
  815. this.isRequestingMoreData = false;
  816. this.lastestUsedSearchKey = lastestUsedSearchKey;
  817. }
  818. );
  819. },
  820. onClickDeleteInPreview(index) {
  821. this.del(this.list[index]);
  822. },
  823. },
  824. };
  825. </script>
  826. <style lang="less" scoped></style>
  827. <style lang="less" scoped>
  828. @import "../style.less";
  829. </style>