Browse Source

修改学生上传

11wqe1 5 hours ago
parent
commit
0f4008e923

+ 45 - 38
src/components/pages/studentManageNew/component/addstu.vue

@@ -573,6 +573,10 @@ export default {
     },
     // 手动输入添加学生
     addStu() {
+      if (this.uploadfileLoading) {
+        this.$message.warning(this.lang.ssUploading);
+        return;
+      }
       this.selectedStuData = this.selectedStuData.filter((item) => item != "");
       if (this.selectedStuData.length == 0) {
         this.$message.error(this.lang.ssEnterStu);
@@ -631,52 +635,55 @@ export default {
         e.mail = e.account;
       });
 
-      const batchSize = 50;
-      if (data1.length > 0) {
-        if (data1.length > batchSize) {
-          // 计算总批次数
-          const totalBatches = Math.ceil(data1.length / batchSize);
-          for (let i = 0; i < totalBatches; i++) {
-            const batch = data1.slice(i * batchSize, (i + 1) * batchSize);
-            await this.uploadBatch(batch); // 假设 uploadBatch 返回 Promise
-            console.log(`普通上传第 ${i + 1} 批上传完成`, batch);
+      try {
+        const batchSize = 50;
+        if (data1.length > 0) {
+          if (data1.length > batchSize) {
+            // 计算总批次数
+            const totalBatches = Math.ceil(data1.length / batchSize);
+            for (let i = 0; i < totalBatches; i++) {
+              const batch = data1.slice(i * batchSize, (i + 1) * batchSize);
+              await this.uploadBatch(batch); // 假设 uploadBatch 返回 Promise
+              console.log(`普通上传第 ${i + 1} 批上传完成`, batch);
+            }
+          } else {
+            // 长度不超过 10,直接上传整个数组
+            await this.uploadBatch(data1);
           }
-        } else {
-          // 长度不超过 10,直接上传整个数组
-          await this.uploadBatch(data1);
         }
-      }
 
-      if (data2.length > 0) {
-        if (data2.length > batchSize) {
-          // 计算总批次数
-          const totalBatches = Math.ceil(data2.length / batchSize);
-          for (let i = 0; i < totalBatches; i++) {
-            const batch = data2.slice(i * batchSize, (i + 1) * batchSize);
-            await this.uploadBatchAccount (batch); // 假设 uploadBatch 返回 Promise
-            console.log(`自定义账号上传第 ${i + 1} 批上传完成`, batch);
+        if (data2.length > 0) {
+          if (data2.length > batchSize) {
+            // 计算总批次数
+            const totalBatches = Math.ceil(data2.length / batchSize);
+            for (let i = 0; i < totalBatches; i++) {
+              const batch = data2.slice(i * batchSize, (i + 1) * batchSize);
+              await this.uploadBatchAccount (batch); // 假设 uploadBatch 返回 Promise
+              console.log(`自定义账号上传第 ${i + 1} 批上传完成`, batch);
+            }
+          } else {
+            // 长度不超过 10,直接上传整个数组
+            await this.uploadBatchAccount (data2);
           }
-        } else {
-          // 长度不超过 10,直接上传整个数组
-          await this.uploadBatchAccount (data2);
         }
-      }
 
 
-      this.$message({
-        message: this.lang.ssAddOk,
-        type: "success",
-      });
-      this.uploadfileLoading = false;
+        this.$message({
+          message: this.lang.ssAddOk,
+          type: "success",
+        });
 
-      this.deltypy = 0;
-      this.popBoxdia= true;
-      // this.addStuVisible = false;
-      console.log('this.selectedStuData',this.selectedStuData);
-      
-      // this.selectedStuData = [];
-      this.$emit("getCascaderData");
-      this.addOp3('1', "", { type: "student_add" }, "success")
+        this.deltypy = 0;
+        this.popBoxdia= true;
+        // this.addStuVisible = false;
+        console.log('this.selectedStuData',this.selectedStuData);
+        
+        // this.selectedStuData = [];
+        this.$emit("getCascaderData");
+        this.addOp3('1', "", { type: "student_add" }, "success")
+      } finally {
+        this.uploadfileLoading = false;
+      }
     },
     async uploadBatch(box){
       return new Promise((resolve, reject) => {

+ 9 - 0
src/components/pages/studentManageNew/component/allClaAddStu.vue

@@ -207,6 +207,7 @@ export default {
       boxLoading: false,
       tableLoading: false,
       editTabloading: false,
+      confirmLoading: false,
       cascaderDataPath: [],
       cascaderData: [],
       searchStuName: "",
@@ -275,6 +276,10 @@ export default {
       this.$emit("closeAllClaAddStu");
     },
     confirmAllClaAddStu() {
+      if (this.confirmLoading) {
+        this.$message.warning(this.lang.ssUploading);
+        return;
+      }
       if (this.selectedStuData.length === 0) {
         this.$message({
           message: this.lang.ssSelectStu,
@@ -283,6 +288,7 @@ export default {
         return;
       }
       console.log("上传学生数据");
+      this.confirmLoading = true;
       const promises2 = this.selectedStuData.map((item) => {
         let box = [...item.classid.split(","), this.classInfo.id];
         box = box.filter((item) => item != "");
@@ -304,6 +310,9 @@ export default {
             type: "error",
           });
           this.addOp3('1', "", { type: "student_move" }, err)
+        })
+        .finally(() => {
+          this.confirmLoading = false;
         });
     },
     moveClassStudentPromise(item, cid) {