index.vue 17 KB

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