Browse Source

题目不能为空

test
lenghui 5 months ago
parent
commit
10c9a621b5
  1. 79
      work/src/views/DoHomeworkView.vue
  2. 3
      work/src/views/WorksShowView.vue

79
work/src/views/DoHomeworkView.vue

@ -14,9 +14,7 @@
<div v-for="(answer, index) in question.content" :key="index" class="answer">
<div class="selected">
<input :id="`select-${questionIndex}-${index}`" :name="`radio-group-${questionIndex}`" type="radio"
v-model="selectedAnswers[questionIndex]"
:value="answer.text"
>
v-model="selectedAnswers[questionIndex]" :value="answer.text">
<label :for="`select-${questionIndex}-${index}`">{{ answer.text }}</label>
</div>
</div>
@ -30,9 +28,7 @@
<div v-for="(answer, index) in question.content" :key="index" class="answer">
<div class="selected">
<input :id="`checkbox-${questionIndex}-${index}`" name="checkbox" type="checkbox"
v-model="selectedAnswers[questionIndex]"
:value="answer.text"
>
v-model="selectedAnswers[questionIndex]" :value="answer.text">
<label :for="`checkbox-${questionIndex}-${index}`">{{ answer.text }}</label>
</div>
</div>
@ -44,31 +40,15 @@
<div class="question">
{{ questionIndex + 1 }}. {{ question.description }}
</div>
<el-input
v-model="editorTitles[questionIndex]"
style="width: 100%; padding: 3.5%"
size="large"
placeholder="请输入标题(5-100字符)"
maxlength="100"
minlength="5"
show-word-limit
/>
<el-input v-model="editorTitles[questionIndex]" style="width: 100%; padding: 3.5%" size="large"
placeholder="请输入标题" />
<div class="editor">
<div style="border: 1px solid #ccc">
<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRefs[questionIndex]"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<Editor
style="height: 500px; overflow-y: hidden;"
v-model="editorContents[questionIndex]"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="editor => handleCreated(editor, questionIndex)"
/>
<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRefs[questionIndex]"
:defaultConfig="toolbarConfig" :mode="mode" />
<Editor style="height: 500px; overflow-y: hidden;" v-model="editorContents[questionIndex]"
:defaultConfig="editorConfig" :mode="mode"
@onCreated="editor => handleCreated(editor, questionIndex)" />
</div>
</div>
</div>
@ -103,6 +83,7 @@ const router = useRouter();
const route = useRoute();
let groupId = route.params.id;
let sub = route.params.sub;
// shallowRef
const editorRefs = ref([]);
@ -163,7 +144,6 @@ const handleCreated = (editor, questionIndex) => {
const questionList = ref([]);
function getQuestionList() {
console.log("ljghasjkhdjksahjkhsajkhjkasd",groupId);
homeworkApi.getHomeworkQuestion(groupId).then(resp => {
if (resp.code == 200) {
questionList.value = resp.data;
@ -194,6 +174,23 @@ questionList.value.forEach(() => {
function submit() {
homework.value = [];
for (let i = 0; i < questionList.value.length; i++) {
//
if (questionList.value[i].type == 1 || questionList.value[i].type == 2) {
if (selectedAnswers.value[i].length == 0) {
ElMessage.error("您有题目未作答");
return;
}
} else if (questionList.value[i].type == 3) {
//
if (editorTitles.value[i] == '') {
ElMessage.error("标题不能为空");
return;
}
if (editorTitles.value[i] == '') {
ElMessage.error("您有题目未作答");
return;
}
}
if (questionList.value[i].type == 1 || questionList.value[i].type == 2) {
homework.value.push({
"id": questionList.value[i].id,
@ -267,12 +264,15 @@ function submit() {
}
.content::-webkit-scrollbar-track {
background: #f1f1f1; /* 滚动条轨道的背景色 */
background: #f1f1f1;
/* 滚动条轨道的背景色 */
}
.content::-webkit-scrollbar-thumb {
background: #d9d9d9; /* 滚动条滑块的颜色 */
border-radius: 6px; /* 滑块的圆角 */
background: #d9d9d9;
/* 滚动条滑块的颜色 */
border-radius: 6px;
/* 滑块的圆角 */
}
.title {
@ -309,25 +309,30 @@ function submit() {
height: 1rem;
/* 透明度 */
opacity: 0.8;
cursor: pointer; /* 鼠标悬停时变成手的形状 */
cursor: pointer;
/* 鼠标悬停时变成手的形状 */
}
.selected input[type="radio"] {
margin-right: 1%;
width: 1.2rem;
height: 1rem;
/* 透明度 */
opacity: 0.8;
cursor: pointer; /* 鼠标悬停时变成手的形状 */
cursor: pointer;
/* 鼠标悬停时变成手的形状 */
}
/* 单选按钮选中时的样式 */
.selected input[type="radio"]:checked {
accent-color: blue; /* 设置选中时的颜色为蓝色 */
accent-color: blue;
/* 设置选中时的颜色为蓝色 */
}
/* 多选按钮选中时的样式 */
.selected input[type="checkbox"]:checked {
accent-color: blue; /* 设置选中时的颜色为蓝色 */
accent-color: blue;
/* 设置选中时的颜色为蓝色 */
}
.selected label {

3
work/src/views/WorksShowView.vue

@ -98,6 +98,7 @@ body {
width: 50%;
/* 如果需要,也可以设置宽度 */
padding-top: 4%;
}
@ -183,7 +184,7 @@ body {
height: 30%;
/* 设置高度,根据需要调整 */
width: 50%;
/* 如果需要,也可以设置宽度 */
/* 如果内容超过两行,省略号显示 */
}
.work-content {

Loading…
Cancel
Save