Browse Source

增加注释

dusenyao 1 year ago
parent
commit
97832c55ca

+ 1 - 0
src/views/exercise_questions/answer/index.vue

@@ -302,6 +302,7 @@ export default {
         })
         .catch(() => {});
     },
+    // 得到练习的题目索引列表
     getExerciseQuestionIndexList() {
       GetExerciseQuestionIndexList({ exercise_id: this.exercise_id }).then(({ index_list }) => {
         this.questionList = index_list.map((item) => ({

+ 19 - 0
src/views/exercise_questions/create/components/exercises/DialogueQuestion.vue

@@ -259,6 +259,7 @@ export default {
       });
       this.data.answer.answer_list = answer_list;
     },
+    // 音频上传前处理
     handleBeforeAudio(file) {
       if (this.curRole.length <= 0) {
         this.$message.error('请先选择角色');
@@ -270,6 +271,7 @@ export default {
         return false;
       }
     },
+    // 图片上传前处理
     handleBeforeImage(file) {
       if (this.curRole.length <= 0) {
         this.$message.error('请先选择角色');
@@ -281,12 +283,15 @@ export default {
         return false;
       }
     },
+    // 音频上传
     handleAudio(file) {
       this.upload('audio', file);
     },
+    // 图片上传
     handleImage(file) {
       this.upload('image', file);
     },
+    // 上传
     upload(type, file) {
       fileUpload('Mid', file, { isGlobalprogress: true }).then(({ file_info_list }) => {
         if (file_info_list.length > 0) {
@@ -299,6 +304,7 @@ export default {
         }
       });
     },
+    // 处理输入文本
     handleText() {
       if (this.curRole.length <= 0) {
         return this.$message.error('请先选择角色');
@@ -339,12 +345,21 @@ export default {
       });
       this.textInput = '';
     },
+    /**
+     * 移动选项
+     * @param {'up'|'down'} type 类型
+     * @param {number} i 索引
+     */
     moveOption(type, i) {
       if ((type === 'up' && i === 0) || (type === 'down' && i === this.data.option_list.length - 1)) return;
       const item = this.data.option_list[i];
       this.data.option_list.splice(i, 1);
       this.data.option_list.splice(type === 'up' ? i - 1 : i + 1, 0, item);
     },
+    /**
+     * 删除选项
+     * @param {number} i 索引
+     */
     deleteOption(i) {
       let type = this.data.option_list[i].type;
       this.data.option_list.splice(i, 1);
@@ -353,6 +368,10 @@ export default {
         this.identifyText();
       }
     },
+    /**
+     * 保存音频
+     * @param {string} file_id 文件id
+     */
     saveWav(file_id) {
       this.data.option_list.push({
         role: this.curRole,

+ 6 - 0
src/views/exercise_questions/create/components/exercises/ReadQuestion.vue

@@ -129,6 +129,7 @@ export default {
     };
   },
   methods: {
+    // 添加子题目
     addQuestion() {
       AddQuestionToExercise({
         exercise_id: this.exercise_id,
@@ -175,6 +176,11 @@ export default {
       this.data.question_list[i].additional_type = type === 'select' ? 'single' : '';
     },
 
+    /**
+     * 更新预览数据
+     * @param {number} i 题目索引
+     * @param {object} data 预览数据
+     */
     updatePreviewData(i, data) {
       this.$set(this.childPreviewData, i, data);
     },

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

@@ -182,6 +182,11 @@ export default {
     },
   },
   methods: {
+    /**
+     *鼠标拖动更改列宽
+     * @param {MouseEvent} e 鼠标事件
+     * @param {number} i 选项列表的索引
+     */
     resize(e, i) {
       let target = e.target;
       let startX = e.clientX;
@@ -210,6 +215,7 @@ export default {
       target.setCapture && target.setCapture(); // 该函数在属于当前线程的指定窗口里设置鼠标捕获
       return false;
     },
+    // 计算选项样式
     computedOptionStyle() {
       let gridTemplateColumns = this.data.option_header_list.reduce((acc, { width }, i) => {
         if (i === this.data.option_header_list.length - 1) {
@@ -244,7 +250,7 @@ export default {
       if (isStart) {
         this.handleSpecialCharacterStart(arr, answerIndex, newValue.mark, i, j);
       } else {
-        let str = arr.join().replace(/<span class="rich-fill".*?>(.*?)<\/span>/gi, '###$1$2###');
+        let str = arr.join().replace(/<span class="rich-fill".*?>(.*?)<\/span>/gi, '###$1###');
         this.handleFill(str, answerIndex, newValue.mark, i, j);
       }
     },
@@ -309,7 +315,7 @@ export default {
       // 去除第一个元素的 ##
       arr[0] = arr[0].slice(2);
       let _arr = arr.map((item) => {
-        return item.replace(/<span class="rich-fill".*?>(.*?)<\/span>|([_]{3,})/gi, '$1$2');
+        return item.replace(/<span class="rich-fill".*?>(.*?)<\/span>/gi, '$1');
       });
       let mark = getRandomNumber();
 

+ 5 - 4
src/views/exercise_questions/create/index.vue

@@ -14,7 +14,7 @@
       </div>
       <div class="exercise-list">
         <ul>
-          <draggable v-model="index_list" animation="300" @end="onEnd">
+          <draggable v-model="index_list" animation="300" @end="moveQuestion">
             <transition-group>
               <li v-for="(item, i) in index_list" :key="i" :class="['exercise-item', { active: i === curIndex }]">
                 <SvgIcon icon-class="child" :size="20" />
@@ -295,10 +295,11 @@ export default {
     },
     /**
      * 移动题目
-     * @param {object} param0 移动参数
-     * @param {number} param0.newIndex 移动后的索引
+     * @param {object} param 移动参数
+     * @param {number} param.newIndex 移动后的索引
+     * @param {number} param.oldIndex 移动前的索引
      */
-    onEnd({ newIndex, oldIndex }) {
+    moveQuestion({ newIndex, oldIndex }) {
       let order = newIndex > oldIndex;
       MoveQuestion({
         question_id: this.index_list[newIndex].id,

+ 4 - 0
src/views/exercise_questions/preview/FillPreview.vue

@@ -191,6 +191,10 @@ export default {
       }
       return classList;
     },
+    /**
+     * 计算正确答案文本
+     * @param {string} mark 选项标识
+     */
     computedAnswerText(mark) {
       if (!this.isShowRightAnswer) return '';
       let selectOption = this.answer.answer_list.find((item) => item.mark === mark);

+ 10 - 0
src/views/exercise_questions/preview/JudgePreview.vue

@@ -56,10 +56,20 @@ export default {
     };
   },
   methods: {
+    /**
+     * 判断是否已选中
+     * @param {string} mark 选项标识
+     * @param {string} option_type 选项类型
+     */
     isAnswer(mark, option_type) {
       return this.answer.answer_list.some((li) => li.mark === mark && li.option_type === option_type);
     },
 
+    /**
+     * 选择答案
+     * @param {string} mark 选项标识
+     * @param {string} option_type 选项类型
+     */
     selectAnswer(mark, option_type) {
       if (this.disabled) return;
       const index = this.answer.answer_list.findIndex((li) => li.mark === mark);

+ 9 - 0
src/views/exercise_questions/preview/MatchingPreview.vue

@@ -476,6 +476,10 @@ export default {
       return fMark;
     },
 
+    /**
+     * 计算答题对错选项class
+     * @param {string} mark 选项标识
+     */
     computedAnswerClass(mark) {
       if (!this.isJudgingRightWrong) return '';
       let answer = this.data.answer.answer_list.find((item) => {
@@ -483,6 +487,11 @@ export default {
       });
       return this.is2DArrayContains1DArray(this.answer.answer_list, answer) ? 'right' : 'wrong';
     },
+    /**
+     * 判断二维数组是否包含一维数组
+     * @param {array} arr2D 二维数组
+     * @param {array} arr1D 一维数组
+     */
     is2DArrayContains1DArray(arr2D, arr1D) {
       for (let i = 0; i < arr2D.length; i++) {
         const currentArray = arr2D[i];

+ 16 - 3
src/views/exercise_questions/preview/ReadPreview.vue

@@ -107,6 +107,13 @@ export default {
     );
   },
   methods: {
+    /**
+     * 改变答案
+     * @param {number} i 序号
+     * @param {string} type 类型
+     * @param {object} param2
+     * @param {array} param2.answer_list 答案列表
+     */
     changeAnswer(i, type, { answer_list }) {
       if (this.disabled) return;
       this.answer.question_list[i].answer_list = answer_list;
@@ -114,10 +121,10 @@ export default {
     },
     /**
      * 显示答案
-     * @param {Boolean} isJudgingRightWrong 是否判断对错
-     * @param {Boolean} isShowRightAnswer 是否显示正确答案
+     * @param {boolean} isJudgingRightWrong 是否判断对错
+     * @param {boolean} isShowRightAnswer 是否显示正确答案
      * @param {Object} userAnswer 用户答案
-     * @param {Boolean} disabled 是否禁用
+     * @param {boolean} disabled 是否禁用
      */
     showAnswer(isJudgingRightWrong, isShowRightAnswer, userAnswer, disabled) {
       this.isJudgingRightWrong = isJudgingRightWrong;
@@ -131,6 +138,12 @@ export default {
         this.fillAnswer(isJudgingRightWrong, isShowRightAnswer, disabled);
       });
     },
+    /**
+     * 填充答案
+     * @param {boolean} isJudgingRightWrong 是否判断对错
+     * @param {boolean} isShowRightAnswer 是否显示正确答案
+     * @param {boolean} disabled 是否禁用
+     */
     fillAnswer(isJudgingRightWrong, isShowRightAnswer, disabled) {
       this.answer.question_list.forEach(({ id, answer_list }) => {
         const index = this.question_list.findIndex((item) => item.id === id);

+ 15 - 0
src/views/exercise_questions/preview/SelectPreview.vue

@@ -70,12 +70,22 @@ export default {
     },
   },
   methods: {
+    /**
+     * 判断是否为选中答案
+     * @param {string} mark 标记
+     * @param {string} parent_mark 父级标记
+     */
     isAnswer(mark, parent_mark) {
       if (isEnable(this.data.property.is_option_subdivision)) {
         return this.answer.answer_list.find((item) => item.mark === parent_mark)?.value_list?.includes(mark);
       }
       return this.answer.answer_list.includes(mark);
     },
+    /**
+     * 选择答案
+     * @param {string} mark 标记
+     * @param {string} parent_mark 父级标记
+     */
     selectAnswer(mark, parent_mark) {
       if (this.disabled) return;
       let answer_list = this.answer.answer_list;
@@ -114,6 +124,11 @@ export default {
         }
       }
     },
+    /**
+     * 计算答题对错选项class样式
+     * @param {string} mark 选项标识
+     * @param {string} parent_mark 选项父级标识
+     */
     computedAnswerClass(mark, parent_mark) {
       if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
         return [];

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

@@ -124,6 +124,7 @@ export default {
     }
   },
   methods: {
+    // 得到分享记录信息
     getShareRecordInfo() {
       GetShareRecordInfo({
         share_record_id: this.share_record_id,