diff --git a/work/src/views/AddWork.vue b/work/src/views/AddWork.vue index d9419ee..578fe74 100644 --- a/work/src/views/AddWork.vue +++ b/work/src/views/AddWork.vue @@ -78,7 +78,7 @@
- 确认 + 确认
@@ -132,6 +132,16 @@ const articleTitle = ref(''); const questions = ref([]); const onSubmit = () => { + let hasEmptyDescription = false; + questions.value.forEach(question => { + if (question.description === '') { + hasEmptyDescription = true; + } + }); + if (hasEmptyDescription) { + ElMessage.error('存在题目未填写描述内容,请填写完整后再提交!'); + return; + } // 从picker中获取日期数据并进行格式转换 if (form.value.picker && form.value.picker.length === 2) { const startDate = dayjs(form.value.picker[0]).format('YYYY-MM-DD HH:mm:00'); @@ -258,12 +268,19 @@ const addMultipleChoice = () => { }); }; +//const hasAddedBlank=ref(false); const addBlank = () => { - questions.value.push({ - type: 3, // 假设3代表简答题,和后端格式对应起来 - description: '', - content: [{ "id": "", "text": "" }] - }); +// 在这里添加判断逻辑,如果还没有添加过填空题,才允许添加,添加后将hasAddedBlank设置为true +//if (!hasAddedBlank.value) { + questions.value.push({ + type: 3, // 假设3代表简答题,和后端格式对应起来 + description: '', + content: [{ "id": "", "text": "" }] + }); + // hasAddedBlank.value = true; + // }else { + // ElMessage.warning('只能添加一个简答题'); + // } }; @@ -277,9 +294,9 @@ const addOption = (questionIndex) => { }; const removeOption = (questionIndex, optionIndex) => { const currentQuestion = questions.value[questionIndex]; - // 判断当前题目类型是否为多选题(这里假设类型值2代表多选题,根据实际情况调整) + // 判断当前题目类型 if (currentQuestion.type === 1) { - // 如果当前题目是多选题,则需要判断选项数量是否小于等于2,否则不允许删除 + // 如果当前题目是单选,则需要判断选项数量是否小于等于2,否则不允许删除 if (currentQuestion.content.length <= 1) { ElMessage.warning('单选题至少需要保留一个选项,不能继续删除'); return; diff --git a/work/src/views/HomeWork.vue b/work/src/views/HomeWork.vue index 767b5c4..ab1e793 100644 --- a/work/src/views/HomeWork.vue +++ b/work/src/views/HomeWork.vue @@ -58,7 +58,7 @@ diff --git a/work/src/views/UpdateWork.vue b/work/src/views/UpdateWork.vue index 08ec3ac..eb2b3ae 100644 --- a/work/src/views/UpdateWork.vue +++ b/work/src/views/UpdateWork.vue @@ -305,6 +305,16 @@ const articleTitle = ref(""); // 问题列表数据 const questions = ref([]); const onSubmit = () => { + let hasEmptyDescription = false; + questions.value.forEach(question => { + if (question.description === '') { + hasEmptyDescription = true; + } + }); + if (hasEmptyDescription) { + ElMessage.error('存在题目未填写描述内容,请填写完整后再提交!'); + return; + } // 从picker中获取日期数据并进行格式转换 if (form.value.picker && form.value.picker.length === 2) { const startDate = dayjs(form.value.picker[0]).format("YYYY-MM-DD HH:mm:00"); @@ -464,16 +474,19 @@ const addMultipleChoice = () => { } }; +//const hasAddedBlank=ref(false); const addBlank = () => { - if (isPublished.value === 1) { - ElMessage.warning("处于发布中,不能添加新题目"); - } else { +// 在这里添加判断逻辑,如果还没有添加过填空题,才允许添加,添加后将hasAddedBlank设置为true +//if (!hasAddedBlank.value) { questions.value.push({ - type: 3, // 假设3代表简答题,和后端格式对应起来 - description: "", - content: [{ id: "", text: "" }], + type: 3, // 假设3代表简答题,和后端格式对应起来 + description: '', + content: [{ "id": "", "text": "" }] }); - } + // hasAddedBlank.value = true; + // }else { + // ElMessage.warning('只能添加一个简答题'); + // } }; const addOption = (questionIndex) => {