index.vue 28 KB

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