index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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.audio')"
  8. @click-path="onClickPath"
  9. />
  10. <div v-if="lastestUsedSearchKey" class="">
  11. {{ $i18n.t("gather.audio") }}
  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="audio_size" />
  24. <upload
  25. ref="uploadFile"
  26. :failString="audio_fail"
  27. :limitFailStr="audio_limit"
  28. accept-type="audio/mp3"
  29. media-type="audio"
  30. :limit="20"
  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. <div
  87. slot-scope="{ itemData, lineData, headerItem }"
  88. slot="tableItem"
  89. style="width: 100%"
  90. >
  91. <div class="handle" v-if="headerItem.canclick">
  92. <i
  93. class="iconfont icon-material_operation_editor hover-tips"
  94. @click="onClickRename(lineData)"
  95. >
  96. <div>
  97. <div class="remark">{{ rename }}</div>
  98. </div>
  99. </i>
  100. <i
  101. class="iconfont icon-material_operation_delete hover-tips-warn"
  102. @click="del(lineData)"
  103. >
  104. <div>
  105. <div class="remark">{{ deltips }}</div>
  106. </div>
  107. </i>
  108. </div>
  109. <div
  110. v-else-if="headerItem.type == 'audio' && lineData.type !== 'dir'"
  111. class="audio"
  112. >
  113. <v-audio
  114. :vkey="lineData.id"
  115. :idleft="`_${$randomWord(true, 8, 8)}`"
  116. :idright="`_${$randomWord(true, 8, 8)}`"
  117. :myAudioUrl="itemData"
  118. ></v-audio>
  119. </div>
  120. <div
  121. v-else-if="headerItem.type == 'audio' && 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="AUDIO"
  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. </div>
  256. </template>
  257. <script>
  258. import config from "@/config";
  259. import tableList from "@/components/table";
  260. import crumbs from "@/components/crumbs";
  261. import { data } from "./audio";
  262. import rename from "../popup/rename";
  263. import vAudio from "@/components/audio/index.vue";
  264. import Upload from "@/components/shared/uploads/UploadMultiple";
  265. import { changeByteUnit } from "@/utils/file";
  266. import UploadTaskList from "../components/uploadList1.1.0.vue";
  267. import { debounce } from "@/utils/other.js";
  268. import { mapState } from "vuex";
  269. import { i18n } from "@/lang";
  270. import folderMixinFactory from "../folderMixinFactory.js";
  271. import {
  272. getMaterialList,
  273. uploadMaterial,
  274. editMaterial,
  275. delMaterial,
  276. checkUserSize,
  277. } from "@/api";
  278. const TYPE = "audio";
  279. const folderMixin = folderMixinFactory(TYPE);
  280. export default {
  281. mixins: [folderMixin],
  282. components: {
  283. tableList,
  284. crumbs,
  285. rename,
  286. Upload,
  287. vAudio,
  288. UploadTaskList,
  289. },
  290. data() {
  291. return {
  292. upload_material: i18n.t("gather.upload_material"),
  293. audio_size: i18n.t("gather.audio_size"),
  294. audio_limit: i18n.t("gather.audio_limit"),
  295. audio_fail: i18n.t("gather.audio_fail"),
  296. serch_material: i18n.t("gather.serch_material"),
  297. rename: i18n.t("gather.rename"),
  298. deltips: i18n.t("gather.delete"),
  299. no_serch_result: i18n.t("gather.no_serch_result"),
  300. no_material_result: i18n.t("gather.no_material_result"),
  301. config,
  302. showRename: false,
  303. showList: false,
  304. popupItem: null,
  305. tabHeader: data,
  306. // 因为searchKey的变化经过debounce、异步请求的延时,才会反映到数据列表的变化上,所以是否显示、显示哪种无数据提示,也要等到数据列表变化后,根据数据列表是否为空,以及引发本次变化的那个searchKey瞬时值来决定。本变量就是用来保存那个瞬时值。
  307. lastestUsedSearchKey: "",
  308. isFilterFocus: false,
  309. searchKey: "",
  310. list: [],
  311. hasMoreData: true,
  312. isRequestingMoreData: false,
  313. };
  314. },
  315. computed: {
  316. ...mapState({
  317. uploadListForUI: "uploadStatusListAudio",
  318. }),
  319. had_load() {
  320. return i18n.t("gather.had_load", { msg: this.list.length });
  321. },
  322. },
  323. mounted() {},
  324. watch: {
  325. searchKey: {
  326. handler: function (val) {
  327. if (val.length > 0) {
  328. this.selectedList = [];
  329. }
  330. this.refreshListDebounced();
  331. },
  332. immediate: false,
  333. },
  334. },
  335. methods: {
  336. onUploadFile() {
  337. checkUserSize({}, (data) => {
  338. //判断已用是否大于3G
  339. if (data.data / 1024 / 1024 > 3) {
  340. this.$alert({ content: i18n.t("tips_code.FAILURE_3024") });
  341. } else {
  342. this.$refs.uploadFile.click();
  343. }
  344. });
  345. },
  346. onFilterFocus() {
  347. this.isFilterFocus = true;
  348. },
  349. onFilterBlur() {
  350. this.isFilterFocus = false;
  351. },
  352. refreshListDebounced: debounce(
  353. function () {
  354. this.list = [];
  355. this.isRequestingMoreData = false;
  356. this.hasMoreData = true;
  357. this.$refs["table-list"].requestMoreData();
  358. },
  359. 500,
  360. false
  361. ),
  362. stopAllAudio() {
  363. Array.from($("audio")).forEach((item) => {
  364. if (!item.paused) {
  365. item.pause();
  366. }
  367. });
  368. },
  369. handleRename(newName) {
  370. editMaterial(
  371. {
  372. id: this.popupItem.id,
  373. name: newName,
  374. },
  375. () => {
  376. this.$msg.success(i18n.t("gather.edit_success"));
  377. const index = this.list.findIndex((eachItem) => {
  378. return eachItem.id === this.popupItem.id;
  379. });
  380. if (index >= 0) {
  381. this.list[index].name = newName;
  382. } else {
  383. console.error("在素材列表里没找到要重命名的那一项!");
  384. }
  385. this.showRename = false;
  386. this.popupItem = null;
  387. }
  388. );
  389. },
  390. onClickRename(lineData) {
  391. this.popupItem = lineData;
  392. if (lineData.type !== "dir") {
  393. this.showRename = true;
  394. } else {
  395. this.isShowRenameFolder = true;
  396. }
  397. },
  398. del(item) {
  399. if (item.type === "dir") {
  400. this.delFolder(item.id, (lastestUsedSearchKey) => {
  401. getMaterialList(
  402. {
  403. dirId: this.currentFolderId,
  404. pageNum: this.list.length,
  405. pageSize: 1,
  406. searchKey: this.searchKey,
  407. type: TYPE,
  408. },
  409. (data) => {
  410. const index = this.list.findIndex((eachItem) => {
  411. return eachItem.id === item.id;
  412. });
  413. //去掉已存在移动的id
  414. const alreadySelectIndex = this.selectedList.findIndex(
  415. (i) => i.id === item.id
  416. );
  417. if (alreadySelectIndex > -1) {
  418. this.selectedList.splice(alreadySelectIndex, 1);
  419. }
  420. if (index >= 0) {
  421. this.list.splice(index, 1);
  422. const newData = data.data.list.map((i) => {
  423. i.fileSize = changeByteUnit(Number(i.fileSize));
  424. return i;
  425. });
  426. this.list = this.list.concat(newData);
  427. if (this.list.length === data.data.total) {
  428. this.hasMoreData = false;
  429. }
  430. this.$bus.emit("deletedAudio"); // 各个Audio组件需要重新初始化
  431. } else {
  432. console.error("在素材列表里没找到要删除的那一项!");
  433. }
  434. this.isRequestingMoreData = false;
  435. this.lastestUsedSearchKey = lastestUsedSearchKey;
  436. },
  437. () => {
  438. this.isRequestingMoreData = false;
  439. this.lastestUsedSearchKey = lastestUsedSearchKey;
  440. }
  441. );
  442. });
  443. } else {
  444. this.$confirm({
  445. title: i18n.t("gather.delete_material"),
  446. content: i18n.t("gather.comfirm_delete_material"),
  447. okText: i18n.t("gather.delete"),
  448. ok: () => {
  449. delMaterial(item.id, () => {
  450. this.$msg.success(i18n.t("gather.delete_success"));
  451. this.isRequestingMoreData = true;
  452. const lastestUsedSearchKey = this.searchKey;
  453. getMaterialList(
  454. {
  455. dirId: this.currentFolderId,
  456. pageNum: this.list.length,
  457. pageSize: 1,
  458. searchKey: this.searchKey,
  459. type: TYPE,
  460. },
  461. (data) => {
  462. const index = this.list.findIndex((eachItem) => {
  463. return eachItem.id === item.id;
  464. });
  465. //去掉已存在移动的id
  466. const alreadySelectIndex = this.selectedList.findIndex(
  467. (i) => i.id === item.id
  468. );
  469. if (alreadySelectIndex > -1) {
  470. this.selectedList.splice(alreadySelectIndex, 1);
  471. }
  472. if (index >= 0) {
  473. this.list.splice(index, 1);
  474. const newData = data.data.list.map((i) => {
  475. i.fileSize = changeByteUnit(Number(i.fileSize));
  476. return i;
  477. });
  478. this.list = this.list.concat(newData);
  479. if (this.list.length === data.data.total) {
  480. this.hasMoreData = false;
  481. }
  482. this.$bus.emit("deletedAudio"); // 各个Audio组件需要重新初始化
  483. } else {
  484. console.error("在素材列表里没找到要删除的那一项!");
  485. }
  486. this.isRequestingMoreData = false;
  487. this.lastestUsedSearchKey = lastestUsedSearchKey;
  488. },
  489. () => {
  490. this.isRequestingMoreData = false;
  491. this.lastestUsedSearchKey = lastestUsedSearchKey;
  492. }
  493. );
  494. });
  495. },
  496. });
  497. }
  498. },
  499. onFileChange(e) {
  500. e.files.forEach((eachFile, i) => {
  501. console.log(
  502. "check-audio-1",
  503. eachFile.name,
  504. eachFile.name.toLowerCase().indexOf("mp3")
  505. );
  506. if (eachFile.name.toLowerCase().indexOf("mp3") <= -1) {
  507. setTimeout(() => {
  508. this.$msg({
  509. message: `“${eachFile.name}”${i18n.t("gather.audio_fail")}`,
  510. type: "warning",
  511. });
  512. }, i * 100);
  513. return;
  514. }
  515. if (
  516. eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50
  517. ) {
  518. setTimeout(() => {
  519. this.$msg({
  520. message: `“${
  521. eachFile.name.substring(0, 50) +
  522. "..." +
  523. eachFile.name.split(".")[1]
  524. }”${i18n.t("gather.too_long_word_audio")}`,
  525. type: "warning",
  526. });
  527. }, i * 100);
  528. return;
  529. }
  530. let itemInUploadList = {
  531. title: eachFile.name,
  532. ifKnowProgress: true,
  533. progress: 0,
  534. status: "LOADING",
  535. statusText: i18n.t("gather.uploading_material"),
  536. uid: `u_${this.$randomWord(true, 8, 8)}`,
  537. abortHandler: null,
  538. parentFolderId: this.currentFolderId,
  539. };
  540. itemInUploadList.abortHandler = uploadMaterial(
  541. {
  542. dirId: this.currentFolderId,
  543. file: eachFile,
  544. temId: itemInUploadList.uid,
  545. type: TYPE,
  546. },
  547. () => {
  548. // 上传成功
  549. const index = this.uploadListForUI.findIndex((eachItem) => {
  550. return eachItem.uid === itemInUploadList.uid;
  551. });
  552. this.uploadListForUI.splice(index, 1);
  553. this.refreshListDebounced();
  554. },
  555. (err) => {
  556. if (err.statusText === "abort") {
  557. // 用户取消了上传任务。
  558. const index = this.uploadListForUI.findIndex((eachItem) => {
  559. return eachItem.uid === itemInUploadList.uid;
  560. });
  561. this.uploadListForUI.splice(index, 1);
  562. } else {
  563. itemInUploadList.status = "FAIL";
  564. itemInUploadList.statusText = i18n.t(
  565. "gather.material_upload_fail"
  566. );
  567. }
  568. },
  569. (progress) => {
  570. itemInUploadList.progress = progress;
  571. }
  572. );
  573. this.uploadListForUI.push(itemInUploadList);
  574. });
  575. },
  576. onCancelTask(uid) {
  577. const index = this.uploadListForUI.findIndex((eachItem) => {
  578. return eachItem.uid === uid;
  579. });
  580. if (this.uploadListForUI[index].status === "LOADING") {
  581. this.uploadListForUI[index].abortHandler.abort();
  582. } else {
  583. this.uploadListForUI.splice(index, 1);
  584. }
  585. },
  586. getMoreMaterialItem() {
  587. this.isRequestingMoreData = true;
  588. const lastestUsedSearchKey = this.searchKey;
  589. getMaterialList(
  590. {
  591. dirId: this.currentFolderId,
  592. pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
  593. pageSize: config.PAGE_SIZE,
  594. searchKey: this.searchKey,
  595. type: TYPE,
  596. },
  597. (data) => {
  598. const newData = data.data.list.map((i) => {
  599. if (i.type !== "dir") {
  600. i.fileSize = changeByteUnit(Number(i.fileSize));
  601. }
  602. return i;
  603. });
  604. this.list = this.list.concat(newData);
  605. if (this.list.length === data.data.total) {
  606. this.hasMoreData = false;
  607. }
  608. this.isRequestingMoreData = false;
  609. this.lastestUsedSearchKey = lastestUsedSearchKey;
  610. },
  611. () => {
  612. this.isRequestingMoreData = false;
  613. this.lastestUsedSearchKey = lastestUsedSearchKey;
  614. }
  615. );
  616. },
  617. },
  618. };
  619. </script>
  620. <style lang="less" scoped>
  621. .second-line {
  622. &.disabled {
  623. button {
  624. opacity: 0.5;
  625. pointer-events: none;
  626. }
  627. }
  628. }
  629. </style>
  630. <style lang="less" scoped>
  631. @import "../style.less";
  632. </style>