Browse Source

对话题,插入学生支持角色

dusenyao 1 năm trước cách đây
mục cha
commit
25d42cd7c7

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

@@ -23,12 +23,16 @@
               class="avatar"
               :style="{
                 backgroundColor:
-                  type === 'input_student'
+                  type === 'input_student' && role.length === 0
                     ? '#306EFF'
                     : data.property.role_list.find((item) => item.mark === role).color,
               }"
             >
-              {{ type === 'input_student' ? '学生' : data.property.role_list.find((item) => item.mark === role).name }}
+              {{
+                type === 'input_student' && role.length === 0
+                  ? '学生'
+                  : data.property.role_list.find((item) => item.mark === role).name
+              }}
             </span>
 
             <div v-if="type === 'text'" class="text">{{ text }}</div>
@@ -115,6 +119,7 @@
       </div>
 
       <div v-if="isEnable(data.property.is_enable_reference_answer)" class="reference-answer">
+        <div class="reference-title">参考答案:</div>
         <el-input v-model="data.reference_answer" type="textarea" rows="3" placeholder="输入参考答案" />
       </div>
     </template>
@@ -360,6 +365,7 @@ export default {
     insertStudent() {
       this.data.option_list.push({
         mark: getRandomNumber(),
+        role: '',
         file_id: '',
         type: 'input_student',
       });
@@ -538,6 +544,11 @@ export default {
 
 .reference-answer {
   margin-top: 8px;
+
+  .reference-title {
+    margin-bottom: 8px;
+    font-size: 14px;
+  }
 }
 
 .el-form {

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

@@ -26,12 +26,19 @@ export function analysisRecognitionDialogueData(arr) {
   // 角色列表
   let roleList = [];
   arr.forEach((item) => {
+    if (item.match(/^-\S+/)) {
+      let role = item.split(/^-/)[1];
+      if (!roleList.includes(role) && role !== '学生') {
+        roleList.push(role);
+      }
+    }
     if (!item.match(/.+[::].+/)) return;
     let [role] = item.split(/[::]/);
     if (!roleList.includes(role)) {
       roleList.push(role);
     }
   });
+
   if (roleList.length < 1 || roleList.length > 5) {
     Message.warning('角色数不符合要求,最小为 1,最大为 5');
     return {};
@@ -39,6 +46,7 @@ export function analysisRecognitionDialogueData(arr) {
   let role_number = roleList.length;
   let role_list = roleList.map((item, i) => getRole(i, item));
 
+  // 选项列表
   let option_list = [];
   arr.forEach((item) => {
     if (item.match(/.+[::].+/)) {
@@ -50,14 +58,19 @@ export function analysisRecognitionDialogueData(arr) {
         type: 'text',
       });
     }
-    if (item.match(/^-学生$/)) {
+
+    if (item.match(/^-\S+/)) {
+      let isStudent = /^-学生$/.test(item); // 是否是学生
+
       option_list.push({
         mark: getRandomNumber(),
+        role: isStudent ? '' : role_list.find(({ name }) => name === item.split(/^-/)[1]).mark,
         file_id: '',
         type: 'input_student',
       });
     }
   });
+
   return {
     'data.property.role_number': role_number,
     'data.property.role_list': role_list,

+ 2 - 2
src/views/exercise_questions/preview/DialoguePreview.vue

@@ -24,13 +24,13 @@
           class="avatar"
           :style="{
             backgroundColor:
-              item.type === 'input_student'
+              item.type === 'input_student' && item.role.length === 0
                 ? '#306EFF'
                 : data.property.role_list?.find(({ mark }) => mark === item.role).color,
           }"
         >
           {{
-            item.type === 'input_student'
+            item.type === 'input_student' && item.role.length === 0
               ? '学生'
               : data.property.role_list?.find(({ mark }) => mark === item.role).name
           }}