index.vue 19 KB

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