Prechádzať zdrojové kódy

Merge branch 'master' of http://60.205.254.193:3000/GCLS/GCLS_Page_Exercise

dusenyao 1 rok pred
rodič
commit
94d0121d91

+ 5 - 0
src/icons/svg/file-3-line.svg

@@ -0,0 +1,5 @@
+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="file-3-line">
+<path id="Vector" d="M14 5.33301V13.9951C14 14.3664 13.7035 14.6663 13.3377 14.6663H2.66227C2.29663 14.6663 2 14.3703 2 14.0051V1.99421C2 1.63655 2.29913 1.33301 2.66814 1.33301H9.99787L14 5.33301ZM12.6667 5.99967H9.33333V2.66634H3.33333V13.333H12.6667V5.99967Z" fill="currentColor"/>
+</g>
+</svg>

+ 18 - 4
src/views/exercise_questions/preview/WritePreview.vue

@@ -26,7 +26,15 @@
     </template>
     <template v-if="isEnable(data.property.is_enable_upload_accessory)">
       <!-- 上传附件 -->
-      <UploadFiles />
+      <UploadFiles
+        :fille-number="999"
+        file-type-name="文件"
+        :upload-type="'*'"
+        :file-id-list="user_answer.accessory_file_id"
+        upload-title="上传附件:"
+        @upload="handleUpload"
+        @deleteFile="handleDelete"
+      />
     </template>
     <template v-if="isEnable(data.property.is_enable_sample_text)">
       <el-divider content-position="center"
@@ -64,9 +72,7 @@ export default {
       },
     };
   },
-  created() {
-    console.log(this.data);
-  },
+  created() {},
   methods: {
     // 清除录音
     deleteWav() {
@@ -78,6 +84,14 @@ export default {
       this.user_answer.voice_file_id = wav;
       this.user_answer.audio_wav_time = time;
     },
+    // 文件上传成功
+    handleUpload(fileId) {
+      this.user_answer.accessory_file_id.push(fileId);
+    },
+    // 删除文件
+    handleDelete(fileId) {
+      this.user_answer.accessory_file_id.splice(this.user_answer.accessory_file_id.indexOf(fileId), 1);
+    },
   },
 };
 </script>

+ 117 - 42
src/views/exercise_questions/preview/components/common/UploadFiles.vue

@@ -1,69 +1,107 @@
 <template>
   <div class="upload-wrapper">
+    <h5 v-if="uploadTitle" class="upload-title">{{ uploadTitle }}</h5>
     <el-upload
       ref="upload"
-      :limit="1"
+      :limit="filleNumber"
       action="no"
-      accept="audio/*"
+      :accept="uploadType"
       :show-file-list="false"
       :before-upload="beforeUpload"
       :http-request="upload"
+      :on-exceed="handleExceed"
     >
       <div class="upload-audio">
-        <SvgIcon icon-class="upload" />
-        <span>上传音频</span>
+        <span>上传{{ fileTypeName }}</span>
       </div>
     </el-upload>
-    <div v-show="file_url.length > 0" class="file-wrapper">
-      <div class="file-name">{{ file_name }}</div>
-      <SvgIcon icon-class="delete" class-name="delete pointer" @click="deleteFile" />
+    <div v-show="file_list_show.length > 0" class="file-wrapper">
+      <div v-for="(item, index) in file_list_show" :key="index" class="file-item">
+        <div class="file-name" @click="handlePreview(item.file_url)">
+          <SvgIcon icon-class="file-3-line" class-name="file-icon" /><span>{{ item.file_name }}</span>
+        </div>
+        <SvgIcon icon-class="delete" class-name="delete pointer" @click="deleteFile(item.file_id)" />
+      </div>
     </div>
+    <el-dialog
+      v-if="resourceFlag"
+      :visible.sync="resourceFlag"
+      :show-close="true"
+      :close-on-click-modal="false"
+      :modal-append-to-body="false"
+      width="1200px"
+      class="file-dialog"
+    >
+      <iframe :src="resourceUrl" width="100%" height="600px"></iframe>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import { fileUpload, GetFileStoreInfo } from '@/api/app';
+const Base64 = require('js-base64').Base64;
+import { getConfig } from '@/utils/auth';
 
 export default {
   name: 'UploadFiles',
   props: {
-    fileId: {
+    fileIdList: {
+      type: Array,
+      default: () => [],
+    },
+    filleNumber: {
+      type: Number,
+      default: 1,
+    },
+    fileTypeName: {
+      type: String,
+      default: '文件',
+    },
+    uploadType: {
+      type: String,
+      default: '*',
+    },
+    uploadTitle: {
       type: String,
       default: '',
     },
   },
   data() {
     return {
+      file_list_show: [],
       file_id: '',
       file_url: '',
       file_name: '',
+      resourceUrl: '', // 资源预览地址
+      resourceFlag: false,
+      file_preview_url: '',
     };
   },
   watch: {
-    fileId: {
+    fileIdList: {
       handler(val) {
-        if (!val) return;
-        GetFileStoreInfo({ file_id: val }).then(({ file_id, file_url, file_name }) => {
-          this.file_id = file_id;
-          this.file_url = file_url;
-          this.file_name = file_name;
+        if (!val.length === 0) return;
+        this.file_list_show = [];
+        val.forEach((item) => {
+          GetFileStoreInfo({ file_id: item }).then(({ file_id, file_url, file_name }) => {
+            let obj = {
+              file_id,
+              file_url,
+              file_name,
+            };
+            this.file_list_show.push(obj);
+          });
         });
       },
       immediate: true,
     },
   },
+  created() {
+    this.file_preview_url = getConfig() ? getConfig().doc_preview_service_address : '';
+  },
   methods: {
     beforeUpload(file) {
-      if (this.file_id.length > 0) {
-        this.$message.warning('只能上传一个音频文件');
-        return false;
-      }
-      const fileName = file.name;
-      const suffix = fileName.slice(fileName.lastIndexOf('.') + 1, fileName.length).toLowerCase();
-      if (!['mp3', 'wav', 'aac', 'm4a'].includes(suffix)) {
-        this.$message.warning('音频格式不正确');
-        return false;
-      }
+      // 可以用来限制文件大小
     },
     upload(file) {
       fileUpload('Mid', file).then(({ file_info_list }) => {
@@ -76,49 +114,86 @@ export default {
         }
       });
     },
-    deleteFile() {
-      this.$confirm('是否删除当前音频文件?', '提示', {
+    deleteFile(id) {
+      this.$confirm('是否删除当前文件?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning',
       })
         .then(() => {
-          this.$emit('deleteFile', this.file_id);
-          this.file_id = '';
-          this.file_url = '';
-          this.file_name = '';
+          this.$emit('deleteFile', id);
           this.$refs.upload.clearFiles();
         })
         .catch(() => {});
     },
+    handleExceed(files, fileList) {
+      this.$message.warning(
+        `当前限制选择 ${this.filleNumber ? this.filleNumber : 1} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
+          files.length + fileList.length
+        } 个文件`,
+      );
+    },
+    // 预览文件
+    handlePreview(url) {
+      let path = `${this.file_preview_url}/onlinePreview?url=${Base64.encode(url)}`;
+      this.resourceUrl = path;
+      this.resourceFlag = true;
+    },
   },
 };
 </script>
 
 <style lang="scss" scoped>
 .upload-wrapper {
-  display: flex;
-  column-gap: 12px;
-  align-items: center;
-  margin-top: 8px;
+  .upload-title {
+    margin: 0;
+    margin-bottom: 8px; // 因为这个title可能没有 所以给了bottom
+    font-size: 14px;
+    font-weight: 400;
+    line-height: 22px;
+    color: #000;
+  }
 
   .upload-audio {
     display: flex;
     column-gap: 12px;
     align-items: center;
-    width: 233px;
-    padding: 4px 12px;
-    background-color: $fill-color;
+    padding: 5px 16px;
+    font-size: 14px;
+    line-height: 22px;
+    color: #fff;
+    background: #165dff;
+    border-radius: 2px;
   }
 
   .file-wrapper {
-    display: flex;
-    column-gap: 12px;
-    align-items: center;
+    .file-item {
+      display: flex;
+      align-items: center;
+      margin-top: 8px;
+    }
 
     .file-name {
-      padding: 4px 12px;
-      background-color: $fill-color;
+      display: flex;
+      align-items: center;
+      width: 360px;
+      padding: 7px 12px;
+      margin-right: 12px;
+      cursor: pointer;
+      background: $main-background-color;
+      border-radius: 2px;
+
+      .file-icon {
+        flex-shrink: 0;
+        width: 16px;
+        height: 16px;
+        margin-right: 12px;
+        color: #000;
+      }
+
+      > span {
+        flex: 1;
+      }
     }
   }
 }