vue elementui 上传视频 以及上传视频失败重新上传没反应的处理方法

news2025/2/23 21:34:12

<template>
  <el-drawer
    title="上传视频"
    size="50%"
    :visible.sync="drawer"
    :direction="direction">
    <div class="content">
      <div class="upload-box" v-if="!secondStep">
        <!--
          on-exceed:超出数量限制时的钩子
          file-list:上传的文件列表          
        -->
        <el-upload
          class="upload-demo"
          drag
          :data="uploadData"
          :action="actionUrl"
          :headers="headers"
          :on-success="handleSuccess"
          :on-error="handleError"
          :before-upload="beforeUpload"
          :file-list="fileList"
          :limit="1"
          accept=".mp4,.mov,.mpeg,.avi"
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">
            <div>(1) 文件大小: 最大 500 MB。</div>
            <div>(2) 比例:9:16, 16:9 和 1:1。</div>
            <div>(3) 格式:.mp4, .mov, .mpeg, .avi。</div>
            <div>投放位置为TikTok限制:分辨率大于720*1280 px , 码率大于 516 Kbps , 时长 5-60s。</div>
          </div>
        </el-upload>
      </div>
      <div class="batch-box" v-if="secondStep">
        <el-table
          ref="multipleTable"
          :data="fileList"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column label="文件名">
            <template slot-scope="scope">
              <div class="video-mes">
                <div class="video-mes-lef">
                  <img :src="scope.row.video_cover_url" />
                </div>
                <div class="video-mes-rig">
                  <div class="name-box">
                    {{ scope.row.file_name }}
                    <!-- <i class="el-icon-edit"></i> -->
                  </div>
                  <div class="video-mes-cont">
                    <span>{{ scope.row.duration }}</span> | <span>{{ scope.row.width }}*{{ scope.row.height }}</span> | <span>{{ scope.row.bit_rate }} Mbps</span> | <span>{{ scope.row.size }} MB</span>
                  </div>
                </div>                
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="name"
            label="广告位要求校验"
            width="180">
            <template slot-scope="scope">
              <i class="el-icon-circle-check"></i>
              <i class="el-icon-circle-close"></i>
              准备好上传
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态" width="180">
            <template slot-scope="scope">
              <i class="el-icon-circle-check"></i>
              <i class="el-icon-circle-close"></i>
              准备好上传
            </template>
          </el-table-column>
          <el-table-column
            prop="remark"
            label="需要解决的问题">
          </el-table-column> -->
        </el-table>
      </div>
    </div>
    
    <div class="demo-drawer__footer">
      <div class="footer-lef">选择了 {{ multipleSelection.length }}/{{ fileList.length }}</div>
      <div class="footer-rig">
        <el-button @click="cancelForm">取 消</el-button>
        <el-button type="primary" @click="dataFormSubmit" >上传</el-button>
      </div>
    </div>
</el-drawer>
</template>
<script>
  //import { filetiktokupload } from "@/api/advertising/index";
  import store from "@/store";
  export default {
    data() {
      return {          
        actionUrl: '/api/file/tiktok/upload',
        headers: {
          agent_token: store.getters.access_token,
        },
        fileList: [],  // 存储上传的文件列表
        uploadData: {
          advertiserId: '', // Replace with actual advertiserId
          type: 'video'       // Replace with actual type if necessary
        },
        secondStep: false,
        multipleSelection: [],
        advertiser_id: "",
        checkedItem: null,
        checkedIndex: null,     
        checked: false,         
        drawer: false,
        loading:false,    
        direction: 'rtl',    
      };
    },
    methods: {
      init(advertiserId){
        this.reset()
        this.uploadData.advertiserId = advertiserId
        this.drawer = true;
      },      

      reset(){
        this.secondStep = false
        this.fileList = []//视频上传失败的时候 该字段重置才能重新上传
        this.multipleSelection = []        
      },
      
      beforeUpload(file) {
        const isVideo = file.type.indexOf('video/') > -1;
        const isLt1G = file.size / 1024 / 1024 / 1024 < 0.5;  // 限制文件大小为500Mb

        if (!isVideo) {
          this.$message.error('上传文件只能是视频格式!');
          return false;
        }
        if (!isLt1G) {
          this.$message.error('上传视频大小不能超过500Mb!');
          return false;
        }
        return true;
      },

      handleError(err, file, fileList){
        this.init()
      },

      handleSuccess(response, file, fileList) {
        if(response.code == 0){
          let info = response.data
          this.$message.success('视频上传成功')
          this.fileList = []
          this.fileList.push({            
            video_id: info.video_id,
            video_cover_url: info.video_cover_url,
            preview_url: info.preview_url,
            file_name: info.file_name,
            width: info.width,
            height: info.height,
            duration: info.duration,
            bit_rate: (info.bit_rate/1024/1024).toFixed(2),
            size: (info.size/1024/1024).toFixed(2)
          })
          this.secondStep = true
        }else if(response.code == -1){
          this.$message.error('上传视频失败,请重试');
          this.init(this.uploadData.advertiserId)
        }
      },
      
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },

      dataFormSubmit(){                
        if(this.multipleSelection.length == 0) {
          this.$message.error('请选择上传的文件');
          return
        }
        this.$emit("refreshDataList", this.multipleSelection);
        this.drawer = false;
      },

      cancelForm(){
        this.reset()
        this.drawer = false;
      },

    }
  };
</script>
<style scoped>
.video-mes-lef{ margin-right: 20px; width: 60px; height: 60px;}
.video-mes-lef img{ width: 100%; height: 100%; object-fit: contain;}
.video-mes{ display: flex; align-items: center;}
.content >>> .el-upload, .content >>> .el-upload-dragger{ width: 100%;}
.content >>> .el-upload-dragger{ height: 267px;}
.content >>> .el-upload-dragger .el-icon-upload{ margin-top: 90px;}
.el-icon-circle-check,.el-icon-circle-close{ margin-right: 6px;}
.el-icon-circle-check{ color: green}
.el-icon-circle-close{ color: red}
.el-icon-edit{ font-size: 14px;}
.footer-lef{ font-size: 14px;}
.content{ padding: 0 20px; height: calc(100% - 50px); overflow-y: scroll;}
>>>.demo-drawer__footer{
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
>>>.el-drawer__header{
  border-bottom: 1px solid #EBEEF5;
  padding-bottom: 15px;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1954296.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

谷粒商城实战笔记-72-商品服务-API-属性分组-获取分类属性分组

文章目录 一&#xff0c;后端接口开发Controller层修改接口接口测试 二&#xff0c;前端开发 这一节的内容是开发获取分类属性分组的接口。 一&#xff0c;后端接口开发 Controller层修改接口 修改AttrGroupController接口。 RequestMapping("/list/{catelogId}")p…

Linuxnat网络配置

&#x1f4d1;打牌 &#xff1a; da pai ge的个人主页 &#x1f324;️个人专栏 &#xff1a; da pai ge的博客专栏 ☁️宝剑锋从磨砺出&#xff0c;梅花香自苦寒来 ☁️运维工程师的职责&#xff1a;监…

python—pandas基础(3)

文章目录 虚拟变量变换数值变量分段数据分组基于拆分进行筛选分组汇总使用 agg 函数进行汇总引用自定义函数 长宽格式转换长宽型格式的自由互转 多个数据源的合并数据的横向合并concat 命令一维的Series拼接df对象拼接两个df对象拼接&#xff0c;按列进行拼接两个df对象拼接&am…

55事务、批处理、CBLOB

day55 事务 MySQL&#xff1a;每一条语句都属于独立事务,默认自动管理提交的。 如果需要把多条语句当成一个整体&#xff0c;那么就需要把多条语句放在一个事务里面 开启事务&#xff1a;start transaction 提交事务&#xff1a;commit; 回滚事务&#xff1a;rollback 封装事务…

【安装笔记-20240727-Windows-OpenWrt 23.05 docker 安装 wordpress】

安装笔记-系列文章目录 安装笔记-20240727-Windows-OpenWrt 23.05 docker 安装 wordpress 文章目录 安装笔记-系列文章目录安装笔记-20240727-Windows-OpenWrt 23.05 docker 安装 wordpress 前言一、调试环境操作系统&#xff1a;Windows 10 专业版调试环境 二、安装步骤测试版…

基于SpringBoot的商业航班执飞飞机机型信息管理

目录 前言 一、数据库模型的设计与实现 1、表结构设计 2、数据去重和消歧 二、后台应用程序设计 1、实体类设计 2、业务层及控制层设计与实现 3、视图层的实现 三、系统成果展示 1、飞机机型管理列表 2、机型信息编辑 四、总结 前言 在之前的信息中&#xff0c;我们对…

流媒体服务器二:RTMP协议详解 以及 RTMP学习到什么程度算是合格?

一个问题&#xff1f; 在上一节我们使用SRS搭建了RTMP环境&#xff0c;那么在企业开发中&#xff0c;是否使用第三方的RTMP服务器&#xff08;例如上一节的SRS&#xff09;就可以了呢&#xff1f;或者说&#xff1a;作为一个音视频开发人员&#xff0c;就会配置就OK了呢&#…

windows USB 设备驱动开发-创建安装 Winusb.sys 的驱动程序包

要将 WinUSB 用作设备的功能驱动程序&#xff0c;请创建一个驱动程序包。 驱动程序包必须包含以下文件&#xff1a; WinUSB 辅助安装程序 (Winusbcoinstaller.dll)&#xff1b;KMDF 辅助安装程序 (WdfcoinstallerXXX.dll)&#xff1b;一个 .inf 文件&#xff0c;用于将 Winusb…

MYSQL 第三次作业

1、第三次作业 01、SELECT * FROM student; SELECT * FROM score; 02、SELECT * FROM student LIMIT 1, 3; 03、SELECT * FROM student WHERE department IN (计算机系, 英语系); 04、SELECT * FROM student WHERE birth_year > 1998; 05、SELECT department, COUNT(*) as c…

Corel VideoStudio 会声会影2023旗舰版视频软件

使用新版 Corel VideoStudio 会声会影2023是 一次激活永久使用。 享受有趣轻松的视频编辑体验。通过数百种滤镜、效果、标题、过渡和图形 — 包括新增面部追踪贴纸 — 探索拖放创意。运用直观的工具和即时项目模板&#xff0c;几分钟即可创建出色的视频&#xff01;探索有趣简单…

【JUC】CAS(轻量级加锁)

文章目录 原子类没有CAS之前使用CAS之后CAS是什么&#xff1f;compareAndSet 源码 CAS底层原理&#xff1f;谈谈对Unsafe类的理解&#xff1f;Unsafei是线程不安全的&#xff0c;AtomicInteger.getAndIncrement()如何保证原子性&#xff1f; 源码分析底层汇编语言面试回答 原子…

OriginPro 2024b (学习版) 绘制3D坐标下 边际直方图

OriginPro 2024b (学习版) 绘制3D坐标下 边际直方图 时间 2024年7月27日 1.导入数据 需要3列数据&#xff0c;分别作为x,y,z, 其中z值随便设置。快速设置z值的方法&#xff1a;在第4行“F(x)”输入1&#xff0c;这一列的值全设置为1了。 设置x,y,z的方法如下&#xff1a;点击…

【机器学习】周志华《机器学习》西瓜书勘误:按章节排序整理(截至2024年1月第45次印刷)

文章目录 按章节排序第 1 章 绪论第 2 章 模型评估与选择第 3 章 线性模型第 4 章 决策树第 5 章 神经网络第 6 章 支持向量机第 7 章 贝叶斯分类器第 8 章 集成学习第 9 章 聚类第10章 降维与度量学习第11章 特征选择与稀疏学习第12章 计算学习理论第13章 半监督学习第14章 概…

使用两台虚拟机分别部署前端和后端项目

使用两台虚拟机分别部署前端和后端项目 1 部署方案2 准备两台虚拟机&#xff0c;并配置网络环境3 部署后端项目3.1 打包服务3.2 上传jar包到服务器3.3 集成Systemd3.3.1 移动端服务集成Systemd3.3.2 后台管理系统集成Systemd 4 配置域名映射5 部署前端项目5.1 移动端5.1.1 打包…

JVM系列(二) -类的加载过程

一、背景介绍 我们知道 Java 是先通过编译器将.java类文件转成.class字节码文件&#xff0c;然后再通过虚拟机将.class字节码文件加载到内存中来实现应用程序的运行。 那么虚拟机是什么时候加载class文件&#xff1f;如何加载class文件&#xff1f;class文件进入到虚拟机后发…

ARCH和GARCH模型★★

该博客为个人学习清风建模的学习笔记&#xff0c;部分课程可以在B站&#xff1a;【强烈推荐】清风&#xff1a;数学建模算法、编程和写作培训的视频课程以及Matlab等软件教学_哔哩哔哩_bilibili 该节是针对时间序列分析中对证券指数分析不能使用传统时间序列模型做出的模型&a…

C++ 基础(类和对象下)

目录 一. 再探构造函数 1.1. 初始化列表&#xff08;尽量使用列表初始化&#xff09; 二. static成员 2.1static成员初始化 三.友元 3.1友元&#xff1a;提供了⼀种 突破类访问限定符封装的方式. 四.内部类 4.1如果⼀个类定义在另⼀个类的内部&#xff0c;这个内部类就叫…

数据结构第三讲:单链表的实现

数据结构第三讲&#xff1a;单链表的实现 1.什么是单链表2. 节点3.单链表的实现3.1节点的结构3.2打印单链表3.3申请一个新节点3.4单链表尾部插入3.5单链表头部插入3.6单链表的尾部删除3.7单链表头部删除3.8查找3.9在指定位置之前插入数据3.10在指定位置之后插入数据3.11删除pos…

全国区块链职业技能大赛样题第9套前端源码

后端源码地址:https://blog.csdn.net/Qhx20040819/article/details/140746050 前端源码地址:https://blog.csdn.net/Qhx20040819/article/details/140746216 智能合约+数据库表设计:https://blog.csdn.net/Qhx20040819/article/details/140746646 登录 ​ 用户管理

Java httpclient请求form-data格式,并设置boundary代码实现

文章目录 form-data 数据请求格式样例报错信息: **MissingServletRequestParameterException**解决方法报错信息: **no multipart boundary was found** 解决方法Java代码实现【错误】使用 UrlEncodedFormEntity 、BasicNameValuePair 请求失败&#xff08;error&#xff09;【…