xiangpei
2024-05-17 3b7181ccc8f3e9c233de96fc1221d8ffe73ac001
张先强改文件
2个文件已修改
50 ■■■■ 已修改文件
src/components/UploadC.vue 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/onlineStudy/file.vue 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/UploadC.vue
@@ -4,6 +4,7 @@
        :action="uploadUrl"
        :show-file-list="true"
        :limit="uploadNum"
        :accept="acceptList"
        multiple
        :file-list="fileUrl"
        :on-remove="handleRemove"
@@ -13,7 +14,7 @@
      <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 v-if="fileUrl && fileUrl.length > 0 && uploadNum === 1">
        <video class="returnShow" v-if="fileType === 'video'" :src="'/api/files/' + fileUrl[0].url"></video>
        <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"/>
      </div>
    </el-upload>
@@ -64,6 +65,7 @@
      this.$emit('getUploadUrl', this.fileUrl);
    },
    beforeUpload(file) {
      const limit = file.size / 1024 / 1024 < this.fileSizeLimitM;
      if (!limit) {
        this.$message.error(`上传文件大小不能超过 ${this.fileSizeLimitM}MB!`);
@@ -71,6 +73,18 @@
      return limit;
    },
  },
  computed: {
    acceptList: () => {
      let temp = '.jgp,.png,.jpeg'
      if(this.fileType === 'video') {
        temp = '.mp4,.avi'
      }
      if(this.fileType === 'pdf') {
        temp = '.pdf'
      }
      return temp;
    }
  }
}
</script>
src/views/onlineStudy/file.vue
@@ -33,7 +33,7 @@
      </el-table-column>
      <el-table-column label="文件内容">
        <template slot-scope="scope">
          <video v-if="scope.row.contentType === 'video'" :src="'/api/files/' + scope.row.contentUrl.url"
          <video controls v-if="scope.row.contentType === 'video'" :src="'/api/files/' + scope.row.contentUrl.url"
            class="showContent" />
          <img v-if="scope.row.contentType === 'img'" :src="'/api/files/' + scope.row.contentUrl.url"
            class="showContent" />
@@ -74,7 +74,7 @@
          </el-select>
        </el-form-item>
        <el-form-item label="文件类型" prop="contentType">
          <el-select v-model="form.contentType" placeholder="不同类型的文件阅览方式不同,多余文件请以附件形式上传">
          <el-select v-model="form.contentType" placeholder="不同类型的文件阅览方式不同,多余文件请以附件形式上传" @change="fileChange">
            <el-option label="视频" value="video"></el-option>
            <el-option label="PDF" value="pdf"></el-option>
            <el-option label="图片" value="img"></el-option>
@@ -148,6 +148,10 @@
    };
  },
  methods: {
    fileChange() {
      console.log(1111111)
      this.form.contentUrl = [];
    },
    handleSelectionChange(val) {
      this.ids = val.map(item => item.id);
    },
@@ -176,7 +180,7 @@
      this.form.attachment = uploadData;
    },
    getUploadUrl(uploadData) {
      this.form.contentUrl = uploadData[0];
      this.form.contentUrl = uploadData;
    },
    remove(id) {
      OnlineStudyAPI.remove([id]).then(res => {
@@ -202,9 +206,11 @@
    handlerSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.form.contentUrl = this.form.contentUrl[0]
          if (this.form.id) {
            OnlineStudyAPI.update(this.form).then(res => {
          const temp = JSON.parse(JSON.stringify(this.form));
          // this.form.contentUrl = this.form.contentUrl[0]
          temp.contentUrl = temp.contentUrl[0];
          if (temp.id) {
            OnlineStudyAPI.update(temp).then(res => {
              if (res.code === 1) {
                this.$message.success('修改成功');
                this.open = false;
@@ -212,7 +218,7 @@
              }
            });
          } else {
            OnlineStudyAPI.add(this.form).then(res => {
            OnlineStudyAPI.add(temp).then(res => {
              if (res.code === 1) {
                this.$message.success('添加成功');
                this.open = false;
@@ -223,12 +229,22 @@
        }
      });
    },
    resetForm() {
      this.form = {
        contentType: 'video',
        subject: '',
        belongType: 2,
        contentUrl: [],
        attachment: [],
        temp: []
      }
    },
    handleClose() {
      this.open = false;
      this.form = {};
      this.resetForm();
    },
    handlerAdd() {
      this.form = {};
      this.resetForm();
      this.open = true;
      this.dialogTitle = '添加学习内容';
    },