Bläddra i källkod

报告配置报表配置增加文件上传功能

Bella 2 år sedan
förälder
incheckning
e66e37f527

+ 3 - 2
src/api/data/template.js

@@ -32,6 +32,7 @@ const addReportTemplate = (options) => {
     params.append("template_format", options.templateFormat);
   options.introduction !== "" &&
     params.append("introduction", options.introduction);
+  options.file !=="" && params.append("template_file",options.file)
   if (options.templateType === 1 && options.reportType !== "") {
     params.append("report_type", options.reportType);
   }
@@ -85,8 +86,8 @@ const modifySingleTemplate = (options) => {
     params.append("template_format", options.templateFormat);
   options.introduction !== "" &&
     params.append("introduction", options.introduction);
-  // options.file !== "" &&
-  // params.append("template_file", options.file);
+  options.file !== "" &&
+  params.append("template_file", options.file);
   if (options.templateType === 1 && options.reportType !== "") {
     params.append("report_type", options.reportType);
   }

+ 7 - 5
src/views/dataManagement/reportConfig.vue

@@ -76,8 +76,8 @@
               size="mini"
               type="text"
               style="color: #2ea8e6"
-              @click="downloadTemplate(scope.row.templateUrl)"
-              ><a :href="scope.row.templateUrl" download>点击下载</a></el-button
+              @click="downloadTemplate(scope.row.template)"
+              >点击下载</el-button
             >
             <el-button
               v-show="scope.row.templateName == null ? false : true"
@@ -202,8 +202,8 @@ export default {
       if (!value) return true;
       return data.label.indexOf(value) !== -1;
     },
-    downloadTemplate(url) {
-      console.log(url, "url");
+    downloadTemplate(data) {
+      console.log(data, "template");
     },
     getTableData(val) {
       this.tableData = [];
@@ -226,7 +226,7 @@ export default {
               createUser: v.creator,
               createTime: v.create_time,
               alterTime: v.update_time,
-              templateUrl: v.template_url,
+              template: v.template,
               introduction: v.introduction,
             };
           });
@@ -301,6 +301,7 @@ export default {
           introduction: data.introduction,
           reportType: data.reportType,
           templateType: 1,
+          file:data.file
         };
         addReportTemplate(options).then((res) => {
           if (res.data.code === -1) {
@@ -321,6 +322,7 @@ export default {
           introduction: data.introduction,
           reportType: data.reportType,
           templateType: 1,
+          file:data.file
         };
         modifySingleTemplate(options).then((res) => {
           if (res.data.code === -1) {

+ 8 - 4
src/views/dataManagement/statementConfig.vue

@@ -66,7 +66,8 @@
               size="mini"
               type="text"
               style="color: #2ea8e6"
-              >查看</el-button
+              @click="downloadTemplate(scope.row.template)"
+              >点击下载</el-button
             >
             <el-button
               v-show="scope.row.templateName == null ? false : true"
@@ -187,15 +188,16 @@ export default {
               createUser: v.creator,
               createTime: v.create_time,
               alterTime: v.update_time,
-              templateUrl: v.template_url,
+              template: v.template,
               introduction: v.introduction,
             };
           });
         }
       });
     },
-    downloadTemplate(url) {
-      console.log(url);
+    downloadTemplate(data) {
+      // 调用下载接口
+      console.log(data);
     },
     handleSizeChange(val) {
       this.currentPageSize = val;
@@ -266,6 +268,7 @@ export default {
           templateFormat: data.format,
           introduction: data.introduction,
           templateType: 0,
+          file:data.file
         };
         addReportTemplate(options).then((res) => {
           if (res.data.code === -1) {
@@ -285,6 +288,7 @@ export default {
           templateFormat: data.format,
           introduction: data.introduction,
           templateType: 0,
+          file:data.file
         };
         modifySingleTemplate(options).then((res) => {
           if (res.data.code === -1) {

+ 18 - 5
src/views/dataManagement/templatePopup.vue

@@ -5,6 +5,7 @@
     :visible.sync="dialogVisible"
     width="500px"
     height="60%"
+    :before-close="handleClose"
     center
   >
     <div class="dialog-container">
@@ -61,12 +62,14 @@
             action="https://jsonplaceholder.typicode.com/posts/"
             :on-success="handleSuccess"
             :before-upload="beforeUpload"
+            :on-remove="handleRemove"
             :accept="'.doc,.docx,.xls,.xlsx,.pdf'"
+            :file-list="fileList"
           >
             <el-button slot="trigger"
               ><i class="el-icon-upload"></i> 请将文件拖拽或点击上传</el-button
             >
-            <div slot="tip" class="el-upload__tip" style="width: 220px">
+            <div slot="tip" class="el-upload__tip" style="width: 265px;line-height:20px;">
               仅支持 .doc / .docx / .xls / .xlsx / .pdf 格式的文件
             </div>
           </el-upload>
@@ -97,6 +100,7 @@ export default {
   },
   data() {
     return {
+      fileList:[],
       dialogVisible: false,
       formData: {
         name: "",
@@ -105,6 +109,7 @@ export default {
         id: "",
         reportType: "",
         templateType: 0,
+        file: "",
       },
       temFormatOptions: [
         {
@@ -146,10 +151,16 @@ export default {
       this.formData.format = "Excel";
       this.formData.introduction = "";
       this.formData.reportType = "";
+      this.formData.file = "";
+      this.fileList=[]
     },
     searchEvent() {
       this.$emit("confirmEvent", this.formData);
     },
+    handleClose(){
+      this.fileList=[]
+      this.dialogVisible = false
+    },
     beforeUpload(file) {
       const isAllowedSize = file.size / 1024 / 1024 < 10; // 限制文件大小小于10MB
       const isAllowedType = [".doc", ".docx", ".xls", ".xlsx", ".pdf"].includes(
@@ -167,10 +178,12 @@ export default {
       }
       return true;
     },
+    handleRemove(file,fileList){
+      this.fileList=[]
+    },
     handleSuccess(response, file, fileList) {
-      console.log(response); // 上传成功后返回的数据
-      console.log(file); // 上传的文件信息
-      console.log(fileList); // 上传的所有文件信息
+      this.formData.file = file.raw;
+      this.fileList.push(file)
     },
   },
 };
@@ -212,7 +225,7 @@ export default {
       height: 60px;
     }
     &-upload {
-      height: 100px;
+      height: 95px;
     }
     &-bottom {
       margin: 0 auto;