Bläddra i källkod

增加了一个简单的智能识别

dusenyao 1 år sedan
förälder
incheckning
ebca6bcc5f

+ 50 - 0
src/views/exercise_questions/create/components/common/IntelligentRecognition.vue

@@ -0,0 +1,50 @@
+<template>
+  <el-dialog :visible="visible" width="600px" @close="dialogClose">
+    <el-input v-model="text" type="textarea" rows="8" resize="none" placeholder="请输入内容" />
+
+    <template slot="footer">
+      <el-button @click="dialogClose">取消</el-button>
+      <el-button type="primary" @click="recognition">识别</el-button>
+    </template>
+  </el-dialog>
+</template>
+
+<script>
+export default {
+  name: 'IntelligentRecognition',
+  props: {
+    visible: {
+      type: Boolean,
+      required: true
+    }
+  },
+  data() {
+    return {
+      text: ''
+    };
+  },
+  methods: {
+    // 识别
+    recognition() {
+      this.$emit('recognition', this.text);
+      this.text = '';
+      this.$emit('update:visible', false);
+    },
+    dialogClose() {
+      this.$emit('update:visible', false);
+    }
+  }
+};
+</script>
+
+<style lang="scss" scoped>
+.el-dialog__wrapper {
+  :deep .el-dialog__header {
+    display: none;
+  }
+
+  :deep .el-textarea__inner {
+    font-size: 14px;
+  }
+}
+</style>

+ 14 - 2
src/views/exercise_questions/create/components/common/SelectQuestionType.vue

@@ -7,17 +7,24 @@
       :props="{ expandTrigger: 'hover' }"
       @change="handleChange"
     />
-    <div class="intelligent-recognition"><SvgIcon icon-class="copy" :size="14" />智能识别</div>
+    <div class="intelligent-recognition" @click="showRecognition"><SvgIcon icon-class="copy" :size="14" />智能识别</div>
     <div class="save-tip">{{ saveDate }} 已自动保存</div>
+
+    <IntelligentRecognition :visible.sync="dialogVisible" @recognition="recognition" />
   </div>
 </template>
 
 <script>
 import { questionTypeOption } from '@/views/exercise_questions/data/common';
 
+import IntelligentRecognition from '../common/IntelligentRecognition.vue';
+
 export default {
   name: 'SelectQuestionType',
-  inject: ['curSaveDate'],
+  components: {
+    IntelligentRecognition
+  },
+  inject: ['curSaveDate', 'recognition'],
   props: {
     type: {
       type: Array,
@@ -26,6 +33,7 @@ export default {
   },
   data() {
     return {
+      dialogVisible: false, // 智能识别弹窗
       typeArr: this.type,
       options: questionTypeOption
     };
@@ -38,6 +46,10 @@ export default {
   methods: {
     handleChange(val) {
       console.log(val);
+    },
+
+    showRecognition() {
+      this.dialogVisible = true;
     }
   }
 };

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

@@ -47,7 +47,8 @@ export default {
   },
   provide() {
     return {
-      curSaveDate: () => this.curSaveDate
+      curSaveDate: () => this.curSaveDate,
+      recognition: this.recognition
     };
   },
   props: {
@@ -154,6 +155,13 @@ export default {
       } catch (err) {
         console.log(err);
       }
+    },
+    /**
+     * 智能识别
+     * @param {String} text
+     */
+    recognition(text) {
+      this.$refs.exercise[0]?.recognition(text);
     }
   }
 };

+ 20 - 0
src/views/exercise_questions/create/components/exercises/SelectQuestion.vue

@@ -174,6 +174,26 @@ export default {
         this.data.file_id_list.splice(index, 1);
       }
     },
+    /**
+     * 智能识别
+     * @param {String} text 识别数据
+     */
+    recognition(text) {
+      let arr = text
+        .split(/[\r\n]/)
+        .map((item) => item.trim())
+        .filter((item) => item);
+
+      if (arr.length > 0) {
+        this.data.stem = arr[0];
+        this.data.options = arr.slice(1).map((content) => {
+          return {
+            mark: getRandomNumber(),
+            content
+          };
+        });
+      }
+    },
 
     getQuestion() {
       GetQuestion({ question_id: this.questionId })

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

@@ -56,7 +56,7 @@
 
 <script>
 import { exerciseNames } from '../data/common';
-import { AddQuestionToExercise, SaveQuestion, GetExerciseQuestionIndexList } from '@/api/exercise';
+import { AddQuestionToExercise, GetExerciseQuestionIndexList } from '@/api/exercise';
 
 import CreateMain from './components/create.vue';
 import SelectPreview from '@/views/exercise_questions/preview/SelectPreview.vue';

+ 1 - 1
src/views/home/personal_question/components/CreateExercise.vue

@@ -103,7 +103,7 @@ export default {
       });
     },
     dialogClose() {
-      this.$emit('update:dialogVisible');
+      this.$emit('update:dialogVisible', false);
     },
     createdExercise() {
       this.$refs.form.validate((valid) => {

+ 2 - 1
src/views/home/personal_question/index.vue

@@ -17,11 +17,12 @@
         <el-table-column prop="last_modifier_name" label="最近编辑" width="140" />
         <el-table-column prop="last_modify_time" label="最近编辑时间" width="180" />
         <el-table-column prop="intro" label="简介" width="240" />
-        <el-table-column label="状态" width="100">
+        <el-table-column label="状态" min-width="100">
           <template slot-scope="{ row }">
             <span :class="statusList[row.status].class">{{ statusList[row.status].name }}</span>
           </template>
         </el-table-column>
+
         <el-table-column prop="operation" label="操作" fixed="right" width="200">
           <template slot-scope="{ row }">
             <span class="link" @click="$router.push({ path: '/exercise', query: { id: row.id } })">编辑</span>

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

@@ -13,7 +13,7 @@
       </el-table-column>
       <el-table-column prop="intro" label="简介" width="280" />
       <el-table-column prop="teacher_name" label="发布者" width="180" />
-      <el-table-column prop="create_time" label="创建日期" width="180" />
+      <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>