update question
This commit is contained in:
parent
c149785de7
commit
8c23c987b7
|
@ -88,6 +88,13 @@ export function createQuestion(data) {
|
|||
data
|
||||
})
|
||||
}
|
||||
export function getQuestion(id) {
|
||||
return request({
|
||||
url: `/question/question/${id}/`,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
export function updateQuestion(id, data) {
|
||||
return request({
|
||||
url: `/question/question/${id}/`,
|
||||
|
|
|
@ -115,6 +115,13 @@ export const asyncRoutes = [
|
|||
component: () => import('@/views/question/questioncreate.vue'),
|
||||
meta: { title: '新建题目', noCache: true, icon: '', perms: ['question_create']},
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: 'question/update',
|
||||
name: 'UpdateQuestion',
|
||||
component: () => import('@/views/question/questionupdate.vue'),
|
||||
meta: { title: '编辑题目', noCache: true, icon: '', perms: ['question_update']},
|
||||
hidden: true
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -104,12 +104,19 @@
|
|||
@click="handleDetail(scope)"
|
||||
icon="el-icon-more"
|
||||
></el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="handleEdit(scope)"
|
||||
icon="el-icon-edit"
|
||||
:disabled="!checkPermission(['question_edit'])"
|
||||
></el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="handleDelete(scope)"
|
||||
icon="el-icon-delete"
|
||||
:disabled="!checkPermission(['questioncat_delete'])"
|
||||
:disabled="!checkPermission(['question_delete'])"
|
||||
></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
@ -264,6 +271,9 @@ export default {
|
|||
this.dialogVisible = true
|
||||
this.question = scope.row
|
||||
},
|
||||
handleEdit(scope) {
|
||||
this.$router.push({path:"/Qmanage/question/update",query:{id:scope.row.id}})
|
||||
},
|
||||
handleDelete(scope) {
|
||||
this.$confirm("确认删除该题目吗?将丢失数据!", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<el-form-item label="题型" prop="type">
|
||||
<el-select
|
||||
v-model="Form.type"
|
||||
style="width: 400px"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in typeOptions"
|
||||
|
@ -19,14 +20,23 @@
|
|||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="type">
|
||||
<el-cascader
|
||||
v-model="Form.questioncat"
|
||||
:options="catOptions"
|
||||
:show-all-levels="false"
|
||||
clearable
|
||||
style="width: 400px"
|
||||
></el-cascader>
|
||||
</el-form-item>
|
||||
<el-form-item label="题干" prop="name">
|
||||
<el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项A" prop="optionA" >
|
||||
<el-input v-model="Form.options.A" style="width:600px"></el-input>
|
||||
<el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项B" >
|
||||
<el-input v-model="Form.options.B" style="width:600px"></el-input>
|
||||
<el-form-item label="选项B" prop="optionB" >
|
||||
<el-input v-model="Form.options.B" style="width:600px" :disabled="inputDisable"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项C" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.C" style="width:600px"></el-input>
|
||||
|
@ -40,6 +50,35 @@
|
|||
<el-form-item label="选项F" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.F" style="width:600px"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-if="Form.type =='多选'">
|
||||
<el-checkbox-group v-model="Form.right">
|
||||
<el-checkbox label="A"></el-checkbox>
|
||||
<el-checkbox label="B"></el-checkbox>
|
||||
<el-checkbox label="C"></el-checkbox>
|
||||
<el-checkbox label="D"></el-checkbox>
|
||||
<el-checkbox label="E"></el-checkbox>
|
||||
<el-checkbox label="F"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else-if="Form.type =='单选'">
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
<el-radio label="C"></el-radio>
|
||||
<el-radio label="D"></el-radio>
|
||||
<el-radio label="E"></el-radio>
|
||||
<el-radio label="F"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else>
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="解析">
|
||||
<el-input v-model="Form.resolution" style="width:600px" type="textarea" :rows=3></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm('Form')" :loading="submitLoding">立即创建</el-button>
|
||||
<el-button @click="resetForm('Form')">重置</el-button>
|
||||
|
@ -49,36 +88,31 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { createQuestion } from "@/api/question";
|
||||
import { createQuestion,getQuestioncatAll } from "@/api/question";
|
||||
import { genTree, deepClone } from "@/utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
Form: {
|
||||
name: "",
|
||||
type:"",
|
||||
questioncat:null,
|
||||
right:'',
|
||||
options:{
|
||||
A:'',
|
||||
B:''
|
||||
}
|
||||
},
|
||||
catOptions:[],
|
||||
inputDisable: false,
|
||||
submitLoding:false,
|
||||
rules: {
|
||||
type: [
|
||||
{ required: true, message: "请选择", trigger: "blur" }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: "名称不能为空", trigger: "blur" }
|
||||
// { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
limit: [
|
||||
{ required: true, message: "时间限制不能为空"},
|
||||
{ type: "number", message: "时间限制必须是数字"}
|
||||
],
|
||||
pass_score: [
|
||||
{ required: true, message: "及格分数不能为空"},
|
||||
{ type: "number", message: "及格分数必须是数字"}
|
||||
]
|
||||
|
||||
},
|
||||
typeOptions: [
|
||||
{ key: 1, label: "单选", value: "单选" },
|
||||
|
@ -88,22 +122,28 @@ export default {
|
|||
};
|
||||
},
|
||||
watch:{
|
||||
|
||||
'Form.type':'setOptions'
|
||||
},
|
||||
created() {
|
||||
this.getQuestioncatAll()
|
||||
},
|
||||
methods: {
|
||||
submitForm(formName) {
|
||||
this.$refs[formName].validate(valid => {
|
||||
if (valid) {
|
||||
this.submitLoding = true
|
||||
this.Form.questioncat = this.Form.questioncat.pop()
|
||||
createQuestion(this.Form).then(response => {
|
||||
this.submitLoding = false
|
||||
if(response.code >= 200){
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "新建成功!"
|
||||
});
|
||||
type: "success",
|
||||
message: "新建成功!"
|
||||
});
|
||||
this.goBack()
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
|
@ -115,6 +155,31 @@ export default {
|
|||
},
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
},
|
||||
getQuestioncatAll() {
|
||||
getQuestioncatAll().then(response => {
|
||||
this.catOptions = genTree(response.data);
|
||||
});
|
||||
},
|
||||
setOptions() {
|
||||
if(this.Form.type=='判断'){
|
||||
this.Form.options ={
|
||||
A:'对',
|
||||
B:'错'
|
||||
}
|
||||
this.inputDisable = true
|
||||
}else{
|
||||
this.Form.options = {
|
||||
A:'',
|
||||
B:''
|
||||
}
|
||||
this.inputDisable = false
|
||||
}
|
||||
if(this.Form.type=='多选'){
|
||||
this.Form.right = []
|
||||
}else{
|
||||
this.Form.right = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-form
|
||||
:model="Form"
|
||||
:rules="rules"
|
||||
ref="Form"
|
||||
label-width="100px"
|
||||
status-icon
|
||||
>
|
||||
<el-form-item label="题型" prop="type">
|
||||
<el-select
|
||||
v-model="Form.type"
|
||||
style="width: 400px"
|
||||
:disabled="true"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in typeOptions"
|
||||
:key="item.key"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="type">
|
||||
<el-cascader
|
||||
v-model="Form.questioncat"
|
||||
:options="catOptions"
|
||||
:show-all-levels="false"
|
||||
clearable
|
||||
style="width: 400px"
|
||||
></el-cascader>
|
||||
</el-form-item>
|
||||
<el-form-item label="题干" prop="name">
|
||||
<el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项A" prop="optionA" >
|
||||
<el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项B" prop="optionB" >
|
||||
<el-input v-model="Form.options.B" style="width:600px" :disabled="inputDisable"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项C" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.C" style="width:600px"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项D" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.D" style="width:600px"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项E" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.E" style="width:600px"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项F" v-show="Form.type!='判断'">
|
||||
<el-input v-model="Form.options.F" style="width:600px"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-if="Form.type =='多选'">
|
||||
<el-checkbox-group v-model="Form.right">
|
||||
<el-checkbox label="A"></el-checkbox>
|
||||
<el-checkbox label="B"></el-checkbox>
|
||||
<el-checkbox label="C"></el-checkbox>
|
||||
<el-checkbox label="D"></el-checkbox>
|
||||
<el-checkbox label="E"></el-checkbox>
|
||||
<el-checkbox label="F"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else-if="Form.type =='单选'">
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
<el-radio label="C"></el-radio>
|
||||
<el-radio label="D"></el-radio>
|
||||
<el-radio label="E"></el-radio>
|
||||
<el-radio label="F"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else>
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="解析">
|
||||
<el-input v-model="Form.resolution" style="width:600px" type="textarea" :rows=3></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm('Form')" :loading="submitLoding">保存</el-button>
|
||||
<el-button type="warning" @click="goBack()">返回</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { createQuestion,getQuestioncatAll, getQuestion, getQuestioncatList, updateQuestion } from "@/api/question";
|
||||
import { genTree, deepClone } from "@/utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
Form: {
|
||||
id:0,
|
||||
name: "",
|
||||
type:"",
|
||||
questioncat:null,
|
||||
right:'',
|
||||
options:{
|
||||
A:'',
|
||||
B:''
|
||||
}
|
||||
},
|
||||
catOptions:[],
|
||||
inputDisable: false,
|
||||
submitLoding:false,
|
||||
rules: {
|
||||
type: [
|
||||
{ required: true, message: "请选择", trigger: "blur" }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
},
|
||||
typeOptions: [
|
||||
{ key: 1, label: "单选", value: "单选" },
|
||||
{ key: 2, label: "多选", value: "多选"},
|
||||
{ key: 3, label: "判断", value: "判断" }
|
||||
],
|
||||
};
|
||||
},
|
||||
watch:{
|
||||
},
|
||||
created() {
|
||||
this.Form.id = this.$route.query.id //接收参数
|
||||
this.getQuestion();
|
||||
this.getQuestioncatAll()
|
||||
},
|
||||
methods: {
|
||||
submitForm(formName) {
|
||||
this.$refs[formName].validate(valid => {
|
||||
if (valid) {
|
||||
this.submitLoding = true
|
||||
if(this.Form.questioncat instanceof Array){
|
||||
this.Form.questioncat = this.Form.questioncat.pop()
|
||||
}
|
||||
updateQuestion(this.Form.id, this.Form).then(response => {
|
||||
this.submitLoding = false
|
||||
if(response.code >= 200){
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "修改成功!"
|
||||
});
|
||||
this.goBack()
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
getQuestion() {
|
||||
getQuestion(this.Form.id).then(response => {
|
||||
this.Form = response.data ;
|
||||
});
|
||||
},
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
},
|
||||
getQuestioncatAll() {
|
||||
getQuestioncatAll().then(response => {
|
||||
this.catOptions = genTree(response.data);
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-17 03:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('question', '0010_auto_20200402_2346'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='question',
|
||||
name='resolution',
|
||||
field=models.TextField(blank=True, verbose_name='解析'),
|
||||
),
|
||||
]
|
|
@ -42,7 +42,7 @@ class Question(SoftCommonModel):
|
|||
questioncat = models.ForeignKey(Questioncat, blank=True, null=True, on_delete=models.SET_NULL, verbose_name='所属题库', related_name='questioncat')
|
||||
options = JSONField(verbose_name='选项')
|
||||
right = JSONField(verbose_name='正确答案')
|
||||
resolution = models.TextField(verbose_name='解析')
|
||||
resolution = models.TextField(verbose_name='解析', blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '题目'
|
||||
|
|
Loading…
Reference in New Issue