Skip to content

Commit 9c209ed

Browse files
committed
feat[problem]support show user answer
1 parent dcb9ff1 commit 9c209ed

File tree

9 files changed

+52
-45
lines changed

9 files changed

+52
-45
lines changed

src/views/problems/Problem/ProblemAnalysis/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default {
6262
data: { type: Object, default: null },
6363
showAnswer: { type: Boolean, default: false },
6464
options: { type: Object, default: null },
65-
userAnswer: { type: [Object, Array, Boolean, String], default: null },
65+
userAnswer: { type: [Object, Array, Boolean, String, Number], default: null },
6666
userAnswerResult: { type: Boolean, default: null },
6767
userAnswerConfirmResult: { type: Boolean, default: false }
6868
},

src/views/problems/Problem/ProblemBase/ProblemHeader/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default {
5353
requireShowAnswer (show = true) {
5454
this.$emit('update:showAnswer', show)
5555
},
56-
practice_submit ({ is_right, is_manual }) {
56+
practice_submit ({ is_right, is_manual, answer }) {
5757
if (this.beenSolved) {
5858
this.$message.warning('已提交过答案啦')
5959
return
@@ -62,7 +62,7 @@ export default {
6262
else this.$message.success(is_manual ? '我会做!' : '做对啦~')
6363
this.requireShowAnswer()
6464
this.beenSolved = true
65-
this.$emit('onAnswer', { is_right, is_manual })
65+
this.$emit('onAnswer', { is_right, is_manual, answer })
6666
}
6767
}
6868
}

src/views/problems/Problem/ProblemBase/index.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export default {
7777
const c = this.$refs.header
7878
c && c.reset()
7979
},
80-
onSubmit ({ is_right, is_manual }) {
80+
onSubmit ({ is_right, is_manual, answer }) {
8181
const c = this.$refs.header
82-
c && c.practice_submit({ is_right, is_manual })
82+
c && c.practice_submit({ is_right, is_manual, answer })
8383
},
8484
onMouseEnter () {
8585
this.lastEnter = new Date()
@@ -100,19 +100,19 @@ export default {
100100
if (is_right && this.lighting_mode) return this.onAnswerResult({ is_right, is_manual })
101101
if (!is_right) this.update_problem({ is_right: false, is_manual })
102102
},
103-
onAnswerResult ({ is_right, is_manual }) {
103+
onAnswerResult ({ is_right, is_manual, answer }) {
104104
this.userAnswerConfirmResult = true
105105
if (this.userAnswerResult === false) return
106106
this.showAnswer = false
107-
this.update_problem({ is_right, is_manual })
107+
this.update_problem({ is_right, is_manual, answer })
108108
},
109-
update_problem ({ is_right, is_manual }) {
109+
update_problem ({ is_right, is_manual, answer }) {
110110
const database = this.current_database.name
111111
const { data, time_spent } = this
112112
api.user_problem_result({ database }).then(v => {
113113
const problem_id = data.id || data.content
114114
const val = statistics_problem(v[problem_id], is_right, time_spent)
115-
this.$emit('onSubmit', { is_right, is_manual })
115+
this.$emit('onSubmit', { is_right, is_manual, answer })
116116
console.log('update problem', problem_id, val)
117117
api.user_problem_result({ database, problem_id, val })
118118
})

src/views/problems/Problem/ProblemBlanking/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export default {
8080
const is_right = !answer.find((i, index) => {
8181
return i !== result[index]
8282
})
83-
return this.directSubmit({ is_right })
83+
return this.directSubmit({ is_right, answer: result })
8484
},
85-
directSubmit({ is_right, is_manual }) {
86-
return this.$emit('onUserSubmit', { is_right, is_manual })
85+
directSubmit ({ is_right, is_manual, answer }) {
86+
return this.$emit('onUserSubmit', { is_right, is_manual, answer })
8787
},
8888
refresh (v) {
8989
const content = this.data && this.data.content

src/views/problems/Problem/ProblemJudging/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ export default {
108108
const answer = this.data.answer ? 1 : 2
109109
if (!answer) return this.$message.warning('本题无答案')
110110
const is_right = Number(answer) === Number(result)
111-
return this.directSubmit({ is_right })
111+
return this.directSubmit({ is_right, answer: result })
112112
},
113-
directSubmit ({ is_right, is_manual }) {
114-
return this.$emit('onUserSubmit', { is_right, is_manual })
113+
directSubmit ({ is_right, is_manual, answer }) {
114+
return this.$emit('onUserSubmit', { is_right, is_manual, answer })
115115
},
116116
refresh (v) {
117117
const content = this.data && this.data.content

src/views/problems/Problem/ProblemLongAnswer/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export default {
101101
const answer = this.data.answer
102102
if (!answer) return this.$message.warning('本题无答案')
103103
const is_right = answer === result
104-
return this.directSubmit({ is_right })
104+
return this.directSubmit({ is_right, answer: result })
105105
},
106-
directSubmit({ is_right, is_manual }) {
107-
return this.$emit('onUserSubmit', { is_right, is_manual })
106+
directSubmit ({ is_right, is_manual, answer }) {
107+
return this.$emit('onUserSubmit', { is_right, is_manual, answer })
108108
},
109109
refresh (v) {
110110
const content = this.data && this.data.content

src/views/problems/Problem/ProblemMultiSelect/index.vue

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,37 @@
22
<span>
33
<component
44
:is="b.type"
5-
v-for="(b,bindex) in blanking"
5+
v-for="(b, bindex) in blanking"
66
:ref="`${b.type}${b.i}`"
77
:key="bindex"
88
v-model="user_input[b.i]"
99
v-bind="b.attrs"
1010
:style="b.style"
11-
@keyup.enter.native="onSubmit(b)"
11+
@keyup.enter.native="onSubmit({})"
1212
>{{ b.value }}
1313
</component>
1414
<div class="p-ms">
1515
<el-checkbox-group v-model="user_input" size="mini">
16-
<el-checkbox v-for="(opt,oindex) in filtered_options" :key="oindex" :disabled="oindex<options.length && is_select_all" :label="oindex+1" class="opt-single">{{ `${String.fromCharCode(65+oindex)}.${opt}` }}
16+
<el-checkbox
17+
v-for="(opt, oindex) in filtered_options"
18+
:key="oindex"
19+
:disabled="oindex < options.length && is_select_all"
20+
:label="oindex + 1"
21+
class="opt-single"
22+
>{{
23+
`${String.fromCharCode(65 + oindex)}.${opt}`
24+
}}
1725
</el-checkbox>
1826
</el-checkbox-group>
1927
</div>
20-
<el-button :type="btn_submit.btn_types||'text'" :size="btn_submit.btn_sizes||'mini'" class="pb" @click="onSubmit">提交</el-button>
28+
<el-button :type="btn_submit.btn_types || 'text'" :size="btn_submit.btn_sizes || 'mini'" class="pb" @click="onSubmit()">
29+
提交</el-button>
2130
<el-button
2231
v-if="btn_select_all.btn_show || false"
2332
:type="btn_select_all.btn_types || 'text'"
2433
:size="btn_select_all.btn_sizes || 'mini'"
2534
class="pb"
26-
@click="onSubmitAll"
35+
@click="onSubmit({ is_select_all: true })"
2736
>全选并提交</el-button>
2837
</span>
2938
</template>
@@ -49,7 +58,7 @@ export default {
4958
focus_callback_set: null
5059
}),
5160
computed: {
52-
btn_submit() {
61+
btn_submit () {
5362
return (this.preferences && this.preferences.btn_submit) || {}
5463
},
5564
btn_select_all () {
@@ -58,15 +67,15 @@ export default {
5867
user_options () {
5968
return this.$store.state.problems.current_options
6069
},
61-
enable_select_all() {
70+
enable_select_all () {
6271
return this.user_options && this.user_options.enable_select_all
6372
},
64-
filtered_options() {
73+
filtered_options () {
6574
const { options, enable_select_all } = this
6675
if (!options) return []
6776
return enable_select_all ? options.concat(['全选']) : options
6877
},
69-
is_select_all() {
78+
is_select_all () {
7079
const { enable_select_all, user_input, options } = this
7180
return (enable_select_all && user_input[user_input.length - 1] > options.length)
7281
}
@@ -86,11 +95,11 @@ export default {
8695
immediate: true
8796
}
8897
},
89-
destroyed() {
98+
destroyed () {
9099
this.setKeyHandler(false)
91100
},
92101
methods: {
93-
setKeyHandler(is_set) {
102+
setKeyHandler (is_set) {
94103
if (is_set && !this.focus_callback_set) {
95104
console.log('callback is set to', this.index)
96105
document.addEventListener('keyup', this.keyInput)
@@ -120,29 +129,26 @@ export default {
120129
}
121130
if (this.filtered_options.length >= value) { this.user_input.push(value) }
122131
},
123-
onSubmit () {
132+
onSubmit ({ is_select_all }) {
133+
is_select_all |= this.is_select_all
124134
const { user_input, options } = this
125-
const result = this.is_select_all ? options.map((i, index) => index) : user_input
135+
const result = is_select_all ? options.map((i, index) => index + 1) : user_input
126136
const v = result
127137
.filter(i => i > 0)
128138
.sort((a, b) => a - b)
129139
return this.judgeSubmit(v)
130140
},
131-
onSubmitAll() {
132-
this.is_select_all = true
133-
return this.onSubmit()
134-
},
135141
judgeSubmit (result) {
136142
let answer = this.data.answer
137143
if (!answer) return this.$message.warning('本题无答案')
138144
answer = answer.sort((a, b) => a - b)
139145
const is_right = answer.length === result.length && !answer.find((i, index) => {
140146
return i !== result[index]
141147
})
142-
return this.directSubmit({ is_right })
148+
return this.directSubmit({ is_right, answer: result })
143149
},
144-
directSubmit({ is_right, is_manual }) {
145-
return this.$emit('onUserSubmit', { is_right, is_manual })
150+
directSubmit ({ is_right, is_manual, answer }) {
151+
return this.$emit('onUserSubmit', { is_right, is_manual, answer })
146152
},
147153
refresh (v) {
148154
const { data } = this
@@ -171,6 +177,7 @@ export default {
171177
.content-container {
172178
display: flex;
173179
}
180+
174181
.p-ms {
175182
display: flex;
176183
align-items: center;

src/views/problems/Problem/ProblemSingleSelect/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export default {
102102
const answer = this.data.answer
103103
if (!answer) return this.$message.warning('本题无答案')
104104
const is_right = Number(answer) === Number(result)
105-
return this.directSubmit({ is_right })
105+
return this.directSubmit({ is_right, answer: result })
106106
},
107-
directSubmit({ is_right, is_manual }) {
108-
return this.$emit('onUserSubmit', { is_right, is_manual })
107+
directSubmit ({ is_right, is_manual, answer }) {
108+
return this.$emit('onUserSubmit', { is_right, is_manual, answer })
109109
},
110110
refresh (v) {
111111
const { data } = this

src/views/problems/Problem/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ export default {
5656
}
5757
},
5858
methods: {
59-
handle_submit ({ is_right, is_manual }) {
59+
handle_submit ({ is_right, is_manual, answer }) {
6060
if (this.submitted) return
6161
this.submitted = true
62-
return this.$emit('onSubmit', { is_right, is_manual })
62+
return this.$emit('onSubmit', { is_right, is_manual, answer })
6363
},
6464
onClick () {
6565
this.$emit('requireFocus')
6666
},
67-
onSubmit ({ is_right, is_manual }) {
67+
onSubmit ({ is_right, is_manual, answer }) {
6868
const c = this.$refs.base
69-
c && c.onSubmit({ is_right, is_manual })
69+
c && c.onSubmit({ is_right, is_manual, answer })
7070
},
7171
reset () {
7272
this.completed = false

0 commit comments

Comments
 (0)