Skip to content

Commit bde5940

Browse files
committed
feat[practice]show problem duplicate count
1 parent 27ff1d5 commit bde5940

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

public/data/problems/database/multi.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
"answer": [4],
4444
"analysis": "除了{{OPT:4}}是2+2=4,其他的都是2"
4545
},
46+
{
47+
"content": "这是一道判断题(重复测试)",
48+
"answer": true,
49+
"analysis": "明显是对的"
50+
},
51+
{
52+
"content": "这是一道判断题(重复测试)",
53+
"answer": true,
54+
"analysis": "明显是对的"
55+
},
4656
{
4757
"content": "M单选题,2+2=",
4858
"options": ["2", "4-2", "4/2", "1+3", "sqrt(4)"],

src/views/problems/Practice/Train/ProblemList/CompletionTip/index.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ export default {
5656
updatedb ({ db, is_manual = true }) {
5757
this.$emit('requireRestProblem', { is_manual, db })
5858
},
59-
init_status (d) {
59+
init_status ({ prblems, duplicated }) {
6060
const status = {
61-
total: d.length,
61+
total: prblems.length,
6262
solved: 0,
63-
wrong: 0
63+
wrong: 0,
64+
duplicated
6465
}
6566
this.status = status
6667
},

src/views/problems/Practice/Train/ProblemList/index.vue

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
/>
2929
</li>
3030
</transition-group>
31-
<CompletionTip ref="completion_tip" @onStatus="v => $emit('onStatus', v)" @requireRestProblem="v => reset_by_dict(v)" />
31+
<CompletionTip
32+
ref="completion_tip"
33+
@onStatus="v => $emit('onStatus', v)"
34+
@requireRestProblem="v => reset_by_dict(v)"
35+
/>
3236
<el-backtop target=".train" />
3337
</div>
3438
</template>
@@ -185,9 +189,9 @@ export default {
185189
},
186190
init (data) {
187191
this.loading = true
188-
this.init_problems(data).then(d => {
189-
this.$refs.completion_tip.init_status(d)
190-
this.$refs.completion_tip.init_wrong_set(d)
192+
this.init_problems(data).then(({ prblems, duplicated }) => {
193+
this.$refs.completion_tip.init_status({ prblems, duplicated })
194+
this.$refs.completion_tip.init_wrong_set(prblems)
191195
setTimeout(() => {
192196
const item = this.filtered_data[0]
193197
if (!item) return
@@ -211,7 +215,7 @@ export default {
211215
if (problem_max_num > 0) r = r.slice(0, problem_max_num)
212216
return r
213217
},
214-
do_attach_analysis(r) {
218+
do_attach_analysis (r) {
215219
r.map(i => {
216220
let { analysis } = i
217221
if (!analysis) {
@@ -226,7 +230,7 @@ export default {
226230
}
227231
})
228232
},
229-
do_shuffle_options(r, is_to_shuffle) {
233+
do_shuffle_options (r, is_to_shuffle) {
230234
const convert = (map_to, options, answers) => {
231235
const new_options = options.map((i, index) => {
232236
const new_index = map_to[index]
@@ -257,23 +261,24 @@ export default {
257261
})
258262
},
259263
init_problems (data) {
260-
let d = data || this.data || []
264+
let prblems = data || this.data || []
261265
return new Promise((res, rej) => {
262266
const id_dict = {}
263-
d = d.map((i) => {
267+
prblems = prblems.map((i) => {
264268
const r = Object.assign({}, i) // 创建新的题目对象
265269
if (!r.id) r.id = `${i.content}${JSON.stringify(i.answer)}` // 若题目没有定义id,则通过题目内容创建id
266270
if (id_dict[r.id]) {
271+
id_dict[r.id]++
267272
return null // 如果id重复,则标记题目为待删除
268273
}
269-
id_dict[r.id] = r // 将题目加入重复判断字典中
274+
id_dict[r.id] = 1 // 将题目加入重复判断字典中
270275
r.completed = false
271276
return r
272277
}).filter(i => i)
273-
d = this.do_filter_problems(d)
274-
d = d.map((i, page_index) => Object.assign({ page_index }, i)) // 初始化题目的页面位置
275-
this.filtered_data = d
276-
return res(d)
278+
prblems = this.do_filter_problems(prblems)
279+
prblems = prblems.map((i, page_index) => Object.assign({ page_index }, i)) // 初始化题目的页面位置
280+
this.filtered_data = prblems
281+
return res({ prblems, duplicated: id_dict })
277282
})
278283
},
279284
}

src/views/problems/Practice/Train/TrainStatus/index.vue

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<el-card>
33
<el-form v-if="data" label-width="5rem">
44
<el-form-item label="总题数">
5-
<span>{{ data.total }}</span>
5+
<span>
6+
<span>{{ data.total }}</span>
7+
<el-button v-if="duplicated.length" type="text" @click="showDuplicated = !showDuplicated">({{ duplicated.length
8+
}}题重复)</el-button>
9+
</span>
610
</el-form-item>
711
<el-form-item label="已完成">
812
<span>{{ data.solved }}</span>
@@ -14,9 +18,23 @@
1418
<span>{{ parseTime(time_start) }}</span>
1519
</el-form-item>
1620
<el-form-item label="已耗时">
17-
<span>{{ time_spent||'未开始' }}</span>
21+
<span>{{ time_spent || '未开始' }}</span>
1822
</el-form-item>
1923
</el-form>
24+
<el-dialog v-if="showDuplicated" :visible="showDuplicated">
25+
<el-table :data="duplicated">
26+
<el-table-column label="重复次数">
27+
<template slot-scope="{row}">
28+
<span>{{ data.duplicated[row] - 1 }}</span>
29+
</template>
30+
</el-table-column>
31+
<el-table-column label="题目内容">
32+
<template slot-scope="{row}">
33+
<span>{{ row }}</span>
34+
</template>
35+
</el-table-column>
36+
</el-table>
37+
</el-dialog>
2038
</el-card>
2139
</template>
2240

@@ -30,8 +48,18 @@ export default {
3048
data: () => ({
3149
time_start: new Date(),
3250
time_spent: null,
33-
timer: null
51+
timer: null,
52+
showDuplicated: false
3453
}),
54+
computed: {
55+
duplicated () {
56+
if (!this.data) return []
57+
const { data } = this
58+
const { duplicated } = data
59+
if (!duplicated) return []
60+
return Object.keys(duplicated).filter(i => data.duplicated[i] > 1)
61+
}
62+
},
3563
mounted () {
3664
this.timer = setInterval(() => {
3765
const t = new Date()

0 commit comments

Comments
 (0)