接口上传视频和oss直传视频到阿里云组件

在这里插入图片描述

接口视频上传

<template>
  <div class="component-upload-video">
    <el-upload
      class="avatar-uploader"
      :action="uploadImgUrl"
      :on-progress="uploadVideoProcess"
      :on-success="handleUploadSuccess"
      :limit="limit"
      :file-list="fileList"
      :before-upload="handleBeforeUpload"
      :show-file-list="false"
      :headers="headers"
      ref="uploadRef"
    >
      <video
        v-if="videoForm.showVideoPath && !videoFlag"
        :src="videoForm.showVideoPath"
        class="avatar video-avatar"
        controls="controls"
      >
        您的浏览器不支持视频播放
      </video>
      <!-- //i标签是上传前的那个+上传后隐藏 -->
      <i
        v-else-if="!videoForm.showVideoPath && !videoFlag"
        class="el-icon-plus avatar-uploader-icon"
      ></i>
      <el-progress
        v-if="videoFlag == true"
        type="circle"
        :percentage="videoUploadPercent"
        style="margin-top: 7px"
      ></el-progress>
    </el-upload>
    <el-button
      v-if="isShowBtn && videoForm.showVideoPath"
      class="mt-20"
      plain
      round
      @click="handleDelete"
      size="small"
      type="primary"
      >重新上传<i class="el-icon-upload el-icon--right"></i
    ></el-button>
  </div>
</template>

<script>
import {
   
    getToken } from "@/utils/auth";

export default {
   
   
  props: {
   
   
    value: [String, Object, Array],
    // 图片数量限制
    limit: {
   
   
      type: Number,
      default: 5,
    },
    // 大小限制(MB)
    fileSize: {
   
   
      type: Number,
      default: 50,
    },
    // 序号
    indexValue: {
   
   
      type: Number,
      default: null,
    },
    // 文件类型, 例如['video/avi', 'video/wmv', 'video/rmvb']
    fileType: {
   
   
      type: Array,
      default: () => ["video/mp4", "video/ogg", "video/flv"],
    },
    // 是否显示提示
    isShowTip: {
   
   
      type: Boolean,
      default: false,
    },
    // 是否显示进度条
    isShowUploadVideo: {
   
   
      type: Boolean,
      default: false,
    },
    // 是否显示重新上传按钮
    isShowBtn: {
   
   
      type: Boolean,
      default: true,
    },
  },
  data() {
   
   
    return {
   
   
      number: 0,
      dialogVisible: false,
      hideUpload: false,
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的服务器地址
      headers: {
   
   
        Authorization: "Bearer " + getToken(),
      },
      fileList: [],
      videoForm: {
   
   
        showVideoPath: "", //回显的变量
      },
      duration: 0, //时长秒
      videoFlag: false,
      videoUploadPercent: 0,
    };
  },

  watch: {
   
   
    value: {
   
   
      handler(val) {
   
   
        if (val) {
   
   
          this.videoForm.showVideoPath = val;
          // 首先将值转为数组
          const list = Array.isArray(val) ? val : this.value.split(",");
          // 然后将数组转为对象数组
          this.fileList = list.map((item) => {
   
   
            if (typeof item === "string") {
   
   
              item = {
   
    name: item, url: item };
            }
            return item;
          });
        } else {
   
   
          this.fileList = [];
          return [];
        }
      },
      deep: true
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小曲曲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值