|
|
@@ -6,7 +6,7 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
6
|
6
|
import { onMounted, ref } from 'vue';
|
|
7
|
7
|
import { useRoute, useRouter } from 'vue-router';
|
|
8
|
8
|
|
|
9
|
|
-import { Page, useVbenDrawer } from '@vben/common-ui';
|
|
|
9
|
+import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
|
10
|
10
|
|
|
11
|
11
|
import {
|
|
12
|
12
|
DArrowLeft,
|
|
|
@@ -29,7 +29,11 @@ import {
|
|
29
|
29
|
deleteQuestionCategory,
|
|
30
|
30
|
questionCategoryTree,
|
|
31
|
31
|
} from '#/api/exam/question/category';
|
|
|
32
|
+import { deleteQuestion, questionList } from '#/api/exam/question/question';
|
|
|
33
|
+// 导入预览组件
|
|
|
34
|
+import QuestionPreview from '#/components/questionPreview';
|
|
32
|
35
|
|
|
|
36
|
+import { queryFormSchema, tableColumns } from './config-data';
|
|
33
|
37
|
import ChapterDrawer from './cpn/chapter/drawer.vue';
|
|
34
|
38
|
|
|
35
|
39
|
// 路由实例
|
|
|
@@ -44,58 +48,7 @@ const isCollapse = ref(false);
|
|
44
|
48
|
const chapterData = ref([]);
|
|
45
|
49
|
|
|
46
|
50
|
// 选中的章节
|
|
47
|
|
-const selectedChapter = ref({});
|
|
48
|
|
-
|
|
49
|
|
-// 模拟试题数据
|
|
50
|
|
-const mockQuestionData = ref([
|
|
51
|
|
- {
|
|
52
|
|
- id: 1,
|
|
53
|
|
- content: '下列关于JavaScript的说法,错误的是?',
|
|
54
|
|
- questionType: 'single_choice',
|
|
55
|
|
- questionTypeName: '单选题',
|
|
56
|
|
- category: '基础知识',
|
|
57
|
|
- creator: '管理员',
|
|
58
|
|
- difficulty: 'medium',
|
|
59
|
|
- difficultyName: '中等',
|
|
60
|
|
- reminder: '重要',
|
|
61
|
|
- },
|
|
62
|
|
- {
|
|
63
|
|
- id: 2,
|
|
64
|
|
- content: 'Vue.js的核心特性有哪些?',
|
|
65
|
|
- questionType: 'multiple_choice',
|
|
66
|
|
- questionTypeName: '多选题',
|
|
67
|
|
- category: '框架知识',
|
|
68
|
|
- creator: '教师1',
|
|
69
|
|
- difficulty: 'hard',
|
|
70
|
|
- difficultyName: '困难',
|
|
71
|
|
- reminder: '一般',
|
|
72
|
|
- },
|
|
73
|
|
- {
|
|
74
|
|
- id: 3,
|
|
75
|
|
- content: '简述CSS盒模型的概念',
|
|
76
|
|
- questionType: 'essay',
|
|
77
|
|
- questionTypeName: '简答题',
|
|
78
|
|
- category: '前端基础',
|
|
79
|
|
- creator: '教师2',
|
|
80
|
|
- difficulty: 'easy',
|
|
81
|
|
- difficultyName: '简单',
|
|
82
|
|
- reminder: '重要',
|
|
83
|
|
- },
|
|
84
|
|
-]);
|
|
85
|
|
-
|
|
86
|
|
-// 提醒选项
|
|
87
|
|
-const reminderOptions = [
|
|
88
|
|
- { label: '重要', value: '重要' },
|
|
89
|
|
- { label: '一般', value: '一般' },
|
|
90
|
|
- { label: '普通', value: '普通' },
|
|
91
|
|
-];
|
|
92
|
|
-
|
|
93
|
|
-// 试题难度选项
|
|
94
|
|
-const difficultyOptions = [
|
|
95
|
|
- { label: '简单', value: 'easy' },
|
|
96
|
|
- { label: '中等', value: 'medium' },
|
|
97
|
|
- { label: '困难', value: 'hard' },
|
|
98
|
|
-];
|
|
|
51
|
+const selectedChapter: any = ref({});
|
|
99
|
52
|
|
|
100
|
53
|
// 表单配置
|
|
101
|
54
|
const formOptions: VbenFormProps = {
|
|
|
@@ -105,34 +58,7 @@ const formOptions: VbenFormProps = {
|
|
105
|
58
|
allowClear: true,
|
|
106
|
59
|
},
|
|
107
|
60
|
},
|
|
108
|
|
- schema: [
|
|
109
|
|
- {
|
|
110
|
|
- component: 'Input',
|
|
111
|
|
- fieldName: 'content',
|
|
112
|
|
- label: '试题内容',
|
|
113
|
|
- componentProps: {
|
|
114
|
|
- placeholder: '请输入试题内容',
|
|
115
|
|
- },
|
|
116
|
|
- },
|
|
117
|
|
- {
|
|
118
|
|
- component: 'Select',
|
|
119
|
|
- fieldName: 'reminder',
|
|
120
|
|
- label: '提醒',
|
|
121
|
|
- componentProps: {
|
|
122
|
|
- placeholder: '请选择提醒等级',
|
|
123
|
|
- options: reminderOptions,
|
|
124
|
|
- },
|
|
125
|
|
- },
|
|
126
|
|
- {
|
|
127
|
|
- component: 'Select',
|
|
128
|
|
- fieldName: 'difficulty',
|
|
129
|
|
- label: '试题难度',
|
|
130
|
|
- componentProps: {
|
|
131
|
|
- placeholder: '请选择试题难度',
|
|
132
|
|
- options: difficultyOptions,
|
|
133
|
|
- },
|
|
134
|
|
- },
|
|
135
|
|
- ],
|
|
|
61
|
+ schema: queryFormSchema(),
|
|
136
|
62
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4',
|
|
137
|
63
|
};
|
|
138
|
64
|
|
|
|
@@ -143,44 +69,7 @@ const gridOptions: VxeGridProps = {
|
|
143
|
69
|
reserve: true,
|
|
144
|
70
|
trigger: 'default',
|
|
145
|
71
|
},
|
|
146
|
|
- columns: [
|
|
147
|
|
- {
|
|
148
|
|
- type: 'checkbox',
|
|
149
|
|
- width: 80,
|
|
150
|
|
- },
|
|
151
|
|
- {
|
|
152
|
|
- field: 'content',
|
|
153
|
|
- title: '试题内容',
|
|
154
|
|
- minWidth: 300,
|
|
155
|
|
- },
|
|
156
|
|
- {
|
|
157
|
|
- field: 'questionTypeName',
|
|
158
|
|
- title: '题型',
|
|
159
|
|
- minWidth: 100,
|
|
160
|
|
- },
|
|
161
|
|
- {
|
|
162
|
|
- field: 'category',
|
|
163
|
|
- title: '类别',
|
|
164
|
|
- minWidth: 120,
|
|
165
|
|
- },
|
|
166
|
|
- {
|
|
167
|
|
- field: 'creator',
|
|
168
|
|
- title: '创建人',
|
|
169
|
|
- minWidth: 120,
|
|
170
|
|
- },
|
|
171
|
|
- {
|
|
172
|
|
- field: 'difficultyName',
|
|
173
|
|
- title: '试题难度',
|
|
174
|
|
- minWidth: 100,
|
|
175
|
|
- },
|
|
176
|
|
- {
|
|
177
|
|
- field: 'action',
|
|
178
|
|
- fixed: 'right',
|
|
179
|
|
- slots: { default: 'action' },
|
|
180
|
|
- title: '操作',
|
|
181
|
|
- width: 150,
|
|
182
|
|
- },
|
|
183
|
|
- ],
|
|
|
72
|
+ columns: tableColumns,
|
|
184
|
73
|
size: 'medium',
|
|
185
|
74
|
// 固定表格高度,避免高度不断增加
|
|
186
|
75
|
height: 800,
|
|
|
@@ -201,40 +90,20 @@ const gridOptions: VxeGridProps = {
|
|
201
|
90
|
},
|
|
202
|
91
|
ajax: {
|
|
203
|
92
|
query: async ({ page }, formValues = {}) => {
|
|
204
|
|
- // 模拟API请求
|
|
205
|
|
- console.log('查询参数:', formValues, page);
|
|
206
|
|
-
|
|
207
|
|
- // 模拟搜索过滤
|
|
208
|
|
- let filteredData = [...mockQuestionData.value];
|
|
209
|
|
-
|
|
210
|
|
- if (formValues.content) {
|
|
211
|
|
- filteredData = filteredData.filter((item) =>
|
|
212
|
|
- item.content.includes(formValues.content),
|
|
213
|
|
- );
|
|
214
|
|
- }
|
|
215
|
|
-
|
|
216
|
|
- if (formValues.reminder) {
|
|
217
|
|
- filteredData = filteredData.filter(
|
|
218
|
|
- (item) => item.reminder === formValues.reminder,
|
|
219
|
|
- );
|
|
220
|
|
- }
|
|
221
|
|
-
|
|
222
|
|
- if (formValues.difficulty) {
|
|
223
|
|
- filteredData = filteredData.filter(
|
|
224
|
|
- (item) => item.difficulty === formValues.difficulty,
|
|
225
|
|
- );
|
|
226
|
|
- }
|
|
227
|
|
-
|
|
228
|
|
- // 模拟分页
|
|
229
|
|
- const start = (page.currentPage - 1) * page.pageSize;
|
|
230
|
|
- const end = start + page.pageSize;
|
|
231
|
|
- const paginatedData = filteredData.slice(start, end);
|
|
232
|
|
- console.log('分页数据:', paginatedData);
|
|
|
93
|
+ // 调用API获取试题列表
|
|
|
94
|
+ // 当前选择的章节ID
|
|
|
95
|
+ const chapterId = selectedChapter.value.id || 0;
|
|
|
96
|
+ const res: any = await questionList({
|
|
|
97
|
+ ...formValues,
|
|
|
98
|
+ categoryId: chapterId,
|
|
|
99
|
+ currentPage: page.currentPage,
|
|
|
100
|
+ pageSize: page.pageSize,
|
|
|
101
|
+ });
|
|
233
|
102
|
|
|
234
|
103
|
// 确保返回格式正确,使用 items 作为数据键
|
|
235
|
104
|
return {
|
|
236
|
|
- items: paginatedData,
|
|
237
|
|
- total: filteredData.length,
|
|
|
105
|
+ items: res.rows || [],
|
|
|
106
|
+ total: res.total || 0,
|
|
238
|
107
|
};
|
|
239
|
108
|
},
|
|
240
|
109
|
},
|
|
|
@@ -306,20 +175,29 @@ const exportQuestions = () => {
|
|
306
|
175
|
};
|
|
307
|
176
|
|
|
308
|
177
|
// 编辑试题
|
|
309
|
|
-const editQuestion = (row) => {
|
|
|
178
|
+const editQuestion = (row: any) => {
|
|
310
|
179
|
// 跳转到编辑页面,并传递试题ID
|
|
311
|
180
|
router.push(`/examManage/questionBank/questionEdit?id=${row.id}`);
|
|
312
|
181
|
};
|
|
313
|
|
-
|
|
|
182
|
+const previewQuestions: any = ref([]);
|
|
314
|
183
|
// 预览试题
|
|
315
|
|
-const previewQuestion = (row) => {
|
|
316
|
|
- // 跳转到预览页面,并传递试题ID
|
|
317
|
|
- router.push(`/examManage/questionBank/questionPreview?id=${row.id}`);
|
|
|
184
|
+const previewQuestion = (row: any) => {
|
|
|
185
|
+ // 打开预览模态框,并传递试题数据
|
|
|
186
|
+ previewQuestions.value = [row];
|
|
|
187
|
+ previewModalApi.open();
|
|
318
|
188
|
};
|
|
319
|
189
|
|
|
320
|
190
|
// 删除试题
|
|
321
|
|
-const deleteQuestion = (row) => {
|
|
322
|
|
- ElMessage.info('删除试题功能待实现');
|
|
|
191
|
+const deleteQuestionEvent = async (row: any) => {
|
|
|
192
|
+ // 二次确认
|
|
|
193
|
+ ElMessageBox.confirm('确认删除该试题吗?', '提示', {
|
|
|
194
|
+ confirmButtonText: '确定',
|
|
|
195
|
+ cancelButtonText: '取消',
|
|
|
196
|
+ type: 'warning',
|
|
|
197
|
+ }).then(async () => {
|
|
|
198
|
+ await deleteQuestion([row.id]);
|
|
|
199
|
+ await basicTableApi.reload();
|
|
|
200
|
+ });
|
|
323
|
201
|
};
|
|
324
|
202
|
|
|
325
|
203
|
// 批量删除试题
|
|
|
@@ -335,8 +213,7 @@ const deleteHandle = () => {
|
|
335
|
213
|
cancelButtonText: '取消',
|
|
336
|
214
|
type: 'warning',
|
|
337
|
215
|
}).then(async () => {
|
|
338
|
|
- // 模拟批量删除操作
|
|
339
|
|
- console.log('批量删除试题:', ids);
|
|
|
216
|
+ await deleteQuestion(ids);
|
|
340
|
217
|
await basicTableApi.reload();
|
|
341
|
218
|
});
|
|
342
|
219
|
};
|
|
|
@@ -345,9 +222,18 @@ const [ChapterVbenDrawer, chapterVbenDrawerApi] = useVbenDrawer({
|
|
345
|
222
|
connectedComponent: ChapterDrawer,
|
|
346
|
223
|
});
|
|
347
|
224
|
|
|
|
225
|
+// 预览试题模态框
|
|
|
226
|
+const [PreviewModal, previewModalApi] = useVbenModal({
|
|
|
227
|
+ // connectedComponent: QuestionPreview,
|
|
|
228
|
+ title: '预览',
|
|
|
229
|
+ width: 800,
|
|
|
230
|
+ height: 600,
|
|
|
231
|
+ showCancelBtn: false,
|
|
|
232
|
+});
|
|
|
233
|
+
|
|
348
|
234
|
const getChapterTree = async () => {
|
|
349
|
|
- const { rows } = await questionCategoryTree();
|
|
350
|
|
- chapterData.value = rows;
|
|
|
235
|
+ const data: any = await questionCategoryTree();
|
|
|
236
|
+ chapterData.value = data.rows || [];
|
|
351
|
237
|
};
|
|
352
|
238
|
|
|
353
|
239
|
// 页面加载时获取数据
|
|
|
@@ -457,9 +343,9 @@ onMounted(() => {
|
|
457
|
343
|
<ElButton type="primary" @click="importQuestions">
|
|
458
|
344
|
导入
|
|
459
|
345
|
</ElButton>
|
|
460
|
|
- <ElButton type="primary" @click="exportQuestions">
|
|
|
346
|
+ <!-- <ElButton type="primary" @click="exportQuestions">
|
|
461
|
347
|
导出
|
|
462
|
|
- </ElButton>
|
|
|
348
|
+ </ElButton> -->
|
|
463
|
349
|
</ElSpace>
|
|
464
|
350
|
</template>
|
|
465
|
351
|
<template #action="{ row }">
|
|
|
@@ -478,7 +364,7 @@ onMounted(() => {
|
|
478
|
364
|
<ElButton
|
|
479
|
365
|
type="text"
|
|
480
|
366
|
size="small"
|
|
481
|
|
- @click="deleteQuestion(row)"
|
|
|
367
|
+ @click="deleteQuestionEvent(row)"
|
|
482
|
368
|
class="text-red-500"
|
|
483
|
369
|
>
|
|
484
|
370
|
<ElIcon><Delete /></ElIcon>
|
|
|
@@ -492,6 +378,9 @@ onMounted(() => {
|
|
492
|
378
|
</div>
|
|
493
|
379
|
</div>
|
|
494
|
380
|
<ChapterVbenDrawer @reload="getChapterTree" />
|
|
|
381
|
+ <PreviewModal>
|
|
|
382
|
+ <QuestionPreview :questions="previewQuestions" />
|
|
|
383
|
+ </PreviewModal>
|
|
495
|
384
|
</Page>
|
|
496
|
385
|
</template>
|
|
497
|
386
|
|
|
|
@@ -624,6 +513,6 @@ onMounted(() => {
|
|
624
|
513
|
|
|
625
|
514
|
.action-buttons {
|
|
626
|
515
|
display: flex;
|
|
627
|
|
- gap: 8px;
|
|
|
516
|
+ //gap: 8px;
|
|
628
|
517
|
}
|
|
629
|
518
|
</style>
|