index.vue 19 KB

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