index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <div class="panorama con">
  3. <div class="top">
  4. <crumbs
  5. v-if="!lastestUsedSearchKey"
  6. :rootName="$i18n.t('gather.image')"
  7. :list="folderPath"
  8. @click-path="onClickPath"
  9. />
  10. <div v-if="lastestUsedSearchKey" class="">
  11. {{ $i18n.t("gather.image") }}
  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-material_prompt" v-tooltip="img_size" />
  24. <upload
  25. ref="uploadFile"
  26. :failString="img_fail"
  27. :limitFailStr="img_limit"
  28. accept-type="image/png,image/jpeg,image/jpg"
  29. media-type="image"
  30. :limit="10"
  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="serch_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(`zh_key.${headerItem.name}`) }}
  85. </div>
  86. <!-- 内容各单元格 -->
  87. <div
  88. slot-scope="{ itemData, lineData, headerItem }"
  89. slot="tableItem"
  90. style="width: 100%"
  91. >
  92. <div v-if="headerItem.canclick" class="handle">
  93. <i
  94. class="iconfont icon-material_operation_editor hover-tips"
  95. @click="onClickRename(lineData)"
  96. >
  97. <div>
  98. <div class="remark">{{ rename }}</div>
  99. </div>
  100. </i>
  101. <i
  102. class="iconfont icon-material_operation_delete hover-tips-warn"
  103. @click="del(lineData)"
  104. >
  105. <div>
  106. <div class="remark">{{ deltips }}</div>
  107. </div>
  108. </i>
  109. </div>
  110. <div
  111. v-else-if="headerItem.type == 'image'"
  112. class="img"
  113. :class="{
  114. dirIcon: lineData.type === 'dir',
  115. }"
  116. >
  117. <img
  118. :id="'img' + lineData.id"
  119. :src="
  120. lineData.type === 'dir'
  121. ? require('@/assets/images/icons/folder-blue.png')
  122. : itemData + $imgsuffix
  123. "
  124. alt=""
  125. @click="
  126. lineData.type === 'dir'
  127. ? onClickFolder(lineData)
  128. : previewImage(lineData)
  129. "
  130. />
  131. </div>
  132. <!-- 文字型单元格 -->
  133. <div v-else class="textItem">
  134. <!-- 名称 -->
  135. <div v-if="headerItem.key === 'name'" class="name">
  136. <!-- 不是搜索出来的 -->
  137. <div v-if="!lastestUsedSearchKey" class="not-search-res">
  138. <!-- 文件夹名称 -->
  139. <div
  140. v-if="lineData.type === 'dir'"
  141. class="dirName"
  142. @click="onClickFolder(lineData)"
  143. >
  144. {{ itemData || "-" }}
  145. </div>
  146. <!-- 素材名称 -->
  147. <div v-else class="not-dir">
  148. {{ itemData || "-" }}
  149. </div>
  150. </div>
  151. <!-- end of 不是搜索出来的 -->
  152. <!-- 搜索出来的 -->
  153. <div v-if="lastestUsedSearchKey" class="search-res">
  154. <!-- 文件夹名称 -->
  155. <div v-if="lineData.type === 'dir'" class="dirName">
  156. <div class="self-name" @click="onClickFolder(lineData)">
  157. {{ itemData || "-" }}
  158. </div>
  159. <div class="parent-name-wrap">
  160. 目录
  161. <span
  162. class="parent-name"
  163. @click="onClickParentFolder(lineData)"
  164. >{{
  165. lineData.dirId === 1
  166. ? $i18n.t("gather.root_dir")
  167. : lineData.dirName
  168. }}</span
  169. >
  170. </div>
  171. </div>
  172. <!-- 素材名称 -->
  173. <div v-else class="not-dir">
  174. <div class="self-name">
  175. {{ itemData || "-" }}
  176. </div>
  177. <div class="parent-name-wrap">
  178. 目录
  179. <span
  180. class="parent-name"
  181. @click="onClickParentFolder(lineData)"
  182. >{{
  183. lineData.dirId === 1
  184. ? $i18n.t("gather.root_dir")
  185. : lineData.dirName
  186. }}</span
  187. >
  188. </div>
  189. </div>
  190. </div>
  191. <!-- end of 搜索出来的 -->
  192. </div>
  193. <!-- end of 名称 -->
  194. <!-- 不是名称 -->
  195. <div v-else class="not-name">
  196. {{ itemData || "-" }}
  197. </div>
  198. <!-- end of 不是名称 -->
  199. </div>
  200. <!-- end of 文字型单元格 -->
  201. </div>
  202. </tableList>
  203. <UploadTaskList
  204. class="upload-task-list"
  205. fileType="IMAGE"
  206. :taskList="uploadListForUI"
  207. :targetFolderId="lastestUsedSearchKey ? -1 : currentFolderId"
  208. @cancel-task="onCancelTask"
  209. />
  210. <div class="total-number" v-if="list.length !== 0 || hasMoreData">
  211. {{ had_load }}
  212. </div>
  213. <div
  214. class="nodata"
  215. v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey"
  216. >
  217. <img :src="$noresult" alt="" />
  218. <span>{{ no_serch_result }}</span>
  219. </div>
  220. <div
  221. class="nodata"
  222. v-if="list.length == 0 && !hasMoreData && !lastestUsedSearchKey"
  223. >
  224. <img :src="config.empty" alt="" />
  225. <span>{{ no_material_result }}</span>
  226. <button @click="$refs.uploadFile.click()" class="upload-btn-in-table">
  227. {{ upload_material }}
  228. </button>
  229. </div>
  230. </div>
  231. <CreateFolder
  232. v-if="isShowNewFolder"
  233. :validate="validateNewFolderName"
  234. @close="isShowNewFolder = false"
  235. @submit="onSubmitNewFolder"
  236. />
  237. <RenameFolder
  238. v-if="isShowRenameFolder"
  239. :oldName="popupItem.name"
  240. :validate="validateRenameFolderName"
  241. @close="isShowRenameFolder = false"
  242. @submit="onSubmitRenameFolder"
  243. />
  244. <MoveFolder
  245. v-if="isShowMoveFolder"
  246. :folderTree="folderTree"
  247. :selectedList="selectedList"
  248. @close="isShowMoveFolder = false"
  249. @submit="onSubmitMoveFolder"
  250. />
  251. <rename
  252. v-if="showRename"
  253. :item="popupItem"
  254. @rename="handleRename"
  255. @close="showRename = false"
  256. />
  257. <preview
  258. ref="image-previewer"
  259. :canFullScreen="false"
  260. :imageList="list.map((item) => item.icon)"
  261. :imageTitleList="list.map((item) => item.name)"
  262. @click-delete="onClickDeleteInPreview"
  263. />
  264. </div>
  265. </template>
  266. <script>
  267. import config from "@/config";
  268. import tableList from "@/components/table";
  269. import crumbs from "@/components/crumbs";
  270. import { data } from "./image";
  271. import rename from "../popup/rename";
  272. import UploadTaskList from "../components/uploadList1.1.0.vue";
  273. import Upload from "@/components/shared/uploads/UploadMultiple";
  274. import { changeByteUnit } from "@/utils/file";
  275. import preview from "../popup/imagePreviewer.vue";
  276. import { debounce } from "@/utils/other.js";
  277. import { mapState } from "vuex";
  278. import { i18n } from "@/lang";
  279. import folderMixinFactory from "../folderMixinFactory.js";
  280. import {
  281. getMaterialList,
  282. uploadMaterial,
  283. editMaterial,
  284. delMaterial,
  285. checkUserSize,
  286. } from "@/api";
  287. const TYPE = "image";
  288. const folderMixin = folderMixinFactory(TYPE);
  289. export default {
  290. mixins: [folderMixin],
  291. components: {
  292. tableList,
  293. crumbs,
  294. rename,
  295. Upload,
  296. preview,
  297. UploadTaskList,
  298. },
  299. data() {
  300. return {
  301. upload_material: i18n.t("gather.upload_material"),
  302. img_fail: i18n.t("gather.img_fail"),
  303. img_limit: i18n.t("gather.img_limit"),
  304. img_size: i18n.t("gather.img_size"),
  305. serch_material: i18n.t("gather.serch_material"),
  306. rename: i18n.t("gather.rename"),
  307. deltips: i18n.t("gather.delete"),
  308. no_serch_result: i18n.t("gather.no_serch_result"),
  309. no_material_result: i18n.t("gather.no_material_result"),
  310. config, // TODO: 没必要这么弄
  311. showRename: false,
  312. showList: false,
  313. popupItem: null,
  314. tabHeader: data,
  315. // 因为searchKey的变化经过debounce、异步请求的延时,才会反映到数据列表的变化上,所以是否显示、显示哪种无数据提示,也要等到数据列表变化后,根据数据列表是否为空,以及引发本次变化的那个searchKey瞬时值来决定。本变量就是用来保存那个瞬时值。
  316. lastestUsedSearchKey: "",
  317. isFilterFocus: false,
  318. searchKey: "",
  319. list: [],
  320. hasMoreData: true,
  321. isRequestingMoreData: false,
  322. };
  323. },
  324. computed: {
  325. ...mapState({
  326. uploadListForUI: "uploadStatusListImage",
  327. }),
  328. had_load() {
  329. return i18n.t("gather.had_load", { msg: this.list.length });
  330. },
  331. },
  332. mounted() {},
  333. watch: {
  334. searchKey: {
  335. handler: function (val) {
  336. if (val.length > 0) {
  337. this.selectedList = [];
  338. }
  339. this.refreshListDebounced();
  340. },
  341. immediate: false,
  342. },
  343. },
  344. methods: {
  345. async onUploadFile() {
  346. const res = await checkUserSize();
  347. if (res)
  348. if (Number(res.useSpace) > Number(res.totalSpace)) {
  349. this.$alert({ content: i18n.t("tips_code.FAILURE_3024") });
  350. } else {
  351. this.$refs.uploadFile.click();
  352. }
  353. },
  354. onFilterFocus() {
  355. this.isFilterFocus = true;
  356. },
  357. onFilterBlur() {
  358. this.isFilterFocus = false;
  359. },
  360. refreshListDebounced: debounce(
  361. function () {
  362. this.list = [];
  363. this.isRequestingMoreData = false;
  364. this.hasMoreData = true;
  365. this.$refs["table-list"].requestMoreData();
  366. },
  367. 500,
  368. false
  369. ),
  370. handleRename(newName) {
  371. editMaterial(
  372. {
  373. id: this.popupItem.id,
  374. name: newName,
  375. },
  376. () => {
  377. this.$msg.success(i18n.t("gather.edit_success"));
  378. const index = this.list.findIndex((eachItem) => {
  379. return eachItem.id === this.popupItem.id;
  380. });
  381. if (index >= 0) {
  382. this.list[index].name = newName;
  383. } else {
  384. console.error("在素材列表里没找到要重命名的那一项!");
  385. }
  386. this.showRename = false;
  387. this.popupItem = null;
  388. }
  389. );
  390. },
  391. onClickRename(lineData) {
  392. this.popupItem = lineData;
  393. if (lineData.type !== "dir") {
  394. this.showRename = true;
  395. } else {
  396. this.isShowRenameFolder = true;
  397. }
  398. },
  399. del(item) {
  400. if (item.type === "dir") {
  401. this.delFolder(item.id, (lastestUsedSearchKey) => {
  402. getMaterialList(
  403. {
  404. dirId: this.currentFolderId,
  405. pageNum: this.list.length,
  406. pageSize: 1,
  407. searchKey: this.searchKey,
  408. type: TYPE,
  409. },
  410. (data) => {
  411. const index = this.list.findIndex((eachItem) => {
  412. return eachItem.id === item.id;
  413. });
  414. //去掉已存在移动的id
  415. const alreadySelectIndex = this.selectedList.findIndex(
  416. (i) => i.id === item.id
  417. );
  418. if (alreadySelectIndex > -1) {
  419. this.selectedList.splice(alreadySelectIndex, 1);
  420. }
  421. if (index >= 0) {
  422. this.list.splice(index, 1);
  423. const newData = data.data.list.map((i) => {
  424. i.fileSize = changeByteUnit(Number(i.fileSize));
  425. return i;
  426. });
  427. this.list = this.list.concat(newData);
  428. if (this.list.length === data.data.total) {
  429. this.hasMoreData = false;
  430. }
  431. if (this.list.length === 0) {
  432. this.$refs["image-previewer"].onClickClose();
  433. }
  434. } else {
  435. console.error("在素材列表里没找到要删除的那一项!");
  436. }
  437. this.isRequestingMoreData = false;
  438. this.lastestUsedSearchKey = lastestUsedSearchKey;
  439. },
  440. () => {
  441. this.isRequestingMoreData = false;
  442. this.lastestUsedSearchKey = lastestUsedSearchKey;
  443. }
  444. );
  445. });
  446. } else {
  447. this.$confirm({
  448. title: i18n.t("gather.delete_material"),
  449. content: i18n.t("gather.comfirm_delete_material"),
  450. okText: i18n.t("gather.delete"),
  451. ok: () => {
  452. delMaterial(item.id, () => {
  453. this.$msg.success(i18n.t("gather.delete_success"));
  454. this.isRequestingMoreData = true;
  455. const lastestUsedSearchKey = this.searchKey;
  456. getMaterialList(
  457. {
  458. dirId: this.currentFolderId,
  459. pageNum: this.list.length,
  460. pageSize: 1,
  461. searchKey: this.searchKey,
  462. type: TYPE,
  463. },
  464. (data) => {
  465. const index = this.list.findIndex((eachItem) => {
  466. return eachItem.id === item.id;
  467. });
  468. //去掉已存在移动的id
  469. const alreadySelectIndex = this.selectedList.findIndex(
  470. (i) => i.id === item.id
  471. );
  472. if (alreadySelectIndex > -1) {
  473. this.selectedList.splice(alreadySelectIndex, 1);
  474. }
  475. if (index >= 0) {
  476. this.list.splice(index, 1);
  477. const newData = data.data.list.map((i) => {
  478. i.fileSize = changeByteUnit(Number(i.fileSize));
  479. return i;
  480. });
  481. this.list = this.list.concat(newData);
  482. if (this.list.length === data.data.total) {
  483. this.hasMoreData = false;
  484. }
  485. if (this.list.length === 0) {
  486. this.$refs["image-previewer"].onClickClose();
  487. }
  488. } else {
  489. console.error("在素材列表里没找到要删除的那一项!");
  490. }
  491. this.isRequestingMoreData = false;
  492. this.lastestUsedSearchKey = lastestUsedSearchKey;
  493. },
  494. () => {
  495. this.isRequestingMoreData = false;
  496. this.lastestUsedSearchKey = lastestUsedSearchKey;
  497. }
  498. );
  499. });
  500. },
  501. });
  502. }
  503. },
  504. previewImage(targetItem) {
  505. const index = this.list.findIndex((eachItem) => {
  506. return eachItem.id === targetItem.id;
  507. });
  508. this.$refs["image-previewer"].show(index);
  509. },
  510. onFileChange(e) {
  511. e.files.forEach((eachFile, i) => {
  512. if (
  513. eachFile.type.indexOf("jpeg") <= -1 &&
  514. eachFile.type.indexOf("png") <= -1
  515. ) {
  516. setTimeout(() => {
  517. this.$msg({
  518. message: `“${eachFile.name}”${i18n.t("gather.img_fail")}`,
  519. type: "warning",
  520. });
  521. }, i * 100);
  522. return;
  523. }
  524. if (
  525. eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50
  526. ) {
  527. setTimeout(() => {
  528. this.$msg({
  529. message: `“${
  530. eachFile.name.substring(0, 50) +
  531. "..." +
  532. eachFile.name.split(".")[1]
  533. }”${i18n.t("gather.too_long_word")}`,
  534. type: "warning",
  535. });
  536. }, i * 100);
  537. return;
  538. }
  539. let itemInUploadList = {
  540. title: eachFile.name,
  541. ifKnowProgress: true,
  542. progress: 0,
  543. status: "LOADING",
  544. statusText: i18n.t("gather.uploading_material"),
  545. uid: `u_${this.$randomWord(true, 8, 8)}`,
  546. abortHandler: null,
  547. parentFolderId: this.currentFolderId,
  548. };
  549. itemInUploadList.abortHandler = uploadMaterial(
  550. {
  551. dirId: this.currentFolderId,
  552. file: eachFile,
  553. temId: itemInUploadList.uid,
  554. type: TYPE,
  555. },
  556. () => {
  557. // 上传成功
  558. const index = this.uploadListForUI.findIndex((eachItem) => {
  559. return eachItem.uid === itemInUploadList.uid;
  560. });
  561. this.uploadListForUI.splice(index, 1);
  562. this.refreshListDebounced();
  563. },
  564. (err) => {
  565. if (err.statusText === "abort") {
  566. // 用户取消了上传任务。
  567. const index = this.uploadListForUI.findIndex((eachItem) => {
  568. return eachItem.uid === itemInUploadList.uid;
  569. });
  570. this.uploadListForUI.splice(index, 1);
  571. } else {
  572. itemInUploadList.status = "FAIL";
  573. itemInUploadList.statusText = i18n.t(
  574. "gather.material_upload_fail"
  575. );
  576. }
  577. },
  578. (progress) => {
  579. itemInUploadList.progress = progress;
  580. }
  581. );
  582. this.uploadListForUI.push(itemInUploadList);
  583. });
  584. },
  585. onCancelTask(uid) {
  586. const index = this.uploadListForUI.findIndex((eachItem) => {
  587. return eachItem.uid === uid;
  588. });
  589. if (this.uploadListForUI[index].status === "LOADING") {
  590. this.uploadListForUI[index].abortHandler.abort();
  591. } else {
  592. this.uploadListForUI.splice(index, 1);
  593. }
  594. },
  595. getMoreMaterialItem() {
  596. this.isRequestingMoreData = true;
  597. const lastestUsedSearchKey = this.searchKey;
  598. getMaterialList(
  599. {
  600. dirId: this.currentFolderId,
  601. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  602. pageSize: config.PAGE_SIZE,
  603. searchKey: this.searchKey,
  604. type: TYPE,
  605. },
  606. (data) => {
  607. const newData = data.data.list.map((i) => {
  608. if (i.type !== "dir") {
  609. i.fileSize = changeByteUnit(Number(i.fileSize));
  610. }
  611. return i;
  612. });
  613. this.list = this.list.concat(newData);
  614. if (this.list.length === data.data.total) {
  615. this.hasMoreData = false;
  616. }
  617. this.isRequestingMoreData = false;
  618. this.lastestUsedSearchKey = lastestUsedSearchKey;
  619. },
  620. () => {
  621. this.isRequestingMoreData = false;
  622. this.lastestUsedSearchKey = lastestUsedSearchKey;
  623. }
  624. );
  625. },
  626. onClickDeleteInPreview(index) {
  627. this.del(this.list[index]);
  628. },
  629. },
  630. };
  631. </script>
  632. <style lang="less" scoped></style>
  633. <style lang="less" scoped>
  634. @import "../style.less";
  635. </style>