diff --git a/src/views/teacher/ExamPages/AddQuestion.vue b/src/views/teacher/ExamPages/AddQuestion.vue
index a7115fd..ce34cf8 100644
--- a/src/views/teacher/ExamPages/AddQuestion.vue
+++ b/src/views/teacher/ExamPages/AddQuestion.vue
@@ -500,7 +500,7 @@ const createNewQuestion = async (bankId: string) => {
try {
// 只调用一次API创建题目
const questionData = {
- parentId: null, // 父题目ID,普通题目为null
+ parentId: undefined, // 父题目ID,普通题目为undefined
type: getQuestionTypeNumber(questionForm.type),
content: questionForm.title,
analysis: questionForm.explanation || '',
@@ -547,43 +547,6 @@ const createNewQuestion = async (bankId: string) => {
}
};
-// 处理单选题的选项和答案
-const handleSingleChoiceQuestion = async (questionId: string) => {
- try {
- // 添加选项
- const optionPromises = questionForm.options.map((option, index) => {
- const isCorrect = questionForm.correctAnswer === index ? 1 : 0;
- return ExamApi.createQuestionOption({
- questionId,
- content: option.content,
- izCorrent: isCorrect,
- orderNo: index + 1
- });
- });
-
- console.log('🚀 第二步:添加选项,选项数量:', questionForm.options.length);
- await Promise.all(optionPromises);
- console.log('✅ 选项添加成功');
-
- // 添加正确答案
- if (questionForm.correctAnswer !== null) {
- const correctOption = questionForm.options[questionForm.correctAnswer];
- const answerData = {
- questionId,
- answerText: correctOption.content,
- orderNo: 1
- };
-
- console.log('🚀 第三步:添加答案:', answerData);
- await ExamApi.createQuestionAnswer(answerData);
- console.log('✅ 答案添加成功');
- }
-
- } catch (error: any) {
- console.error('处理单选题失败:', error);
- throw error;
- }
-};
// 验证答案设置
const validateAnswers = (): boolean => {
@@ -600,7 +563,7 @@ const validateAnswers = (): boolean => {
message.error('单选题至少需要2个选项');
return false;
}
- if (questionForm.options.some(option => !option.content.trim())) {
+ if (questionForm.options.some((option: any) => !option.content.trim())) {
message.error('请填写所有选项的内容');
return false;
}
@@ -615,7 +578,7 @@ const validateAnswers = (): boolean => {
message.error('多选题至少需要2个选项');
return false;
}
- if (questionForm.options.some(option => !option.content.trim())) {
+ if (questionForm.options.some((option: any) => !option.content.trim())) {
message.error('请填写所有选项的内容');
return false;
}
@@ -631,7 +594,7 @@ const validateAnswers = (): boolean => {
}
break;
case 'fill_blank':
- if (questionForm.fillBlankAnswers.length === 0 || questionForm.fillBlankAnswers.every(answer => !answer.content.trim())) {
+ if (questionForm.fillBlankAnswers.length === 0 || questionForm.fillBlankAnswers.every((answer: any) => !answer.content.trim())) {
message.error('请设置填空题的参考答案');
return false;
}
diff --git a/src/views/teacher/ExamPages/QuestionManagement.vue b/src/views/teacher/ExamPages/QuestionManagement.vue
index 98a460e..3014517 100644
--- a/src/views/teacher/ExamPages/QuestionManagement.vue
+++ b/src/views/teacher/ExamPages/QuestionManagement.vue
@@ -3,94 +3,61 @@
-
+
+
+
题库管理
{{ currentBankTitle }}
-
+
-
+
-
+
-
+
已选择 {{ selectedRowKeys.length }} 个试题
-
+
-
+
-
+
-
+
添加
@@ -98,7 +65,7 @@
-
+
@@ -113,12 +80,7 @@
-
+
-
+
-
+
添加
@@ -144,7 +102,7 @@
-
+
@@ -163,7 +121,7 @@
-
+
关闭
@@ -210,6 +168,8 @@ interface Question {
score: number;
creator: string;
createTime: string;
+ parentId?: string; // 添加可选的 parentId 字段
+ analysis?: string; // 添加可选的 analysis 字段
}
// 筛选条件
@@ -333,7 +293,7 @@ const createColumns = ({
width: 100,
align: 'center' as const,
render(row: Question) {
- const categoryInfo = allCategoryOptions.value.find(cat => cat.value === row.category);
+ const categoryInfo = allCategoryOptions.value.find((cat: any) => cat.value === row.category);
return categoryInfo ? categoryInfo.label : row.category;
}
},
@@ -377,27 +337,27 @@ const createColumns = ({
align: 'center' as const,
render(row: Question) {
const buttons: VNode[] = [];
-
+
buttons.push(
- h(NButton, {
- size: 'small',
- type: 'primary',
- ghost: true,
- style: 'margin: 0 3px;',
- onClick: () => handleAction('编辑', row)
+ h(NButton, {
+ size: 'small',
+ type: 'primary',
+ ghost: true,
+ style: 'margin: 0 3px;',
+ onClick: () => handleAction('编辑', row)
}, { default: () => '编辑' })
);
-
+
buttons.push(
- h(NButton, {
- size: 'small',
- type: 'error',
- ghost: true,
- style: 'margin: 0 3px;',
- onClick: () => handleAction('删除', row)
+ h(NButton, {
+ size: 'small',
+ type: 'error',
+ ghost: true,
+ style: 'margin: 0 3px;',
+ onClick: () => handleAction('删除', row)
}, { default: () => '删除' })
);
-
+
return h(NSpace, {}, { default: () => buttons });
}
}
@@ -420,7 +380,7 @@ const generateMockData = (): Question[] => {
const mockData: Question[] = [];
const types = ['single_choice', 'multiple_choice', 'true_false', 'fill_blank', 'short_answer'];
const difficulties = ['easy', 'medium', 'hard'];
- const categories = customCategories.value.map(cat => cat.value);
+ const categories = customCategories.value.map((cat: any) => cat.value);
const creators = ['王建国', '李明', '张三', '刘老师'];
for (let i = 1; i <= 50; i++) {
@@ -492,7 +452,7 @@ const loadQuestions = async () => {
let allData: Question[] = [];
// 处理API响应数据
- if (response.data && (response.data.code === 200 || response.data.code === 0) && response.data.result) {
+ if (response.data && typeof response.data === 'object' && 'code' in response.data && (response.data.code === 200 || response.data.code === 0) && 'result' in response.data && response.data.result && Array.isArray(response.data.result)) {
// 将API返回的数据转换为前端格式
allData = response.data.result.map((item: any, index: number) => ({
id: item.id || `question_${index}`,
@@ -746,7 +706,7 @@ const addNewCategory = () => {
}
// 检查是否已存在
- const exists = customCategories.value.some(cat => cat.label === trimmedName);
+ const exists = customCategories.value.some((cat: any) => cat.label === trimmedName);
if (exists) {
message.warning('该分类已存在');
return;
@@ -775,8 +735,8 @@ const applyCategoryChange = async () => {
await new Promise(resolve => setTimeout(resolve, 300));
// 更新本地数据
- const selectedCategoryLabel = allCategoryOptions.value.find(cat => cat.value === selectedCategory.value)?.label || selectedCategory.value;
- questionList.value.forEach(question => {
+ const selectedCategoryLabel = allCategoryOptions.value.find((cat: any) => cat.value === selectedCategory.value)?.label || selectedCategory.value;
+ questionList.value.forEach((question: any) => {
if (selectedRowKeys.value.includes(question.id)) {
question.category = selectedCategory.value;
}
@@ -811,7 +771,7 @@ const addCategoryInManage = () => {
}
// 检查是否已存在
- const exists = customCategories.value.some(cat => cat.label === trimmedName);
+ const exists = customCategories.value.some((cat: any) => cat.label === trimmedName);
if (exists) {
message.warning('该分类已存在');
return;
@@ -841,13 +801,13 @@ const editCategory = (category: { label: string; value: string }) => {
const deleteCategory = (categoryValue: string) => {
// 检查是否有试题使用该分类
- const hasQuestions = questionList.value.some(q => q.category === categoryValue);
+ const hasQuestions = questionList.value.some((q: any) => q.category === categoryValue);
if (hasQuestions) {
message.warning('该分类下还有试题,不能删除');
return;
}
- const index = customCategories.value.findIndex(cat => cat.value === categoryValue);
+ const index = customCategories.value.findIndex((cat: any) => cat.value === categoryValue);
if (index > -1) {
const categoryName = customCategories.value[index].label;
customCategories.value.splice(index, 1);