ZhangXianQiang
2024-05-17 0a9d8e014803308c2eef22ca1e83c50d4086b37d
fix:上传类型限制
2个文件已修改
36 ■■■■ 已修改文件
src/components/UploadC.vue 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/onlineStudy/file.vue 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/UploadC.vue
@@ -4,7 +4,7 @@
      :file-list="fileUrl" :on-remove="handleRemove" :before-remove="beforeRemove" :on-success="handleUploadSuccess"
      :before-upload="beforeUpload">
      <el-button size="small" type="primary">点击上传</el-button>
      <div slot="tip" class="el-upload__tip">只能上传pdf、mp4、mp3、png、jpg、jpge文件,且不超过{{ fileSizeLimitM }}M</div>
      <div slot="tip" class="el-upload__tip">只能上传pdf、mp4、avi、png、jpg、jpge文件,且不超过{{ fileSizeLimitM }}M</div>
      <div v-if="fileUrl && fileUrl.length > 0 && uploadNum === 1">
        <video controls class="returnShow" v-if="fileType === 'video'" :src="'/api/files/' + fileUrl[0].url"></video>
        <img class="returnShow" v-if="fileType === 'img'" :src="'/api/files/' + fileUrl[0].url" />
@@ -41,10 +41,10 @@
  data() {
    return {
      uploadUrl: "http://localhost:8085/api/upload/upload",
      fileTypeList:{
        'video': ['.mp4', '.avi'],
        'img': ['.jgp', '.png', '.jpeg'],
        'pdf': ['.pdf'],
      fileTypeList: {
        'video': ['mp4', 'avi'],
        'img': ['jgp', 'png', 'jpeg'],
        'pdf': ['pdf'],
      }
    };
  },
@@ -53,7 +53,9 @@
      this.fileUrl = [];
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}?`);
      if (file && file.status === "success") {
        return this.$confirm(`确定移除 ${file.name}?`);
      }
    },
    handleRemove(file, fileList) {
      this.$emit('removeFile', this.fileUrl, file.name);
@@ -63,19 +65,34 @@
      this.$emit('getUploadUrl', this.fileUrl);
    },
    beforeUpload(file) {
      const { type } = file;
      const typeList = this.fileTypeList[this.fileType];
      let limitType = true;
      if (typeList) {
        const tempType = typeList.find(item => {
          if (type.includes(item)) {
            return true;
          } else {
            return false;
          }
        });
        if (!tempType) {
          this.$message.error(`请上传正确的文件格式!`);
          limitType = false;
        }
      }
      const limit = file.size / 1024 / 1024 < this.fileSizeLimitM;
      if (!limit) {
        this.$message.error(`上传文件大小不能超过 ${this.fileSizeLimitM}MB!`);
      }
      return limit;
      return limitType && limit;
    },
  },
  computed: {
    acceptList() {
      let temp = '.*';
      if (this.fileTypeList[this.fileType]) {
        temp = this.fileTypeList[this.fileType].join(',');
        temp = this.fileTypeList[this.fileType].map(item => '.' + item).join(',');
      }
      return temp;
    }
src/views/onlineStudy/file.vue
@@ -149,7 +149,6 @@
  },
  methods: {
    fileChange() {
      console.log(1111111)
      this.form.contentUrl = [];
    },
    handleSelectionChange(val) {