Pārlūkot izejas kodu

剔除无效导入组件,手动指向导入接口

luojun 2 gadi atpakaļ
vecāks
revīzija
f813b274d2
1 mainītis faili ar 42 papildinājumiem un 2 dzēšanām
  1. 42 2
      src/views/system/user/index.vue

+ 42 - 2
src/views/system/user/index.vue

@@ -503,6 +503,7 @@
         :on-progress="handleFileUploadProgress"
         :on-success="handleFileSuccess"
         :auto-upload="false"
+        :before-upload="beforeUpload"
         drag
       >
         <i class="el-icon-upload"></i>
@@ -548,6 +549,7 @@ import { deptTreeSelect } from "@/api/system/public";
 import tableList from "@/mixins/tableList";
 import { getInfo } from "@/api/login";
 import { getRoles } from "@/api/system/public";
+import request from "@/utils/request";
 export default {
   name: "User",
   dicts: [
@@ -798,7 +800,7 @@ export default {
     },
     /** 重置按钮操作 */
     resetQuery() {
-      this.queryParams.roleId=null;
+      this.queryParams.roleId = null;
       this.resetForm("queryForm");
       this.queryParams.onlyManager = false;
       this.handleQuery();
@@ -1006,7 +1008,7 @@ export default {
       this.download(
         "system/user/export",
         {
-          template:true,
+          template: true,
         },
         `人员信息管理-模板文件.xlsx`
       );
@@ -1036,6 +1038,8 @@ export default {
     // 文件上传中处理
     handleFileUploadProgress(event, file, fileList) {
       this.upload.isUploading = true;
+      console.log(file, "file");
+      console.log(fileList, "fileList");
     },
     // 文件上传成功处理
     handleFileSuccess(response, file, fileList) {
@@ -1051,8 +1055,44 @@ export default {
       );
       this.getList();
     },
+    beforeUpload(file) {
+      // file 为上传的文件对象
+      console.log(file, "file");
+      // 返回 false 可以阻止文件上传
+      // 创建 FormData 对象
+      const formData = new FormData();
+      // 添加文件到 FormData
+      formData.append("file", file);
+      request
+        .post("/system/user/importData", formData, {
+          headers: {
+            "Content-Type": "multipart/form-data",
+          },
+        })
+        .then((response) => {
+          // 在接收到后端响应时执行的逻辑
+          // console.log(response,"response");
+          this.upload.open = false;
+          this.upload.isUploading = false;
+          this.$refs.upload.clearFiles();
+          this.$alert(
+            "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
+              response.msg +
+              "</div>",
+            "导入结果",
+            { dangerouslyUseHTMLString: true }
+          );
+          this.getList();
+        })
+        .catch((error) => {
+          // 在请求失败时执行的逻辑
+          // console.log(error,"error");
+        });
+      return false;
+    },
     // 提交上传文件
     submitFileForm() {
+      // console.log(this.$refs.upload.getFile(),"this.$refs.upload")
       this.$refs.upload.submit();
     },
   },