liuyu
4 小时以前 82a74ba0402ab546ba524d23ce62198c4d00d2f7
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<script lang="ts" setup>
import type { GradeExamDetail, GradeExamItem } from './types';
 
import { computed, onMounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
 
import { getGradeExamDetail, submitGrade } from '#/api/x/tms/examGrade';
import { labelOfType } from '#/views/x/tms/question/constants';
 
import { colorOfGradeStatus, labelOfGradeStatus } from './constants';
 
defineOptions({ name: 'TmsExamGradeMark' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const loading = ref(false);
const saving = ref(false);
const detail = ref<GradeExamDetail | null>(null);
const scoreMap = reactive<Record<string, number | undefined>>({});
 
const readonly = computed(() => detail.value?.gradeStatus === 'graded');
 
const subjectiveTotal = computed(() => {
  if (!detail.value) return 0;
  return detail.value.items
    .filter((x) => x.isSubjective === '1')
    .reduce((sum, x) => sum + Number(scoreMap[x.id] ?? 0), 0);
});
 
const previewTotal = computed(() => {
  if (!detail.value) return 0;
  return Number(detail.value.objectiveScore || 0) + subjectiveTotal.value;
});
 
onMounted(() => {
  loadDetail();
});
 
async function loadDetail() {
  const id = String(route.params.id || '');
  if (!id) {
    router.replace('/tms/examGrade');
    return;
  }
  loading.value = true;
  try {
    detail.value = await getGradeExamDetail(id);
    detail.value.items.forEach((it) => {
      if (it.isSubjective === '1') {
        scoreMap[it.id] = it.gotScore;
      }
    });
  } catch (e: any) {
    createMessage.error(e?.message || '加载答卷失败');
    router.back();
  } finally {
    loading.value = false;
  }
}
 
function stripHtml(html?: string) {
  if (!html) return '';
  return html.replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').trim();
}
 
function goBack() {
  if (detail.value?.sessionId) {
    router.push(`/tms/examGrade/session/${detail.value.sessionId}`);
  } else {
    router.push('/tms/examGrade');
  }
}
 
function validateScores(): string | null {
  if (!detail.value) return '答卷不存在';
  for (const it of detail.value.items) {
    if (it.isSubjective !== '1') continue;
    const v = scoreMap[it.id];
    if (v === undefined || v === null || Number.isNaN(Number(v))) {
      return '请为所有主观题打分';
    }
    if (Number(v) < 0 || Number(v) > Number(it.score)) {
      return `主观题得分需在 0 ~ ${it.score} 之间`;
    }
  }
  return null;
}
 
async function handleSubmit() {
  if (!detail.value || readonly.value) return;
  const err = validateScores();
  if (err) {
    createMessage.warning(err);
    return;
  }
  saving.value = true;
  try {
    const items = detail.value.items
      .filter((x) => x.isSubjective === '1')
      .map((x) => ({ id: x.id, gotScore: Number(scoreMap[x.id] || 0) }));
    await submitGrade({ examId: detail.value.examId, items });
    createMessage.success(`阅卷完成,总分 ${previewTotal.value}`);
    goBack();
  } catch (e: any) {
    createMessage.error(e?.message || '提交失败');
  } finally {
    saving.value = false;
  }
}
 
function itemClass(it: GradeExamItem) {
  return it.isSubjective === '1' ? 'grade-item subjective' : 'grade-item';
}
</script>
 
<template>
  <div class="jnpf-content-wrapper tms-grade-page">
    <div class="jnpf-content-wrapper-center tms-grade-center">
      <div class="jnpf-content-wrapper-content tms-grade-mark-wrap">
        <div class="mark-top">
          <div class="mark-header">
            <div>
              <div class="text-base font-medium">
                {{ detail?.paperName || '阅卷' }} · 阅卷
              </div>
              <div v-if="detail" class="mt-1 text-gray-400 text-sm">
                考生:{{ detail.userName }}
                <span v-if="detail.deptName">({{ detail.deptName }})</span>
                <span class="ml-3">交卷:{{ detail.submitTime || '-' }}</span>
                <span class="ml-3" :style="{ color: colorOfGradeStatus(detail.gradeStatus) }">
                  {{ labelOfGradeStatus(detail.gradeStatus) }}
                </span>
              </div>
            </div>
            <a-space>
              <a-button @click="goBack">返回</a-button>
              <a-button v-if="detail && !readonly" type="primary" :loading="saving" @click="handleSubmit">
                提交阅卷
              </a-button>
            </a-space>
          </div>
 
          <div v-if="detail" class="score-bar">
            <span>客观题 {{ detail.objectiveScore }} 分</span>
            <span class="mx-3">主观题 {{ subjectiveTotal }} 分</span>
            <span>
              合计
              <b class="text-primary">{{ previewTotal }}</b>
              / {{ detail.totalScore }}(合格 {{ detail.passScore }})
            </span>
          </div>
        </div>
 
        <div class="mark-body">
          <a-spin :spinning="loading">
            <template v-if="detail">
              <div
                v-for="(it, idx) in detail.items"
                :key="it.id"
                :class="itemClass(it)"
              >
                <div class="mb-2 text-sm text-gray-500">
                  第 {{ idx + 1 }} 题 · {{ labelOfType(it.questionType) }}
                  ({{ it.score }} 分)
                  <span v-if="it.isSubjective === '1'" class="text-orange-500 ml-2">主观题</span>
                </div>
                <div class="stem mb-3">{{ stripHtml(it.stem) }}</div>
 
                <div v-if="it.options?.length" class="mb-2 text-sm text-gray-600">
                  <div v-for="opt in it.options" :key="opt.optionLabel">
                    {{ opt.optionLabel }}. {{ opt.optionContent }}
                  </div>
                </div>
 
                <div class="answer-row text-sm">
                  <div>考生答案:{{ it.userAnswer || '(未作答)' }}</div>
                  <div v-if="it.isSubjective !== '1'">正确答案:{{ it.correctAnswer || '-' }}</div>
                  <div v-if="it.analysis" class="text-gray-400">解析:{{ it.analysis }}</div>
                </div>
 
                <div class="mt-3 flex items-center gap-2">
                  <template v-if="it.isSubjective === '1'">
                    <span>得分</span>
                    <a-input-number
                      v-model:value="scoreMap[it.id]"
                      :min="0"
                      :max="it.score"
                      :precision="1"
                      :disabled="readonly"
                      class="!w-[120px]"
                    />
                    <span class="text-gray-400">/ {{ it.score }}</span>
                  </template>
                  <template v-else>
                    <span class="text-gray-500">自动得分:{{ it.gotScore ?? 0 }}</span>
                  </template>
                </div>
              </div>
            </template>
          </a-spin>
        </div>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
/* 全局 jnpf-content-wrapper* 为 overflow:hidden 且无 min-height:0,必须整条链补齐 */
.tms-grade-page {
  min-height: 0;
}
 
.tms-grade-center {
  min-height: 0 !important;
}
 
.tms-grade-mark-wrap {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 0 !important;
  min-height: 0 !important;
  height: auto !important;
  overflow: hidden !important;
  background: #fff;
  padding: 0;
}
 
.mark-top {
  flex-shrink: 0;
  padding: 16px 20px 0;
}
 
.mark-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}
 
.score-bar {
  background: #fafafa;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
 
.mark-body {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: hidden;
  padding: 0 20px 32px;
  -webkit-overflow-scrolling: touch;
}
 
.grade-item {
  border: 1px solid #f0f0f0;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
 
.grade-item.subjective {
  border-color: #ffd591;
  background: #fffbe6;
}
 
.stem {
  font-size: 15px;
  line-height: 1.7;
}
 
.answer-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: rgba(0, 0, 0, 0.75);
}
</style>