소스 검색

答题纸模板上传

qinchao 4 년 전
부모
커밋
d3b44fa9ce
1개의 변경된 파일145개의 추가작업 그리고 0개의 파일을 삭제
  1. 145 0
      src/modules/basic/view/clientConfig.vue

+ 145 - 0
src/modules/basic/view/clientConfig.vue

@@ -248,6 +248,45 @@
                 />
               </div>
             </el-form-item>
+            <el-form-item label="离线答题纸模板" prop="ANSWERS_TEMPLATE">
+              <el-upload
+                ref="uploadAnswer"
+                class="upload-width"
+                accept=".zip"
+                :action="uploadAnswer"
+                :headers="uploadHeaders"
+                :data="uploadData"
+                :before-upload="beforeUploadAnswer"
+                :on-progress="uploadProgress"
+                :on-success="uploadAnswerSuccess"
+                :on-error="uploadError"
+                :on-remove="handleAnswerRemove"
+                :file-list="answerFileList"
+                :auto-upload="false"
+                :multiple="false"
+                :limit="1"
+                :on-exceed="handleAnswerExceed"
+                list-type="zip"
+              >
+                <el-button slot="trigger" size="small" type="primary"
+                  >选择文件</el-button
+                >&nbsp;
+                <el-button
+                  size="small"
+                  type="success"
+                  @click="submitUploadAnswer"
+                  >确认上传</el-button
+                >
+                <el-button size="small" type="danger" @click="removeAnswerFile"
+                  >清空文件</el-button
+                >
+                <div slot="tip" class="el-upload__tip">上传的格式为ZIP格式</div>
+              </el-upload>
+              <el-input
+                v-show="false"
+                v-model="ruleForm.ANSWERS_TEMPLATE"
+              ></el-input>
+            </el-form-item>
           </el-tab-pane>
         </el-tabs>
       </el-form>
@@ -403,6 +442,7 @@ export default {
         orgId: null,
         OE_STUDENT_SYS_NAME: "",
         LOGO_FILE_URL: "",
+        ANSWERS_TEMPLATE: "",
         LOGIN_TYPE: "",
         PREVENT_CHEATING_CONFIG: "",
         STUDENT_CLIENT_VERSION: "",
@@ -416,6 +456,7 @@ export default {
         properties: {
           OE_STUDENT_SYS_NAME: "",
           LOGO_FILE_URL: "",
+          ANSWERS_TEMPLATE: "",
           LOGIN_TYPE: "",
           PREVENT_CHEATING_CONFIG: "",
           STUDENT_CLIENT_VERSION: "",
@@ -434,6 +475,7 @@ export default {
       },
       logoDialog: false,
       uploadAction: "",
+      uploadAnswer: "",
       uploadHeaders: {},
       uploadData: {},
       fileList: [],
@@ -543,6 +585,7 @@ export default {
       uploadMenuLogoHeaders: {},
       uploadMenuLogoData: {},
       menuLogoFileList: [],
+      answerFileList: [],
       originalCusMenuForm: {},
       cusMenuTreeDialog: {
         show: false,
@@ -643,6 +686,8 @@ export default {
               this.originalRuleForm.IDENTITY_NUMBER_LOGIN_ALIAS &&
             newForm.IS_CUSTOM_MENU_LOGO ==
               this.originalRuleForm.IS_CUSTOM_MENU_LOGO &&
+            newForm.ANSWERS_TEMPLATE ==
+              this.originalRuleForm.ANSWERS_TEMPLATE &&
             newForm.CUS_MENU_LOGO_FILE_URL ==
               this.originalRuleForm.CUS_MENU_LOGO_FILE_URL
           );
@@ -804,6 +849,8 @@ export default {
 
     async initForm() {
       this.uploadAction = CORE_API + "/org/importLogo/" + this.ruleForm.orgId;
+      this.uploadAnswer =
+        CORE_API + "/org/importAnswers/" + this.ruleForm.orgId;
       this.ruleForm.STUDENT_CLIENT_DEFAULT_SIZE = "1400*900";
       this.ruleForm.relatedPropertyGroupIdList = ["studentClientConfig"];
 
@@ -817,6 +864,12 @@ export default {
       }
       console.log(file);
     },
+    beforeUploadAnswer(file) {
+      if (!this.checkUploadAnswer()) {
+        return false;
+      }
+      console.log(file);
+    },
     uploadProgress() {
       console.log("uploadProgress");
     },
@@ -838,6 +891,24 @@ export default {
       this.logoDialog = false;
       // this.removeFile();
     },
+    uploadAnswerSuccess(response) {
+      console.log("uploadSuccess");
+      console.log(response);
+      if (response && response.length > 0) {
+        this.$notify({
+          message: "上传成功",
+          type: "success",
+        });
+        let fileUrl = response;
+
+        this.ruleForm.ANSWERS_TEMPLATE = this.ruleForm.properties.ANSWERS_TEMPLATE = fileUrl;
+      } else {
+        this.errDialog = true;
+      }
+      this.fileLoading = false;
+      this.logoDialog = false;
+      // this.removeFile();
+    },
     uploadError(response) {
       let json = JSON.parse(response.message);
       if (response.status == 500) {
@@ -949,6 +1020,9 @@ export default {
           this.ruleForm.LOGO_FILE_URL =
             this.ruleForm.properties.LOGO_FILE_URL ||
             this.ruleForm.LOGO_FILE_URL;
+          this.ruleForm.ANSWERS_TEMPLATE =
+            this.ruleForm.properties.ANSWERS_TEMPLATE ||
+            this.ruleForm.ANSWERS_TEMPLATE;
           this.ruleForm.LOGIN_TYPE =
             this.ruleForm.properties.LOGIN_TYPE || this.ruleForm.LOGIN_TYPE;
           this.ruleForm.LOGIN_SUPPORT =
@@ -1025,6 +1099,7 @@ export default {
             this.ruleForm.studentClientVersion = defaultValue;
             // console.log(defaultValue);
           }
+
           let fileUrl = response.data.LOGO_FILE_URL;
           let fname = "";
           if (fileUrl) {
@@ -1036,6 +1111,19 @@ export default {
             this.fileList = [];
           }
 
+          let answersUrl = response.data.ANSWERS_TEMPLATE;
+          let answersName = "";
+          if (answersUrl) {
+            let lastIndex = answersUrl.lastIndexOf("/");
+            let len = answersUrl.length;
+            answersName = answersUrl.substr(lastIndex + 1, len - lastIndex);
+            this.answerFileList = [
+              { name: answersName, url: this.ruleForm.ANSWERS_TEMPLATE },
+            ];
+          } else {
+            this.answerFileList = [];
+          }
+
           this.uploadMenuLogoAction =
             CORE_API + "/org/importCusMenuLogo/" + this.ruleForm.orgId;
 
@@ -1205,6 +1293,63 @@ export default {
       }
       this.fileLoading = false;
     },
+    //确定上传
+    submitUploadAnswer() {
+      if (!this.checkUploadAnswer()) {
+        return false;
+      }
+      this.$refs.uploadAnswer.submit();
+      this.fileLoading = true;
+    },
+    checkUploadAnswer() {
+      let fileList = this.$refs.uploadAnswer.uploadFiles;
+      if (fileList.length == 0) {
+        this.$notify({
+          message: "上传文件不能为空",
+          type: "error",
+        });
+        return false;
+      }
+      if (fileList.length > 1) {
+        this.$notify({
+          message: "每次只能上传一个文件",
+          type: "error",
+        });
+        return false;
+      }
+      for (let file of fileList) {
+        let fileName = file.name;
+        if (!fileName.endsWith(".zip")) {
+          this.$notify({
+            message: "上传文件格式必须为[zip]",
+            type: "error",
+          });
+          this.menuLogoFileList = [];
+          return false;
+        }
+      }
+      return true;
+    },
+    //清空文件
+    removeAnswerFile() {
+      this.answerFileList = [];
+      this.ruleForm.ANSWERS_TEMPLATE = this.ruleForm.properties.ANSWERS_TEMPLATE =
+        "";
+      if (this.$refs.uploadAnswer) {
+        this.$refs.uploadAnswer.clearFiles();
+      }
+    },
+    handleAnswerRemove(file, fileList) {
+      console.log(file, fileList);
+      this.removeAnswerFile();
+    },
+    handleAnswerExceed() {
+      this.$notify({
+        message: "当前限制选择 1 个文件,请先清空文件再试",
+        type: "error",
+      });
+    },
+
     //确定上传
     submitUploadMenuLogo() {
       if (!this.checkUploadMenuLogo()) {