123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <template>
- <div class="panorama con">
- <div class="top">
- <crumbs :list="tablist" />
- </div>
- <div class="second-line">
- <div class="btn">
- <button
- @mouseover.stop="showList = true"
- @click="onUploadFile"
- class="ui-button submit"
- >
- <span>{{upload_material}}</span>
- <i class="iconfont icon-material_prompt hover-tips hover-tips-upload-icon">
- <div>
- <div class="remark">{{video_size}}</div>
- </div>
- </i>
- <upload
- ref="uploadFile"
- :failString="video_limit"
- :limitFailStr="video_fail"
- accept-type="video/mp4"
- media-type="video"
- :limit="200"
- @file-change="onFileChange"
- ></upload>
- </button>
- </div>
- <div class="filter">
- <div :class="{active: isFilterFocus}" @focusin="onFilterFocus" @focusout="onFilterBlur">
- <i class="iconfont icon-works_search search"></i>
- <input
- type="text"
- v-model="searchKey"
- :placeholder="serch_material"
- />
- <i v-if="searchKey" @click="searchKey=''" class="iconfont icontoast_red del"></i>
- </div>
- </div>
- </div>
- <div class="list">
- <tableList
- @selection-change="
- (data) => {
- selectedArr = data;
- }
- "
- @request-more-data="getMoreMaterialItem"
- :canRequestMoreData="hasMoreData && !isRequestingMoreData"
- :header="tabHeader"
- :showLine="true"
- :selection="false"
- :data="list"
- class="table-list"
- ref="table-list"
- >
- <div slot-scope="{ data }" slot="header">
- {{ data.name }}
- </div>
- <div slot-scope="{ data, item, sub }" slot="item" style="width: 100%">
- <div class="handle" v-if="sub.canclick">
- <i
- class="iconfont icon-material_operation_editor hover-tips"
- @click="(showRename = true), (popupItem = item)"
- >
- <div>
- <div class="remark">{{rename}}</div>
- </div>
- </i>
- <i class="iconfont icon-material_operation_delete hover-tips-warn" @click="del(item)">
- <div>
- <div class="remark">{{del}}</div>
- </div>
- </i>
- </div>
- <div
- class="img"
- v-else-if="sub.type == 'image'"
- @click="previewVedio(item)"
- >
- <div class="video-icon-mask">
- <i class="iconfont icon-editor_play" />
- </div>
- <img :src="`${data}` || $thumb" alt="" />
- </div>
- <span
- v-else
- >{{ data || "-" }}</span
- >
- </div>
- </tableList>
- <UploadTaskList class="upload-task-list" fileType="VIDEO" :taskList="uploadListForUI" @cancel-task="onCancelTask"></UploadTaskList>
- <div class="total-number" v-if="list.length !== 0 || hasMoreData">{{had_load}}</div>
- <div class="nodata" v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey">
- <img :src="$noresult" alt="" />
- <span>{{no_serch_result}}</span>
- </div>
- <div class="nodata" v-if="list.length == 0 && !hasMoreData && !lastestUsedSearchKey">
- <img :src="config.empty" alt="" />
- <span>{{no_material_result}}</span>
- <button @click="$refs.uploadFile.click()" class="upload-btn-in-table">{{upload_material}}</button>
- </div>
- </div>
- <rename
- v-if="showRename"
- :item="popupItem"
- @rename="handleRename"
- @close="showRename = false"
- />
- <preview
- ref="video-previewer"
- :item="popupItem"
- />
- </div>
- </template>
- <script>
- import config from "@/config";
- import tableList from "@/components/table/index.vue";
- import crumbs from "@/components/crumbs";
- import { data } from "./video";
- import rename from "../popup/rename";
- import Upload from "@/components/shared/uploads/UploadMultiple";
- import { changeByteUnit } from "@/utils/file";
- import preview from "../popup/videoPreviewer.vue";
- import UploadTaskList from "../components/uploadList1.1.0.vue";
- import { debounce } from "@/utils/other.js"
- import { mapState } from 'vuex';
- import {i18n} from "@/lang"
- import {
- getMaterialList,
- uploadMaterial,
- editMaterial,
- delMaterial,
- checkUserSize
- } from "@/api";
- const TYPE = "video";
- export default {
- components: {
- tableList,
- preview,
- crumbs,
- rename,
- UploadTaskList,
- Upload,
- },
- data() {
- return {
- upload_material: i18n.t("gather.upload_material"),
- video_size: i18n.t("gather.video_size"),
- video_limit: i18n.t("gather.video_limit"),
- video_fail: i18n.t("gather.video_fail"),
- serch_material: i18n.t("gather.serch_material"),
- rename: i18n.t("gather.rename"),
- deltips: i18n.t("gather.delete"),
- no_serch_result: i18n.t("gather.no_serch_result"),
- no_material_result: i18n.t("gather.no_material_result"),
- config,
- showRename: false,
- showList: false,
- popupItem: null,
- tabHeader: data,
- selectedArr: [],
- searchKey: "",
- // 因为searchKey的变化经过debounce、异步请求的延时,才会反映到数据列表的变化上,所以是否显示、显示哪种无数据提示,也要等到数据列表变化后,根据数据列表是否为空,以及引发本次变化的那个searchKey瞬时值来决定。本变量就是用来保存那个瞬时值。
- lastestUsedSearchKey: '',
- isFilterFocus: false,
- tablist: [
- {
- name: i18n.t("gather.video"),
- id: TYPE,
- },
- ],
- list: [],
- hasMoreData: true,
- isRequestingMoreData: false,
- };
- },
- computed: {
- ...mapState({
- uploadListForUI: 'uploadStatusListVideo',
- }),
- had_load(){
- return i18n.t("gather.had_load",{msg:this.list.length})
- }
- },
- mounted() {
- },
- watch: {
- searchKey: {
- handler: function () {
- this.refreshListDebounced()
- },
- immediate: false,
- },
- },
- methods: {
- onUploadFile(){
- checkUserSize({},(data)=>{
- //判断已用是否大于3G
- if ((data.data / 1024 / 1024) > 3) {
- this.$alert({ content: "空间已满" });
- }else{
- this.$refs.uploadFile.click()
- }
- })
- },
- previewVedio(clickItem) {
- const index = this.list.findIndex((eachItem) => {
- return eachItem.id === clickItem.id
- })
- index >= 0 && this.$refs['video-previewer'].show(this.list[index].name, this.list[index].ossPath)
- },
- onFilterFocus() {
- this.isFilterFocus = true
- },
- onFilterBlur() {
- this.isFilterFocus = false
- },
- refreshListDebounced: debounce(function() {
- this.list = []
- this.isRequestingMoreData = false
- this.hasMoreData = true
- this.$refs['table-list'].requestMoreData()
- }, 700, false),
- handleRename(newName) {
- editMaterial(
- {
- id: this.popupItem.id,
- name: newName,
- },
- () => {
- this.$msg.success("修改成功");
- const index = this.list.findIndex((eachItem) => {
- return eachItem.id === this.popupItem.id
- })
- if (index >= 0) {
- this.list[index].name = newName
- } else {
- console.error('在素材列表里没找到要重命名的那一项!');
- }
- this.showRename = false;
- this.popupItem = null;
- }
- );
- },
- del(item) {
- this.$confirm({
- title: '删除素材',
- content: "确定要删除素材吗?",
- okText: '删除',
- ok: () => {
- delMaterial(item.id, () => {
- this.$msg.success("删除成功");
- this.isRequestingMoreData = true
- const lastestUsedSearchKey = this.searchKey
- getMaterialList(
- {
- pageNum: this.list.length + 1,
- pageSize: 1,
- searchKey: this.searchKey,
- type: TYPE,
- },
- (data) => {
- const index = this.list.findIndex((eachItem) => {
- return eachItem.id === item.id
- })
- if (index >= 0) {
- this.list.splice(index, 1)
- const newData = data.data.list.map((i) => {
- i.fileSize = changeByteUnit(Number(i.fileSize));
- i.icon = i.ossPath + this.$videoImg;
- i.createTime = i.createTime.substring(0, i.createTime.length - 3)
- i.updateTime = i.updateTime.substring(0, i.updateTime.length - 3)
- return i;
- });
- this.list = this.list.concat(newData)
- if (this.list.length === data.data.total) {
- this.hasMoreData = false
- }
- } else {
- console.error('在素材列表里没找到要删除的那一项!');
- }
- this.isRequestingMoreData = false
- this.lastestUsedSearchKey = lastestUsedSearchKey
- },
- () => {
- this.lastestUsedSearchKey = lastestUsedSearchKey
- this.isRequestingMoreData = false
- }
- )
- });
- },
- });
- },
- onFileChange(e) {
- e.files.forEach((eachFile, i) => {
- if (eachFile.name.toLowerCase().indexOf("mp4") <= -1) {
- setTimeout(() => {
- this.$msg({
- message: `“${eachFile.name}”格式错误,请上传200MB以内、mp4格式的视频`,
- type: "warning",
- });
- }, i * 100);
- return;
- }
- if (eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50) {
- setTimeout(() => {
- this.$msg({
- message: `“${eachFile.name}”名称过长,请上传标题在50字以内的视频`,
- type: "warning",
- });
- }, i * 100);
- return;
- }
- let itemInUploadList = {
- title: eachFile.name,
- ifKnowProgress: true,
- progress: 0,
- status: 'LOADING',
- statusText: "正在上传素材",
- uid: `u_${this.$randomWord(true, 8, 8)}`,
- abortHandler: null,
- };
-
- itemInUploadList.abortHandler = uploadMaterial(
- {
- file: eachFile
- },
- {
- type: TYPE,
- uid: itemInUploadList.uid,
- },
- () => { // 上传成功
- const index = this.uploadListForUI.findIndex((eachItem) => {
- return eachItem.uid === itemInUploadList.uid
- })
- this.uploadListForUI.splice(index, 1)
- this.refreshListDebounced()
- },
- (err) => {
- if (err.statusText === 'abort') { // 用户取消了上传任务。
- const index = this.uploadListForUI.findIndex((eachItem) => {
- return eachItem.uid === itemInUploadList.uid
- })
- this.uploadListForUI.splice(index, 1)
- } else {
- itemInUploadList.status = 'FAIL'
- itemInUploadList.statusText = '素材上传失败'
- }
- },
- (progress) => {
- itemInUploadList.progress = progress
- }
- );
- this.uploadListForUI.push(itemInUploadList);
- });
- },
- onCancelTask(uid) {
- const index = this.uploadListForUI.findIndex((eachItem) => {
- return eachItem.uid === uid
- })
- if (this.uploadListForUI[index].status === 'LOADING') {
- this.uploadListForUI[index].abortHandler.abort()
- } else {
- this.uploadListForUI.splice(index, 1)
- }
- },
- getMoreMaterialItem() {
- this.isRequestingMoreData = true
- const lastestUsedSearchKey = this.searchKey
- getMaterialList(
- {
- pageNum: Math.floor(this.list.length / config.PAGE_SIZE) + 1,
- pageSize: config.PAGE_SIZE,
- searchKey: this.searchKey,
- type: TYPE,
- },
- (data) => {
- const newData = data.data.list.map((i) => {
- i.fileSize = changeByteUnit(Number(i.fileSize));
- i.icon = i.ossPath + '?x-oss-process=video/snapshot,t_0,f_jpg,w_89,h_50,m_fast,ar_auto';
- i.createTime = i.createTime.substring(0, i.createTime.length - 3)
- i.updateTime = i.updateTime.substring(0, i.updateTime.length - 3)
- return i;
- });
- this.list = this.list.concat(newData)
- if (this.list.length === data.data.total) {
- this.hasMoreData = false
- }
- this.isRequestingMoreData = false
- this.lastestUsedSearchKey = lastestUsedSearchKey
- },
- () => {
- this.isRequestingMoreData = false
- this.lastestUsedSearchKey = lastestUsedSearchKey
- }
- );
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .img {
- position: relative;
- width: 89px !important;
- .video-icon-mask {
- display: none;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- .icon-editor_play {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- color: #fff;
- font-size: 20px;
- }
- }
- &:hover {
- .video-icon-mask {
- display: block;
- }
- }
- }
- </style>
- <style lang="less" scoped>
- @import "../style.less";
- </style>
|