index.vue 14 KB

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