index.vue 13 KB

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