sunjh 6 years ago
parent
commit
d8bdbf4158
3 changed files with 67 additions and 24 deletions
  1. 45 13
      src/components/report/Report.vue
  2. 21 11
      src/components/report/ReportCreate.vue
  3. 1 0
      src/js/api.js

+ 45 - 13
src/components/report/Report.vue

@@ -44,7 +44,7 @@
             v-if="isModifyMode"
             drag
             class="upload-demo"
-            action="https://jsonplaceholder.typicode.com/posts/"
+            action=""
             :on-remove="handleRemove"
             :before-remove="beforeRemove"
             multiple
@@ -52,6 +52,7 @@
             :on-exceed="handleExceed"
             :before-upload="beforeFileUpload"
             :file-list="report.file"
+            :http-request="uploadReportFile"
           >
             <i class="el-icon-upload"></i>
             <div class="el-upload__text">
@@ -61,9 +62,9 @@
             <div class="el-upload__tip" slot="tip">请上传报告文件</div>
           </el-upload>
           <div v-if="!isModifyMode">
-            <span v-if="report.file==null">暂无文件</span>
-            <a :href="report.file" v-if="report.file!=null"><i class="fa fa-file-text-o"></i>
-              {{report.file}}</a>
+            <span v-if="report.fileUrl==null">暂无文件</span>
+            <a :href="report.fileUrl" v-if="report.fileUrl!=null"><i class="fa fa-file-text-o"></i>
+              {{report.fileUrl}}</a>
           </div>
         </el-form-item>
 
@@ -97,16 +98,18 @@ export default {
     return {
       reportId: 0,
       projectId: '',
-      taskId:'',
+      taskId: '',
       isModifyMode: false,
       serviceType: ServiceType,
       report: {
         name: '',
         type: '',
         description: '',
-        content:'',
+        target: '',
+        content: '',
         file: [],
-        conclusion:''
+        fileUrl: '',
+        conclusion: ''
       },
       rules: {
         // name: [
@@ -156,11 +159,11 @@ export default {
         conclusion: this.report.conclusion
       }
       console.log(newReport)
-      if (this.taskId == null){
+      if (this.taskId == null) {
         Http.put(Apis.REPORT.UPDATE_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId), newReport).then((res) => {
           console.log(res)
         })
-      }else {
+      } else {
         Http.put(Apis.REPORT.UPDATE_TASK_REPORT.replace('{projectId}', this.projectId).replace('{taskId}', this.taskId).replace('{reportId}', this.reportId), newReport).then((res) => {
           console.log(res)
         })
@@ -221,17 +224,46 @@ export default {
       console.log(this.taskId)
       console.log(this.reportId)
       console.log('***')
-      if (this.taskId == null){
+      if (this.taskId == null) {
         Http.get(Apis.REPORT.GET_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId)).then((res) => {
           console.log(res)
-          this.report = res.crowdReportVO
+          this.report.name = res.crowdReportVO.name
+          this.report.crowdTestTaskId = res.crowdReportVO.crowdTestTaskId
+          this.report.scope = res.crowdReportVO.scope
+          this.report.type = res.crowdReportVO.type
+          this.report.description = res.crowdReportVO.description
+          this.report.content = res.crowdReportVO.content
+          this.report.fileUrl = res.crowdReportVO.file
+          this.report.conclusion = res.crowdReportVO.conclusion
+          this.report.target = res.crowdReportVO.target
         })
-      }else {
+      } else {
         Http.get(Apis.REPORT.GET_TASK_REPORT.replace('{projectId}', this.projectId).replace('{taskId}', this.taskId).replace('{reportId}', this.reportId)).then((res) => {
           console.log(res)
-          this.report = res.crowdReportVO
+          this.report.name = res.crowdReportVO.name
+          this.report.crowdTestTaskId = res.crowdReportVO.crowdTestTaskId
+          this.report.scope = res.crowdReportVO.scope
+          this.report.type = res.crowdReportVO.type
+          this.report.description = res.crowdReportVO.description
+          this.report.content = res.crowdReportVO.content
+          this.report.fileUrl = res.crowdReportVO.file
+          this.report.conclusion = res.crowdReportVO.conclusion
+          this.report.target = res.crowdReportVO.target
         })
       }
+    },
+    uploadReportFile (param) {
+      const formData = new FormData()
+      let config = {
+        //添加请求头
+        headers: {'Content-Type': 'multipart/form-data'},
+      }
+      formData.append('file', param.file)
+      Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', 3), formData, config).then((res) => {
+        console.log('上传成功')
+        this.report.fileUrl = res.data
+        console.log(res)
+      })
     }
   }
 }

+ 21 - 11
src/components/report/ReportCreate.vue

@@ -23,7 +23,7 @@
                 <span>测试对象</span>
               </el-col>
               <el-col :span="10">
-                <el-input type="textarea" v-model="report.abstract.target"></el-input>
+                <el-input type="textarea" v-model="report.target"></el-input>
               </el-col>
             </el-row>
             <el-row :gutter="2">
@@ -31,7 +31,7 @@
                 <span>测试内容</span>
               </el-col>
               <el-col :span="10">
-                <el-input type="textarea" v-model="report.abstract.content"></el-input>
+                <el-input type="textarea" v-model="report.content"></el-input>
               </el-col>
             </el-row>
           </div>
@@ -48,6 +48,7 @@
             :on-exceed="handleExceed"
             :before-upload="beforeFileUpload"
             :file-list="report.file"
+            :http-request="uploadReportFile"
           >
             <i class="el-icon-upload"></i>
             <div class="el-upload__text">
@@ -88,11 +89,10 @@ export default {
       dependencyCode: '',
       report: {
         name: '',
-        abstract: {
-          target: '',
-          content: ''
-        },
+        target: '',
+        content: '',
         file: [],
+        fileUrl: '',
         type: '',
         conclusion: ''
       },
@@ -138,9 +138,9 @@ export default {
         scope: this.scope,
         type: this.report.type,
         dependencyCode: this.dependencyCode,
-        target: this.report.abstract.target,
-        content: this.report.abstract.content,
-        file: '123.pdf',
+        target: this.report.target,
+        content: this.report.content,
+        file: this.report.fileUrl,
         conclusion: this.report.conclusion
       }
       console.log(newReport)
@@ -197,8 +197,18 @@ export default {
     beforeFileUpload () {
     },
     loadData () {
-      Http.get(Apis.REPORT).then((res) => {
-        this.report = res.report
+    },
+    uploadReportFile (param) {
+      const formData = new FormData()
+      let config = {
+        //添加请求头
+        headers: {'Content-Type': 'multipart/form-data'},
+      }
+      formData.append('file', param.file)
+      Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', 3), formData, config).then((res) => {
+        console.log('上传成功')
+        this.report.fileUrl = res.data
+        console.log(res)
       })
     }
   }

+ 1 - 0
src/js/api.js

@@ -26,6 +26,7 @@ export default {
   FILE: {
     REQUIREMENT_FILE: '/api/files/requirementfile/{userId}/',
     APK: '/api/files/apk/{userId}/',
+    UPLOAD_REPORT_FILE: '/api/files/report/{userId}/',
     UPLOAD_EXCEL: '',
     UPLOAD_IMAGE: '/api/files/image/{userId}/',
   },