Browse Source

fix axios cache bug. fix style

Michael Wang 6 years ago
parent
commit
935ec22af3

+ 13 - 2
src/features/OnlineExam/Examing/BooleanQuestionView.vue

@@ -5,11 +5,11 @@
       <div class="stu-answer">{{{'true': '正确', 'false' : '错误'}[studentAnswer]}}</div>
       <div class="score">({{examQuestion.questionScore}}分)</div>
     </div>
-    <div @click="() => answerQuestion('true')">
+    <div @click="() => answerQuestion('true')" :class="[studentAnswer === 'true' && 'row-selected', 'option']">
       <input type="radio" name="question" value="true" :checked="studentAnswer === 'true'" />
       <span class="question-options">正确</span>
     </div>
-    <div @click="() => answerQuestion('false')">
+    <div @click="() => answerQuestion('false')" :class="[studentAnswer === 'false' && 'row-selected', 'option']">
       <input type="radio" name="question" value="false" :checked="studentAnswer === 'false'" />
       <span class="question-options">错误</span>
     </div>
@@ -127,7 +127,18 @@ export default {
 
 .option {
   display: flex;
+  cursor: pointer;
 }
+
+.option:hover {
+  background-color: aliceblue;
+}
+
+.row-selected {
+  background-color: aliceblue;
+  width: 100%;
+}
+
 .question-options {
   text-align: left;
   margin-left: 10px;

+ 16 - 3
src/features/OnlineExam/Examing/MultipleQuestionView.vue

@@ -6,9 +6,11 @@
       <div class="score">({{examQuestion.questionScore}}分)</div>
     </div>
     <div v-for="(option, index) in newQuestionOptions" :key="index" class="option" @click="toggleAnswer(option.oldIndex)">
-      <input type="checkbox" name="question" value="option.oldIndex" :checked="studentAnswer && studentAnswer.includes(option.oldIndex)" />
-      <span style="padding: 0 10px;">{{optionName[index]}}: </span>
-      <span class="question-options" v-if="option.value" v-html="option.value.body"></span>
+      <div :class="studentAnswer.includes(option.oldIndex) && 'row-selected'">
+        <input type="checkbox" name="question" value="option.oldIndex" :checked="studentAnswer && studentAnswer.includes(option.oldIndex)" />
+        <span style="padding: 0 10px;">{{optionName[index]}}: </span>
+        <span class="question-options" v-if="option.value" v-html="option.value.body"></span>
+      </div>
     </div>
     <div class="reset">
       <i-button type="warning" size="large" @click="() => answerQuestion(null)">重置答案</i-button>
@@ -184,7 +186,18 @@ export default {
 
 .option {
   display: flex;
+  cursor: pointer;
+}
+
+.option:hover {
+  background-color: aliceblue;
 }
+
+.row-selected {
+  background-color: aliceblue;
+  width: 100%;
+}
+
 .question-options {
   text-align: left;
 }

+ 16 - 3
src/features/OnlineExam/Examing/SingleQuestionView.vue

@@ -6,9 +6,11 @@
       <div class="score">({{examQuestion.questionScore}}分)</div>
     </div>
     <div v-for="(option, index) in newQuestionOptions" :key="index" class="option" @click="() => {answerQuestion(option.oldIndex);}">
-      <input type="radio" name="question" :value="option.oldIndex" :checked="studentAnswer === option.oldIndex" />
-      <span style="padding: 0 10px;">{{optionName[index]}}: </span>
-      <span class="question-options" v-if="option.value" v-html="option.value.body"></span>
+      <div :class="studentAnswer === option.oldIndex && 'row-selected'">
+        <input type="radio" name="question" :value="option.oldIndex" :checked="studentAnswer === option.oldIndex" />
+        <span style="padding: 0 10px;">{{optionName[index]}}: </span>
+        <span class="question-options" v-if="option.value" v-html="option.value.body"></span>
+      </div>
     </div>
     <div class="reset">
       <i-button type="warning" size="large" @click="() => answerQuestion(null)">重置答案</i-button>
@@ -160,7 +162,18 @@ export default {
 
 .option {
   display: flex;
+  cursor: pointer;
+}
+
+.option:hover {
+  background-color: aliceblue;
 }
+
+.row-selected {
+  background-color: aliceblue;
+  width: 100%;
+}
+
 .question-options {
   text-align: left;
 }

+ 4 - 1
src/utils/axios.js

@@ -111,16 +111,19 @@ upyunInstance.defaults.headers.common = {};
 // upyunInstance.defaults.headers.common["Authorization"] = UPYUN_HEADER_AUTH;
 
 let __upyunAuth = null;
+let __upyunBucketUrl = null;
 upyunInstance.interceptors.request.use(
   config => {
     if (__upyunAuth) {
+      config.baseURL = __upyunBucketUrl;
       config.headers.common["Authorization"] = __upyunAuth;
       return config;
     } else {
       return qmInstance
         .get("/api/ecs_oe_student_face/upyun")
         .then(res => {
-          config.baseURL = res.data.bucketUrl;
+          __upyunBucketUrl = res.data.bucketUrl;
+          config.baseURL = __upyunBucketUrl;
           const authorization =
             "Basic " +
             btoa(atob(res.data.upyunOperator) + ":" + atob(res.data.upyunCred));

+ 2 - 2
src/utils/axiosCache.js

@@ -13,8 +13,8 @@ export default function(get, regexes) {
       } else {
         const request = get(...arguments);
         return request.then(v => {
-          if (v.response) {
-            // 如果能取到数据
+          if (v.status === 200) {
+            // 如果能取到数据,才缓存
             cache.set(key, request);
           }
           return request;