Commit f2396170 authored by Damon's avatar Damon

refactor: 练习模式回答完全部试题逻辑修改

parent 712675d8
...@@ -246,6 +246,7 @@ export default { ...@@ -246,6 +246,7 @@ export default {
if(this.source === 1){ // 顺序答题,如果答满则清空数据 if(this.source === 1){ // 顺序答题,如果答满则清空数据
const check = this.questionList.every(v => v.id) const check = this.questionList.every(v => v.id)
if (check) { if (check) {
this.$u.vuex('lastIndex', 0)
this.$u.vuex('questionList', []) this.$u.vuex('questionList', [])
} }
} }
...@@ -260,7 +261,12 @@ export default { ...@@ -260,7 +261,12 @@ export default {
recordId: this.recordId, recordId: this.recordId,
source: this.source source: this.source
} }
uni.showLoading({
title: '加载中'
})
this.$u.api.getQuestionTotal(params).then(res => { this.$u.api.getQuestionTotal(params).then(res => {
uni.hideLoading()
// 列表总长度,一定要在第一次请求列表数据前明确该值 // 列表总长度,一定要在第一次请求列表数据前明确该值
// 否则无法知道下一页是否还有数据 // 否则无法知道下一页是否还有数据
let total = parseInt(res) || 0 let total = parseInt(res) || 0
...@@ -295,14 +301,14 @@ export default { ...@@ -295,14 +301,14 @@ export default {
if (current == NO_PREV_PAGE) { if (current == NO_PREV_PAGE) {
return uni.showToast({ return uni.showToast({
title: '已经是第一题了', title: '已经是第一道试题',
icon: 'none', icon: 'none',
}) })
} }
if (current == NO_NEXT_PAGE) { if (current == NO_NEXT_PAGE) {
return uni.showToast({ return uni.showToast({
title: '已经是最后一题了', title: '已经是最后一道试题',
icon: 'none', icon: 'none',
}) })
} }
...@@ -410,6 +416,19 @@ export default { ...@@ -410,6 +416,19 @@ export default {
this.questionList[this.currentIndex] = item this.questionList[this.currentIndex] = item
this.$u.vuex('questionList', this.questionList) this.$u.vuex('questionList', this.questionList)
this.$u.vuex('lastIndex', this.currentIndex) this.$u.vuex('lastIndex', this.currentIndex)
// 统计是否达满所有试题
const count = this.questionList.reduce((accumulator, currentValue) => {
if (currentValue.id) accumulator++
return accumulator
}, 0)
if (count === this.total) {
return uni.showToast({
title: '您已经答完全部试题',
icon: 'none',
})
}
} }
// 如果回答错误或者是考试模式,自动进入下一题 // 如果回答错误或者是考试模式,自动进入下一题
...@@ -437,14 +456,7 @@ export default { ...@@ -437,14 +456,7 @@ export default {
source: this.source source: this.source
} }
this.$u.api.answer([params]).then(res => { this.$u.api.answer([params]).then(res => {
if (this.source === 1) { if (this.source === 2) { // 每日一练
if (res === this.total) {
return uni.showToast({
title: '你已经回答了全部试题',
icon: 'none',
})
}
} else if (this.source === 2) {
if (this.daily.status && res === 10) this.dailyComplete() if (this.daily.status && res === 10) this.dailyComplete()
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment