|
|
@@ -1,7 +1,10 @@
|
|
|
<template>
|
|
|
<div class="edit-question">
|
|
|
- <back-title>修改题目</back-title>
|
|
|
- <question-editor-factory :kind="question.kind" :init-value="question" @submit="edit($event)" />
|
|
|
+ <back-title>
|
|
|
+ 修改题目
|
|
|
+ <c-button theme="red" icon="close" text :left="12" @click="handleDeleteQuestion">删除题目</c-button>
|
|
|
+ </back-title>
|
|
|
+ <question-editor-factory :kind="question.type" :init-value="question" @submit="edit($event)"/>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -10,43 +13,53 @@ import BackTitle from '@/components/Basic/BackTitle'
|
|
|
import QuestionKind from '@/server/enums/question-kind'
|
|
|
// import { getQuestionById, updateQuestion } from '@/server/question-backup'
|
|
|
import QuestionEditorFactory from '@/views/quiz/components/QuestionEditorFactory'
|
|
|
+import { deleteQuestion, getOneQuestion, modifyQuestion } from '@/server/question'
|
|
|
+import CButton from '@/components/Basic/CButton'
|
|
|
|
|
|
export default {
|
|
|
name: 'EditQuestion',
|
|
|
- components: { QuestionEditorFactory, BackTitle },
|
|
|
- data() {
|
|
|
+ components: { CButton, QuestionEditorFactory, BackTitle },
|
|
|
+ data () {
|
|
|
return {
|
|
|
currentKind: QuestionKind.choice,
|
|
|
question: {}
|
|
|
}
|
|
|
},
|
|
|
- mounted() {
|
|
|
- this.$setErrorMessage('这部分API需要等题库系统加入权限管理')
|
|
|
+ mounted () {
|
|
|
this.fetchQuestionDetail()
|
|
|
},
|
|
|
methods: {
|
|
|
- fetchQuestionDetail() {
|
|
|
- // const { questionId } = this.$route.params
|
|
|
- // getQuestionById(questionId)
|
|
|
- // .then(res => (this.question = res))
|
|
|
- // .catch(err => this.$setErrorMessage(err.response.data.msg))
|
|
|
+ fetchQuestionDetail () {
|
|
|
+ const { questionId } = this.$route.params
|
|
|
+ getOneQuestion({ questionId })
|
|
|
+ .then(res => (this.question = res))
|
|
|
+ .catch(err => this.$setErrorMessage(err.response.data.msg))
|
|
|
},
|
|
|
- edit(questionBody) {
|
|
|
- // updateQuestion({ questionId: questionBody.id, questionBody })
|
|
|
- // .then(() => this.$setSuccessMessage('修改成功'))
|
|
|
- // .then(() => this.$router.go(-1))
|
|
|
- // .catch(err =>
|
|
|
- // this.$setErrorMessage(err.response.data.msg)
|
|
|
- // )
|
|
|
+ edit (questionBody) {
|
|
|
+ modifyQuestion({ ...questionBody, questionId: questionBody.id })
|
|
|
+ .then(() => this.$setSuccessMessage('修改成功'))
|
|
|
+ .then(() => this.$router.go(-1))
|
|
|
+ .catch(err =>
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ )
|
|
|
+ },
|
|
|
+ handleDeleteQuestion () {
|
|
|
+ const { questionId } = this.$route.params
|
|
|
+ deleteQuestion({ questionId })
|
|
|
+ .then(res => {
|
|
|
+ this.$setSuccessMessage('删除成功')
|
|
|
+ this.$router.go(-1)
|
|
|
+ })
|
|
|
+ .catch(err => this.$setErrorMessage(err.response.data.msg))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
- .edit-question {
|
|
|
- margin: 0 auto;
|
|
|
- max-width: 1100px;
|
|
|
- padding: 64px 24px;
|
|
|
- }
|
|
|
+.edit-question {
|
|
|
+ margin: 0 auto;
|
|
|
+ max-width: 800px;
|
|
|
+ padding: 64px 24px;
|
|
|
+}
|
|
|
</style>
|