调整试题流程

This commit is contained in:
zyy 2020-05-27 14:13:47 +08:00
parent b4c6c2a5dd
commit 160587e333
7 changed files with 30 additions and 230 deletions

View File

@ -27,27 +27,9 @@ export function deleteQuestion(questionId) {
} }
// 更新题目 // 更新题目
export function updateQuestion(questionId, data) { export function updateOption(data) {
return request({ return request({
url: `/api/questionBank/questions/${questionId}`, url: `/api/questionBank/questions/${data.id}`,
method: 'put',
data
});
}
// 更新正确选项
export function updateAnswer(questionId, data) {
return request({
url: `/api/questionBank/questions/${questionId}/answer`,
method: 'put',
data
});
}
// 更新选项
export function updateOption(optionId, data) {
return request({
url: `/api/questionBank/questions/options/${optionId}`,
method: 'put', method: 'put',
data data
}); });
@ -61,10 +43,3 @@ export function getQuestionInfo(questionId) {
}); });
} }
// 根据题目查询选项
export function getOptionsByQuestionId(questionId) {
return request({
url: `/api/questionBank/questions/${questionId}/options`,
method: 'get'
});
}

View File

@ -1,70 +0,0 @@
<template>
<el-dialog v-dialogDrag :close-on-click-moda="false" :title="title" :visible.sync="show" width="40%" :close-on-click-modal="false" :before-close="doClose">
<div class="ql-editor notes" v-html="$escapeHTML(`${formParam.topic}`)" />
<item-answer v-model="formParam.answer" :option-list="optionList" :type="formParam.type" @change="onAnswerChnage" />
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doUpdate"> </el-button>
<el-button @click="show = false"> </el-button>
</span>
</el-dialog>
</template>
<script>
import ItemAnswer from './item-answer';
import { getOptionsByQuestionId } from '@/api/questionBank.js';
export default {
components: {
ItemAnswer
},
data() {
return {
show: false,
content: '',
optionList: [],
formParam: {}
};
},
computed: {
title() {
return '更新答案';
}
},
methods: {
doShow({index, row}) {
this.formParam = row;
this.content = row.topic;
getOptionsByQuestionId(row.id).then(resp => {
this.optionList = resp.data;
this.optionList.forEach((el, i) => {
if (el.correct) {
this.formParam.answer = i;
}
});
});
this.show = true;
},
doClose(done) {
this.show = false;
},
onAnswerChnage(answer) {
this.optionList.forEach((el, i) => { el.correct = i == answer; });
},
doUpdate() {
const index = this.optionList.findIndex((el, i) => { return i == this.formParam.answer; });
if (index >= 0) {
const answer = this.optionList[index];
this.$emit('updateAnswer', {questionId: answer.questionId, id: answer.id, correct: answer.correct});
}
this.doClose();
}
}
};
</script>
<style lang="scss" scoped>
.notes {
padding: 0 0 20px 0;
color: #6666;
}
</style>

View File

@ -1,42 +0,0 @@
<template>
<el-dialog v-dialogDrag :close-on-click-moda="false" :title="title" :visible.sync="show" width="40%" :close-on-click-modal="false" :before-close="doClose">
<quill-editor v-model="content" placeholder="请输入内容" />
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doInput"> </el-button>
<el-button @click="show = false"> </el-button>
</span>
</el-dialog>
</template>
<script>
export default {
data() {
return {
show: false,
content: '',
formParam: null
};
},
computed: {
title() {
return '更新题目';
}
},
methods: {
doShow({index, row}) {
this.formParam = row;
this.content = row.topic;
this.show = true;
},
doClose(done) {
this.show = false;
},
doInput() {
this.formParam.topic = this.content;
this.$emit('updateQuestion', this.formParam);
this.doClose();
}
}
};
</script>

View File

@ -1,23 +1,17 @@
<template> <template>
<div> <div>
<query-list-page ref="user" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" /> <query-list-page ref="user" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" />
<dialog-update-question ref="question" @updateQuestion="updateQuestion" />
<dialog-update-answer ref="answer" @updateAnswer="updateAnswer" />
<dialog-detail ref="detail" /> <dialog-detail ref="detail" />
</div> </div>
</template> </template>
<script> <script>
import { UrlConfig } from '@/scripts/ConstDic'; import { UrlConfig } from '@/scripts/ConstDic';
import { listQuestionPage, deleteQuestion, updateQuestion, updateAnswer } from '@/api/questionBank.js'; import { listQuestionPage, deleteQuestion } from '@/api/questionBank.js';
import DialogUpdateQuestion from './dialog-update-question';
import DialogUpdateAnswer from './dialog-update-answer';
import DialogDetail from './dialog-detail'; import DialogDetail from './dialog-detail';
export default { export default {
components: { components: {
DialogUpdateQuestion,
DialogUpdateAnswer,
DialogDetail DialogDetail
}, },
data() { data() {
@ -72,11 +66,6 @@ export default {
return ''; return '';
} }
}, },
{
title: '分值',
prop: 'score',
width: '100'
},
// { // {
// title: '', // title: '',
// prop: 'createUserName', // prop: 'createUserName',
@ -88,22 +77,8 @@ export default {
width: '420', width: '420',
buttons: [ buttons: [
{ {
name: '更新题目', name: '编辑',
handleClick: this.doUpdateQuestion, handleClick: this.edit
// showControl: (row) => { return row.createUserId == this.userId; },
type: 'success'
},
{
name: '更新选项',
handleClick: this.doupdateAnswers,
// showControl: (row) => { return row.createUserId == this.userId && row.type != 'judge'; },
type: 'success'
},
{
name: '更新答案',
handleClick: this.doUpdateAnswer,
// showControl: (row) => { return row.createUserId == this.userId; },
type: 'success'
}, },
{ {
name: '删 除', name: '删 除',
@ -114,7 +89,6 @@ export default {
{ {
name: '预 览', name: '预 览',
handleClick: this.doDetail handleClick: this.doDetail
// showControl: (row) => { return row.createUserId != this.userId; }
} }
] ]
} }
@ -135,18 +109,10 @@ export default {
this.$router.push({path: `${UrlConfig.bank.questionCreate}`}); this.$router.push({path: `${UrlConfig.bank.questionCreate}`});
}, },
doUpdateQuestion(index, row) { edit(index, row) {
this.$refs.question.doShow({index, row});
},
doupdateAnswers(index, row) {
this.$router.push({path: `${UrlConfig.bank.questionUpdate}/${row.id}`}); this.$router.push({path: `${UrlConfig.bank.questionUpdate}/${row.id}`});
}, },
doUpdateAnswer(index, row) {
this.$refs.answer.doShow({index, row});
},
doDelete(index, row) { doDelete(index, row) {
this.$confirm('删除试题,是否继续?', '提 示', { this.$confirm('删除试题,是否继续?', '提 示', {
confirmButtonText: '确 定', confirmButtonText: '确 定',
@ -165,21 +131,6 @@ export default {
this.$refs.detail.doShow({index, row}); this.$refs.detail.doShow({index, row});
}, },
updateQuestion(form) {
updateQuestion(form.id, form).then(resp => {
this.reloadTable();
}).catch(error => {
this.$message.error(`修改问题失败: ${error.message}`);
});
},
updateAnswer(form) {
updateAnswer(form.questionId, form).then(resp => {
this.reloadTable();
}).catch(error => {
this.$message.error(`修改答案失败: ${error.message}`);
});
},
answerTags(row) { answerTags(row) {
const answer = []; const answer = [];
row.optionList.forEach((el, i) => { row.optionList.forEach((el, i) => {

View File

@ -32,7 +32,6 @@ export default {
topic: '', topic: '',
type: 'select', type: 'select',
answer: 0, answer: 0,
score: '',
optionList: [] optionList: []
} }
}; };

View File

@ -1,11 +1,8 @@
<template> <template>
<div> <div>
<el-form ref="form" :model="option" :rules="rules" label-width="80px"> <el-form ref="form" :model="option" :rules="rules" label-width="80px">
<el-form-item label="分 值" prop="score">
<el-input v-model="option.score" placeholder="请输入分值" style="width: 200px;" />
</el-form-item>
<el-form-item label="类 型" prop="type"> <el-form-item label="类 型" prop="type">
<el-select v-model="option.type" :disabled="disabled" placeholder="请选择试题类型" @change="onTypeChnage"> <el-select v-model="option.type" :disabled="update" placeholder="请选择试题类型" @change="onTypeChnage">
<el-option v-for="it in QuestionTypeList" :key="it.value" :label="it.label" :value="it.value" /> <el-option v-for="it in QuestionTypeList" :key="it.value" :label="it.label" :value="it.value" />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -36,10 +33,6 @@ export default {
ItemAnswer ItemAnswer
}, },
props: { props: {
disabled: {
type: Boolean,
default: false
},
option: { option: {
type: Object, type: Object,
required: true required: true
@ -51,6 +44,10 @@ export default {
remove: { remove: {
type: Boolean, type: Boolean,
default: false default: false
},
update: {
type: Boolean,
default: false
} }
}, },
data() { data() {
@ -90,10 +87,6 @@ export default {
topic: [ topic: [
{ required: true, message: '请输入试题内容', trigger: 'blur' } { required: true, message: '请输入试题内容', trigger: 'blur' }
], ],
score: [
{ required: true, message: '请输入试题分值', trigger: 'blur' },
{ validator: this.validateScore, trigger: 'blur' }
],
type: [ type: [
{ required: true, message: '请输入试题类型', trigger: 'change' } { required: true, message: '请输入试题类型', trigger: 'change' }
], ],
@ -119,16 +112,6 @@ export default {
this.option.optionList = this.templateMap[type](); this.option.optionList = this.templateMap[type]();
} }
}, },
validateScore(rule, value, callback) {
if (Number(value) <= 0) {
callback(new Error('请输入正确的分值'));
} else if (Number(value)) {
this.option.score = Number(value);
callback();
} else {
callback(new Error('请输入数字'));
}
},
onAnswerChnage(answer) { onAnswerChnage(answer) {
this.option.optionList.forEach((el, i) => { el.correct = i == answer; }); this.option.optionList.forEach((el, i) => { el.correct = i == answer; });
}, },

View File

@ -2,24 +2,25 @@
<div class="page"> <div class="page">
<div class="page__container"> <div class="page__container">
<el-card class="page__container-body"> <el-card class="page__container-body">
<item-options :option-list="optionList" :type="formModel.type" @modify="doModify" /> <question-form ref="info" :option="formModel" :remove="true" :update="true" @modify="doModify" />
</el-card> </el-card>
</div> </div>
<div class="page__container-footer"> <div class="page__container-footer">
<el-button type="primary" :is-create="true" @click="update"> </el-button>
<el-button @click="back"> </el-button> <el-button @click="back"> </el-button>
</div> </div>
<dialog-modify-rich ref="rich" @update="update" /> <dialog-modify-rich ref="rich" />
</div> </div>
</template> </template>
<script> <script>
import ItemOptions from './item-options'; import QuestionForm from './question-form.vue';
import DialogModifyRich from './dialog-modify-rich'; import DialogModifyRich from './dialog-modify-rich';
import { getQuestionInfo, getOptionsByQuestionId, updateOption } from '@/api/questionBank.js'; import { getQuestionInfo, updateOption } from '@/api/questionBank.js';
export default { export default {
components: { components: {
ItemOptions, QuestionForm,
DialogModifyRich DialogModifyRich
}, },
data() { data() {
@ -27,9 +28,9 @@ export default {
formModel: { formModel: {
id: '', id: '',
topic: '', topic: '',
type: '', type: 'select',
answer: 0, answer: 0,
score: '' optionList: []
}, },
optionList: [] optionList: []
}; };
@ -51,9 +52,7 @@ export default {
loadInitData() { loadInitData() {
getQuestionInfo(this.questionId).then(resp => { getQuestionInfo(this.questionId).then(resp => {
this.formModel = resp.data; this.formModel = resp.data;
getOptionsByQuestionId(this.questionId).then(resp => { this.formModel.answer = this.formModel.optionList.findIndex(ele => ele.correct);
this.optionList = resp.data;
});
}); });
}, },
doBack() { doBack() {
@ -62,11 +61,16 @@ export default {
doModify(node) { doModify(node) {
this.$refs.rich.doShow(node); this.$refs.rich.doShow(node);
}, },
update(data) { update() {
updateOption(data.id, data).then(resp => { this.$refs.info.validate().then(valid => {
if (valid) {
updateOption(this.formModel).then(resp => {
this.doBack();
}).catch(error => { }).catch(error => {
this.$message.error(`更新选项失败: ${error.message}`); this.$message.error(`创建试题失败: ${error.message}`);
}); });
}
}).catch(error => { this.$message.warning(error.message); });
}, },
back() { back() {
this.$router.go(-1); this.$router.go(-1);