Browse Source

上传控件 及pdf的地方修改 (文件系统何老师修改过再测试)

秦鹏 3 năm trước cách đây
mục cha
commit
0d3dcb1079

+ 3 - 2
src/components/Adult/common/Upload.vue

@@ -43,6 +43,7 @@ export default {
     "index",
     "uiType",
     "handleMp3Base64",
+    "index2"
   ],
   data() {
     return {
@@ -113,7 +114,7 @@ export default {
           : 10;
         this.$message.success("用户上传成功");
 
-        this.changeFillId(fileList, response.duration, this.index);
+        this.changeFillId(fileList, response.duration, this.index,this.index2);
 
         this.loading.close();
       } else {
@@ -145,7 +146,7 @@ export default {
       });
     },
     handleRemove(file, fileList) {
-      this.changeFillId(fileList, "", this.index);
+      this.changeFillId(fileList, "", this.index,this.index2);
       this.$message.success("移除成功");
     },
     beforeRemove(file, fileList) {

+ 29 - 25
src/components/Adult/common/UploadView.vue

@@ -14,6 +14,8 @@
       :file-list="currentfileList"
       :show-file-list="showList"
       :limit="filleNumber"
+      :before-remove="beforeRemove"
+      :on-remove="handleRemove"
     >
       <div class="uploadBtn">
         <img
@@ -92,7 +94,10 @@ export default {
   created() {
     this.currentfileList = this.fileList || [];
     // this.showList = this.fileList ? true : false;
-    if (this.type == "upload_control_preview_chs"||this.type=='upload_pdf_chs') {
+    if (
+      this.type == "upload_control_preview_chs" ||
+      this.type == "upload_pdf_chs"
+    ) {
       this.showList = true;
     } else {
       this.showList = false;
@@ -127,23 +132,23 @@ export default {
       }
     },
     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
-            }
+      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",
@@ -151,14 +156,13 @@ export default {
         background: "rgba(0, 0, 0, 0.7)",
       });
     },
-    // handleRemove(file, fileList) {
-    //   this.changeFillId(fileList);
-    //   this.$message.success("移除成功");
-    // },
-    // handleRemove(file, fileList) {
-    //   this.changeFillId(fileList);
-    //   this.$message.success("移除成功");
-    // },
+    handleRemove(file, fileList) {
+      this.changeFillId(fileList, "", this.index, this.index2);
+      this.$message.success("移除成功");
+    },
+    beforeRemove(file, fileList) {
+      return this.$confirm(`确定移除 ${file.name}?`);
+    },
     beforeRemove(file, fileList) {
       return this.$confirm(`确定移除 ${file.name}?`);
     },

+ 14 - 11
src/components/Adult/inputModules/UploadPdf.vue

@@ -55,31 +55,34 @@ export default {
   activated() {},
   // 方法集合
   methods: {
-    remove() {
-      // this.data = null;
-      // this.curQue.data = null;
-      // this.curQue.fileList = [];
-      // this.$message.success("删除成功");
-    },
+    // remove() {
+    //   this.data = null;
+    //   this.curQue.data = null;
+    //   this.curQue.fileList = [];
+    // },
     changeFillId(fileList, item, index) {
       this.curQue.fileList = JSON.parse(JSON.stringify(fileList));
       if (fileList.length > 0) {
         this.curQue.data = fileList[0]?.response?.file_info_list[0];
-      //   this.curQue.data.fileRelativePath = this.curQue.data.file_relative_path;
-      //   this.getNumPages();
+        //   this.curQue.data.fileRelativePath = this.curQue.data.file_relative_path;
+        //   this.getNumPages();
+      } else {
+        this.curQue.data = null;
       }
     },
     // 获取pdf的页数
     getNumPages() {
       let _this = this;
-      let loadingTask = pdf.createLoadingTask(`${process.env.VUE_APP_PDF}${_this.curQue.data.fileRelativePath}`);
+      let loadingTask = pdf.createLoadingTask(
+        `${process.env.VUE_APP_PDF}${_this.curQue.data.fileRelativePath}`
+      );
       loadingTask.promise
-        .then(pdff => {
+        .then((pdff) => {
           _this.numPages = pdff.numPages;
           _this.curQue.data.numPages = pdff.numPages;
           this.$forceUpdate();
         })
-        .catch(err => {
+        .catch((err) => {
           this.$message.success("pdf 加载失败", err);
           this.data = null;
           this.curQue.data = null;

+ 4 - 1
src/components/Adult/preview/PdfView.vue

@@ -32,6 +32,7 @@
 <script>
 import pdf from "vue-pdf";
 const Base64 = require("js-base64").Base64;
+import { getToken, getConfig } from "../../../utils/auth";
 
 export default {
   // import引入的组件需要注入到对象中才能使用
@@ -49,8 +50,10 @@ export default {
   },
   created() {
     // this.getNumPages();
+    let data = JSON.parse(getConfig());
+    let file_preview_url = data.doc_preview_service_address;
     let path =
-      `http://docpreview.utschool.cn/onlinePreview?url=` +
+      `${file_preview_url}/onlinePreview?url=` +
       Base64.encode(this.curQue.data.file_url);
     this.curQue.data.newpath = path;
   },

+ 6 - 3
src/components/Adult/preview/UploadControlView.vue

@@ -110,7 +110,7 @@
 <script>
 import UploadView from "../common/UploadView.vue";
 import pdf from "vue-pdf";
-import { getToken } from "../../../utils/auth";
+import { getToken, getConfig } from "../../../utils/auth";
 const Base64 = require("js-base64").Base64;
 
 export default {
@@ -139,6 +139,7 @@ export default {
         ],
       },
       loading: false,
+      file_preview_url: "",
     };
   },
   computed: {},
@@ -186,7 +187,7 @@ export default {
       if (this.curQue.Bookanswer.file_name.indexOf("pdf") != -1) {
         this.curQue.Bookanswer = fileList[0].response.file_info_list[0];
         let path =
-          `http://docpreview.utschool.cn/onlinePreview?url=` +
+          `${this.file_preview_url}/onlinePreview?url=` +
           Base64.encode(this.curQue.Bookanswer.file_url);
         this.curQue.Bookanswer.newpath = path;
         // this.curQue.Bookanswer.fileRelativePath =
@@ -221,7 +222,7 @@ export default {
       let single = null;
       if (this.curQue.data) {
         let path =
-          `http://docpreview.utschool.cn/onlinePreview?url=` +
+           `${this.file_preview_url}/onlinePreview?url=` +
           Base64.encode(this.curQue.data.file_url);
         this.curQue.data.newpath = path;
         single = JSON.parse(JSON.stringify(this.curQue.data));
@@ -236,6 +237,8 @@ export default {
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {
+    let data = JSON.parse(getConfig());
+    this.file_preview_url = data.doc_preview_service_address;
     this.handleData();
   },
   //生命周期 - 挂载完成(可以访问DOM元素)