浏览代码

课程管理-课程题库 添加题库默认-展示4个选项、新增选项位置调整

Long 3 周之前
父节点
当前提交
7d12de3cbf
共有 1 个文件被更改,包括 12 次插入3 次删除
  1. 12 3
      src/views/course/courseQuestionBank/index.vue

+ 12 - 3
src/views/course/courseQuestionBank/index.vue

@@ -227,6 +227,7 @@
         <el-alert v-if="!form.type" title="选择题目类别后添加选项" type="warning" show-icon></el-alert>
 
         <el-form-item label="选项"  v-if="form.type">
+          <el-button @click="addRow" size="mini" type="primary">新增选项</el-button>
           <el-table border :data="question"  :cell-style="{ textAlign: 'center' }"		 :header-cell-style="{textAlign: 'center'}"   >
             <el-table-column label="序号" width="65px" >
               <template slot-scope="scope">
@@ -267,7 +268,6 @@
             <el-table-column label="操作">
               <template slot-scope="scope">
                 <el-button @click="deleteRow(scope.$index)"   size="mini" type="text" v-if="question.length>1">删除</el-button>
-                <el-button @click="addRow(scope.$index+1)" size="mini" type="text" >新增</el-button>
               </template>
             </el-table-column>
           </el-table>
@@ -344,6 +344,9 @@ export default {
       statusOptions: [],
       question:[
         { name: "", isAnswer: 0, indexId:0},
+        { name: "", isAnswer: 0, indexId:1},
+        { name: "", isAnswer: 0, indexId:2},
+        { name: "", isAnswer: 0, indexId:3},
       ],
       // 遮罩层
       loading: true,
@@ -486,8 +489,8 @@ export default {
       }
 
     },
-    addRow(val) {
-      this.question.push({ name: '', isAnswer: 0,indexId:val});},
+    addRow() {
+      this.question.push({ name: '', isAnswer: 0,indexId: this.question.length});},
     deleteRow(index) {
       if (this.form.type === 1 && this.question[index] === this.selectedAnswer) {
         this.selectedAnswer = null;
@@ -570,6 +573,12 @@ export default {
     submitForm() {
       this.$refs["form"].validate(valid => {
         if (valid) {
+
+          if (this.question.some(q => q.name === "")) {
+            this.$message.error("不能存在空选项")
+            return
+          }
+
           this.form.question=JSON.stringify(this.question)
 
           if (this.form.type===2){