Browse Source

feat: 删除测试按钮

ChenYangfan 6 years ago
parent
commit
216b9ad1fa

+ 2 - 2
src/server/quiz.js

@@ -60,9 +60,9 @@ export function deleteQuiz ({ quizId }) {
 }
 
 // 提交答案
-export function submitQuizStudentAnswer ({ quizId, answers = [] }) {
+export function submitQuizStudentAnswer ({ quizId, answers = {} }) {
   return axios
-    .post(useQuizServer('/student-answer'), { quizId, answers })
+    .post(useQuizServer(`/${quizId}/student-answer`), { answers })
 }
 
 // 老师获取某一测试学生的作答列表

+ 5 - 2
src/views/quiz/CreateQuiz.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="create-quiz">
-    <quiz-editor back-title="创建测试" @submit="handleSubmit" />
+    <quiz-editor back-title="创建测试" @submit="handleSubmit" @delete="handleDelete"/>
   </div>
 </template>
 
@@ -12,7 +12,7 @@ export default {
   name: 'CreateQuiz',
   components: { QuizEditor },
   methods: {
-    handleSubmit(quizData) {
+    handleSubmit (quizData) {
       const { slideId } = this.$route.params
       createQuiz({ ...quizData, slideId })
         .then(() => this.$setSuccessMessage('创建成功'))
@@ -20,6 +20,9 @@ export default {
         .catch(err =>
           this.$setErrorMessage(err.response.data.msg)
         )
+    },
+    handleDelete ({ quizId }) {
+      this.$router.go(-1)
     }
   }
 }

+ 10 - 3
src/views/quiz/EditQuiz.vue

@@ -1,11 +1,11 @@
 <template>
   <div class="edit-quiz">
-    <quiz-editor back-title="修改测试" :init-quiz="initQuiz" @submit="handleSubmit"/>
+    <quiz-editor back-title="修改测试" :init-quiz="initQuiz" @submit="handleSubmit" @delete="handleDelete"/>
   </div>
 </template>
 
 <script>
-import { updateQuiz, getOneQuiz } from '@/server/quiz'
+import { updateQuiz, getOneQuiz, deleteQuiz } from '@/server/quiz'
 import QuizEditor from '@/views/quiz/components/QuizEditor'
 
 export default {
@@ -31,11 +31,18 @@ export default {
     },
     handleSubmit (quizData) {
       updateQuiz({ ...quizData, slideId: this.initQuiz?.slide?.id })
-        .then(() => this.$setSuccessMessage('创建成功'))
+        .then(() => this.$setSuccessMessage('修改成功'))
         .then(() => this.$router.go(-1))
         .catch(err =>
           this.$setErrorMessage(err.response.data.msg)
         )
+    },
+    handleDelete ({ quizId }) {
+      deleteQuiz({ quizId }).then(() => {
+        this.$setSuccessMessage('删除成功')
+      }).catch(err => {
+        this.$setErrorMessage(err.response.data.msg)
+      })
     }
   }
 }

+ 15 - 1
src/views/quiz/components/QuizEditor.vue

@@ -22,7 +22,10 @@
             <c-input type="number" v-model="quiz.maxSubmitTime"></c-input>
           </div>
         </div>
-        <c-button theme="green" icon="check" block @click="handleSubmit">{{backTitle}}</c-button>
+        <div class="form-button-area">
+          <c-button :right="8" theme="red" icon="close" block @click="handleDelete">删除测试</c-button>
+          <c-button :left="8" standout theme="green" icon="check" block @click="handleSubmit">{{backTitle}}</c-button>
+        </div>
       </div>
       <div class="sub-title mt-32" v-if="selectedQuestions && selectedQuestions.length">
         测试题目列表
@@ -114,6 +117,12 @@ export default {
       this.$setInfoMessage('正在上传测试内容')
       this.$emit('submit', { ...this.quiz, questions: this.selectedQuestions.map(item => item.id) })
     },
+    handleDelete () {
+      const msg = '确定删除该测试吗?'
+      if (confirm(msg)) {
+        this.$emit('delete', { quizId: this.quiz.id })
+      }
+    },
     moveIndexQuestionUp (index) {
       if (index < this.selectedQuestions.length && index >= 1) {
         const nextQuestions = [...this.selectedQuestions]
@@ -231,4 +240,9 @@ export default {
   font-size: 14px;
   word-break: break-all;
 }
+
+.form-button-area {
+  display: flex;
+  align-items: center;
+}
 </style>