1
0

index.vue 15 KB

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