Commit 394c246b authored by 纪泽龙's avatar 纪泽龙

录入题目增加单选多选判断选项

parent b8d06cbb
......@@ -5,6 +5,18 @@
目前录入题目是第<span>{{ questionNextNum }}</span
>道题
</div>
<div>
<el-radio-group
v-model="form.topicType"
size="mini"
@input="topicTypeChange"
>
<el-radio-button :label="1">单选</el-radio-button>
<el-radio-button :label="2">多选</el-radio-button>
<el-radio-button :label="3">判断</el-radio-button>
</el-radio-group>
</div>
<div class="right">{{ courseName }}</div>
</div>
......@@ -40,15 +52,11 @@
:label="'选项' + (index + 1)"
:key="question.key"
:prop="'questions.' + index + '.value'"
:rules="
index === 0
? {
required: true,
message: '第一项不能为空不能为空',
trigger: 'blur',
}
: {}
"
:rules="{
required: true,
message: '选项内容不能为空不能为空',
trigger: 'change',
}"
>
<div class="add-select flex">
<el-input
......@@ -62,7 +70,9 @@
<div
@click="rightAnswerClick(index)"
class="right"
:class="{ active: answerNum === index }"
:class="{
active: answerNum.indexOf(index) >= 0,
}"
>
设为正确答案
</div>
......@@ -100,7 +110,7 @@
>
设为正确答案
</div> -->
<div style="padding-left:30px">
<div style="padding-left: 30px" v-if="form.topicType != 3">
<el-button size="mini" type="primary" @click.prevent="add(addValue)"
>新增选项</el-button
>
......@@ -140,11 +150,13 @@ export default {
components: {},
data() {
return {
// topicType:1,
form: {
topicType: 1,
topicTitle: "",
questions: [{ value: "" }, { value: "" }],
},
answerNum: null,
answerNum: [],
addValue: "",
// 录入的是第几道题
questionNextNum: 1,
......@@ -159,10 +171,11 @@ export default {
console.log(res.data);
const data = res.data;
this.form = {
topicType :data.topicType,
topicTitle: data.topicTitle,
questions: JSON.parse(data.topicOption),
};
this.answerNum = data.answer;
this.answerNum = JSON.parse(data.answer);
});
}
......@@ -172,6 +185,23 @@ export default {
this.getLessonById(this.courseId);
},
methods: {
// 题目类型变化
topicTypeChange(num) {
if (num == 1) {
this.answerNum = [];
} else if (num == 2) {
this.answerNum = [];
// this.form.questions=[{ value: "" }, { value: "" }];
} else {
this.answerNum = [];
const form = {
topicType: 3,
topicTitle: this.form.topicTitle,
questions: [{ value: "对" }, { value: "错" }],
};
this.form = form;
}
},
getQuestion() {
getQuestion({ courseId: this.courseId }).then((res) => {
// 如果是修改 就是原来的值,如果不是,就是总数+1
......@@ -202,19 +232,46 @@ export default {
}
},
rightAnswerClick(index) {
this.answerNum = index;
console.log(index);
if (this.form.topicType === 2) {
const ind = this.answerNum.indexOf(index);
if (ind < 0) {
this.answerNum.push(index);
} else {
this.answerNum.splice(ind, 1);
}
this.answerNum = this.answerNum.sort((a, b) => {
return a - b;
});
console.log(this.answerNum);
} else {
// 判断跟单选模式差不多
this.answerNum = [index];
}
},
// 删除选项
removeDomain(question) {
const index = this.form.questions.indexOf(question);
console.log(index);
// 如果是正确答案,就让正确答案清空
if (this.answerNum === index) {
this.answerNum = null;
const ind = this.answerNum.indexOf(index);
if (ind >= 0) {
this.answerNum.splice(ind, 1);
}
// 如果是最后一位呗删除,那不用管,如果不是最后一位置,这一位删除之后,则这一位后面的所有数字都要-1;
if (index != this.form.questions.length - 1) {
this.answerNum = this.answerNum.map((item, i) => {
if (item >= index) {
return item - 1;
} else {
return item;
}
});
}
if (index >= 0) {
this.form.questions.splice(index, 1);
}
console.log(this.answerNum);
// console.log(this.form.questions)
},
// 新增选项
add(addValue) {
......@@ -223,7 +280,7 @@ export default {
},
save(num = 2) {
return new Promise((resove) => {
if (!this.answerNum && this.answerNum !== 0) {
if (this.answerNum.length<=0) {
this.$message({
message: "警告,请设置一个正确答案",
type: "warning",
......@@ -235,11 +292,14 @@ export default {
const data = {};
data.topicTitle = this.form.topicTitle;
data.topicOption = JSON.stringify(this.form.questions);
data.answer = this.answerNum;
data.answer = JSON.stringify(this.answerNum);
data.topicType=this.form.topicType;
console.log(data)
this.addQuestion(data).then((res) => {
if (res.code == 200) {
// 把修改的这个归位,变成正常添加
this.$emit("update:topicId", null);
console.log("updateTopicId", this.topicId);
this.$message({
message: "添加题目成功",
type: "success",
......@@ -264,11 +324,13 @@ export default {
});
},
reset() {
const topicType = this.form.topicType
this.form = {
topicType,
topicTitle: "",
questions: [{ value: "" }, { value: "" }, { value: "" }],
questions: [{ value: "" }, { value: "" }],
};
this.answerNum = null;
this.answerNum = [];
this.addValue = "";
},
},
......
......@@ -35,7 +35,7 @@ module.exports = {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: process.env.VUE_APP_TARGET,
//target: `http://192.168.31.87:8908/dangerManage`,
// target: `http://192.168.2.21:8908/dangerManage`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment