index.vue 19 KB

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