• qzhxx's avatar
    优化 · e26256ac
    qzhxx authored
    e26256ac
uploadFile copy.vue 3.26 KB
<template>
<div>

  <el-upload
    ref="upload"
    accept=".mp4,.flv,.mpeg,.mpg"
    :multiple="true"
    :http-request="uploadFile"
    :file-list="fileList"
    action
    :auto-upload="false"
    :before-upload="beforeAvatarUpload"
  >
    <i class="el-icon-plus fileUpload"></i>

  </el-upload>
   <el-button style="margin-left: 10px;" size="small" type="success" v-loading="loading" @click="submitUpload">上传到服务器</el-button>
</div>

</template>

<script>
export default {
   props:{
    fileList:{
      type:Array,
      default:[]
    },
  },
  data() {
    return {
      fullscreenLoading: false,
      loading:false,
      filedata:[],
      fileArr: [],
      fileList:[],
    //   fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
    };
  },
  methods: {
     openFullScreen2() {
        const loading = this.$loading({
          lock: true,
          text: '上传中,请稍候。。。',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        
      },
    submitUpload() {  // 导入
    // this.openFullScreen2()
     const loading = this.$loading({
          lock: true,
          text: '上传中,请稍候。。。',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
    // this.loading = true
        let tempData =  this.filedata
        this.filedata = new FormData()  //  用FormData存放上传文件
        this.$refs.upload.submit()  // 会循环调用uploadFile方法,多个文件调用多次

         let _this = this;
      _this
        .$https(
          {
            method: "post",
            url: "file/video/content/upload",
            authType: this.backToken
          },
          this.filedata
        )
        .then(res => {
          let resData = res.data;
          console.log(res)
          
          // this.loading = false
          if (resData.resultCode == "200") {
            loading.close();
             _this.$message.success('上传成功!')
            const data = resData.data.fileList;
            let newArray = data.map((item) => item.id);
            let editArray =[]
            if(this.fileList.length){
              editArray = this.fileList.map(item=>item.id)
            }
            this.$emit("videoList", [...newArray,...editArray]);

          } else {
            _this.$message.error(resData.msg || resData.message);
          }
        })
        .catch(err => {
          console.log(err);
          _this.$message.error(err.msg || err.message);
        });


    },
    uploadFile(file) {
         this.filedata.append('file', file.file)
    },
    beforeAvatarUpload(file) {
      const isLt10G = file.size / 1024 / 1024 / 1024 < 10;
      if (!isLt10G) {
        this.$message.error("上传文件大小不能超过 10GB!");
      }
      return isLt10G;
    }
  }
};
</script>

<style>
.el-upload .fileUpload {
  width: 148px;
  height: 148px;
  line-height: 148px!important;
  margin: 0 auto;
  border: 1px dashed #c0ccda;
  font-size: 24px;
  font: #ccc;
}
</style>