xiangpei
2024-05-17 f7ab917bed7dd916f412d23025fa3febd7ac4bd0
src/views/onlineStudy/file.vue
@@ -33,12 +33,12 @@
      </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" />
          <el-link type="primary" v-if="scope.row.contentType === 'pdf'" :src="'/api/files/' + scope.row.contentUrl.url"
            class="showContent">点击查看</el-link>
          <el-link type="primary" v-if="scope.row.contentType === 'pdf'"
            class="showContent" @click="checkPdf('/api/files/' + scope.row.contentUrl.url)">点击查看</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="attachment" label="附件">
@@ -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>
@@ -94,6 +94,11 @@
        <el-button type="primary" @click="handlerSubmit">保 存</el-button>
      </span>
    </el-dialog>
    <el-dialog title="PDF查看" :visible.sync="pdfDialog" width="80%" :before-close="closePdfDialog">
      <vue-office-pdf :src="pdf" @rendered="rendered" />
    </el-dialog>
  </div>
</template>
@@ -102,9 +107,11 @@
import OnlineStudyAPI from '@/api/online-study';
import StudyTypeAPI from '@/api/study-type';
import Upload from '@/components/UploadC';
import VueOfficePdf from '@vue-office/pdf';
export default {
  name: 'type',
  components: { Upload, Pagination },
  components: { Upload, Pagination, VueOfficePdf },
  computed: {
    fileContentUrl: () => {
      return this.form ? this.form.contentUrl ? [this.form.contentUrl] : [] : [];
@@ -112,19 +119,23 @@
  },
  data() {
    return {
      pdf: '',
      dialogTitle: '添加学习内容',
      ids: [],
      typeList: [],
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        pageSize: 5,
        typeName: ''
      },
      total: 0,
      tableData: [],
      open: false,
      pdfDialog: false,
      form: {
        contentType: 'video',
        subject: '',
        belongType: 2,
        contentUrl: [],
        attachment: [],
        temp: []
@@ -146,6 +157,19 @@
    };
  },
  methods: {
    checkPdf(url) {
      this.pdf = url;
      this.pdfDialog = true;
    },
    closePdfDialog() {
      this.pdfDialog = false;
    },
    rendered() {
    },
    fileChange() {
      this.form.contentUrl = [];
    },
    handleSelectionChange(val) {
      this.ids = val.map(item => item.id);
    },
@@ -174,7 +198,7 @@
      this.form.attachment = uploadData;
    },
    getUploadUrl(uploadData) {
      this.form.contentUrl = uploadData[0];
      this.form.contentUrl = uploadData;
    },
    remove(id) {
      OnlineStudyAPI.remove([id]).then(res => {
@@ -200,9 +224,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;
@@ -210,7 +236,7 @@
              }
            });
          } else {
            OnlineStudyAPI.add(this.form).then(res => {
            OnlineStudyAPI.add(temp).then(res => {
              if (res.code === 1) {
                this.$message.success('添加成功');
                this.open = false;
@@ -221,12 +247,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 = '添加学习内容';
    },