jiajunchen пре 1 недеља
родитељ
комит
aefbd76946
2 измењених фајлова са 167 додато и 5 уклоњено
  1. 118
    0
      src/components/QuizResultPopup.vue
  2. 49
    5
      src/view/dati/classOne/sectionList.vue

+ 118
- 0
src/components/QuizResultPopup.vue Прегледај датотеку

@@ -0,0 +1,118 @@
1
+
2
+<template>
3
+  <van-popup v-model:show="innerShow" position="top" style="height: 100%">
4
+    <van-sticky>
5
+      <van-nav-bar title="错题回顾" left-arrow @click-left="close" />
6
+    </van-sticky>
7
+
8
+    <div v-if="loading" class="loading-wrapper">
9
+      <van-loading>加载中...</van-loading>
10
+    </div>
11
+
12
+    <div v-else-if="error" class="error">加载失败:{{ error }}</div>
13
+
14
+    <div v-else>
15
+      <div style="margin: 10px 20px; font-weight: bold;">
16
+        本次得分:{{ totalScore }}
17
+      </div>
18
+      <van-divider />
19
+
20
+      <!-- 遍历错题/全部题 -->
21
+      <div v-for="item in mistakeData" :key="item.id" class="question">
22
+        <p>
23
+          <span v-if="item.category === '单选'">[单选]</span>
24
+          <span v-if="item.category === '多选'">[多选]</span>
25
+          <span v-if="item.category === '判断'">[判断]</span>
26
+          {{ item.stem }}
27
+        </p>
28
+
29
+        <p>
30
+          <span :style="{ color: item.userAnswer === item.answer ? '#007aff' : 'red' }">
31
+            提交答案: {{ item.userAnswer || '未作答' }}
32
+          </span>
33
+        </p>
34
+        <p style="color: #007aff">正确答案: {{ item.answer }}</p>
35
+
36
+        <div v-if="item.category === '单选' || item.category === '多选'" class="kong">
37
+          <div>A. {{ item.optionA }}</div>
38
+          <div>B. {{ item.optionB }}</div>
39
+          <div>C. {{ item.optionC }}</div>
40
+          <div v-if="item.optionD">D. {{ item.optionD }}</div>
41
+          <div v-if="item.optionE">E. {{ item.optionE }}</div>
42
+        </div>
43
+        <div v-if="item.category === '判断'" class="kong">
44
+          <div>A. 正确</div>
45
+          <div>B. 错误</div>
46
+        </div>
47
+
48
+        <van-divider />
49
+      </div>
50
+
51
+      <!-- ✅ 新增:底部确定按钮 -->
52
+      <div style="text-align: center; margin: 20px 0;">
53
+        <van-button type="primary" size="large" @click="close">确定</van-button>
54
+      </div>
55
+    </div>
56
+  </van-popup>
57
+</template>
58
+
59
+<script setup>
60
+import { getCurrentInstance, ref, watch } from 'vue';
61
+import { showFailToast } from 'vant';
62
+const { proxy } = getCurrentInstance();
63
+const props = defineProps({
64
+  show: Boolean,
65
+  courseId: String,
66
+  userId: String
67
+});
68
+
69
+const emit = defineEmits(['update:show']);
70
+
71
+const innerShow = ref(false);
72
+const loading = ref(false);
73
+const error = ref('');
74
+const mistakeData = ref([]);
75
+const totalScore = ref(0);
76
+
77
+// 同步外部 show 控制
78
+watch(() => props.show, (val) => {
79
+  innerShow.value = val;
80
+  if (val) {
81
+    loadMistakeData();
82
+  }
83
+});
84
+
85
+const close = () => {
86
+  innerShow.value = false;
87
+  emit('update:show', false);
88
+};
89
+
90
+const loadMistakeData = async () => {
91
+  loading.value = true;
92
+  error.value = '';
93
+  try {
94
+    const query = { headId: props.courseId };
95
+    const res = await proxy.$axios.post('/sgsafe/ExamLine/queryMistake', {
96
+      params: JSON.stringify(query)
97
+    });
98
+
99
+    if (res.data.code === 0) {
100
+      const data = res.data.data || [];
101
+      mistakeData.value = data;
102
+
103
+      // 注意:queryMistake 返回的是每道题的 userAnswer 和 answer
104
+      // 总分通常是 userScore 字段之和
105
+      totalScore.value = data.reduce((sum, item) => sum + (Number(item.userScore) || 0), 0);
106
+    } else {
107
+      error.value = res.data.msg || '获取错题失败';
108
+      showFailToast(error.value);
109
+    }
110
+  } catch (err) {
111
+    console.error('加载错题失败', err);
112
+    error.value = '网络错误';
113
+    showFailToast('加载错题失败');
114
+  } finally {
115
+    loading.value = false;
116
+  }
117
+};
118
+</script>

+ 49
- 5
src/view/dati/classOne/sectionList.vue Прегледај датотеку

@@ -54,27 +54,34 @@
54 54
             </template>
55 55
 
56 56
             <template #right>
57
-
58 57
               <div style="display: flex; align-items: center; justify-content: flex-end; height: 100%;">
59 58
                 <van-button v-if="item.studyorExam =='study'" @click="goaddLearn(item)" class="red-rounded-box-wide" text="学习"/>
59
+                <van-button
60
+                  v-if="item.isFinish === '1'"
61
+                  @click="openWrongRecord(item)"
62
+                  class="red-rounded-box-wide"
63
+                  text="错题集"
64
+                />
60 65
                 <van-button v-else-if="item.studyorExam =='exam'"  @click="goaddPeo(item)" class="red-rounded-box-wide" text="考试"/>
61
-
62 66
               </div>
63
-
64 67
             </template>
65 68
           </van-swipe-cell>
66 69
         </div>
67 70
 
68 71
       </van-list>
69 72
     </van-pull-refresh>
70
-
73
+    <QuizResultPopup
74
+      v-model:show="showWrongPopup"
75
+      :course-id="selectedCourseId"
76
+      :user-id="userId"
77
+    />
71 78
   </div>
72 79
 </template>
73 80
 
74 81
 <script setup>
75 82
 import { ref, reactive, onMounted, getCurrentInstance, nextTick, toRaw } from 'vue';
76 83
 import { Dialog, showDialog, showSuccessToast, showToast, Toast } from 'vant';
77
-
84
+import QuizResultPopup from '@/components/QuizResultPopup.vue'; // 路径按你实际的改
78 85
 const { proxy } = getCurrentInstance();
79 86
 
80 87
 
@@ -243,6 +250,43 @@ const goaddLearn =async (item) => {
243 250
     }
244 251
   })
245 252
 }
253
+
254
+const showWrongPopup = ref(false);
255
+const selectedCourseId = ref('');
256
+const openWrongRecord = (item) => {
257
+  selectedCourseId.value = item.id; // 或 item.courseId,看你字段名
258
+  showWrongPopup.value = true;
259
+};
260
+
261
+const openWrongQuestions = async (item) => {
262
+  // 1. 先获取该小节的所有题目(和你 goaddPeo 里 prepareQuizData 一样)
263
+  await prepareQuizData(item.id);
264
+
265
+  // 2. 模拟或获取用户的答题记录(你可能需要调另一个接口)
266
+  //    假设你已经有 userAnswers 数据结构,或者可以从本地/接口获取
267
+  //    这里我们假设有一个 getUserAnswers(sectionId) 方法
268
+
269
+  const userAnswers = await getUserAnswers(item.id); // ← 你需要实现这个!
270
+
271
+  // 3. 把题目 + 用户答案 + 得分等传给弹窗
272
+  currentSectionWrongData.value = {
273
+    questions: questionData.value,
274
+    userAnswers: userAnswers,
275
+    totalScore: calculateScore(questionData.value, userAnswers), // 你自己的评分逻辑
276
+    sectionName: item.sectionName
277
+  };
278
+
279
+  // 4. 显示弹窗
280
+  showWrongQuestionsPopup.value = true;
281
+};
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
246 290
 const  questionData=ref([])
247 291
 const prepareQuizData = async (sectionId) => {
248 292
 

Loading…
Откажи
Сачувај