dusenyao 1 éve
szülő
commit
bd4cd4d8d3

+ 0 - 3
src/router/guard/index.js

@@ -1,5 +1,4 @@
 import { getSessionID, getConfig } from '@/utils/auth';
-import { setItem } from '@/utils/storage';
 
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
@@ -24,8 +23,6 @@ export function setupRouterGuard(router) {
       next();
     } else {
       // 其他无权访问的页面将重定向到登录页面
-      // 如果是要跳转到答题页或练习页,将临时链接存入本地,并跳转到登录页
-      if (['/answer', '/exercise'].includes(to.path)) setItem('temporary_link', `GCLS-Exercise/#${to.fullPath}`);
       if (process.env.NODE_ENV === 'production') {
         window.location.href = '/';
       } else {

+ 12 - 1
src/utils/http.js

@@ -54,7 +54,18 @@ service.interceptors.response.use(
         duration: 3 * 1000,
       });
       store.dispatch('user/signOut');
-      window.location.href = '/';
+      const match = /#\/(.*?)\?/.exec(window.location.hash); // 使用 exec 方法进行匹配
+
+      // 答题跳转链接
+      let extractedString = '';
+      if (match && match.length > 1) {
+        extractedString = match[1];
+      }
+      if (extractedString === 'open/share/exercise') {
+        window.location.href = `/#/login?temporary_link=${encodeURIComponent(`GCLS-Exercise/${window.location.hash}`)}`;
+      } else {
+        window.location.href = '/';
+      }
     }
 
     return res;

+ 43 - 8
src/views/exercise_questions/answer/index.vue

@@ -18,7 +18,7 @@
 
     <main class="main">
       <StartQuestion
-        v-if="curQuestionIndex === -1 && !(user_answer_record_info.is_exist_answer_record === 'true')"
+        v-if="curQuestionIndex === -1 && !(user_answer_record_info.is_exist_answer_record === 'true') && !isShow"
         :question-length="questionList.length"
         :answer-time-limit-minute="answer_time_limit_minute"
         @startAnswer="startAnswer"
@@ -103,9 +103,9 @@
         </template>
 
         <template v-else>
-          <el-button round @click="fillQuestionAnswer('pre')">上一题</el-button>
+          <el-button v-if="curQuestionIndex > 0" round @click="fillQuestionAnswer('pre')">上一题</el-button>
           <el-button
-            v-if="curQuestionIndex === questionList.length - 1 && !isTeacherAnnotations"
+            v-if="curQuestionIndex === questionList.length - 1 && !isTeacherAnnotations && !isShow"
             type="primary"
             round
             @click="confirmSubmitAnswer"
@@ -113,7 +113,7 @@
             提交
           </el-button>
           <el-button
-            v-else-if="curQuestionIndex < questionList.length - 1 || !isTeacherAnnotations"
+            v-else-if="curQuestionIndex < questionList.length - 1"
             type="primary"
             round
             @click="fillQuestionAnswer('next')"
@@ -136,6 +136,7 @@ import {
   GetQuestionInfo_AnswerRecord,
   FillQuestionAnswerRemark,
   GetAnswerRecordReport,
+  GetQuestionInfo,
 } from '@/api/exercise';
 import { subjectiveQuestionList } from './answer';
 import { fileUpload } from '@/api/app';
@@ -152,10 +153,19 @@ export default {
   },
   mixins: [PreviewQuestionTypeMixin],
   data() {
-    const { id, share_record_id, answer_record_id, exercise_id, question_index, back_url } = this.$route.query;
+    const {
+      id,
+      share_record_id,
+      answer_record_id,
+      exercise_id,
+      question_index,
+      back_url,
+      type = 'answer',
+    } = this.$route.query;
     let questionIndex = Number(question_index);
 
     return {
+      isShow: type === 'show', // 是否是展示模式
       exercise_id: id || exercise_id, // 练习题id
       share_record_id, // 分享记录id
       answer_record_id: answer_record_id ?? '', // 答题记录id
@@ -225,6 +235,10 @@ export default {
   },
   watch: {
     curQuestionIndex() {
+      if (this.isShow) {
+        this.getQuestionInfo();
+        return;
+      }
       this.getQuestionInfo_AnswerRecord();
     },
     isSubmit(val) {
@@ -257,7 +271,7 @@ export default {
             this.time = answer_time_limit_minute * 60;
             this.loading = false;
             // 如果已经存在答题记录,则直接显示答题报告
-            if (this.user_answer_record_info.is_exist_answer_record === 'true' && !this.isTeacher) {
+            if (this.user_answer_record_info.is_exist_answer_record === 'true') {
               this.answer_record_id = this.user_answer_record_info.answer_record_id;
               this.answer_mode = answer_mode;
               this.isSubmit = true;
@@ -291,8 +305,13 @@ export default {
           ...item,
           isFill: this.isTeacherAnnotations || this.user_answer_record_info.is_exist_answer_record === 'true',
         }));
+        if (this.isShow) {
+          this.curQuestionIndex = 0;
+          return;
+        }
         if (this.question_index >= 0) {
           this.curQuestionIndex = this.question_index;
+          return;
         }
       });
     },
@@ -349,11 +368,14 @@ export default {
       if (type === 'pre' && this.curQuestionIndex <= 0) return;
       if (type === 'next' && this.curQuestionIndex > this.questionList.length - 1) return;
       if (!this.answer_record_id) {
-        this.curQuestionIndex = type === 'pre' ? this.curQuestionIndex - 1 : this.curQuestionIndex + 1;
+        this.curQuestionIndex =
+          type === 'pre'
+            ? Math.max(0, this.curQuestionIndex - 1)
+            : Math.min(this.questionList.length - 1, this.curQuestionIndex + 1);
         return;
       }
       // 如果已填写,直接跳转
-      if (this.questionList[this.curQuestionIndex].isFill) {
+      if (this.questionList[this.curQuestionIndex].isFill || this.isShow) {
         if (type === 'pre') return this.preQuestion();
         if (type === 'next') return this.nextQuestion();
       }
@@ -375,6 +397,19 @@ export default {
         );
       });
     },
+    getQuestionInfo() {
+      if (this.questionList.length === 0) return;
+      GetQuestionInfo({ question_id: this.questionList[this.curQuestionIndex].id }).then(({ question, file_list }) => {
+        if (!question.content) return;
+        this.curQuestionPage =
+          this.curQuestionIndex < 0 ? '' : this.previewComponents[this.questionList[this.curQuestionIndex].type];
+        // 将题目文件id列表添加到题目内容中
+        let file_id_list = file_list.map(({ file_id }) => file_id);
+        let content = JSON.parse(question.content);
+        content.file_id_list = file_id_list;
+        this.currentQuestion = content;
+      });
+    },
     // 得到答题记录题目信息
     getQuestionInfo_AnswerRecord() {
       if (this.questionList.length === 0) return;

+ 10 - 1
src/views/exercise_questions/create/components/create.vue

@@ -17,7 +17,10 @@
           <span>下一题</span><i class="el-icon-right"></i>
         </a>
       </div>
-      <div class="save-tip">{{ curSaveDate }} 已自动保存</div>
+      <div class="save-tip">
+        <span>{{ curSaveDate }} </span><span>已自动保存</span>
+        <span class="now-save" @click="saveQuestion">立即保存</span>
+      </div>
       <div class="right-operate">
         <a class="setting" @click="setUp"><SvgIcon icon-class="setting" /><span>设置</span></a>
         <span class="line"></span>
@@ -282,6 +285,12 @@ export default {
     .save-tip {
       font-size: 12px;
       color: #858585;
+
+      .now-save {
+        margin-left: 8px;
+        color: $main-color;
+        cursor: pointer;
+      }
     }
 
     .right-operate {

+ 2 - 2
src/views/exercise_questions/create/components/exercises/FillQuestion.vue

@@ -170,8 +170,8 @@ export default {
         .filter((item) => item)
         .forEach((item) => {
           if (item.charCodeAt() === 10) return;
-          // 匹配 span 标签和三个以上的_,并将它们组成数组
-          let str = item.replace(/<span.*?>(.*?)<\/span>|([_]{3,})/gi, '###$1$2###');
+          // 匹配 class 名为 rich-fill 的 span 标签和三个以上的_,并将它们组成数组
+          let str = item.replace(/<span class="rich-fill".*?>(.*?)<\/span>|([_]{3,})/gi, '###$1$2###');
           this.data.model_essay.push(this.splitRichText(str));
         });
     },

+ 6 - 1
src/views/exercise_questions/create/index.vue

@@ -3,7 +3,12 @@
     <div class="list">
       <el-button icon="el-icon-back" @click="back">返回练习管理</el-button>
       <div class="list-title">
-        <el-input v-if="isEditExercise" v-model="exercise.name" @keyup.enter.native="UpdateExerciseName" />
+        <el-input
+          v-if="isEditExercise"
+          v-model="exercise.name"
+          @keyup.enter.native="UpdateExerciseName"
+          @blur="UpdateExerciseName"
+        />
         <span v-else class="nowrap-ellipsis">{{ exercise.name }}</span>
         <SvgIcon icon-class="edit" class-name="edit" @click="editExercise" />
       </div>

+ 11 - 1
src/views/home/public_question/index.vue

@@ -16,7 +16,7 @@
       <el-table-column prop="create_time" label="创建日期" min-width="180" />
       <el-table-column prop="operation" label="操作" fixed="right" width="220">
         <template slot-scope="{ row }">
-          <span class="link">查看</span>
+          <span class="link" @click="showExercise(row.id)">查看</span>
           <span
             v-show="row.teacher_id === $store.state.user.user_code"
             class="link"
@@ -87,6 +87,16 @@ export default {
     getPageList() {
       this.$refs.common.getList();
     },
+    showExercise(exercise_id) {
+      this.$router.push({
+        path: '/answer',
+        query: {
+          exercise_id,
+          type: 'show',
+          back_url: encodeURIComponent(window.location.href),
+        },
+      });
+    },
     pageQueryExerciseList(data) {
       PageQueryExerciseList({
         ...data,

+ 1 - 7
src/views/share/ShareExercise.vue

@@ -48,13 +48,7 @@ export default {
             });
           }
         })
-        .catch(() => {
-          let link = 'GCLS-Exercise/#/open/share/exercise?';
-          for (const [key, value] of this.query.entries()) {
-            link += `${key}=${value}&`;
-          }
-          setItem('temporary_link', link);
-        });
+        .catch(() => {});
     },
   },
 };