Browse Source

保存、编辑、导入等操作加上loading

Michael Wang 4 years ago
parent
commit
915aace216

+ 5 - 0
src/features/Login/Login.vue

@@ -68,6 +68,7 @@
                 class="submit-btn"
                 size="small"
                 @click="submitBtn"
+                :loading="loading"
               >
                 登 录
               </el-button>
@@ -105,6 +106,7 @@ export default {
         password: "",
         errorInfo: "",
       },
+      loading: false,
     };
   },
   async created() {
@@ -116,6 +118,7 @@ export default {
       this.$refs["form"].validate(async (valid) => {
         if (valid) {
           try {
+            this.loading = true;
             await this.$store.dispatch(LOGIN_BY_USERNAME, {
               loginName: this.user.username,
               password: this.user.password,
@@ -133,6 +136,8 @@ export default {
           } catch (error) {
             // console.log(error?.response?.data?.message);
             this.user.errorInfo = error?.response?.data?.message || "";
+          } finally {
+            this.loading = false;
           }
         }
       });

+ 11 - 3
src/features/examwork/ActivityManagement/ActivityEdit.vue

@@ -60,7 +60,9 @@
       </el-form>
     </el-row>
     <el-row class="d-flex justify-content-center">
-      <el-button type="primary" @click="submitForm">保 存</el-button>
+      <el-button type="primary" @click="submitForm" :loading="loading"
+        >保 存</el-button
+      >
       <el-button type="primary" @click="addActivity">新 增</el-button>
       <el-button @click="() => this.$router.back()">取 消</el-button>
     </el-row>
@@ -164,6 +166,7 @@ export default {
       },
       exam: {},
       activity: {},
+      loading: false,
     };
   },
   async created() {
@@ -232,8 +235,13 @@ export default {
         }
       }
 
-      await saveActivities(data);
-      this.$notify({ title: "保存成功", type: "success" });
+      try {
+        this.loading = true;
+        await saveActivities(data);
+        this.$notify({ title: "保存成功", type: "success" });
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 13 - 4
src/features/examwork/ActivityManagement/ActivityManagementDialog.vue

@@ -57,7 +57,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -144,6 +146,7 @@ export default {
         prepareSeconds: [{ required: true, message: "候考时间必填" }],
         openingSeconds: [{ required: true, message: "迟到时长必填" }],
       },
+      loading: false,
     };
   },
   watch: {
@@ -182,9 +185,15 @@ export default {
       if (this.isEdit) {
         data = { ...data, id: this.activity.id };
       }
-      await saveActivity(data);
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await saveActivity(data);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 7 - 1
src/features/examwork/CourseManagement/CoursePaperDialog.vue

@@ -77,7 +77,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading">
+          保 存
+        </el-button>
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -104,6 +106,7 @@ export default {
       rules: {},
       refreshCourse: {},
       papers: [],
+      loading: false,
     };
   },
   watch: {
@@ -143,6 +146,7 @@ export default {
     },
     async submitForm() {
       try {
+        this.loading = true;
         await saveCourse({
           examId: this.refreshCourse.examId,
           courseCode: this.refreshCourse.courseCode,
@@ -165,6 +169,8 @@ export default {
         console.log(error);
         this.initData();
         this.$notify({ title: "保存失败", type: "warning" });
+      } finally {
+        this.loading = false;
       }
     },
   },

+ 13 - 5
src/features/examwork/CourseManagement/PaperImportDialog.vue

@@ -46,7 +46,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -67,6 +69,7 @@ export default {
       visible: false,
       form: {},
       rules: {},
+      loading: false,
     };
   },
   watch: {
@@ -112,10 +115,15 @@ export default {
 
       let data = this.form;
 
-      await importPaper({ ...data, examId: this.examId, md5 });
-      this.$emit("reload");
-      this.$notify({ title: "导入任务已成功启动", type: "success" });
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await importPaper({ ...data, examId: this.examId, md5 });
+        this.$emit("reload");
+        this.$notify({ title: "导入任务已成功启动", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 17 - 8
src/features/examwork/ExamManagement/CopyExamDialog.vue

@@ -33,7 +33,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -55,6 +57,7 @@ export default {
         code: "",
       },
       rules: {},
+      loading: false,
     };
   },
   watch: {
@@ -70,13 +73,19 @@ export default {
       this.visible = false;
     },
     async submitForm() {
-      await copyExam({
-        sourceId: this.exam.id,
-        code: this.form.code,
-        name: this.form.name,
-      });
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await copyExam({
+          sourceId: this.exam.id,
+          code: this.form.code,
+          name: this.form.name,
+        });
+        this.$emit("reload");
+        this.$notify({ title: "复制成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 12 - 4
src/features/examwork/ExamManagement/ExamEdit.vue

@@ -350,7 +350,9 @@
     </el-tabs>
 
     <div class="tab-footer">
-      <el-button type="primary" @click="save">保存</el-button>
+      <el-button type="primary" @click="save" :loading="loading"
+        >保存</el-button
+      >
       <el-button @click="cancel">取消</el-button>
     </div>
   </div>
@@ -482,6 +484,7 @@ export default {
           message: "格式错误",
         },
       },
+      loading: false,
     };
   },
   methods: {
@@ -495,9 +498,14 @@ export default {
         return;
       }
 
-      await saveExam(this.form);
-      this.$notify({ title: "保存成功", type: "success" });
-      this.$router.back();
+      try {
+        this.loading = true;
+        await saveExam(this.form);
+        this.$notify({ title: "保存成功", type: "success" });
+        this.$router.back();
+      } finally {
+        this.loading = false;
+      }
     },
     cancel() {
       this.$router.back();

+ 18 - 10
src/features/examwork/ExamStudentImport/ExamStudentImportDialog.vue

@@ -19,7 +19,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">导入</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >导入</el-button
+        >
         <el-button @click="closeDialog">取消</el-button>
       </el-row>
     </el-form>
@@ -49,6 +51,7 @@ export default {
         fileName: "",
       },
       rules: {},
+      loading: false,
     };
   },
   methods: {
@@ -76,15 +79,20 @@ export default {
       const ab = await blobToArray(this.form.file);
       const md5 = MD5(ab);
 
-      await importExamStudent({
-        examId: this.examId,
-        file: this.form.file,
-        fileName: this.form.fileName,
-        md5,
-      });
-      this.$emit("reload");
-      this.$notify({ title: "导入任务已成功启动", type: "success" });
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await importExamStudent({
+          examId: this.examId,
+          file: this.form.file,
+          fileName: this.form.fileName,
+          md5,
+        });
+        this.$emit("reload");
+        this.$notify({ title: "导入任务已成功启动", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 13 - 4
src/features/examwork/ExamStudentManagement/ExamStudentManagementDialog.vue

@@ -70,7 +70,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -107,6 +109,7 @@ export default {
       rules: {
         courseCode: { required: true, message: "必填" },
       },
+      loading: false,
     };
   },
   watch: {
@@ -147,9 +150,15 @@ export default {
       if (this.isEdit) {
         data = { ...data, id: this.examStudent.id };
       }
-      await saveExamStudent(data);
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await saveExamStudent(data);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 17 - 9
src/features/examwork/InvigilateManagement/InvigilateImportDialog.vue

@@ -19,7 +19,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">导入</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >导入</el-button
+        >
         <el-button @click="closeDialog">取消</el-button>
       </el-row>
     </el-form>
@@ -40,6 +42,7 @@ export default {
         fileName: "",
       },
       rules: {},
+      loading: false,
     };
   },
   methods: {
@@ -67,14 +70,19 @@ export default {
       const ab = await blobToArray(this.form.file);
       const md5 = MD5(ab);
 
-      await importInvigilator({
-        file: this.form.file,
-        fileName: this.form.fileName,
-        md5,
-      });
-      this.$emit("reload");
-      this.$notify({ title: "导入任务已成功启动", type: "success" });
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await importInvigilator({
+          file: this.form.file,
+          fileName: this.form.fileName,
+          md5,
+        });
+        this.$emit("reload");
+        this.$notify({ title: "导入任务已成功启动", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 13 - 4
src/features/examwork/InvigilateManagement/InvigilateManagementDialog.vue

@@ -30,7 +30,9 @@
       </el-row>
 
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -62,6 +64,7 @@ export default {
         userIds: [],
       },
       rules: {},
+      loading: false,
     };
   },
   methods: {
@@ -73,9 +76,15 @@ export default {
     },
     async submitForm() {
       let data = this.form;
-      await saveInvigilator(data);
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await saveInvigilator(data);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 13 - 4
src/features/system/OrgManagement/OrgManagementDialog.vue

@@ -90,7 +90,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -116,6 +118,7 @@ export default {
       visible: false,
       form: {},
       rules: {},
+      loading: false,
     };
   },
   watch: {
@@ -153,9 +156,15 @@ export default {
       if (this.isEdit) {
         data = { ...data, id: this.org.id };
       }
-      await saveOrg(data);
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await saveOrg(data);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 13 - 4
src/features/system/UserManagement/UserManagementDialog.vue

@@ -68,7 +68,9 @@
         </el-form-item>
       </el-row>
       <el-row class="d-flex justify-content-center">
-        <el-button type="primary" @click="submitForm">保 存</el-button>
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >保 存</el-button
+        >
         <el-button @click="closeDialog">取 消</el-button>
       </el-row>
     </el-form>
@@ -95,6 +97,7 @@ export default {
       visible: false,
       form: {},
       rules: {},
+      loading: false,
     };
   },
   watch: {
@@ -126,9 +129,15 @@ export default {
       if (this.isEdit) {
         data = { ...data, id: this.user.id };
       }
-      await saveUser(data);
-      this.$emit("reload");
-      this.closeDialog();
+      try {
+        this.loading = true;
+        await saveUser(data);
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
     },
   },
 };

+ 2 - 2
vue.config.js

@@ -1,11 +1,11 @@
 let proxy = {
   "/api": {
-    target: "http://192.168.10.36:6001/",
+    target: "http://192.168.10.36:8001/",
     // target: "http://192.168.10.86:6001/",
     changeOrigin: true,
   },
   "/file": {
-    target: "http://192.168.10.36:6001/",
+    target: "http://192.168.10.36:8001/",
     // target: "http://192.168.10.86:6001/",
     changeOrigin: true,
   },