index.vue 21 KB

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