调整试题流程
This commit is contained in:
parent
b4c6c2a5dd
commit
160587e333
@ -27,27 +27,9 @@ export function deleteQuestion(questionId) {
|
||||
}
|
||||
|
||||
// 更新题目
|
||||
export function updateQuestion(questionId, data) {
|
||||
export function updateOption(data) {
|
||||
return request({
|
||||
url: `/api/questionBank/questions/${questionId}`,
|
||||
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}`,
|
||||
url: `/api/questionBank/questions/${data.id}`,
|
||||
method: 'put',
|
||||
data
|
||||
});
|
||||
@ -61,10 +43,3 @@ export function getQuestionInfo(questionId) {
|
||||
});
|
||||
}
|
||||
|
||||
// 根据题目查询选项
|
||||
export function getOptionsByQuestionId(questionId) {
|
||||
return request({
|
||||
url: `/api/questionBank/questions/${questionId}/options`,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
@ -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>
|
@ -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>
|
@ -1,23 +1,17 @@
|
||||
<template>
|
||||
<div>
|
||||
<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" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { UrlConfig } from '@/scripts/ConstDic';
|
||||
import { listQuestionPage, deleteQuestion, updateQuestion, updateAnswer } from '@/api/questionBank.js';
|
||||
import DialogUpdateQuestion from './dialog-update-question';
|
||||
import DialogUpdateAnswer from './dialog-update-answer';
|
||||
import { listQuestionPage, deleteQuestion } from '@/api/questionBank.js';
|
||||
import DialogDetail from './dialog-detail';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
DialogUpdateQuestion,
|
||||
DialogUpdateAnswer,
|
||||
DialogDetail
|
||||
},
|
||||
data() {
|
||||
@ -72,11 +66,6 @@ export default {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '分值',
|
||||
prop: 'score',
|
||||
width: '100'
|
||||
},
|
||||
// {
|
||||
// title: '创建人',
|
||||
// prop: 'createUserName',
|
||||
@ -88,22 +77,8 @@ export default {
|
||||
width: '420',
|
||||
buttons: [
|
||||
{
|
||||
name: '更新题目',
|
||||
handleClick: this.doUpdateQuestion,
|
||||
// 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: '编辑',
|
||||
handleClick: this.edit
|
||||
},
|
||||
{
|
||||
name: '删 除',
|
||||
@ -114,7 +89,6 @@ export default {
|
||||
{
|
||||
name: '预 览',
|
||||
handleClick: this.doDetail
|
||||
// showControl: (row) => { return row.createUserId != this.userId; }
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -135,18 +109,10 @@ export default {
|
||||
this.$router.push({path: `${UrlConfig.bank.questionCreate}`});
|
||||
},
|
||||
|
||||
doUpdateQuestion(index, row) {
|
||||
this.$refs.question.doShow({index, row});
|
||||
},
|
||||
|
||||
doupdateAnswers(index, row) {
|
||||
edit(index, row) {
|
||||
this.$router.push({path: `${UrlConfig.bank.questionUpdate}/${row.id}`});
|
||||
},
|
||||
|
||||
doUpdateAnswer(index, row) {
|
||||
this.$refs.answer.doShow({index, row});
|
||||
},
|
||||
|
||||
doDelete(index, row) {
|
||||
this.$confirm('删除试题,是否继续?', '提 示', {
|
||||
confirmButtonText: '确 定',
|
||||
@ -165,21 +131,6 @@ export default {
|
||||
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) {
|
||||
const answer = [];
|
||||
row.optionList.forEach((el, i) => {
|
||||
|
@ -32,7 +32,6 @@ export default {
|
||||
topic: '',
|
||||
type: 'select',
|
||||
answer: 0,
|
||||
score: '',
|
||||
optionList: []
|
||||
}
|
||||
};
|
||||
|
@ -1,11 +1,8 @@
|
||||
<template>
|
||||
<div>
|
||||
<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-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-select>
|
||||
</el-form-item>
|
||||
@ -36,10 +33,6 @@ export default {
|
||||
ItemAnswer
|
||||
},
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
option: {
|
||||
type: Object,
|
||||
required: true
|
||||
@ -51,6 +44,10 @@ export default {
|
||||
remove: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
update: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -90,10 +87,6 @@ export default {
|
||||
topic: [
|
||||
{ required: true, message: '请输入试题内容', trigger: 'blur' }
|
||||
],
|
||||
score: [
|
||||
{ required: true, message: '请输入试题分值', trigger: 'blur' },
|
||||
{ validator: this.validateScore, trigger: 'blur' }
|
||||
],
|
||||
type: [
|
||||
{ required: true, message: '请输入试题类型', trigger: 'change' }
|
||||
],
|
||||
@ -119,16 +112,6 @@ export default {
|
||||
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) {
|
||||
this.option.optionList.forEach((el, i) => { el.correct = i == answer; });
|
||||
},
|
||||
|
@ -2,24 +2,25 @@
|
||||
<div class="page">
|
||||
<div class="page__container">
|
||||
<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>
|
||||
</div>
|
||||
<div class="page__container-footer">
|
||||
<el-button type="primary" :is-create="true" @click="update">更 新</el-button>
|
||||
<el-button @click="back">返 回</el-button>
|
||||
</div>
|
||||
<dialog-modify-rich ref="rich" @update="update" />
|
||||
<dialog-modify-rich ref="rich" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ItemOptions from './item-options';
|
||||
import QuestionForm from './question-form.vue';
|
||||
import DialogModifyRich from './dialog-modify-rich';
|
||||
import { getQuestionInfo, getOptionsByQuestionId, updateOption } from '@/api/questionBank.js';
|
||||
import { getQuestionInfo, updateOption } from '@/api/questionBank.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ItemOptions,
|
||||
QuestionForm,
|
||||
DialogModifyRich
|
||||
},
|
||||
data() {
|
||||
@ -27,9 +28,9 @@ export default {
|
||||
formModel: {
|
||||
id: '',
|
||||
topic: '',
|
||||
type: '',
|
||||
type: 'select',
|
||||
answer: 0,
|
||||
score: ''
|
||||
optionList: []
|
||||
},
|
||||
optionList: []
|
||||
};
|
||||
@ -51,9 +52,7 @@ export default {
|
||||
loadInitData() {
|
||||
getQuestionInfo(this.questionId).then(resp => {
|
||||
this.formModel = resp.data;
|
||||
getOptionsByQuestionId(this.questionId).then(resp => {
|
||||
this.optionList = resp.data;
|
||||
});
|
||||
this.formModel.answer = this.formModel.optionList.findIndex(ele => ele.correct);
|
||||
});
|
||||
},
|
||||
doBack() {
|
||||
@ -62,11 +61,16 @@ export default {
|
||||
doModify(node) {
|
||||
this.$refs.rich.doShow(node);
|
||||
},
|
||||
update(data) {
|
||||
updateOption(data.id, data).then(resp => {
|
||||
update() {
|
||||
this.$refs.info.validate().then(valid => {
|
||||
if (valid) {
|
||||
updateOption(this.formModel).then(resp => {
|
||||
this.doBack();
|
||||
}).catch(error => {
|
||||
this.$message.error(`更新选项失败: ${error.message}`);
|
||||
this.$message.error(`创建试题失败: ${error.message}`);
|
||||
});
|
||||
}
|
||||
}).catch(error => { this.$message.warning(error.message); });
|
||||
},
|
||||
back() {
|
||||
this.$router.go(-1);
|
||||
|
Loading…
Reference in New Issue
Block a user