index.vue 19 KB

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