Sfoglia il codice sorgente

离线考试上传附件增加规则校验

chenken 6 anni fa
parent
commit
4c821b4bb5
1 ha cambiato i file con 64 aggiunte e 31 eliminazioni
  1. 64 31
      src/modules/oe/views/examScheduling.vue

+ 64 - 31
src/modules/oe/views/examScheduling.vue

@@ -524,38 +524,71 @@ export default {
       }
     },
     doUploadAnswer() {
-      this.uploadAnswerDialogLoading = true;
-      let config = {
-        headers: { "Content-Type": "multipart/form-data" }
-      };
-      let param = new FormData();
-      param.append("file", this.offlineAnswerFile);
-      param.append("examRecordDataId", this.currentOfflineExamRecordDataId);
+      var index = this.offlineAnswerFile.name.lastIndexOf(".");
+      var fileNameLength = this.offlineAnswerFile.name.length;
+      var fileSuffix = this.offlineAnswerFile.name
+        .substring(index + 1, fileNameLength)
+        .toUpperCase();
       this.$http
-        .post("/api/ecs_oe_student/offlineExam/submitPaper", param, config)
-        .then(() => {
-          this.$notify({
-            title: "提示",
-            message: "上传成功",
-            type: "success",
-            duration: 2000
-          });
-          this.uploadAnswerDialogVisible = false;
-          this.uploadAnswerDialogLoading = false;
-          this.$refs.offlineFileInput.value = "";
-          this.offlineAnswerFile = "";
-          this.search();
-        })
-        .catch(() => {
-          this.$notify({
-            title: "提示",
-            message: "上传失败",
-            type: "error",
-            duration: 2000
-          });
-          this.uploadAnswerDialogLoading = false;
-          this.$refs.offlineFileInput.value = "";
-          this.offlineAnswerFile = "";
+        .get(
+          "/api/ecs_exam_work/exam/property/" +
+            this.form.examId +
+            "/OFFLINE_UPLOAD_FILE_TYPE"
+        )
+        .then(response => {
+          var allowfileSuffixs = response.data;
+          if (!allowfileSuffixs || allowfileSuffixs.length == 0) {
+            this.$notify({
+              title: "提示",
+              message: "当前考试设置不允许上传附件",
+              type: "error",
+              duration: 2000
+            });
+            return false;
+          }
+          if (allowfileSuffixs.toString().indexOf(fileSuffix) < 0) {
+            this.$notify({
+              title: "提示",
+              message:
+                "当前考试允许上传文件格式为:" + allowfileSuffixs.toString(),
+              type: "error",
+              duration: 2000
+            });
+            return false;
+          }
+          this.uploadAnswerDialogLoading = true;
+          let config = {
+            headers: { "Content-Type": "multipart/form-data" }
+          };
+          let param = new FormData();
+          param.append("file", this.offlineAnswerFile);
+          param.append("examRecordDataId", this.currentOfflineExamRecordDataId);
+          this.$http
+            .post("/api/ecs_oe_student/offlineExam/submitPaper", param, config)
+            .then(() => {
+              this.$notify({
+                title: "提示",
+                message: "上传成功",
+                type: "success",
+                duration: 2000
+              });
+              this.uploadAnswerDialogVisible = false;
+              this.uploadAnswerDialogLoading = false;
+              this.$refs.offlineFileInput.value = "";
+              this.offlineAnswerFile = "";
+              this.search();
+            })
+            .catch(() => {
+              this.$notify({
+                title: "提示",
+                message: "上传失败",
+                type: "error",
+                duration: 2000
+              });
+              this.uploadAnswerDialogLoading = false;
+              this.$refs.offlineFileInput.value = "";
+              this.offlineAnswerFile = "";
+            });
         });
     },
     cleanOfflineFile() {