|
|
@ -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 = () => { |
|
|
|
// 在这里添加判断逻辑,如果还没有添加过填空题,才允许添加,添加后将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; |
|
|
|