浏览代码

update exam module

reghao 1 年之前
父节点
当前提交
19150d4395
共有 5 个文件被更改,包括 950 次插入99 次删除
  1. 5 1
      src/api/exam.js
  2. 7 0
      src/router/admin.js
  3. 2 2
      src/views/admin/Admin.vue
  4. 255 96
      src/views/exam/ExamQuestion.vue
  5. 681 0
      src/views/exam/ExamQuestionAdd.vue

+ 5 - 1
src/api/exam.js

@@ -1,4 +1,4 @@
-import { get, post } from '@/utils/request'
+import {delete0, get, post} from '@/utils/request'
 
 const examApi = {
   getExamSubject: '/api/content/exam/subject',
@@ -25,6 +25,10 @@ export function getExamQuestion() {
   return get(examApi.getExamQuestion1)
 }
 
+export function deleteExamQuestion(questionId) {
+  return delete0(examApi.getExamQuestion + '/' + questionId)
+}
+
 export function getExamQuestion1(questionId) {
   return get(examApi.getExamQuestion1 + '/' + questionId)
 }

+ 7 - 0
src/router/admin.js

@@ -14,6 +14,7 @@ const ExamCard = () => import('views/exam/ExamCard')
 const ExamResult = () => import('views/exam/ExamResult')
 const ExamSubject = () => import('views/exam/ExamSubject')
 const ExamQuestion = () => import('views/exam/ExamQuestion')
+const ExamQuestionAdd = () => import('views/exam/ExamQuestionAdd')
 const ExamPaper = () => import('views/exam/ExamPaper')
 const ExamMarker = () => import('views/exam/ExamMarker')
 const ExamResults = () => import('views/exam/ExamResults')
@@ -60,6 +61,12 @@ export default {
       component: ExamQuestion,
       meta: { needAuth: true }
     },
+    {
+      path: '/exam/question/add',
+      name: 'ExamQuestionAdd',
+      component: ExamQuestionAdd,
+      meta: { needAuth: true }
+    },
     {
       path: '/exam/paper',
       name: 'ExamPaper',

+ 2 - 2
src/views/admin/Admin.vue

@@ -38,7 +38,7 @@
           class="el-menu-vertical-demo"
           :unique-opened="true"
         >
-          <el-submenu index="/exam">
+          <el-submenu index="/exam/my">
             <template slot="title">
               <i class="el-icon-user" />
               <span slot="title">我的考试</span>
@@ -54,7 +54,7 @@
               </el-menu-item>
             </el-menu-item-group>
           </el-submenu>
-          <el-submenu index="/exam">
+          <el-submenu index="/exam/question">
             <template slot="title">
               <i class="el-icon-user" />
               <span slot="title">考试管理</span>

+ 255 - 96
src/views/exam/ExamQuestion.vue

@@ -87,13 +87,18 @@
           prop="createAt"
           label="创建时间"
         />
-        <el-table-column label="操作" width="80" align="center">
+        <el-table-column label="操作">
           <template slot-scope="scope">
             <el-button
               size="mini"
-              type="warning"
+              type="info"
               @click="viewDetail(scope.row.questionId)"
             >查看</el-button>
+            <el-button
+              size="mini"
+              type="danger"
+              @click="onDeleteQuestion(scope.row.questionId)"
+            >删除</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -329,87 +334,169 @@
               :rows="5"
             />
           </el-form-item>
-          <el-button
-            v-if="addQuForm.questionType < 5"
-            type="primary"
-            plain
-            size="small"
-            icon="el-icon-plus"
-            style="margin-left: 40px"
-            @click="addAnswer"
-          >
-            添加问题选项
-          </el-button>
-          <!--存放答案表单的信息-->
-          <el-form-item v-if="addQuForm.questionType < 5" prop="options">
-            <el-table :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)">答案
-                  </el-checkbox>
-                </template>
-              </el-table-column>
-              <el-table-column label="选项图片">
-                <template slot-scope="scope">
+          <div v-if="addQuForm.questionType <= 7">
+            <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 :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)">答案
+                    </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
+                      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>
+            <el-card>
+              <el-form ref="addQuForm" :model="questionForm" :rules="addQuFormRules">
+                <el-form-item label="试题内容" label-width="120px" prop="questionContent">
+                  <el-input
+                    v-model="questionForm.questionContent"
+                    style="margin-left: 5px"
+                    type="textarea"
+                    :rows="5"
+                  />
+                </el-form-item>
+                <el-form-item label="试题图片" label-width="120px" prop="image">
                   <el-upload
-                    :limit="1"
                     :action="uploadImageUrl + '/teacher/uploadQuestionImage'"
                     :on-preview="uploadPreview"
-                    :on-remove="handleAnswerRemove"
+                    :on-remove="handleRemove"
                     :before-upload="beforeAvatarUpload"
                     list-type="picture"
-                    :on-success="(res) => { return uploadAnswerImgSuccess(res,scope.row.id)}"
+                    :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>
-                </template>
-              </el-table-column>
-              <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-form-item>
+                <el-form-item label="试题解析" label-width="120px" prop="analysis">
                   <el-input
-                    v-model="scope.row.analysis"
+                    v-model="questionForm.analysis"
                     style="margin-left: 5px"
                     type="textarea"
-                    :rows="2"
+                    :rows="5"
                   />
-                </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 v-else>
-            <el-divider/>
-            <el-form-item label="答案" label-width="120px" prop="answerContent">
-              <el-input
-                v-model="addQuForm.answerContent"
-                style="margin-left: 5px"
-                type="textarea"
-                :rows="5"
-              />
-            </el-form-item>
-            <el-form-item label="答案解析" label-width="120px" prop="answerAnalysis">
-              <el-input
-                v-model="addQuForm.answerAnalysis"
-                style="margin-left: 5px"
-                type="textarea"
-                :rows="5"
-              />
-            </el-form-item>
+                </el-form-item>
+                <div>
+                  <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 :data="questionForm.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)">答案
+                          </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
+                            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>
+              </el-form>
+            </el-card>
           </div>
         </el-form>
       </el-card>
@@ -433,13 +520,12 @@
           <el-form-item label="试题内容" label-width="120px">
             <span> {{ questionDetail.content }} </span>
           </el-form-item>
-          <el-form-item label="试题图片" label-width="120px">
-          </el-form-item>
+          <el-form-item label="试题图片" label-width="120px" />
           <el-form-item label="试题解析" label-width="120px">
             <span> {{ questionDetail.analysis }} </span>
           </el-form-item>
           <el-divider />
-          <el-form-item v-if="questionDetail.type < 5" label="试题选项" label-width="120px">
+          <el-form-item v-if="questionDetail.type <= 7" label="试题选项" label-width="120px">
             <el-table :data="questionDetail.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
               <el-table-column label="正确答案" align="center">
                 <template slot-scope="scope">
@@ -461,22 +547,49 @@
               />
             </el-table>
           </el-form-item>
-          <el-form-item label="试题答案" label-width="120px">
-            <el-table :data="questionDetail.answers" border style="width: 96%;margin-left: 40px;margin-top: 10px">
-              <el-table-column
-                prop="option"
-                label="选项"
-              />
-              <el-table-column
-                prop="content"
-                label="内容"
-              />
-              <el-table-column
-                prop="analysis"
-                label="答案解析"
-              />
-            </el-table>
-          </el-form-item>
+
+          <div v-if="questionDetail.children">
+            <div v-for="item in questionDetail.children">
+              <el-form :model="item">
+                <el-form-item label="试题类型" label-width="120px">
+                  <span> {{ item.typeStr }} </span>
+                </el-form-item>
+                <el-form-item label="试题难度" label-width="120px">
+                  <span> {{ item.level }} </span>
+                </el-form-item>
+                <el-form-item label="试题内容" label-width="120px">
+                  <span> {{ item.content }} </span>
+                </el-form-item>
+                <el-form-item label="试题图片" label-width="120px" />
+                <el-form-item label="试题解析" label-width="120px">
+                  <span> {{ item.analysis }} </span>
+                </el-form-item>
+                <el-form-item v-if="item.type <= 7" label="试题选项" label-width="120px">
+                  <el-table :data="item.options" border style="width: 96%;margin-left: 40px;margin-top: 10px">
+                    <el-table-column label="正确答案" align="center">
+                      <template slot-scope="scope">
+                        <span v-if="scope.row.correct">YES</span>
+                        <span v-else>NO</span>
+                      </template>
+                    </el-table-column>
+                    <el-table-column
+                      prop="option"
+                      label="选项"
+                    />
+                    <el-table-column
+                      prop="content"
+                      label="内容"
+                    />
+                    <el-table-column
+                      prop="analysis"
+                      label="解析"
+                    />
+                  </el-table>
+                </el-form-item>
+                <el-divider />
+              </el-form>
+            </div>
+          </div>
         </el-form>
       </el-card>
       <div slot="footer" class="dialog-footer">
@@ -551,7 +664,7 @@
 </template>
 
 <script>
-import { getExamSubjectKV, postExamQuestion, getExamQuestion, getExamQuestion1 } from '@/api/exam'
+import {getExamSubjectKV, postExamQuestion, getExamQuestion, getExamQuestion1, deleteExamQuestion} from '@/api/exam'
 import { validFormAndInvoke } from '@/utils/util'
 
 export default {
@@ -604,6 +717,10 @@ export default {
         {
           id: 7,
           name: '理解题'
+        },
+        {
+          id: 8,
+          name: '組题'
         }
       ],
       // 题库信息
@@ -676,10 +793,18 @@ export default {
         analysis: '',
         createPerson: localStorage.getItem('username'),
         // 答案对象
-        // answer: [],
         options: [],
-        answerContent: '',
-        answerAnalysis: ''
+        children: []
+      },
+      questionForm: {
+        questionType: 1,
+        questionLevel: 1,
+        subjectId: '',
+        questionContent: '',
+        images: [],
+        analysis: '',
+        // 答案对象
+        options: []
       },
       // 添加试题表单的验证规则
       addQuFormRules: {
@@ -1079,7 +1204,7 @@ export default {
           postExamQuestion(this.addQuForm).then((resp) => {
             if (resp.code === 0) {
               this.addQuTableVisible = false
-              this.getQuestionInfo()
+              this.getData(this.searchForm)
               this.$notify({
                 title: 'Tips',
                 message: '新增试题成功',
@@ -1091,7 +1216,22 @@ export default {
         } else if (valid && !this.addQuForm.options.some(item => item.correct) && this.addQuForm.questionType < 5) { // 无答案
           this.$message.error('必须有一个答案')
           return false
-        } else if (valid && this.addQuForm.questionType >= 5) { // 简答题 无标准答案直接发请求
+        } else if (valid && this.addQuForm.questionType >= 5 && this.addQuForm.questionType <= 7) { // 简答题 无标准答案直接发请求
+          // 当是简答题的时候需要清除answer
+          this.addQuForm.options = []
+          postExamQuestion(this.addQuForm).then((resp) => {
+            if (resp.code === 0) {
+              this.addQuTableVisible = false
+              this.getQuestionInfo()
+              this.$notify({
+                title: 'Tips',
+                message: '新增试题成功',
+                type: 'success',
+                duration: 2000
+              })
+            }
+          })
+        } else if (this.addQuForm.questionType > 7) { // 組题
           // 当是简答题的时候需要清除answer
           this.addQuForm.options = []
           postExamQuestion(this.addQuForm).then((resp) => {
@@ -1186,7 +1326,6 @@ export default {
       getExamQuestion1(questionId).then(resp => {
         if (resp.code === 0) {
           this.questionDetail = resp.data
-          console.log(this.questionDetail)
           this.questionDetailDialog = true
         } else {
           this.$notify({
@@ -1197,6 +1336,26 @@ export default {
           })
         }
       })
+    },
+    onDeleteQuestion(questionId) {
+      deleteExamQuestion(questionId).then(resp => {
+        if (resp.code === 0) {
+          this.$notify({
+            title: 'Tips',
+            message: '试题 ' + questionId + ' 已删除',
+            type: 'success',
+            duration: 1000
+          })
+          window.location.reload()
+        } else {
+          this.$notify({
+            title: 'Error',
+            message: resp.msg,
+            type: 'error',
+            duration: 1000
+          })
+        }
+      })
     }
   }
 }

+ 681 - 0
src/views/exam/ExamQuestionAdd.vue

@@ -0,0 +1,681 @@
+<template>
+  <el-container>
+    <el-header height="90">
+      <el-breadcrumb
+        class="bread"
+        separator-class="el-icon-arrow-right"
+      >
+        <el-breadcrumb-item :to="{ path: '' }"><a href="/exam/question">返回试题列表</a></el-breadcrumb-item>
+      </el-breadcrumb>
+    </el-header>
+    <el-main>
+      <el-card class="box-card">
+        <div slot="header" class="clearfix">
+          <span>添加试题</span>
+          <el-button style="float: right; padding: 10px" type="text" @click="addQuestion">提交数据</el-button>
+          <el-button style="float: right; padding: 10px" type="text" @click="clear">清空数据</el-button>
+        </div>
+        <div class="text item">
+          <el-form ref="addQuForm" :model="addQuForm" :rules="addQuFormRules">
+            <el-form-item label="所属科目" label-width="120px" prop="subjectId">
+              <el-select v-model="addQuForm.subjectId" placeholder="请选择">
+                <el-option
+                  v-for="item in allSubject"
+                  :key="item.key"
+                  :label="item.value"
+                  :value="item.key"
+                />
+              </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-option
+                  v-for="item in questionType"
+                  :key="item.id"
+                  :label="item.name"
+                  :value="item.id"
+                />
+              </el-select>
+            </el-form-item>
+            <el-form-item label="试题难度" label-width="120px" prop="questionLevel">
+              <el-select v-model="addQuForm.questionLevel" placeholder="请选择">
+                <el-option :value="parseInt(1)" label="简单" />
+                <el-option :value="parseInt(2)" label="中等" />
+                <el-option :value="parseInt(3)" label="困难" />
+              </el-select>
+            </el-form-item>
+            <el-form-item label="试题内容" label-width="120px" prop="questionContent">
+                            <el-input
+                v-model="addQuForm.questionContent"
+                style="margin-left: 5px"
+                type="textarea"
+                :rows="5"
+              />
+            </el-form-item>
+            <el-form-item label="试题解析" label-width="120px" prop="analysis">
+                            <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">
+              <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 :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)">答案
+                      </el-checkbox>
+                    </template>
+                  </el-table-column>
+                  <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="5"
+                      />
+                    </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="5"
+                      />
+                    </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>
+              <el-button
+                type="primary"
+                plain
+                size="small"
+                icon="el-icon-plus"
+                style="margin-left: 40px"
+                @click="addQuTableVisible = true"
+              >
+                添加組题
+              </el-button>
+              <el-button
+                type="primary"
+                plain
+                size="small"
+                icon="el-icon-view"
+                style="margin-left: 40px"
+                @click="viewGroupQuestion"
+              >
+                查看組题
+              </el-button>
+            </div>
+          </el-form>
+        </div>
+      </el-card>
+    </el-main>
+
+    <el-dialog title="添加組题" :visible.sync="addQuTableVisible" width="70%" center @close="resetQuestionForm">
+      <el-card>
+        <el-form ref="questionForm" :model="questionForm" :rules="addQuFormRules">
+          <el-form-item label="试题类型" label-width="120px" prop="questionType">
+            <el-select v-model="questionForm.questionType" placeholder="请选择" @change="questionForm.options = []">
+              <el-option
+                v-for="item in questionType"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              />
+            </el-select>
+          </el-form-item>
+          <el-form-item label="试题内容" label-width="120px" prop="questionContent">
+            <el-input
+              v-model="questionForm.questionContent"
+              style="margin-left: 5px"
+              type="textarea"
+              :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"
+              style="margin-left: 5px"
+              type="textarea"
+              :rows="5"
+            />
+          </el-form-item>
+          <el-button
+            type="primary"
+            plain
+            size="small"
+            icon="el-icon-plus"
+            style="margin-left: 40px"
+            @click="addGroupQuestionAnswer"
+          >
+            添加问题选项
+          </el-button>
+          <!--存放答案表单的信息-->
+          <el-form-item prop="options">
+            <el-table :data="questionForm.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=>checkGroupQuestionAnswer(checked,scope.row.id)"
+                  >答案</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
+                    v-model="scope.row.content"
+                    style="margin-left: 5px"
+                    type="textarea"
+                    :rows="5"
+                  />
+                </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="5"
+                  />
+                </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>
+        </el-form>
+      </el-card>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="addGroupQuestion">添 加</el-button>
+        <el-button @click="addQuTableVisible = false">关 闭</el-button>
+      </div>
+    </el-dialog>
+    <el-dialog title="查看組题" :visible.sync="groupQuestionVisible" width="70%" center @close="resetQuestionForm">
+      <el-table :data="addQuForm.children" border style="width: 96%;margin-left: 40px;margin-top: 10px">
+        <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>
+
+<script>
+import { getExamSubjectKV, postExamQuestion } from '@/api/exam'
+
+export default {
+  name: 'ExamQuestionAdd',
+  data() {
+    return {
+      uploadImageUrl: '/',
+      // 试题类型
+      questionType: [
+        {
+          id: 1,
+          name: '单选题'
+        },
+        {
+          id: 2,
+          name: '多选题'
+        },
+        {
+          id: 3,
+          name: '不定项选择题'
+        },
+        {
+          id: 4,
+          name: '判断题'
+        },
+        {
+          id: 5,
+          name: '填空题'
+        },
+        {
+          id: 6,
+          name: '问答题'
+        },
+        {
+          id: 7,
+          name: '理解题'
+        },
+        {
+          id: 8,
+          name: '組题'
+        }
+      ],
+      // 题库信息
+      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,
+        questionLevel: 1,
+        subjectId: '',
+        questionContent: '',
+        images: [],
+        analysis: '',
+        createPerson: localStorage.getItem('username'),
+        // 答案对象
+        options: [],
+        children: []
+      },
+      questionForm: {
+        questionType: 1,
+        questionLevel: 1,
+        subjectId: '',
+        questionContent: '',
+        images: [],
+        analysis: '',
+        // 答案对象
+        options: []
+      },
+      // 添加试题表单的验证规则
+      addQuFormRules: {
+        questionType: [
+          {
+            required: true,
+            message: '请选择问题类型',
+            trigger: 'blur'
+          }
+        ],
+        questionLevel: [
+          {
+            required: true,
+            message: '请选择问题难度',
+            trigger: 'blur'
+          }
+        ],
+        subjectId: [
+          {
+            required: true,
+            message: '请选择题库',
+            trigger: 'blur'
+          }
+        ],
+        questionContent: [
+          {
+            required: true,
+            message: '请输入题库内容',
+            trigger: 'blur'
+          }
+        ]
+      },
+      // 图片回显的样式
+      backShowImgVisible: false,
+      // 图片回显的图片地址
+      backShowImgUrl: '',
+      groupQuestionVisible: false,
+      radio: 1
+    }
+  },
+  created() {
+    document.title = '添加试题'
+    this.getQuestionBankInfo()
+  },
+  methods: {
+    onRadioChange(val) {
+      this.$notify({
+        title: 'Tips',
+        message: 'radio',
+        type: 'success',
+        duration: 2000
+      })
+    },
+    // 获取所有的题库信息
+    getQuestionBankInfo() {
+      getExamSubjectKV().then((resp) => {
+        if (resp.code === 0) {
+          this.allSubject = resp.data
+        }
+      })
+    },
+    // 处理表格被选中
+    handleTableSectionChange(val) {
+      this.selectionTable = val
+    },
+    // ****************************************************************************************************************
+    // 表单信息重置
+    resetQuestionForm() {
+      this.$refs['questionForm'].resetFields()
+    },
+    resetAddQuForm() {
+      this.$refs['addQuForm'].resetFields()
+    },
+    // ****************************************************************************************************************
+
+    // ****************************************************************************************************************
+    // 新增试题上传后 点击图片的回显
+    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)
+      })
+    },
+    // 新增试题中的上传图片的格式大小限制
+    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() {
+      this.addQuForm.options.push({
+        id: this.addQuForm.options.length,
+        correct: false,
+        content: '',
+        pos: this.addQuForm.options.length + 1,
+        images: [],
+        analysis: ''
+      })
+    },
+    addGroupQuestionAnswer() {
+      this.questionForm.options.push({
+        id: this.questionForm.options.length,
+        correct: false,
+        content: '',
+        pos: this.questionForm.options.length,
+        images: [],
+        analysis: ''
+      })
+    },
+    // 新增试题中的删除答案填写框
+    delAnswer(id) { // 当前答案的id
+      this.addQuForm.options.map((item, index) => {
+        if (item.id === id) this.addQuForm.options.splice(index, 1)
+      })
+    },
+    // 答案上传照片了
+    uploadAnswerImgSuccess(response, id) {
+      this.addQuForm.options[id].images.push(response.data)
+    },
+    // 答案上传成功后删除
+    handleAnswerRemove(file) {
+      this.addQuForm.options.images.map((item, index) => { // 移除图片在表单中的数据
+        if (item === file.response.data) this.addQuForm.images.splice(index, 1)
+      })
+    },
+    // 选择正确答案的按钮变化事件
+    checkAnswer(checked, id) {
+      if (checked) {
+        if (this.addQuForm.questionType === 1 || this.addQuForm.questionType === 3) { // 单选或者判断
+          // 当前已经有一个正确的选择了
+          this.addQuForm.options.map(item => {
+            item.correct = false
+          })
+          this.addQuForm.options.map(item => {
+            if (item.id === id) item.correct = true
+          })
+        } else { // 多选 可以有多个答案
+          this.addQuForm.options.map(item => {
+            if (item.id === id) item.correct = true
+          })
+        }
+      } else {
+        this.addQuForm.options.map(item => {
+          if (item.id === id) item.correct = false
+        })
+      }
+    },
+    checkGroupQuestionAnswer(checked, id) {
+      if (checked) {
+        if (this.questionForm.questionType === 1 || this.questionForm.questionType === 3) { // 单选或者判断
+          // 当前已经有一个正确的选择了
+          this.questionForm.options.map(item => {
+            item.correct = false
+          })
+          this.questionForm.options.map(item => {
+            if (item.id === id) item.correct = true
+          })
+        } else { // 多选 可以有多个答案
+          this.questionForm.options.map(item => {
+            if (item.id === id) item.correct = true
+          })
+        }
+      } else {
+        this.questionForm.options.map(item => {
+          if (item.id === id) item.correct = false
+        })
+      }
+    },
+    // 新增试题
+    addQuestion() {
+      this.$refs['addQuForm'].validate((valid) => {
+        if (valid && this.addQuForm.options.some(item => item.correct) && this.addQuForm.questionType !== 4) {
+          // 单选或者多选或者判断
+          postExamQuestion(this.addQuForm).then((resp) => {
+            if (resp.code === 0) {
+              this.resetAddQuForm()
+              this.addQuTableVisible = false
+              this.$notify({
+                title: 'Tips',
+                message: '试题已添加',
+                type: 'success',
+                duration: 2000
+              })
+            } else {
+              this.$notify({
+                title: 'Tips',
+                message: resp.msg,
+                type: 'success',
+                duration: 2000
+              })
+            }
+          })
+        } else if (valid && !this.addQuForm.options.some(item => item.correct) && this.addQuForm.questionType < 5) {
+          // 无答案
+          this.$message.error('必须有一个答案')
+          return false
+        } else if (valid && this.addQuForm.questionType >= 5 && this.addQuForm.questionType <= 7) {
+          // 简答题 无标准答案直接发请求
+          // 当是简答题的时候需要清除answer
+          this.addQuForm.options = []
+          postExamQuestion(this.addQuForm).then((resp) => {
+            if (resp.code === 0) {
+              this.resetAddQuForm()
+              this.addQuTableVisible = false
+              this.$notify({
+                title: 'Tips',
+                message: '试题已添加',
+                type: 'success',
+                duration: 2000
+              })
+            } else {
+              this.$notify({
+                title: 'Tips',
+                message: resp.msg,
+                type: 'success',
+                duration: 2000
+              })
+            }
+          })
+        } else if (this.addQuForm.questionType > 7) {
+          // 組题
+          // 当是简答题的时候需要清除answer
+          this.addQuForm.options = []
+          postExamQuestion(this.addQuForm).then((resp) => {
+            if (resp.code === 0) {
+              this.resetAddQuForm()
+              this.addQuTableVisible = false
+              this.$notify({
+                title: 'Tips',
+                message: '试题已添加',
+                type: 'success',
+                duration: 2000
+              })
+            } else {
+              this.$notify({
+                title: 'Tips',
+                message: resp.msg,
+                type: 'success',
+                duration: 2000
+              })
+            }
+          })
+        } else if (!valid) {
+          this.$message.error('请填写必要信息')
+          return false
+        }
+      })
+    },
+    addGroupQuestion() {
+      this.$refs['questionForm'].validate((valid) => {
+        console.log(this.questionForm.options.some(item => item.correct))
+        if (valid && !this.questionForm.options.some(item => item.correct)) {
+          // 无答案
+          this.$message.error('必须有一个答案')
+          return false
+        }
+
+        this.addQuForm.children.push(Object.assign({}, this.questionForm))
+        this.$notify({
+          title: 'Tips',
+          message: '組题已添加, 可以继续添加下一道题',
+          type: 'success',
+          duration: 3000
+        })
+        this.resetQuestionForm()
+        console.log(this.addQuForm)
+      })
+    },
+    viewGroupQuestion() {
+      this.groupQuestionVisible = true
+    },
+    clear() {
+      this.resetAddQuForm()
+      this.$notify({
+        title: 'Tips',
+        message: '已清空',
+        type: 'success',
+        duration: 500
+      })
+    }
+  }
+}
+</script>
+
+<style>
+</style>