Ver Fonte

上传的预览

natasha há 9 meses atrás
pai
commit
d27dd9f9db

BIN
src/assets/red_remove.png


+ 0 - 8
src/views/book/courseware/create/components/base/upload_preview/UploadPreview.vue

@@ -50,14 +50,6 @@ export default {
       iconClass: 'picture',
     };
   },
-  watch: {
-    'data.file_list': {
-      handler(val) {
-        console.log(val);
-      },
-      immediate: true,
-    },
-  },
   methods: {
     updateFileList({ file_list, file_id_list, file_info_list }) {
       this.data.file_list = file_list;

+ 123 - 18
src/views/book/courseware/preview/components/upload_control/UploadControlPreview.vue

@@ -1,37 +1,142 @@
 <template>
-  <div>预览开发中</div>
-  <!-- <UploadFile
-    :changeFillId="courseware_id"
-    :accept="acceptFileType"
-    :filleNumber="1"
-    :fileList="fileList"
-    :type="type"
-  /> -->
+  <div class="upload-preview" :style="getAreaStyle()">
+    <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
+
+    <div class="main">
+      <UploadFile
+        :changeFillId="changeFillId"
+        :accept="acceptFileType"
+        :filleNumber="1"
+        :fileList="data.file_list"
+        v-if="data.answer.answer_list.length === 0"
+      />
+      <div v-else class="preview-box">
+        <template
+          v-if="
+            data.answer.answer_list[0].file_name.indexOf('png') !== -1 ||
+            data.answer.answer_list[0].file_name.indexOf('jpg') !== -1 ||
+            data.answer.answer_list[0].file_name.indexOf('jpeg') !== -1
+          "
+        >
+          <el-image
+            style="width: 100%; height: 260px"
+            :src="data.answer.answer_list[0].file_url"
+            :fit="'contain'"
+            :preview-src-list="[data.answer.answer_list[0].file_url]"
+          >
+          </el-image>
+        </template>
+        <template v-else-if="data.answer.answer_list[0].file_name.indexOf('pdf') !== -1">
+          <iframe
+            :src="data.answer.answer_list[0].newpath"
+            id="ifm"
+            width="100%"
+            height="260px"
+            frameborder="0"
+          ></iframe>
+        </template>
+        <div class="dv">
+          <div class="remove" :class="[isJudgingRightWrong ? 'notAllow' : '']" @click="remove">
+            <img src="@/assets/red_remove.png" alt="" />
+          </div>
+          <div class="remove zoom-in" @click="showIframe = true">
+            <i class="el-icon-zoom-in"></i>
+          </div>
+        </div>
+      </div>
+    </div>
+    <el-dialog
+      :visible.sync="showIframe"
+      :show-close="true"
+      :close-on-click-modal="false"
+      :modal-append-to-body="false"
+      width="1000px"
+      class="login-dialog"
+      v-if="showIframe"
+    >
+      <iframe :src="data.answer.answer_list[0].newpath" id="ifms" width="100%" height="600px" frameborder="0"></iframe>
+    </el-dialog>
+  </div>
 </template>
 
 <script>
+import PreviewMixin from '../common/PreviewMixin';
 import UploadFile from './components/UploadView.vue';
+import { getUploadControlData } from '@/views/book/courseware/data/uploadControl';
+const Base64 = require('js-base64').Base64;
+import { getConfig } from '@/utils/auth';
 
 export default {
   name: 'UploadControlPreview',
+  mixins: [PreviewMixin],
   components: { UploadFile },
   data() {
     return {
-      labelText: '文件',
+      data: getUploadControlData(),
       acceptFileType: '.png,.jpg,.pdf',
-      uploadTip:
-        'The size of the uploaded image should not exceed 2MB, the size of the uploaded audio file, pdf file, and excel file should not exceed 20MB, and the size of the uploaded audio file should not exceed 20MB',
-      iconClass: 'picture',
-      fileList: [],
-      type: 'upload_control',
+      file_preview_url: getConfig() ? getConfig().doc_preview_service_address : '',
+      showIframe: false,
     };
   },
   methods: {
-    updateFileList({ file_list, file_id_list, file_info_list }) {
-      this.data.file_list = file_list;
-      this.data.file_id_list = file_id_list;
-      this.data.file_info_list = file_info_list;
+    changeFillId(fileList) {
+      this.data.answer.answer_list = [fileList[0].response.file_info_list[0]];
+      let path =
+        `${this.file_preview_url}/onlinePreview?url=` + Base64.encode(fileList[0].response.file_info_list[0].file_url);
+      this.data.answer.answer_list[0].newpath = path;
+      this.$forceUpdate();
+    },
+    remove() {
+      if (!this.isJudgingRightWrong) {
+        if (this.data.answer.answer_list.length > 0) {
+          this.data.answer.answer_list = [];
+          this.$message.success('删除成功');
+          this.$forceUpdate();
+        }
+      }
     },
   },
 };
 </script>
+<style lang="scss" scoped>
+@use '@/styles/mixin.scss' as *;
+
+.upload-preview {
+  @include preview-base;
+}
+
+.preview-box {
+  display: flex;
+}
+
+.dv {
+  display: flex;
+  flex-flow: wrap;
+  align-items: center;
+  width: 72px;
+  padding: 60px 0;
+
+  .remove {
+    box-sizing: border-box;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 40px;
+    height: 39px;
+    margin-left: 32px;
+    cursor: pointer;
+    background: #fff;
+    border: 1px solid rgba(0, 0, 0, 10%);
+    border-radius: 8px;
+
+    &.notAllow {
+      cursor: not-allowed;
+    }
+
+    img {
+      width: 24px;
+      height: 24px;
+    }
+  }
+}
+</style>

+ 2 - 19
src/views/book/courseware/preview/components/upload_control/components/UploadView.vue

@@ -33,18 +33,7 @@
 import { getToken } from '@/utils/auth';
 export default {
   components: {},
-  props: [
-    'uploadType',
-    'filleNumber',
-    'datafileList',
-    'changeFillId',
-    'deleteImg',
-    'index',
-    'uiType',
-    'fileList',
-    'accept',
-    'type',
-  ],
+  props: ['filleNumber', 'datafileList', 'changeFillId', 'index', 'fileList', 'accept'],
   data() {
     return {
       currentfileList: [],
@@ -62,7 +51,7 @@ export default {
       let UserCode = '';
       let UserType = '';
       if (userInfor) {
-        let user = JSON.parse(getToken());
+        let user = getToken();
         UserCode = user.user_code;
         UserType = user.user_type;
         SessionID = user.session_id;
@@ -85,12 +74,6 @@ export default {
   // 生命周期 - 创建完成(可以访问当前this实例)
   created() {
     this.currentfileList = this.fileList || [];
-    // this.showList = this.fileList ? true : false;
-    if (this.type === 'upload_control_preview_chs' || this.type === 'upload_pdf_chs') {
-      this.showList = true;
-    } else {
-      this.showList = false;
-    }
   },
   // 生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {

+ 0 - 2
src/views/book/courseware/preview/components/upload_preview/UploadPreviewPreview.vue

@@ -28,7 +28,6 @@
 </template>
 
 <script>
-import UploadFile from './components/UploadView.vue';
 import PreviewMixin from '../common/PreviewMixin';
 import { getConfig } from '@/utils/auth';
 import { GetFileURLMap } from '@/api/app';
@@ -38,7 +37,6 @@ import { getUploadPreviewData } from '@/views/book/courseware/data/uploadPreview
 
 export default {
   name: 'UploadControlPreview',
-  components: { UploadFile },
   mixins: [PreviewMixin],
   data() {
     return {

+ 0 - 217
src/views/book/courseware/preview/components/upload_preview/components/UploadView.vue

@@ -1,217 +0,0 @@
-<!--  -->
-<template>
-  <div class="upload upload-view-npc">
-    <el-upload
-      :accept="accept"
-      class="upload-demo"
-      :action="url"
-      :on-preview="handlePreview"
-      multiple
-      :before-upload="handlebeforeUplaod"
-      :on-exceed="handleExceed"
-      :on-success="handleSuccess"
-      :on-change="handleChange"
-      :file-list="currentfileList"
-      :show-file-list="showList"
-      :limit="filleNumber"
-      :before-remove="beforeRemove"
-      :on-remove="handleRemove"
-    >
-      <div class="uploadBtn">
-        <img style="width: 24px; height: 24px" src="@/assets/uploadview.png" alt="" />
-        upload
-      </div>
-      <div slot="tip" style="display: block; padding: 0 10px" class="el-upload__tip">
-        {{ uploadTip }}
-      </div>
-    </el-upload>
-    <!-- <div class="zhezhao" v-loading.fullscreen.lock="fullscreenLoading"></div> -->
-  </div>
-</template>
-
-<script>
-import { getToken } from '@/utils/auth';
-export default {
-  components: {},
-  props: [
-    'uploadType',
-    'filleNumber',
-    'datafileList',
-    'changeFillId',
-    'deleteImg',
-    'index',
-    'uiType',
-    'fileList',
-    'accept',
-    'type',
-  ],
-  data() {
-    return {
-      currentfileList: [],
-      fileTypeName: '',
-      loading: false,
-      showList: false,
-      uploadTip:
-        'The size of the uploaded image should not exceed 2MB, the size of the uploaded audio file, pdf file, and excel file should not exceed 20MB, and the size of the uploaded audio file should not exceed 20MB',
-    };
-  },
-  computed: {
-    url() {
-      let userInfor = getToken();
-      let SessionID = '';
-      let UserCode = '';
-      let UserType = '';
-      if (userInfor) {
-        let user = JSON.parse(getToken());
-        UserCode = user.user_code;
-        UserType = user.user_type;
-        SessionID = user.session_id;
-      }
-      return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid`;
-    },
-  },
-  watch: {
-    datafileList: {
-      handler(val, oldVal) {
-        this.initUpload();
-      },
-      // 深度观察监听
-      deep: true,
-    },
-    fileList(newval, oldval) {
-      this.currentfileList = newval || [];
-    },
-  },
-  // 生命周期 - 创建完成(可以访问当前this实例)
-  created() {
-    this.currentfileList = this.fileList || [];
-    // this.showList = this.fileList ? true : false;
-    if (this.type === 'upload_control_preview_chs' || this.type === 'upload_pdf_chs') {
-      this.showList = true;
-    } else {
-      this.showList = false;
-    }
-  },
-  // 生命周期 - 挂载完成(可以访问DOM元素)
-  mounted() {
-    this.initUpload();
-  },
-  beforeCreate() {}, // 生命周期 - 创建之前
-  beforeMount() {}, // 生命周期 - 挂载之前
-  beforeUpdate() {}, // 生命周期 - 更新之前
-  updated() {}, // 生命周期 - 更新之后
-  beforeDestroy() {}, // 生命周期 - 销毁之前
-  destroyed() {}, // 生命周期 - 销毁完成
-  activated() {},
-  // 方法集合
-  methods: {
-    handleChange(file, fileList) {},
-    handleSuccess(response, file, fileList) {
-      if (response.status === 1) {
-        response.duration = response.file_info_list[0].media_duration ? response.file_info_list[0].media_duration : 10;
-        this.$message.success('用户上传成功');
-        this.changeFillId(fileList, response.duration, this.index);
-        this.loading.close();
-      } else {
-        // this.fileList = [];
-        this.$message.warning(response.msg);
-        this.loading.close();
-      }
-    },
-    handlebeforeUplaod(file) {
-      if (file.type.indexOf('image/') !== -1) {
-        if (file.size > 2 * 1024 * 1024) {
-          this.$message.warning('上传图片大小不能超过2M');
-          return false; // 必须返回false
-        }
-      } else if (file.type.indexOf('application/pdf') !== -1) {
-        if (file.size > 20 * 1024 * 1024) {
-          this.$message.warning('上传pdf大小不能超过20M');
-          return false; // 必须返回false
-        }
-      } else if (file.size > 500 * 1024 * 1024) {
-        this.$message.warning('上传文件大小不能超过500M');
-        return false; // 必须返回false
-      }
-
-      this.loading = this.$loading({
-        lock: true,
-        text: 'Loading',
-        spinner: 'el-icon-loading',
-        background: 'rgba(0, 0, 0, 0.7)',
-      });
-    },
-    handleRemove(file, fileList) {
-      this.changeFillId(fileList, '', this.index, this.index2);
-      this.$message.success('移除成功');
-    },
-    beforeRemove(file, fileList) {
-      return this.$confirm(`确定移除 ${file.name}?`);
-    },
-    handlePreview(file) {},
-    handleExceed(files, fileList) {
-      this.$message.warning(
-        `当前限制选择 ${this.filleNumber ? this.filleNumber : 1} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
-          files.length + fileList.length
-        } 个文件`,
-      );
-    },
-    initUpload() {
-      switch (this.accept) {
-        case '.jpg, .jpeg, .png':
-          this.uploadTip = '只能上传.jpg, .jpeg, .png文件,大小不超过2MB';
-          break;
-        case 'audio/*':
-          this.uploadTip = '只能上传音频文件,大小不超过20MB';
-          break;
-        case 'video/*':
-          this.uploadTip = '只能上传视频文件,大小不超过500MB';
-          break;
-        case '.pdf':
-          this.uploadTip = '只能上传pdf文件,大小不超过20MB';
-          break;
-        case '.xls, .xlsx':
-          this.uploadTip = '只能上传excel文件,大小不超过20MB';
-          break;
-        case '.lrc':
-          this.uploadTip = '只能上传lrc文件,大小不超过20MB';
-          break;
-
-        default:
-          this.uploadName = '';
-          break;
-      }
-    },
-  }, // 如果页面有keep-alive缓存功能,这个函数会触发
-};
-</script>
-
-<style lang="scss" scoped>
-.uploadBtn {
-  box-sizing: border-box;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  width: 141px;
-  height: 39px;
-  margin: -20px auto 10px;
-  font-size: 16px;
-  line-height: 150%;
-  color: #000;
-  background: #fff;
-  border: 1px solid rgba(0, 0, 0, 10%);
-  border-radius: 4px;
-  box-shadow: 0 2px 6px rgba(0, 0, 0, 10%);
-
-  img {
-    margin-right: 13px;
-  }
-}
-</style>
-<style lang="scss">
-.upload-view-npc {
-  .el-upload {
-    width: 100%;
-  }
-}
-</style>