liuyu
22 小时以前 8534025c45b4736975730678b9ccf23570a75f95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<script lang="ts" setup>
import type { SelfTestPaper, SelfTestQuestionItem } from './types';
 
import { computed, onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { useTabbarStore } from '@vben/stores';
 
import { getSelfTestInfo } from '#/api/x/tms/selfTest';
import { labelOfType } from '#/views/x/tms/question/constants';
 
defineOptions({ name: 'TmsSelfTestDetail' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
const tabbarStore = useTabbarStore();
 
const loading = ref(false);
const detail = ref<SelfTestPaper | null>(null);
/** all | wrong */
const filterMode = ref<'all' | 'wrong'>('all');
 
const wrongCount = computed(
  () => detail.value?.questions?.filter((q) => q.isRight !== '1').length || 0,
);
 
const displayQuestions = computed(() => {
  const list = detail.value?.questions || [];
  if (filterMode.value === 'wrong') {
    return list.filter((q) => q.isRight !== '1');
  }
  return list;
});
 
function stripHtml(html?: string) {
  if (!html) return '';
  return html.replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').trim();
}
 
function formatAnswer(ans?: string) {
  if (!ans) return '未作答';
  return ans.split(',').filter(Boolean).join('、');
}
 
function optionClass(q: SelfTestQuestionItem, label: string) {
  const correctSet = new Set((q.correctAnswer || '').split(',').filter(Boolean));
  const userSet = new Set((q.userAnswer || '').split(',').filter(Boolean));
  const isCorrectOpt = correctSet.has(label);
  const isUserOpt = userSet.has(label);
  if (isCorrectOpt) return 'opt-correct';
  if (isUserOpt && !isCorrectOpt) return 'opt-wrong';
  return '';
}
 
async function loadDetail() {
  const id = String(route.params.id || '');
  if (!id) {
    router.replace('/tms/selfTest/records');
    return;
  }
  loading.value = true;
  try {
    detail.value = await getSelfTestInfo(id);
  } catch (e: any) {
    createMessage.error(e?.message || '加载检测详情失败');
    router.replace('/tms/selfTest/records');
  } finally {
    loading.value = false;
  }
}
 
onMounted(() => {
  tabbarStore.renderRouteView = true;
  loadDetail();
});
 
function goBack() {
  tabbarStore.renderRouteView = true;
  router.push('/tms/selfTest/records');
}
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content tms-self-test-detail" v-loading="loading">
        <div class="page-header" v-if="detail">
          <div>
            <div class="text-base font-medium">检测详情 · {{ detail.bankName }}</div>
            <div class="mt-1 text-gray-400 text-sm">
              得分:{{ detail.correctCount ?? 0 }} / {{ detail.totalCount ?? detail.questions?.length ?? 0 }}
              <span v-if="detail.scoreRate != null" class="ml-2">正确率 {{ detail.scoreRate }}%</span>
              <span v-if="detail.submitTime" class="ml-3">交卷时间:{{ detail.submitTime }}</span>
            </div>
          </div>
          <a-space>
            <a-radio-group v-model:value="filterMode" button-style="solid" size="small">
              <a-radio-button value="all">全部题目</a-radio-button>
              <a-radio-button value="wrong">仅错题({{ wrongCount }})</a-radio-button>
            </a-radio-group>
            <a-button @click="goBack">返回记录</a-button>
          </a-space>
        </div>
 
        <a-empty v-if="!loading && detail && !displayQuestions.length" description="暂无题目" />
 
        <div v-for="(q, idx) in displayQuestions" :key="`${q.id}_${idx}`" class="question-card">
          <div class="q-title">
            <span class="q-index">{{ q.sortNo || idx + 1 }}.</span>
            <span class="q-type">{{ labelOfType(q.questionType) }}</span>
            <a-tag :color="q.isRight === '1' ? 'success' : 'error'" class="!ml-2">
              {{ q.isRight === '1' ? '正确' : '错误' }}
            </a-tag>
          </div>
          <div class="q-stem">{{ stripHtml(q.stem) }}</div>
          <div class="q-options">
            <div
              v-for="opt in q.options"
              :key="opt.optionLabel"
              class="q-option"
              :class="optionClass(q, opt.optionLabel)"
            >
              {{ opt.optionLabel }}. {{ opt.optionContent }}
            </div>
          </div>
          <div class="q-answer">
            <span>你的答案:{{ formatAnswer(q.userAnswer) }}</span>
            <span class="ml-4">正确答案:{{ formatAnswer(q.correctAnswer) }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
.tms-self-test-detail {
  background: #fff;
  padding: 20px 24px;
  height: 100%;
  overflow: auto;
}
 
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}
 
.question-card {
  padding: 16px 0;
  border-bottom: 1px solid #f5f5f5;
}
 
.q-title {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
 
.q-index {
  font-weight: 600;
  margin-right: 6px;
}
 
.q-type {
  color: rgba(0, 0, 0, 0.45);
  font-size: 13px;
}
 
.q-stem {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 12px;
  color: rgba(0, 0, 0, 0.88);
}
 
.q-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
 
.q-option {
  padding: 6px 10px;
  border-radius: 4px;
  background: #fafafa;
  color: rgba(0, 0, 0, 0.75);
}
 
.q-option.opt-correct {
  background: #f6ffed;
  color: #389e0d;
  border: 1px solid #b7eb8f;
}
 
.q-option.opt-wrong {
  background: #fff2f0;
  color: #cf1322;
  border: 1px solid #ffccc7;
}
 
.q-answer {
  font-size: 13px;
  color: rgba(0, 0, 0, 0.55);
}
</style>