Browse Source

前端-页面

armg 1 year ago
parent
commit
6111e13eaf

+ 6 - 6
ruoyi-ui/src/api/invest/pool.js

@@ -23,9 +23,9 @@ export function addPool(data) {
     url: '/invest/pool',
     method: 'post',
     data: data,
-    headers: {
-      'Content-Type': 'multipart/form-data'
-    }
+    // headers: {
+    //   'Content-Type': 'multipart/form-data'
+    // }
   })
 }
 
@@ -35,9 +35,9 @@ export function updatePool(data) {
     url: '/invest/pool',
     method: 'put',
     data: data,
-    headers: {
-      'Content-Type': 'multipart/form-data'
-    }
+    // headers: {
+    //   'Content-Type': 'multipart/form-data'
+    // }
   })
 }
 

+ 9 - 0
ruoyi-ui/src/api/system/file.js

@@ -42,3 +42,12 @@ export function delFile(id) {
     method: 'delete'
   })
 }
+
+// 根据附件业务ID()获取附件详情信息列表
+export function listFileBusinessId(id) {
+  return request({
+    url: '/system/file/listFileBusinessId',
+    method: 'get',
+    params: { fileBusinessId: id }
+  })
+}

+ 0 - 5
ruoyi-ui/src/utils/request.js

@@ -22,11 +22,6 @@ const service = axios.create({
 
 // request拦截器
 service.interceptors.request.use(config => {
-  console.log("------------config=",config)
-  
-  // if(config.headers.post){
-  //   config.headers.post['Content-Type']= config.headers
-  // }
   // 是否需要设置 token
   const isToken = (config.headers || {}).isToken === false
   // 是否需要防止数据重复提交

+ 41 - 82
ruoyi-ui/src/views/invest/components/poolForm.vue

@@ -137,18 +137,19 @@
           placeholder="请输入所属类型"
         />
       </el-form-item>
-      <el-form-item label="附件" prop="tProjectCompany.files">
+      <el-form-item label="附件" prop="listFile">
         <el-upload
-          class="upload-demo"
-          action=""
-          :on-preview="handlePreview"
-          :on-remove="handleRemove"
-          :before-remove="beforeRemove"
-          :on-change="handleChange"
+          ref="upload"
+          class="upload"
           multiple
           :file-list="fileList"
-          :auto-upload="false"
+          :action="uploadFileUrl"
+          :headers="headers"
+          :on-remove="handleRemove"
+          :before-remove="beforeRemove"
+          :on-success="handleUploadSuccess"
         >
+          <!-- :auto-upload="false" -->
           <el-button size="small" type="primary">点击上传</el-button>
         </el-upload>
       </el-form-item>
@@ -268,6 +269,8 @@ import {
   addPool,
   updatePool,
 } from "@/api/invest/pool";
+import { getToken } from "@/utils/auth";
+import { listFileBusinessId } from "@/api/system/file";
 
 export default {
   props: {
@@ -284,6 +287,11 @@ export default {
     return {
       title: "新增项目",
       fileList: [],
+      baseUrl: process.env.VUE_APP_BASE_API,
+      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传文件服务器地址
+      headers: {
+        Authorization: "Bearer " + getToken(),
+      },
       // 表单参数
       form: {
         id: null,
@@ -338,7 +346,7 @@ export default {
         createTime: null,
         updateBy: null,
         updateTime: null,
-        files:null
+        listFile: null,
       },
       // 表单校验
       rules1: {},
@@ -422,66 +430,58 @@ export default {
     };
   },
   mounted() {
-    console.log("------mounted------", this.id);
     if (this.id) {
       this.getPoolDetail(this.id);
+      this.getListFileBusinessId(this.id);
     } else {
       this.reset();
     }
   },
   methods: {
+    // 根据附件业务ID()获取附件详情信息列表
+    getListFileBusinessId(id) {
+      listFileBusinessId(id).then((response) => {
+        if (response.data.length > 0) {
+          let list = response.data;
+          for (let i in list) {
+            list[i].name = list[i].newUploadName;
+          }
+          this.fileList = list;
+        }
+      });
+    },
     getPoolDetail(id) {
       getPool(id).then((response) => {
         this.form = response.data;
-        if (this.form.files ) {
-          this.fileList = this.form.files;
-        }
       });
     },
     handleRemove(file, fileList) {
-      console.log(file, fileList);
-    },
-    handlePreview(file) {
-      console.log(file);
+      this.fileList = fileList;
     },
     beforeRemove(file, fileList) {
       return this.$confirm(`确定移除 ${file.name}?`);
     },
-    handleChange(file, fileList) {
-      this.fileList = fileList;
+    handleUploadSuccess(res, file) {
+      if (res.file) {
+        res.file.name = res.file.newUploadName;
+        this.fileList.push(res.file);
+      }
     },
     /** 提交按钮 */
     submitForm() {
       let that = this;
       this.$refs["form"].validate((valid, rules) => {
         if (valid) {
-          // this.form.tProjectCompany.files = this.fileList;
-          // const formData = new FormData();
-          // Object.keys(that.form).map((key) => {
-          //   formData.append(key, that.form[key]);
-          // });
-
-          //使用
-          var r = this.JsonToFormData("", this.form, null);
-          this.fileList.forEach((item) => {
-            //文件信息中raw才是真的文件
-            r.append("files", item.raw);
-            //console.log(item.raw)
-          });
-          //打印转换后的结果
-          for (var [key, value] of r) {
-            console.log("=====", key, value);
-          }
-          // console.log(formData);
+          this.form.listFile = this.fileList;
           if (this.form.id != null) {
-            updatePool(r).then((response) => {
+            updatePool(this.form).then((response) => {
               this.$modal.msgSuccess("修改成功");
               setTimeout(() => {
                 that.goBack();
               }, 1500);
             });
           } else {
-            addPool(r).then((response) => {
+            addPool(this.form).then((response) => {
               this.$modal.msgSuccess("新增成功");
               setTimeout(() => {
                 that.goBack();
@@ -564,51 +564,10 @@ export default {
         createTime: null,
         updateBy: null,
         updateTime: null,
-        files:null
+        listFile: null,
       };
       this.resetForm("form");
-    },
-    /*
- 复杂json转为FormData
- parent:key值,data:数据值,form:FormData实例
- 使用:JsonToFormData("", a, null);
- */
-    JsonToFormData(parent, data, form) {
-      form = form || new FormData();
-      //循环传入的值转换formData
-      let index = 0;
-      Object.keys(data).forEach((key) => {
-        let val = data[key];
-        // console.log(key, typeof val, val.length);
-        if (val == null) {
-          let pk = parent ? `${parent}[${key}]` : key;
-          form.append(pk, this.NVL(val, ""));
-        } else if (typeof val === "object") {
-          if (val.length == 0) {
-          } else if (val.length >= 1) {
-            //数组
-            let pk = parent ? `${parent}[${index}][${key}]` : key;
-            this.JsonToFormData(pk, val, form);
-          } else {
-            //纯对象
-            let pk = parent ? `${parent}[${key}]` : key;
-            this.JsonToFormData(pk, val, form);
-          }
-        } else {
-          let pk = parent ? `${parent}[${key}]` : key;
-          form.append(pk, this.NVL(val, ""));
-        }
-        index++;
-      });
-      if (parent == "") return form;
-    },
-    NVL(obj, newValue) {
-      return obj === null || obj === undefined
-        ? newValue
-          ? newValue
-          : ""
-        : obj;
-    },
+    }
   },
 };
 </script>