Explorar o código

更新 ExamQuestionAdd.vue, 使用的两个 el-table 通过添加 key 属性来区分

reghao hai 1 ano
pai
achega
4cb7309bec
Modificáronse 1 ficheiros con 119 adicións e 143 borrados
  1. 119 143
      src/views/exam/ExamQuestionAdd.vue

+ 119 - 143
src/views/exam/ExamQuestionAdd.vue

@@ -28,7 +28,7 @@
               </el-select>
             </el-form-item>
             <el-form-item label="试题类型" label-width="120px" prop="questionType">
-              <el-select v-model="addQuForm.questionType" placeholder="请选择" @change="addQuForm.answer = []">
+              <el-select v-model="addQuForm.questionType" placeholder="请选择" @change="addQuForm.options = []">
                 <el-option
                   v-for="item in questionType"
                   :key="item.id"
@@ -45,7 +45,7 @@
               </el-select>
             </el-form-item>
             <el-form-item label="试题内容" label-width="120px" prop="questionContent">
-                            <el-input
+              <el-input
                 v-model="addQuForm.questionContent"
                 style="margin-left: 5px"
                 type="textarea"
@@ -53,33 +53,27 @@
               />
             </el-form-item>
             <el-form-item label="试题解析" label-width="120px" prop="analysis">
-                            <el-input
+              <el-input
                 v-model="addQuForm.analysis"
                 style="margin-left: 5px"
                 type="textarea"
                 :rows="5"
               />
             </el-form-item>
-            <el-form-item label="试题答案" label-width="120px" prop="option">
-              <el-radio-group v-model="radio" @change="onRadioChange">
-                <el-radio :label="1">正确</el-radio>
-                <el-radio :label="2">错误</el-radio>
-              </el-radio-group>
-            </el-form-item>
-            <div v-if="addQuForm.questionType <= 7">
+            <div v-if="addQuForm.questionType <= 3">
               <el-button
                 type="primary"
                 plain
                 size="small"
                 icon="el-icon-plus"
                 style="margin-left: 40px"
-                @click="addAnswer"
+                @click="addOptionAnswer"
               >
-                添加答案选项
+                添加候选答案
               </el-button>
-              <!--存放答案表单的信息-->
+              <!-- 存放候选答案的表单 -->
               <el-form-item prop="options">
-                <el-table :data="addQuForm.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
+                <el-table key="optionAnswer" :data="addQuForm.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
                   <el-table-column label="是否答案" width="80" align="center">
                     <template slot-scope="scope">
                       <el-checkbox v-model="scope.row.correct" @change="checked=>checkAnswer(checked,scope.row.id)">答案
@@ -115,7 +109,58 @@
                 </el-table>
               </el-form-item>
             </div>
-            <div v-else>
+            <div v-else-if="addQuForm.questionType === 4">
+              <el-form-item label="试题答案" label-width="120px" prop="option">
+                <el-radio-group v-model="answerContent4" @change="onRadioChange">
+                  <el-radio :label="0">正确</el-radio>
+                  <el-radio :label="1">错误</el-radio>
+                </el-radio-group>
+              </el-form-item>
+            </div>
+            <div v-else-if="addQuForm.questionType === 5">
+              <el-button
+                type="primary"
+                plain
+                size="small"
+                icon="el-icon-plus"
+                style="margin-left: 40px"
+                @click="addAnswer"
+              >
+                添加答案
+              </el-button>
+              <!-- 存放答案的表单 -->
+              <el-form-item prop="options">
+                <el-table key="answer" :data="addQuForm.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
+                  <el-table-column label="顺序" prop="pos" />
+                  <el-table-column label="答案">
+                    <template slot-scope="scope">
+                      <el-input
+                        v-model="scope.row.content"
+                        style="margin-left: 5px"
+                        type="textarea"
+                        :rows="2"
+                      />
+                    </template>
+                  </el-table-column>
+                  <el-table-column label="答案解析">
+                    <template slot-scope="scope">
+                      <el-input
+                        v-model="scope.row.analysis"
+                        style="margin-left: 5px"
+                        type="textarea"
+                        :rows="2"
+                      />
+                    </template>
+                  </el-table-column>
+                  <el-table-column label="操作" width="80" align="center">
+                    <template slot-scope="scope">
+                      <el-button type="danger" icon="el-icon-delete" circle @click="delAnswer(scope.row.id)" />
+                    </template>
+                  </el-table-column>
+                </el-table>
+              </el-form-item>
+            </div>
+            <div v-else-if="addQuForm.questionType === 8">
               <el-button
                 type="primary"
                 plain
@@ -137,6 +182,17 @@
                 查看組题
               </el-button>
             </div>
+            <div v-else>
+              <el-form-item label="参考答案" label-width="120px">
+                <el-input
+                  v-model="answerContent8"
+                  style="margin-left: 5px"
+                  type="textarea"
+                  :rows="5"
+                  @blur="onInputBlur"
+                />
+              </el-form-item>
+            </div>
           </el-form>
         </div>
       </el-card>
@@ -163,20 +219,6 @@
               :rows="5"
             />
           </el-form-item>
-          <el-form-item label="试题图片" label-width="120px" prop="image">
-            <el-upload
-              :action="uploadImageUrl + '/teacher/uploadQuestionImage'"
-              :on-preview="uploadPreview"
-              :on-remove="handleRemove"
-              :before-upload="beforeAvatarUpload"
-              list-type="picture"
-              :on-success="uploadImgSuccess"
-              name="file"
-            >
-              <el-button size="small" type="primary">点击上传</el-button>
-              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过10M</div>
-            </el-upload>
-          </el-form-item>
           <el-form-item label="试题解析" label-width="120px" prop="analysis">
             <el-input
               v-model="questionForm.analysis"
@@ -206,22 +248,6 @@
                   >答案</el-checkbox>
                 </template>
               </el-table-column>
-              <el-table-column label="选项图片">
-                <template slot-scope="scope">
-                  <el-upload
-                    :limit="1"
-                    :action="uploadImageUrl + '/teacher/uploadQuestionImage'"
-                    :on-preview="uploadPreview"
-                    :on-remove="handleAnswerRemove"
-                    :before-upload="beforeAvatarUpload"
-                    list-type="picture"
-                    :on-success="(res) => { return uploadAnswerImgSuccess(res,scope.row.id)}"
-                    name="file"
-                  >
-                    <el-button size="small" type="primary">点击上传</el-button>
-                  </el-upload>
-                </template>
-              </el-table-column>
               <el-table-column label="选项内容">
                 <template slot-scope="scope">
                   <el-input
@@ -261,9 +287,6 @@
         <el-table-column label="题目" prop="questionContent" />
       </el-table>
     </el-dialog>
-    <el-dialog title="图片回显" :visible.sync="backShowImgVisible" @close="backShowImgVisible = false">
-      <img style="width: 100%" :src="backShowImgUrl" alt="">
-    </el-dialog>
   </el-container>
 </template>
 
@@ -312,45 +335,8 @@ export default {
       ],
       // 题库信息
       allSubject: [],
-      // 表格被选中的所有行
-      selectionTable: [],
-      // 表格行被选中后的数据
-      operation: '',
-      // 试题总数
-      total: 0,
-      // 是否显示加入题库对话框
-      addTableVisible: false,
-      // 是否显示移除题库对话框
-      removeTableVisible: false,
       // 是否显示添加试题的对话框
       addQuTableVisible: false,
-      // 添加题库的表单信息
-      addForm: {
-        subjectId: ''
-      },
-      removeForm: {
-        subjectId: ''
-      },
-      // 添加题库表单的验证
-      addFormRules: {
-        subjectId: [
-          {
-            required: true,
-            message: '请选择需要添加进的题库',
-            trigger: 'blur'
-          }
-        ]
-      },
-      // 移除题库表单的验证
-      removeFormRules: {
-        subjectId: [
-          {
-            required: true,
-            message: '请选择需要移除的题库',
-            trigger: 'blur'
-          }
-        ]
-      },
       // 添加试题的表单信息
       addQuForm: {
         questionType: 1,
@@ -364,16 +350,6 @@ export default {
         options: [],
         children: []
       },
-      questionForm: {
-        questionType: 1,
-        questionLevel: 1,
-        subjectId: '',
-        questionContent: '',
-        images: [],
-        analysis: '',
-        // 答案对象
-        options: []
-      },
       // 添加试题表单的验证规则
       addQuFormRules: {
         questionType: [
@@ -405,12 +381,19 @@ export default {
           }
         ]
       },
-      // 图片回显的样式
-      backShowImgVisible: false,
-      // 图片回显的图片地址
-      backShowImgUrl: '',
+      questionForm: {
+        questionType: 1,
+        questionLevel: 1,
+        subjectId: '',
+        questionContent: '',
+        images: [],
+        analysis: '',
+        // 答案对象
+        options: []
+      },
       groupQuestionVisible: false,
-      radio: 1
+      answerContent4: null,
+      answerContent8: null
     }
   },
   created() {
@@ -419,12 +402,28 @@ export default {
   },
   methods: {
     onRadioChange(val) {
-      this.$notify({
-        title: 'Tips',
-        message: 'radio',
-        type: 'success',
-        duration: 2000
-      })
+      let correct = false
+      if (val === 0) {
+        correct = true
+      }
+      this.addQuForm.options[0] = {
+        id: this.addQuForm.options.length,
+        correct: correct,
+        content: '',
+        pos: this.addQuForm.options.length + 1,
+        images: [],
+        analysis: ''
+      }
+    },
+    onInputBlur() {
+      this.addQuForm.options[0] = {
+        id: this.addQuForm.options.length,
+        correct: true,
+        content: this.answerContent,
+        pos: this.addQuForm.options.length + 1,
+        images: [],
+        analysis: ''
+      }
     },
     // 获取所有的题库信息
     getQuestionBankInfo() {
@@ -434,58 +433,35 @@ export default {
         }
       })
     },
-    // 处理表格被选中
-    handleTableSectionChange(val) {
-      this.selectionTable = val
-    },
     // ****************************************************************************************************************
     // 表单信息重置
     resetQuestionForm() {
       this.$refs['questionForm'].resetFields()
+      this.answerContent = ''
     },
     resetAddQuForm() {
       this.$refs['addQuForm'].resetFields()
+      this.addQuForm.options = []
+      this.answerContent = ''
     },
     // ****************************************************************************************************************
 
-    // ****************************************************************************************************************
-    // 新增试题上传后 点击图片的回显
-    uploadPreview(file) {
-      this.backShowImgUrl = file.response.data
-      this.backShowImgVisible = true
-    },
-    // 新增试题中的上传图片的移除
-    handleRemove(file, fileList) {
-      this.addQuForm.images.map((item, index) => { // 移除图片在表单中的数据
-        if (item === file.response.data) this.addQuForm.images.splice(index, 1)
+    // 新增试题中的新增答案填写框
+    addOptionAnswer() {
+      this.addQuForm.options.push({
+        id: this.addQuForm.options.length,
+        correct: false,
+        content: '',
+        pos: this.addQuForm.options.length + 1,
+        images: [],
+        analysis: ''
       })
     },
-    // 新增试题中的上传图片的格式大小限制
-    beforeAvatarUpload(file) {
-      const isImg = file.type === 'image/jpeg' ||
-        file.type === 'image/png' ||
-        file.type === 'image/jpg'
-      const isLt = file.size / 1024 / 1024 < 10
-
-      if (!isImg) {
-        this.$message.error('上传图片只能是 JPG/PNG 格式!')
-      }
-
-      if (!isLt) {
-        this.$message.error('上传头像图片大小不能超过 10MB!')
-      }
-      return isImg && isLt
-    },
-    // 新增试题中的上传图片成功后的钩子函数
-    uploadImgSuccess(response, file, fileList) {
-      this.addQuForm.images.push(response.data)
-    },
-    // ****************************************************************************************************************
-    // 新增试题中的新增答案填写框
     addAnswer() {
+      console.log('添加答案')
       this.addQuForm.options.push({
         id: this.addQuForm.options.length,
-        correct: false,
+        correct: true,
         content: '',
         pos: this.addQuForm.options.length + 1,
         images: [],