index.vue 14 KB

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