Browse Source

对话题删除填空

dusenyao 1 year ago
parent
commit
bf994f2fe9

+ 11 - 47
src/views/exercise_questions/create/components/exercises/DialogueQuestion.vue

@@ -14,7 +14,7 @@
       <div class="content-wrapper">
         <div class="content">
           <div
-            v-for="({ role, type, text, file_id }, i) in data.option_list"
+            v-for="({ role, type, text }, i) in data.option_list"
             :key="i"
             class="option-list"
             :style="{ flexDirection: type === 'input_student' ? 'row-reverse' : 'row' }"
@@ -31,7 +31,7 @@
               {{ type === 'input_student' ? '学生' : data.property.role_list.find((item) => item.mark === role).name }}
             </span>
 
-            <div v-if="type === 'text' || type === 'input'" class="text">{{ text }}</div>
+            <div v-if="type === 'text'" class="text">{{ text }}</div>
 
             <div v-else-if="type === 'image'" class="image">
               <img :src="file_map_list[file_id]" />
@@ -111,15 +111,7 @@
           :autosize="{ minRows: 3 }"
           @keyup.enter.native="handleText"
         />
-      </div>
-
-      <el-button @click="identifyText">识别</el-button>
-      <div v-if="data.answer.answer_list.length > 0" class="correct-answer">
-        <template v-for="{ content_list } in data.answer.answer_list">
-          <el-input v-for="(item, i) in content_list" :key="item.mark" v-model="item.value">
-            <span slot="prefix">{{ i + 1 }}.</span>
-          </el-input>
-        </template>
+        <span class="tips">输入对话内容后请按回车上屏</span>
       </div>
 
       <div v-if="isEnable(data.property.is_enable_reference_answer)" class="reference-answer">
@@ -196,7 +188,7 @@
         </el-form-item>
         <el-form-item label="角色数">
           <el-select v-model="data.property.role_number" placeholder="请选择">
-            <el-option v-for="item in [1, 2, 3, 4, 5]" :key="item" :label="item" :value="item" />
+            <el-option v-for="item in 5" :key="item" :label="item" :value="item" />
           </el-select>
         </el-form-item>
         <el-form-item v-for="(item, i) in data.property.role_list" :key="i" :label="`角色 ${i + 1}`" class="role">
@@ -216,12 +208,7 @@ import SoundRecordPreview from '@/views/exercise_questions/preview/components/co
 
 import { getRandomNumber } from '@/utils';
 import { fileUpload, GetFileURLMap } from '@/api/app';
-import {
-  analysisRecognitionDialogueData,
-  getDialogueData,
-  getRole,
-  getTextContenList,
-} from '@/views/exercise_questions/data/dialogue';
+import { analysisRecognitionDialogueData, getDialogueData, getRole } from '@/views/exercise_questions/data/dialogue';
 
 export default {
   name: 'DialogueQuestion',
@@ -290,25 +277,6 @@ export default {
       let arr = this.recognitionCommon(text);
       let obj = analysisRecognitionDialogueData(arr);
       this.recognitionCommonSetObj(obj);
-      this.identifyText();
-    },
-    // 识别
-    identifyText() {
-      let answer_list = [];
-      this.data.option_list.forEach(({ type, mark, content_list }) => {
-        if (type !== 'input') return;
-        let answer = { mark, content_list: [] };
-        content_list.forEach(({ type, mark }) => {
-          if (type !== 'input') return;
-          answer.content_list.push({
-            mark,
-            value: this.data.answer.answer_list.find((item) => item.mark === mark)?.value || '',
-            type: 'any_one',
-          });
-        });
-        answer_list.push(answer);
-      });
-      this.data.answer.answer_list = answer_list;
     },
     // 音频上传前处理
     handleBeforeAudio(file) {
@@ -360,16 +328,12 @@ export default {
       if (this.curRole.length <= 0) {
         return this.$message.error('请先选择角色');
       }
-      let text = this.textInput.replace(/\n/, '');
 
-      let { hasFill, content_list } = getTextContenList(text);
       this.data.option_list.push({
         role: this.curRole,
         text: this.textInput.replace(/\n/, ''),
         mark: getRandomNumber(),
-        file_id: '',
-        content_list,
-        type: hasFill ? 'input' : 'text',
+        type: 'text',
       });
       this.textInput = '';
     },
@@ -390,12 +354,7 @@ export default {
      * @param {number} i 索引
      */
     deleteOption(i) {
-      let type = this.data.option_list[i].type;
       this.data.option_list.splice(i, 1);
-      // 如果删除的是 input,需要重新识别
-      if (type === 'input') {
-        this.identifyText();
-      }
     },
     // 插入学生
     insertStudent() {
@@ -553,6 +512,11 @@ export default {
       }
     }
   }
+
+  .tips {
+    font-size: 14px;
+    color: #e82d2d;
+  }
 }
 
 .correct-answer {

+ 1 - 38
src/views/exercise_questions/data/dialogue.js

@@ -18,40 +18,6 @@ export function getRole(index, name = '') {
 }
 
 /**
- * 获取文本内容列表
- * @param {string} text 文本
- */
-export function getTextContenList(text) {
-  let str = text;
-  let reg = /_{3,}/;
-  let hasFill = reg.test(str); // 是否有填空
-  let content_list = [];
-  if (hasFill) {
-    str = str.replace(/(_{3,})/g, '###$1###');
-    content_list = str
-      .split('###')
-      .filter((item) => item)
-      .map((content) => {
-        let isInput = reg.test(content);
-        return {
-          content: isInput ? '' : content,
-          mark: isInput ? getRandomNumber() : '',
-          type: isInput ? 'input' : 'text',
-        };
-      });
-  } else {
-    content_list = [
-      {
-        content: str,
-        mark: '',
-        type: 'text',
-      },
-    ];
-  }
-  return { hasFill, content_list };
-}
-
-/**
  * 解析智能识别数据
  * @param {array} arr 智能识别数据
  * @returns object
@@ -77,14 +43,11 @@ export function analysisRecognitionDialogueData(arr) {
   arr.forEach((item) => {
     if (item.match(/.+[::].+/)) {
       let [role, content] = item.split(/[::]/);
-      let { hasFill, content_list } = getTextContenList(content);
       option_list.push({
         role: role_list.find((item) => item.name === role).mark,
         text: content,
         mark: getRandomNumber(),
-        file_id: '',
-        content_list,
-        type: hasFill ? 'input' : 'text',
+        type: 'text',
       });
     }
     if (item.match(/^-学生$/)) {

+ 5 - 94
src/views/exercise_questions/preview/DialoguePreview.vue

@@ -36,34 +36,8 @@
           }}
         </span>
 
-        <div v-if="item.type === 'text' || item.type === 'input'" class="text-wrapper">
-          <div class="text">
-            <template v-for="(li, j) in item.content_list">
-              <span v-if="li.type === 'text'" :key="j">{{ li.content }}</span>
-              <template v-else-if="li.type === 'input'">
-                <el-input
-                  :key="j"
-                  v-model="li.content"
-                  :disabled="disabled"
-                  :class="[...computedAnswerClass(item.mark, li.mark, li.content)]"
-                  :style="[{ width: Math.max(80, li.content.length * 16) + 'px' }]"
-                />
-                <span
-                  v-show="computedAnswerText(item.mark, li.mark, li.content).length > 0"
-                  :key="`answer-${j}`"
-                  class="right-answer"
-                >
-                  {{ computedAnswerText(item.mark, li.mark, li.content) }}
-                </span>
-              </template>
-            </template>
-          </div>
-          <SoundRecordPreview
-            v-if="isEnable(data.property.is_enable_voice_answer) && item.type === 'input'"
-            :wav-blob.sync="item.file_id"
-            :disabled="disabled"
-            type="small"
-          />
+        <div v-if="item.type === 'text'" class="text-wrapper">
+          <div class="text">{{ item.text }}</div>
         </div>
 
         <div v-else-if="item.type === 'image'" class="image">
@@ -136,7 +110,7 @@ export default {
     optionList: {
       handler(val) {
         this.answer.answer_list = [];
-        val.forEach(({ type, content_list, mark, file_id }) => {
+        val.forEach(({ type, mark, file_id }) => {
           if (type === 'input_student') {
             if (file_id.length <= 0) return;
             this.answer.answer_list.push({
@@ -145,22 +119,6 @@ export default {
             });
             return;
           }
-          if (type !== 'input') return;
-          let list = content_list
-            .map(({ type, mark, content }) => {
-              if (type !== 'input') return;
-              return {
-                mark,
-                value: content,
-              };
-            })
-            .filter((item) => item);
-          if (list.length <= 0) return;
-          this.answer.answer_list.push({
-            content_list: list,
-            audio_file_id: file_id,
-            mark,
-          });
         });
       },
       deep: true,
@@ -168,60 +126,13 @@ export default {
     },
     isJudgingRightWrong(val) {
       if (!val) return;
-      this.answer.answer_list.forEach(({ mark, audio_file_id, content_list }) => {
+      this.answer.answer_list.forEach(({ mark, audio_file_id }) => {
         let findOption = this.optionList.find((item) => item.mark === mark);
         findOption.file_id = audio_file_id;
-        findOption?.content_list.forEach((item) => {
-          if (item.type === 'text') return;
-          let find = content_list.find((li) => li.mark === item.mark);
-          item.content = find.value;
-        });
       });
     },
   },
-  methods: {
-    /**
-     * 计算答题对错选项字体颜色
-     * @param {string} optionMark 选项标识
-     * @param {string} mark 选项标识
-     * @param {string} content 选项内容
-     */
-    computedAnswerClass(optionMark, mark, content) {
-      if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
-        return '';
-      }
-      let rightValue = this.data.answer.answer_list
-        .find((item) => item.mark === optionMark)
-        .content_list.find((item) => item.mark === mark).value;
-      let classList = [];
-      let isRight = rightValue.split('/').includes(content);
-
-      if (this.isJudgingRightWrong) {
-        isRight ? classList.push('right') : classList.push('wrong');
-      }
-
-      if (this.isShowRightAnswer && !isRight) {
-        classList.push('show-right-answer');
-      }
-      return classList;
-    },
-    /**
-     * 计算答题对错选项内容
-     * @param {string} optionMark 选项标识
-     * @param {string} mark 选项标识
-     * @param {string} content 选项内容
-     */
-    computedAnswerText(optionMark, mark, content) {
-      if (!this.isShowRightAnswer) return '';
-      if (content.length === 0) return '';
-      let find = this.data.answer.answer_list
-        .find((item) => item.mark === optionMark)
-        .content_list.find((item) => item.mark === mark);
-      if (find.value.split('/').includes(content)) return '';
-      if (!find) return '';
-      return `(${find.value})`;
-    },
-  },
+  methods: {},
 };
 </script>
 

+ 1 - 1
src/views/exercise_questions/preview/components/common/SoundRecordPreview.vue

@@ -234,7 +234,7 @@ export default {
               }, 1000);
             }
           })
-          .catch((error) => {
+          .catch(() => {
             this.$message.warning('请打开浏览器录音权限');
           });
       } else {