瀏覽代碼

任务管理文件上传功能修改

ysc 1 年之前
父節點
當前提交
8a28960879

+ 2 - 0
src/api/file/file.js

@@ -2,6 +2,8 @@ import request from '@/utils/request'
 
 let domain = 'http://localhost:10050';
 
+// let domain = 'http://oa.aivfo.com:36000';
+
 /**
  * 上传文件
  * @param data

+ 20 - 21
src/components/FileUpload/index.vue

@@ -1,13 +1,14 @@
 <template>
   <div>
     <el-upload
-        ref="upload"
-        :action="fileAction"
-        :file-list="fileList"
-        :on-remove="handleRemove"
-        :on-success="handleSuccess"
-        :on-error="handleError"
-        name="file">
+      ref="upload"
+      :headers="headers"
+      :action="fileAction"
+      :file-list="fileList"
+      :on-remove="handleRemove"
+      :on-success="handleSuccess"
+      :on-error="handleError"
+      name="file">
       <el-button slot="trigger" size="mini" type="primary">选取文件</el-button>
     </el-upload>
   </div>
@@ -15,7 +16,8 @@
 </template>
 
 <script>
-import {uploadFileUrl, deleteFile} from "@/api/file/file";
+import {uploadFileUrl, uploadFile, deleteFile} from "@/api/file/file";
+import {getToken} from "@/utils/auth";
 
 export default {
   name: "index",
@@ -28,12 +30,7 @@ export default {
   watch: {
     files: {
       handler(newVal, oldVal) {
-
-        this.fileList = newVal.map(item => {
-          item['name'] = item.fileName.replace('<br/>', '')
-          return item;
-        })
-
+        this.fileList = newVal
       },
       deep: true,
       immediate: true
@@ -41,29 +38,31 @@ export default {
   },
   data() {
     return {
+      headers: {},
       fileAction: '',
       fileList: []
     }
   },
   created() {
     this.fileAction = uploadFileUrl()
+    this.headers = {
+      Satoken: getToken()
+    }
   },
   methods: {
     handleRemove(file, fileList) {
-      let url = file.response.data.url;
-      deleteFile(url).then(res => {
-        this.fileList = this.fileList.filter(item => item != url);
+      this.fileList = fileList
+      deleteFile(file.url).then(res => {
         this.$message({
           message: '操作成功!',
           type: 'success'
         });
       });
-      this.$emit('removeFile', url)
+      this.$emit('removeFile', fileList)
     },
     handleSuccess(response, file, fileList) {
-      let fileUrl = response.data.url
-      this.fileList.push(fileUrl)
-      this.$emit('getFileUrl', fileUrl)
+      this.fileList = fileList
+      this.$emit('getFileUrl', fileList)
     },
     handleError() {
       this.$message({

+ 5 - 7
src/views/task/components/taskDetail.vue

@@ -31,7 +31,7 @@
       <el-form-item label="附件:">
         <div v-for="(file,index) in form.fileList">
           <a :href="file.url" style="color: darkgreen">
-            <span v-html="file.fileName"></span>
+            <span style="margin-left: 5px">{{ file.name }}</span>
           </a>
         </div>
       </el-form-item>
@@ -56,14 +56,12 @@
       <el-table-column width="70" property="hours" label="工时(h)"></el-table-column>
       <el-table-column label="反馈备注">
         <template slot-scope="scope">
-          <div>
-            <div>{{ scope.row.description }}</div>
-            <span v-for="(file,index) in scope.row.fileList">
+          <span>{{ scope.row.description }}</span>
+          <span v-for="(file,index) in scope.row.fileList">
               <a :href="file.url" style="color: darkgreen">
-                <span v-html="file.fileName"></span>
+                <span style="margin-left: 5px">{{ file.name }}</span>
               </a>
-            </span>
-          </div>
+          </span>
         </template>
       </el-table-column>
       <el-table-column label="反馈详情" width="80px">

+ 9 - 9
src/views/task/projectView.vue

@@ -100,12 +100,12 @@
               <el-table-column label="反馈备注">
                 <template slot-scope="scope">
                   <div>
-                    <span v-html="scope.row.description"></span>
+                    <span style="margin-right: 5px">{{ scope.row.description }}</span>
                     <span v-for="(file,index) in scope.row.fileList">
-                                <a :href="file.url" style="color: darkgreen">
-                                  <span v-html="file.fileName"></span>
-                                </a>
-                              </span>
+                      <a :href="file.url" style="color: darkgreen">
+                                  <span style="margin-left: 5px">{{ file.name }}</span>
+                      </a>
+                    </span>
                   </div>
                 </template>
               </el-table-column>
@@ -354,17 +354,17 @@ export default {
       this.resetForm("form");
     },
     getFileUrl(val) {
-      this.form['files'] = this.form.files || []
-      this.form.files.push(val)
+      this.form['files'] = val
     },
     removeFile(val) {
-      this.form.files.splice(val)
+      this.form.files = val
     },
     /** 提交按钮 */
     submitForm() {
       this.$refs["form"].validate(valid => {
         if (valid) {
-          this.form.fileUrl = JSON.stringify(this.form.files)
+          let files = this.form.files.map(item => item.name);
+          this.form.fileUrl = JSON.stringify(files)
           addTaskFeedback(this.form).then(res => {
             this.$message.success("反馈成功");
             this.open = false;

+ 35 - 23
src/views/task/task.vue

@@ -327,7 +327,6 @@ import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import RichTextEditor from '@/components/RichTextEditor'
 import {mapGetters} from "vuex";
-import DateUtil from "@/utils/date"
 
 const statusMap = {
   '0': {name: '待查看', type: 'info'},
@@ -527,12 +526,16 @@ export default {
       this.title = "修改任务";
       let arr = []
       arr.push(getTask(row.id).then(res => {
-        this.form = res.data;
-        this.form['files'] = this.form.files || []
-        if (this.form.fileList.length > 0) {
-          this.form.files = this.form.fileList.map(item => item.url.replace('http://file.aivfo.com:36000/', ''))
+          this.form = res.data;
+          this.form['files'] = this.form.files || []
+          this.form.files = this.form.fileList
+          if (this.form.fileList.length > 0) {
+            this.form.files = this.form.fileList.map(item => {
+              return {name: item.name, url: item.fileUrl}
+            })
+          }
         }
-      }))
+      ))
       arr.push(listProject().then(response => {
         this.projectOptions = this.handleTree(response.data, "id");
       }))
@@ -550,18 +553,16 @@ export default {
       }
     },
     getFileUrl(val) {
-      this.form['files'] = this.form.files || []
-      this.form.files.push(val)
+      this.form.files = val
     },
     removeFile(val) {
-      this.form.files.splice(val)
+      this.form.files = val
     },
     getChildFileUrl(child, val) {
-      child['files'] = child.files || []
-      child.files.push(val)
+      child['files'] = val
     },
     removeChildFile(child, val) {
-      child.files.splice(val)
+      child['files'] = val
     },
     /** 更多操作触发 */
     handleCommand(command, row) {
@@ -612,7 +613,8 @@ export default {
         if (valid) {
           this.form.beginDate = this.form.rangeDate[0]
           this.form.endDate = this.form.rangeDate[1]
-          this.form.fileUrl = JSON.stringify(this.form.files)
+          let tempFiles = this.form.files.map(item => item.name);
+          this.form.fileUrl = JSON.stringify(tempFiles)
           this.form.checkTaskConflict = true;
           if (!this.form.id) {
             addTask(this.form).then(res => {
@@ -658,7 +660,8 @@ export default {
           this.$message.success("操作成功");
         })
       }
-    },
+    }
+    ,
     cancelConfirm() {
       this.open = false;
       this.splitOpen = false;
@@ -669,7 +672,8 @@ export default {
         dutSplit[key].clearText()
       }
       this.resetForm("splitForm");
-    },
+    }
+    ,
 
     /** 审核提交按钮 */
     submitAudit() {
@@ -683,7 +687,8 @@ export default {
           })
         }
       });
-    },
+    }
+    ,
     /** 分解任务提交按钮 */
     submitSplit() {
       if (this.splitForm.children.length === 0) {
@@ -702,7 +707,8 @@ export default {
         return
       }
       this.splitForm.children.forEach(c => {
-        c.fileUrl = JSON.stringify(c.files)
+        let files = c.files.map(item => item.name);
+        c.fileUrl = JSON.stringify(files)
       })
       this.splitForm.checkTaskConflict = true;
       splitTask(this.splitForm).then(res => {
@@ -717,7 +723,8 @@ export default {
         }
       })
 
-    },
+    }
+    ,
 
     /** 终止按钮操作 */
     handleUpdate(row) {
@@ -728,7 +735,8 @@ export default {
         this.$message.success("终止成功");
       }).catch(() => {
       });
-    },
+    }
+    ,
     /** 删除按钮操作 */
     handleDelete(row) {
       this.$confirm('是否确认删除任务编号为"' + row.id + '"的数据项?').then(() => {
@@ -738,7 +746,8 @@ export default {
         this.$message.success("删除成功");
       }).catch(() => {
       });
-    },
+    }
+    ,
 
     addChild() {
       let child = {
@@ -749,12 +758,15 @@ export default {
         description: undefined
       }
       this.splitForm.children.push(child)
-    },
+    }
+    ,
     delChild(index) {
       this.splitForm.children.splice(index, 1)
-    },
+    }
+    ,
   }
-};
+}
+;
 </script>
 <style scoped lang="scss">
 .split-form {

+ 5 - 6
src/views/task/view.vue

@@ -100,10 +100,9 @@
                     <span>{{ item.row.description }}</span>
                     <span v-for="(file,index) in item.row.fileList">
                                 <a :href="file.url" style="color: darkgreen">
-                                  <span v-html="file.fileName"></span>
+                                  <span style="margin-left: 5px">{{ file.name }}</span>
                                 </a>
                     </span>
-
                   </div>
                 </template>
               </el-table-column>
@@ -428,17 +427,17 @@ export default {
       this.resetForm("form");
     },
     getFileUrl(val) {
-      this.form['files'] = this.form.files || []
-      this.form.files.push(val)
+      this.form.files = val
     },
     removeFile(val) {
-      this.form.files.splice(val)
+      this.form.files = val
     },
     /** 提交按钮 */
     submitForm() {
       this.$refs["form"].validate(valid => {
         if (valid) {
-          this.form.fileUrl = JSON.stringify(this.form.files)
+          let files = this.form.files.map(item => item.name);
+          this.form.fileUrl = JSON.stringify(files)
           addTaskFeedback(this.form).then(res => {
             this.$message.success("反馈成功");
             this.open = false;