Browse Source

接口更新

Michael Wang 6 years ago
parent
commit
0e3ee9ad52

+ 8 - 42
src/components/FaceRecognition/FaceRecognition.vue

@@ -86,8 +86,7 @@ export default {
     async uploadToServer(captureBlob) {
       //保存抓拍照片到又拍云
       var fileName = new Date().getTime() + ".jpg";
-      var fileUrl =
-        "/capture_photo/" + this.user.identityNumber + "/" + fileName;
+      var fileUrl = "/capture_photo/" + this.user.userId + "/" + fileName;
       try {
         await this.$upyunhttp.put(fileUrl, captureBlob, {
           headers: {
@@ -101,57 +100,24 @@ export default {
       }
 
       const captureFilePath =
-        UPYUN_URL +
-        "/capture_photo/" +
-        this.user.identityNumber +
-        "/" +
-        fileName;
+        UPYUN_URL + "/capture_photo/" + this.user.userId + "/" + fileName;
       await this.faceCompare(captureFilePath);
     },
     async faceCompare(captureFilePath) {
-      const res = await this.$http.get(
-        "/api/ecs_core/face/studentFace/" + this.user.userId
-      );
-      const faceToken = res.data.faceToken;
-      console.log(faceToken);
-      console.log(captureFilePath);
-
-      // TODO: 研究是否有更合适的位置,只使用了一次. 应该由server进行检测
       try {
-        const faceCompareRes = await fetch(
-          FACEPP_API +
-            "/compare?" +
-            `api_key=${FACEPP_KEY}&api_secret=${FACEPP_SECRET}&face_token1=${faceToken}&image_url2=${captureFilePath}`,
+        const res = await this.$http.post(
+          "/api/ecs_oe_student_face/examCaptureQueue/compareFaceSync?fileUrl=" +
+            captureFilePath,
           {
-            method: "post",
-            headers: {
-              "Content-Type": "application/x-www-form-urlencoded"
-            }
+            fileUrl: captureFilePath
           }
         );
-        const verifyResult = await faceCompareRes.json();
-        console.log("人脸检测结果: ", verifyResult);
-
-        // 告知服务器人脸检测结果
-        const params = new URLSearchParams();
-        params.append("pass", true);
-        params.append("action", "COMPARE");
-        await this.$http.post("/api/face_capture", params);
 
         // TODO: 识别成功、失败的通知或跳转
-
-        let pass = false;
-        if (verifyResult.faces2.length > 0) {
-          var confidence = verifyResult.confidence;
-          var thresholds = verifyResult.thresholds;
-          if (confidence && thresholds && confidence > thresholds["1e-4"]) {
-            pass = true;
-          }
-        }
         this.$emit("on-recognize-result", {
           error: null,
-          pass,
-          faceCount: verifyResult.faces2.length
+          pass: res.data.isPass,
+          stranger: res.data.isStranger
         });
       } catch (e) {
         console.log(e);

+ 20 - 14
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -1,5 +1,5 @@
 <template>
-  <div v-if="exam && examQuestion" class="container">
+  <div v-if="exam && examQuestion()" class="container">
     <div class="header">
       <RemainTime></RemainTime>
       <OverallProgress :exam-question-list="validQuestions"></OverallProgress>
@@ -7,7 +7,7 @@
       <Button class="qm-primary-button" @click="submitPaper">交卷</Button>
     </div>
     <div class="main">
-      <QuestionView :exam-question="examQuestion"></QuestionView>
+      <QuestionView :exam-question="examQuestion()"></QuestionView>
       <ArrowNavView :previous-exam-question="preExamQuestion" :next-exam-question="nextExamQuestion"></ArrowNavView>
     </div>
     <div class="side">
@@ -38,11 +38,9 @@ export default {
   name: "ExamingHome",
   created() {
     this.initData();
-    if (!this.$route.query.examQuestionId) {
+    if (!this.$route.query.order) {
       // created can access this.$route?
-      this.$router.push(
-        this.$route.fullPath + "&examQuestionId=" + this.examQuestionList[0].id
-      );
+      this.$router.push(this.$route.fullPath + "&order=" + 4);
       return;
     }
   },
@@ -55,14 +53,14 @@ export default {
       const exam = await this.$http.get(
         "/api/ecs_exam_work/exam/" + this.$route.params.examId
       );
-
       const paperStruct = await this.$http.get(
-        "/api/exam_question/paper_struct/?exam_record_id=" +
+        "/api/ecs_oe_student/examRecordPaperStruct/getExamRecordPaperStruct?examRecordDataId=" +
           this.$route.query.examRecordId
       );
 
       const examQuestionList = await this.$http.get(
-        "/api/exam_question/?exam_record_id=" + this.$route.query.examRecordId
+        "/api/ecs_oe_student/examQuestion/findExamQuestionList?examRecordDataId=" +
+          this.$route.query.examRecordId
       );
 
       this.updateExamState({
@@ -94,21 +92,29 @@ export default {
       //FIXME: submit precondition
       await this.$http.get("/api/exam_control/submit");
       this.$router.push("/");
+    },
+    examQuestion() {
+      return (
+        this.examQuestionList &&
+        this.examQuestionList.find(
+          eq => eq.order == this.$route.query.order // number == string
+        )
+      );
     }
   },
   computed: {
     ...mapState(["exam", "paperStruct", "examQuestionList"]),
     ...mapGetters(["validQuestions"]),
-    examQuestion: vm =>
-      vm.examQuestionList &&
-      vm.examQuestionList.find(
-        eq => eq.id == vm.$route.query.examQuestionId // number == string
-      ),
     preExamQuestion: vm =>
       vm.examQuestion && vm.validQuestions[vm.examQuestion.orders - 2],
     nextExamQuestion: vm =>
       vm.examQuestion && vm.validQuestions[vm.examQuestion.orders]
   },
+  watch: {
+    $route: function() {
+      this.examQuestion();
+    }
+  },
   components: {
     RemainTime,
     OverallProgress,

+ 7 - 3
src/features/OnlineExam/Examing/OverallProgress.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="progress-container">
-    <i-progress :percent="progressNum" :stroke-width="20" status="active" hide-info>
+    <i-progress :percent="progressNum" :stroke-width="20" status="active" hide-info style="color: black">
     </i-progress>
     <span>{{progress}}</span>
   </div>
@@ -20,13 +20,13 @@ export default {
     progressNum() {
       return (
         100 *
-        (this.examQuestionList.filter(q => q.stuAnswer !== null).length /
+        (this.examQuestionList.filter(q => q.studentAnswer !== null).length /
           this.examQuestionList.length)
       );
     },
     progress: function() {
       return `${
-        this.examQuestionList.filter(q => q.stuAnswer !== null).length
+        this.examQuestionList.filter(q => q.studentAnswer !== null).length
       } / ${this.examQuestionList.length}`;
     }
   }
@@ -42,4 +42,8 @@ export default {
   grid-template-columns: 200px 50px;
   width: 250px;
 }
+
+.ivu-progress-inner {
+  background-color: #02ffff;
+}
 </style>

+ 7 - 4
src/features/OnlineExam/Examing/QuestionBody.vue

@@ -1,13 +1,16 @@
 <template>
-  <div class="question-body" :key="examQuestionId">
-    <div v-html="question.text"></div>
-    <div v-html="question.audio"></div>
+  <div v-if="questionDetail" class="question-body" :key="examQuestionId">
+    <div v-html="questionDetail.text"></div>
+    <div v-html="questionDetail.audio"></div>
   </div>
 </template>
 
 <script>
 export default {
   name: "QuestionBody",
+  data() {
+    return { questionDetail: null };
+  },
   props: {
     questionBody: String,
     examQuestionId: Number
@@ -68,7 +71,7 @@ export default {
         question.text = this.questionBody;
         question.audio = "";
       }
-      return question;
+      this.questionDetail = question;
     }
   },
   computed: {}

+ 2 - 2
src/features/OnlineExam/Examing/QuestionFilters.vue

@@ -29,13 +29,13 @@ export default {
       return this.examQuestionList.length;
     },
     answered: function() {
-      return this.examQuestionList.filter(q => q.stuAnswer !== null).length;
+      return this.examQuestionList.filter(q => q.studentAnswer !== null).length;
     },
     signed: function() {
       return this.examQuestionList.filter(q => q.isSign).length;
     },
     unanswered: function() {
-      return this.examQuestionList.filter(q => q.stuAnswer === null).length;
+      return this.examQuestionList.filter(q => q.studentAnswer === null).length;
     }
   }
 };

+ 12 - 9
src/features/OnlineExam/Examing/QuestionNavView.vue

@@ -2,13 +2,13 @@
   <div>
     <div class="container">
       <template v-if="paperStruct && validQuestions">
-        <div v-for="(struct, index1) in paperStruct" :key="index1" class="section">
-          <div class="title">{{struct.title}} ({{struct.totalScore}}分)</div>
+        <div v-for="(struct, index1) in paperStruct.defaultPaper.questionGroupList" :key="index1" class="section">
+          <div class="title">{{struct.groupName}} ({{struct.groupScore}}分)</div>
           <div class="list">
-            <template v-for="(_, index2) in new Array(struct.questionCount)">
+            <template v-for="(_, index2) in sectionQuestions(index1)">
               <template v-if="isSelectedQuestion(index1, index2)">
                 <div :key="index2" :class="itemClass(index1, index2)">
-                  <router-link :to="{ path: '/online-exam/exam/' + $route.params.examId, query: { 'examRecordId': $route.query.examRecordId, 'examQuestionId': getQuestionNum(index1, index2).id }}">{{index2+1}}</router-link>
+                  <router-link :to="{ path: '/online-exam/exam/' + $route.params.examId, query: { 'examRecordId': $route.query.examRecordId, 'examStudentId': $route.query.examStudentId, 'order': getQuestionNum(index1, index2).order }}">{{index2+1}}</router-link>
                 </div>
               </template>
             </template>
@@ -30,7 +30,7 @@ export default {
     return {};
   },
   props: {
-    paperStruct: Array,
+    paperStruct: Object,
     validQuestions: Array
   },
   methods: {
@@ -44,7 +44,8 @@ export default {
       }
       let total = 0;
       for (var i = 0; i < section; i++) {
-        total += this.paperStruct[i].questionCount;
+        total += this.paperStruct.defaultPaper.questionGroupList[i]
+          .questionWrapperList.length;
       }
       // console.log(section, index, total + index);
       return this.validQuestions[total + index];
@@ -59,7 +60,7 @@ export default {
         return true;
       } else if (
         this.questionFilterType === "UNANSWERED" &&
-        q.stuAnswer === null
+        q.studentAnswer === null
       ) {
         return true;
       }
@@ -67,14 +68,16 @@ export default {
     },
     itemClass(index1, index2) {
       const isCurrentQuestion =
-        this.$route.query.examQuestionId ==
-        this.getQuestionNum(index1, index2).id; // 故意用的 ==
+        this.$route.query.order == this.getQuestionNum(index1, index2).order; // 故意用的 ==
       return {
         item: true,
         "current-question": isCurrentQuestion,
         "star-question": this.getQuestionNum(index1, index2).isSign,
         "is-answered": this.getQuestionNum(index1, index2).stuAnswer !== null
       };
+    },
+    sectionQuestions(section) {
+      return this.validQuestions.filter(q => q.mainNumber === section + 1);
     }
   },
   computed: {

+ 13 - 8
src/features/OnlineExam/Examing/QuestionView.vue

@@ -3,7 +3,7 @@
     <div class="sign-button">
       <Icon :type="examQuestion.isSign ? 'ios-star':'ios-star-outline'" :style="{color: '#ffcc00'}" class="star" @click="toggleSign" />
     </div>
-    <template v-if="question.questionType === 'SINGLE_ANSWER_QUESTION'">
+    <template v-if="question.questionType === 'SINGLE_CHOICE'">
       <single-question-view :question="question" :examQuestion="examQuestion" />
     </template>
     <template v-if="question.questionType === 'MULTIPLE_ANSWER_QUESTION'">
@@ -31,6 +31,7 @@ import BooleanQuestionView from "./BooleanQuestionView";
 import FillBlankQuestionView from "./FillBlankQuestionView";
 import TextQuestionView from "./TextQuestionView";
 import NestedQuestionView from "./NestedQuestionView";
+import { mapState } from "vuex";
 
 export default {
   name: "QuestionView",
@@ -51,9 +52,10 @@ export default {
         return;
       }
       const res = await this.$http.get(
-        "/api/exam_question/question/?question_id=" +
-          (this.examQuestion.questionId ||
-            this.examQuestion.parentQuestion.questionId)
+        "/api/ecs_oe_student/examQuestion/getQuestionStructure?examStudentId=" +
+          this.$route.query.examStudentId +
+          "&questionId=" +
+          this.examQuestion.questionId
       );
       const question = res.data;
 
@@ -100,7 +102,7 @@ export default {
       };
 
       //判断是否为套题
-      if (question.nestedQuestion) {
+      if (question.body) {
         transferWellNumberAndTrustInBody(question);
         for (var j = 0, jmax = question.subQuestionList.length; j < jmax; j++) {
           initQuestion(question.subQuestionList[j]);
@@ -118,10 +120,10 @@ export default {
           });
         }
       } else {
-        initQuestion(question);
+        initQuestion(question.questionUnitList[0]);
       }
 
-      this.question = question;
+      this.question = question.questionUnitList[0];
     },
     async toggleSign() {
       await this.$http.put("/api/exam_question/" + this.examQuestion.id, {
@@ -131,7 +133,7 @@ export default {
     }
   },
   watch: {
-    examQuestion: function() {
+    $route: function() {
       this.updateQuestion();
     }
   },
@@ -142,6 +144,9 @@ export default {
     FillBlankQuestionView,
     TextQuestionView,
     NestedQuestionView
+  },
+  computed: {
+    ...mapState(["user"])
   }
 };
 </script>

+ 2 - 2
src/features/OnlineExam/Examing/RemainTime.vue

@@ -13,8 +13,8 @@ export default {
     };
   },
   async mounted() {
-    const res = await this.$http.get("/api/exam_control/heartbeat");
-    this.remainTime = res.data.leftTime;
+    // const res = await this.$http.get("/api/ecs_oe_student/examControl/examHeartbeat");
+    // this.remainTime = res.data.leftTime;
   },
   computed: {
     remainTimeFormatted: function() {

+ 6 - 6
src/features/OnlineExam/Examing/SingleQuestionView.vue

@@ -3,12 +3,12 @@
     <question-body :questionBody="question.body" :examQuestionId="examQuestion.id"></question-body>
     <div class="ops">
       <div class="stu-answer">{{stuAnswer}}</div>
-      <div class="score">({{question.questionScore}}分)</div>
+      <div class="score">({{examQuestion.questionScore}}分)</div>
     </div>
-    <div v-for="(option, index) in question.options" :key="option.id" class="option" @click="() => answerQuestion(examQuestion.id, optionName[index])">
+    <div v-for="(option, index) in question.questionOptionList" :key="option.id" class="option" @click="() => answerQuestion(examQuestion.id, optionName[index])">
       <input type="radio" name="question" value="optionName[index]" :checked="stuAnswer === optionName[index]" />
       <span style="padding: 0 10px;">{{optionName[index]}}: </span>
-      <span class="question-options" v-html="option.content"></span>
+      <span class="question-options" v-html="option.body"></span>
     </div>
     <div class="reset">
       <i-button type="warning" size="large" @click="resetQuestion(examQuestion.id)">重置答案</i-button>
@@ -27,7 +27,7 @@ export default {
   data() {
     return {
       optionName,
-      stuAnswer: this.examQuestion.stuAnswer
+      stuAnswer: this.examQuestion.studentAnswer
     };
   },
   props: {
@@ -63,7 +63,7 @@ export default {
       }
     },
     async answerQuestion(examQuestionId, stuAnswer) {
-      if (stuAnswer !== this.examQuestion.stuAnswer) {
+      if (stuAnswer !== this.examQuestion.studentAnswer) {
         await this.$http.put("/api/exam_question/" + examQuestionId, {
           stuAnswer
         });
@@ -73,7 +73,7 @@ export default {
   },
   watch: {
     examQuestion: function() {
-      this.stuAnswer = this.examQuestion.stuAnswer;
+      this.stuAnswer = this.examQuestion.studentAnswer;
     }
   },
   components: {

+ 10 - 6
src/features/OnlineExam/OnlineExamFaceCheckModal.vue

@@ -48,6 +48,10 @@ export default {
       "/api/ecs_core/student/getStudentInfoBySession"
     );
     this.userPhoto = res.data.photoPath;
+    if (!this.userPhoto) {
+      this.$Message.error("没有底照");
+      return;
+    }
     // FIXME: 以后api返回的是绝对路径
     if (this.userPhoto.startsWith("http") === false) {
       this.userPhoto = this.userPhoto;
@@ -88,17 +92,17 @@ export default {
             "我承诺由本人参加考试,并且同意接受考试监控系统信息审核,一经发现作弊,立即取消本门课程考试成绩。",
           onOk: () =>
             this.$router.push(
-              `/online-exam/exam/${
-                this.course.onlineBatchId
-              }/overview?stuExamInfoId=${this.course.stuExamInfoId}`
+              `/online-exam/exam/${this.course.examId}/overview?stuExamInfoId=${
+                this.course.examStudentId
+              }`
             )
         });
         return;
       }
       this.$router.push(
-        `/online-exam/exam/${
-          this.course.onlineBatchId
-        }/overview?stuExamInfoId=${this.course.stuExamInfoId}`
+        `/online-exam/exam/${this.course.examId}/overview?stuExamInfoId=${
+          this.course.examStudentId
+        }`
       );
     }
   },

+ 34 - 17
src/features/OnlineExam/OnlineExamOverview.vue

@@ -1,10 +1,10 @@
 <template>
 
-  <div class="container" v-if="exam && startInfo && paperStruct">
+  <div class="container" v-if="beforeExamRemark && startInfo && paperStruct">
     <div class="instructions">
       <h1 class="">考试说明</h1>
       <div class="" style="text-align: left;  padding-bottom: 20px">
-        <p v-html="exam.beforeExamRemark"></p>
+        <p v-html="beforeExamRemark"></p>
         <!-- <p>{{"测试".repeat(500)}}</p> -->
       </div>
       <!-- data-ui-sref="exam.start({examRecordId: startInfo.id,stuExamInfoId:stateParams.stuExamInfoId,examMins:startInfo.paperMins,examId:examInfo.id,faceVerifyMinute:startInfo.faceVerifyMinute})" -->
@@ -19,10 +19,10 @@
       <h4 class="">试卷概览(总分:{{paperTotalScore}})</h4>
       <br>
       <ul class="list-group">
-        <li class="list-group-item" v-for="questionsGroup in paperStruct" :key="questionsGroup.index">
-          {{questionsGroup.index}}、{{questionsGroup.title}}
+        <li class="list-group-item" v-for="(questionsGroup, index) in paperStruct.defaultPaper.questionGroupList" :key="questionsGroup.gruopName">
+          {{index+1}}、{{questionsGroup.groupName}}
           <small class="pull-right">
-            (共{{questionsGroup.questionCount}}题,</span>共{{questionsGroup.totalScore}}分)
+            (共{{questionsGroup.questionWrapperList.length}}题,</span>共{{questionsGroup.groupScore}}分)
           </small>
         </li>
       </ul>
@@ -44,7 +44,7 @@ import moment from "moment";
 export default {
   data() {
     return {
-      exam: null,
+      beforeExamRemark: null,
       startInfo: null,
       paperStruct: null,
       remainTime: 120
@@ -57,17 +57,33 @@ export default {
         this.goToPaper();
       }
     }, 1000);
+
+    // FIXME: 考前说明
     const exam = await this.$http.get(
-      "/api/ecs_exam_work/exam/" + this.$route.params.examId
+      "/api/ecs_exam_work/exam/examOrgProperty/" +
+        this.$route.params.examId +
+        `/BEFORE_EXAM_REMARK`
     );
-    this.exam = exam.data;
+    this.beforeExamRemark = exam.data || "错误:不存在";
     try {
-      const res = await this.$http.get(
-        "/api/exam_control/start?stu_exam_info_id=" +
-          this.$route.query.stuExamInfoId
-      );
+      // await this.$http.get("/api/ecs_oe_student/examControl/endExam");
+      // const res = await this.$http.get(
+      //   "/api/ecs_oe_student/examControl/startExam?examStudentId=" +
+      //     this.$route.query.stuExamInfoId
+      // );
+      var res = {
+        data: {
+          examRecordDataId: 7,
+          courseCode: "W00001",
+          courseName: "英语",
+          studentCode: "20180613",
+          studentName: "王章军",
+          duration: 120,
+          faceLivenessMinute: null
+        }
+      };
       this.startInfo = res.data;
-      this.examRecordId = res.data.id;
+      this.examRecordId = res.data.examRecordDataId;
       // this.startInfo = {
       //   id: 101436,
       //   courseName: "计算机应用基础",
@@ -86,7 +102,8 @@ export default {
       this.$Message.error(error.message);
     }
     const paperStruct = await this.$http.get(
-      "/api/exam_question/paper_struct?exam_record_id=" + this.examRecordId
+      "/api/ecs_oe_student/examRecordPaperStruct/getExamRecordPaperStruct?examRecordDataId=" +
+        this.examRecordId
     );
     this.paperStruct = paperStruct.data;
 
@@ -141,8 +158,8 @@ export default {
     //   }
     // ];
 
-    this.paperTotalScore = this.paperStruct
-      .map(q => q.totalScore)
+    this.paperTotalScore = this.paperStruct.defaultPaper.questionGroupList
+      .map(q => q.groupScore)
       .reduce((p, c) => p + c);
   },
   beforeDestroy() {
@@ -158,7 +175,7 @@ export default {
       this.$router.push(
         `/online-exam/exam/${this.$route.params.examId}/?examRecordId=${
           this.examRecordId
-        }`
+        }&examStudentId=${this.$route.query.stuExamInfoId}`
       );
       window.clearInterval(this.intervalId);
     }

+ 25 - 17
src/features/login/Login.vue

@@ -108,23 +108,31 @@ export default {
       }
       this.loginForm["domain"] = this.$route.query.domain || "";
       let repPara = this.loginForm;
-      const response = await this.$http.post("/api/ecs_core/auth/login", {
-        ...repPara,
-        accountType: this.loginType,
-        // FIXME: 根据域名来确定domain
-        domain: process.env.VUE_APP_LOGIN_DOMAIN
-      });
-      let data = response.data;
-      if (data.token) {
-        this.errorInfo = "";
-        //缓存用户信息
-        window.localStorage.setItem("token", data.token);
-        window.localStorage.setItem("key", data.key);
-
-        this.$store.state.user = data;
-        this.$router.push("/online-exam");
-      } else {
-        this.errorInfo = data.desc;
+      try {
+        const response = await this.$http.post("/api/ecs_core/auth/login", {
+          ...repPara,
+          accountType: this.loginType,
+          // FIXME: 根据域名来确定domain
+          domain: process.env.VUE_APP_LOGIN_DOMAIN
+        });
+        // const student = (await this.$http.get(
+        //   "/api/ecs_core/student/getStudentInfoBySession"
+        // )).data;
+        // console.log(student);
+        let data = response.data;
+        if (data.token) {
+          this.errorInfo = "";
+          //缓存用户信息
+          window.localStorage.setItem("token", data.token);
+          window.localStorage.setItem("key", data.key);
+
+          this.$store.state.user = { ...data };
+          this.$router.push("/online-exam");
+        } else {
+          this.errorInfo = data.desc;
+        }
+      } catch (e) {
+        console.log(e);
       }
     }
   }

+ 5 - 7
src/store.js

@@ -34,10 +34,10 @@ const examingHomeModule = {
     updateQuestionFilter(state, type) {
       state.questionFilterType = type;
     },
-    updateExamQuestionAnswer(state, { examQuestionId, stuAnswer }) {
+    updateExamQuestionAnswer(state, { order, studentAnswer }) {
       state.examQuestionList = state.examQuestionList.map(eq => {
-        if (eq.id === examQuestionId) {
-          return Object.assign({}, eq, { stuAnswer });
+        if (eq.order === order) {
+          return Object.assign({}, eq, { studentAnswer });
         }
         return eq;
       });
@@ -45,11 +45,9 @@ const examingHomeModule = {
   },
   actions: {},
   getters: {
+    // FIXME: 不需要了
     validQuestions: state => {
-      return (
-        state.examQuestionList &&
-        state.examQuestionList.filter(q => q.nestedQuestion === false)
-      );
+      return state.examQuestionList;
     }
   }
 };

+ 31 - 4
src/utils/axios.js

@@ -4,7 +4,7 @@ import { loadProgressBar } from "./axiosProgress";
 import cachingGet from "./axiosCache";
 import { Message } from "iview";
 import router from "../router";
-import { UPYUN_UPLOAD_URL, UPYUN_HEADER_AUTH } from "@/constants/constants.js";
+// import { UPYUN_UPLOAD_URL, UPYUN_HEADER_AUTH } from "@/constants/constants.js";
 //axios配置 start
 
 const qmInstance = axios.create({});
@@ -91,16 +91,43 @@ qmInstance.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; //标
 qmInstance.get = cachingGet(qmInstance.get, [
   /\/api\/exam_question\/question\/\?question_id/,
   /\/api\/exam_question\/paper_struct\/\?exam_record_id=/,
-  /\/api\/ecs_exam_work\/exam\/\d+$/
+  /\/api\/ecs_exam_work\/exam\/\d+$/,
+  /\/api\/ecs_oe_student_face\/upyun$/
 ]);
 loadProgressBar(qmInstance);
 
 const upyunInstance = axios.create({
-  baseURL: UPYUN_UPLOAD_URL
+  // baseURL: UPYUN_UPLOAD_URL
 });
 // FIXME: axios bug. wait 0.19 release. https://github.com/axios/axios/issues/385
 upyunInstance.defaults.headers.common = {};
-upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
+// upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
+
+upyunInstance.interceptors.request.use(
+  config => {
+    return qmInstance
+      .get("/api/ecs_oe_student_face/upyun")
+      .then(res => {
+        config.baseURL = res.data.bucketUrl;
+        const authorization =
+          "Basic " +
+          btoa(atob(res.data.upyunOperator) + ":" + atob(res.data.upyunCred));
+        config.headers.common["Authorization"] = authorization;
+        return config;
+      })
+      .catch(err => {
+        console.log(err);
+      });
+  },
+  error => {
+    Message.error({
+      content: error,
+      duration: 10,
+      closable: true
+    });
+    return Promise.resolve(error);
+  }
+);
 
 loadProgressBar(upyunInstance);