马宇豪
2024-12-18 585d90f0e3194d6b988a424036291921794678ab
src/views/components/upload.vue
@@ -1,6 +1,6 @@
<template>
  <div class="greetings">
  <div class="greetings" v-loading="loading">
    <el-upload accept=".mp4, .mp3, .xls, .xlsx, .doc, .docx, .ppt, .pptx, .pdf"   :on-change="handleFileChange" :on-preview="view"  :auto-upload="false" ref="uploadfileComponent" :limit="1" :on-exceed="handleExceed"  v-model:file-list="fileList">
      <template #trigger>
        <el-button type="primary">选择文件</el-button>
@@ -39,6 +39,7 @@
const fileList=ref([])
const uploadfileComponent=ref(null)
const emit = defineEmits(["getFile"]);
const loading = ref(false)
const props = defineProps({
  responseType: {
    type: Number,
@@ -82,7 +83,7 @@
        autoplay:true,//自动播放
        sources: [
          {
            src: resourcePath.value ? "http://192.168.2.16:9000/trainexam/" + resourcePath.value : '',
            src: resourcePath.value ? resourcePath.value : '',
            // src:'',
            type: 'application/x-mpegURL',
          }
@@ -152,7 +153,7 @@
const view = (file) => {
  console.log('vlco',file)
  // console.log("点击文件=>", file);
  const url = 'http://192.168.2.16:9000/trainexam/' + file.path;
  const url = file.path;
  const link = document.createElement("a");
  link.href = url;
  link.download = file.name;
@@ -290,6 +291,7 @@
      });
      return false
  }
  const filetype = container.file.raw.name.split(".").pop();
  const extension = (filetype === "mp4" || filetype ==="mp3" || filetype ==="xls" || filetype === "xlsx" || filetype ==="doc" || filetype ==="docx" || filetype === "ppt" || filetype ==="pptx" || filetype ==="pdf");
  if (!extension ) {
@@ -317,7 +319,7 @@
      return false;
    }
  }
  loading.value = true
  //文件分片
  const chunkList=createFileChunk(container.file.raw)
  console.log('文件分了多少片:',chunkList.length)
@@ -339,6 +341,7 @@
  }))
  uploadChunks(fileChunkList)
}
//文件分片
@@ -432,6 +435,8 @@
        uploadedCount.value=uploadedCount.value+1
        fileChunkList.value[data.get('index')].percentage=100 //手动更新进度
        console.log(uploadedCount.value,'result--------------')
      }else {
        loading.value = false
      }
      resolve('done')
    })
@@ -450,11 +455,10 @@
    if(filetype == 'mp4' || filetype == 'MP4'){
      container.showVideo = true
      await nextTick(() => {
        console.log("myPlayer.value",myPlayer.value)
        myPlayer.value.src(
            {
              src:"http://192.168.2.16:9000/trainexam/"+data.data.path,
              src: data.data.url,
              type: 'application/x-mpegURL',
            })
        //   myPlayer.value.load()
@@ -477,9 +481,10 @@
    emit("getFile",file)
    loading.value = false
    ElMessage.success("上传成功")
  }else{
    loading.value = false
    ElMessage.success("合并数据失败")
  }
}