From 10c9a621b5b4236ccc81c545178549b1d4f473fb Mon Sep 17 00:00:00 2001 From: lenghui <h280650@163.com> Date: Tue, 24 Dec 2024 10:57:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE=E4=B8=8D=E8=83=BD=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- work/src/views/DoHomeworkView.vue | 91 +++++++++++++++++++++------------------ work/src/views/WorksShowView.vue | 3 +- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/work/src/views/DoHomeworkView.vue b/work/src/views/DoHomeworkView.vue index 712894e..904b8fd 100644 --- a/work/src/views/DoHomeworkView.vue +++ b/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> @@ -81,7 +61,7 @@ </div> <!-- 提交次数 --> <div class="submit-times"> - <span>您已提交{{sub}}次,每个作业可以提交3次</span> + <span>您已提交{{ sub }}次,每个作业可以提交3次</span> </div> </div> </div> @@ -97,12 +77,13 @@ import { ElMessage } from "element-plus"; import '@wangeditor/editor/dist/css/style.css' // 引入 css import { onBeforeUnmount } from 'vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue' -import {useRoute, useRouter} from "vue-router"; +import { useRoute, useRouter } from "vue-router"; const router = useRouter(); const route = useRoute(); let groupId = route.params.id; let sub = route.params.sub; + // 编辑器实例,必须用 shallowRef const editorRefs = ref([]); @@ -145,7 +126,7 @@ const toolbarConfig = { const editorConfig = { placeholder: '请输入内容...', toolbarKeys: toolbarConfig.toolbarKeys - } +} // 组件销毁时,也及时销毁编辑器 onBeforeUnmount(() => { @@ -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, @@ -212,7 +209,7 @@ function submit() { } let groupId = route.params.id; let sub = route.params.sub; - if (sub <=2){ + if (sub <= 2) { homeworkApi.submitHomework(homework.value, groupId).then(resp => { if (resp.code == 200) { ElMessage.success("提交成功"); @@ -222,7 +219,7 @@ function submit() { ElMessage.error("未知错误,请联系管理员"); } }); - }else { + } else { ElMessage.error("提交失败您,已提交3次,每个作业可以提交3次"); } } @@ -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"]{ + +.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 { diff --git a/work/src/views/WorksShowView.vue b/work/src/views/WorksShowView.vue index 7919230..3d59138 100644 --- a/work/src/views/WorksShowView.vue +++ b/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 {