Commit 7ae71cd2 authored by Damon's avatar Damon

feat: 答题兼容其他模式

parent b9656e7c
const globalUrl = process.uniEnv || {}; const globalUrl = process.uniEnv || {}
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量 // 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
const install = (Vue, vm) => { const install = (Vue, vm) => {
const systemApiUrl = globalUrl.apiUrl; const systemApiUrl = globalUrl.apiUrl
// 此为自定义配置参数,具体参数见上方说明 // 此为自定义配置参数,具体参数见上方说明
Vue.prototype.$u.http.setConfig({ Vue.prototype.$u.http.setConfig({
baseUrl: systemApiUrl, baseUrl: systemApiUrl,
header: { header: {
'channel': 'Applets', channel: 'Applets',
'tenant': 'weixiuhui', tenant: 'weixiuhui',
'content-type': 'application/json; charset=utf-8', 'content-type': 'application/json; charset=utf-8',
}, },
loadingTime: 800, loadingTime: 800,
originalData: true, originalData: true,
}); })
// 请求拦截,配置Token等参数 // 请求拦截,配置Token等参数
Vue.prototype.$u.http.interceptor.request = (config) => { Vue.prototype.$u.http.interceptor.request = (config) => {
...@@ -29,46 +29,48 @@ const install = (Vue, vm) => { ...@@ -29,46 +29,48 @@ const install = (Vue, vm) => {
// } // }
// } // }
// 最后需要将config进行return // 最后需要将config进行return
return config; return config
// 如果return一个false值,则会取消本次请求 // 如果return一个false值,则会取消本次请求
// if(config.url == '/user/rest') return false; // 取消某次请求 // if(config.url == '/user/rest') return false; // 取消某次请求
}; }
// 响应拦截,判断状态码是否通过 // 响应拦截,判断状态码是否通过
Vue.prototype.$u.http.interceptor.response = (res) => { Vue.prototype.$u.http.interceptor.response = (res) => {
const data = res.data; const data = res.data
let pages = getCurrentPages()
let route = pages[pages.length - 1].route
if (res.statusCode === 200) { if (res.statusCode === 200) {
if (data.code === 0) { if (data.code === 0) {
return data.data; return data.data
} else if (data.code === 401) { } else if (data.code === 401) {
vm.$u.toast(data.msg); vm.$u.toast(data.msg)
let pages = getCurrentPages();
let route = pages[pages.length - 1].route;
// 如果不是在登录页,则跳转到登录页 // 如果不是在登录页,则跳转到登录页
if (route !== 'pages/login/index') { if (route !== 'pages/login/index') {
setTimeout(() => { setTimeout(() => {
vm.$u.route('/pages/login/index'); vm.$u.route('/pages/login/index')
}, 1500); }, 1500)
} }
return false; return false
} else { } else {
// 如果返回false,则会调用Promise的reject回调, // 如果返回false,则会调用Promise的reject回调,
vm.$u.toast(data.msg); vm.$u.toast(data.msg)
return false; return false
} }
} else if (res.statusCode === 401) { } else if (res.statusCode === 401) {
// 登录过期 // 登录过期
vm.$u.toast(data.msg) vm.$u.toast(data.msg)
setTimeout(() => { if (route !== 'pages/login/index') {
vm.$u.route('/pages/login/index') setTimeout(() => {
}, 1500); vm.$u.route('/pages/login/index')
}else { }, 1500)
}
} else {
// HTTP状态非200 // HTTP状态非200
vm.$u.toast(data.msg || '服务器错误'); vm.$u.toast(data.msg || '服务器错误')
} }
}; }
}; }
export default { export default {
install, install,
}; }
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<view class="u-flex"> <view class="u-flex">
<view class="c-list"> <view class="c-list">
<u-icon name="grid" color="#5A6073" size="40"></u-icon> <u-icon name="grid" color="#5A6073" size="40"></u-icon>
<text>{{ currentIndex + 1 }}/{{ total }}</text> <text>{{ currentNumber }}/{{ total }}</text>
</view> </view>
</view> </view>
<view class="u-flex"> <view class="u-flex">
...@@ -143,6 +143,7 @@ export default { ...@@ -143,6 +143,7 @@ export default {
requesting: false, requesting: false,
// 科目ID // 科目ID
questionWarehouseId: null, questionWarehouseId: null,
// 1.顺序答题 2.随机练习 3.模拟考试 4.收藏答题 5.错题答题 6.专项练习-单选 7.专项练习-多选 8.专项练习-判断 9.专项练习-答案是
source: 0, source: 0,
recordId: 0 recordId: 0
} }
...@@ -157,35 +158,67 @@ export default { ...@@ -157,35 +158,67 @@ export default {
} }
return process.uniEnv.qn_base_url + name return process.uniEnv.qn_base_url + name
}, },
currentNumber() {
let index = this.currentIndex
return index === -2 ? this.total : index + 1
}
}, },
onLoad(e) { onLoad(e) {
this.questionWarehouseId = e?.questionWarehouseId || 1414854649273384960 this.questionWarehouseId = parseInt(e?.questionWarehouseId) || 1414854649273384960
if (e?.source) this.source = e.source if (e?.source) this.source = parseInt(e.source)
if (e?.recordId) this.recordId = e.recordId if (e?.recordId) this.recordId = parseInt(e.recordId)
const params = {
questionWarehouseId: this.questionWarehouseId, switch (this.source) {
recordId: this.recordId, case 1:
source: this.source case 2:
case 6:
case 7:
case 8:
case 9:
this.type = 1
break;
case 3:
this.type = 2
break;
case 4:
this.type = 3
break;
case 5:
this.type = 4
break;
default:
this.type = 1
break;
} }
this.$u.api.getQuestionTotal(params).then(res => {
// 列表总长度,一定要在第一次请求列表数据前明确该值
// 否则无法知道下一页是否还有数据
let total = parseInt(res) || 0
this.total = total
// 初始化答题卡列表
Utils.initAnswerCardList(total, this)
this.cachePageDataMap = new Map()
// 上次答到了第几题
let index = 18
this.refresh(index)
})
// 第一次进入,显示提示 // 第一次进入,显示提示
if (this.questionList.length === 0) { if (this.questionList.length === 0) {
this.show = true this.show = true
} }
this.init()
}, },
methods: { methods: {
init() {
const params = {
questionWarehouseId: this.questionWarehouseId,
recordId: this.recordId,
source: this.source
}
this.$u.api.getQuestionTotal(params).then(res => {
// 列表总长度,一定要在第一次请求列表数据前明确该值
// 否则无法知道下一页是否还有数据
let total = parseInt(res) || 0
this.total = total
// 练习模式-初始化答题卡列表
if (type === 1) Utils.initAnswerCardList(total, this)
this.cachePageDataMap = new Map()
// 上次答到了第几题
let index = this.type === 1 ? (this.lastIndex || 0) : 0
this.refresh(index)
})
},
swiperChange(e) { swiperChange(e) {
let current = e.current let current = e.current
this.currentIndex = current this.currentIndex = current
...@@ -211,17 +244,9 @@ export default { ...@@ -211,17 +244,9 @@ export default {
url: 'pages/learn/source', url: 'pages/learn/source',
}) })
} else { } else {
uni.showModal({ return uni.showToast({
title: '提示', title: '已经是最后一题了',
content: '已经是最后一题了', icon: 'none',
success: (res) => {
if (res.confirm) {
this.$u.route({
url: '/pages/index/index',
type: 'tab',
})
}
},
}) })
} }
} }
...@@ -305,34 +330,35 @@ export default { ...@@ -305,34 +330,35 @@ export default {
// 作答完毕 // 作答完毕
answerChange(status, lists) { answerChange(status, lists) {
// 保存答题状态 // 保存答题状态
this.$set(this.list[this.currentIndex], 'submitStatus', true) const item = this.list.find(v => v.index === this.currentIndex)
this.$set(this.list[this.currentIndex], 'answerList', lists) item.submitStatus = true
this.$set(this.list[this.currentIndex], 'result', status) item.answerList = lists
this.$set( item.result = status
this.list[this.currentIndex], item.errShow = this.type === 2 ? true : status === 'fail'
'errShow',
this.type === 2 ? true : status === 'fail'
)
// 更新答题卡 // 更新答题卡
this.questionList[this.currentIndex] = this.list[this.currentIndex] this.questionList[this.currentIndex] = item
this.$u.vuex('questionList', this.questionList) this.$u.vuex('questionList', this.questionList)
this.$u.vuex('lastIndex', this.currentIndex + 1) this.$u.vuex('lastIndex', this.currentIndex)
// 每日一练数量统计 // 每日一练数量统计
if (this.type === 1 && this.daily) { if (this.type === 1 && this.daily) {
if (this.dailyCount < 3) this.dailyCount++ if (this.dailyCount < 9) this.dailyCount++
if (this.dailyCount === 3) { if (this.dailyCount === 9) {
this.completeType = 'daily' this.completeType = 'daily'
this.visible = true this.visible = true
return return
} }
} }
// 如果回答错误或者是考试模式,自动进入下一题 // 如果回答错误或者是考试模式,自动进入下一题
if (status === 'pass' || this.type === 2) { if (status === 'pass' || this.type === 2) {
if (this.currentIndex + 1 > this.total - 1) { if (this.currentIndex + 1 > this.total - 1) {
return return
} }
this.current = this.currentIndex + 1 this.$nextTick(() => {
this.current = this.currentIndex + 1
})
} }
}, },
// 交卷 // 交卷
...@@ -449,9 +475,23 @@ export default { ...@@ -449,9 +475,23 @@ export default {
list = list.concat(resultItem.questionList) list = list.concat(resultItem.questionList)
}) })
this.list = list this.list = list
this.$nextTick(() => {
this.$refs.swiper.init(currentIndex) if (this.list.length === 0) {
}) uni.showToast({
title: '暂无数据',
icon: 'none',
})
setTimeout(() => {
this.$u.route({
delta: 1,
type: 'back'
})
}, 1500)
} else {
this.$nextTick(() => {
this.$refs.swiper.init(currentIndex)
})
}
} }
}, },
} }
......
...@@ -112,38 +112,46 @@ function request({ currentPage, size, onSuccess, onFailed }, vm) { ...@@ -112,38 +112,46 @@ function request({ currentPage, size, onSuccess, onFailed }, vm) {
let questionList = [] let questionList = []
for (let i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
const info = list[i] const info = list[i]
const content = JSON.parse(info.content) if (info) {
const answerList = content.choiceList.map(v => { const content = JSON.parse(info.content)
return { const answerList = content.choiceList.map(v => {
sort: v.value, return {
text: v.label sort: v.value,
} text: v.label
}) }
})
let type let type
switch (info.echoMap.questionTypeId) { switch (info.echoMap.questionTypeId) {
case '单选题': case '单选题':
type = 1 type = 1
break; break;
case '判断题': case '判断题':
type = 2 type = 2
break; break;
case '多选题': case '多选题':
type = 3 type = 3
break; break;
} }
let item = { let item = {
index: i + (currentPage - 1) * size, index: i + (currentPage - 1) * size,
currentPage: currentPage, currentPage: currentPage,
total: data.total, total: data.total,
title: content.title, title: content.title,
answerList: answerList, answerList: answerList,
answer: info.answer, answer: info.answer,
rightKey: info.answer.split(','), rightKey: info.answer.split(','),
explain: info.analysis, explain: info.analysis,
type: type type: type
}
// 回显已答题目
if (vm.type === 1) { // 练习模式回显
const ansItem = vm.questionList.find(v => v.index === item.index)
questionList.push(ansItem ? ansItem : item)
} else {
questionList.push(item)
}
} }
questionList.push(item)
} }
data.questionList = questionList data.questionList = questionList
onSuccess(data) onSuccess(data)
...@@ -202,7 +210,7 @@ const getInitPageList = function(currentIndex, size, currentPage, total) { ...@@ -202,7 +210,7 @@ const getInitPageList = function(currentIndex, size, currentPage, total) {
} }
function initAnswerCardList(total, vm) { function initAnswerCardList(total, vm) {
if (!vm.questionList) { if (!vm.questionList || vm.questionList.length === 0) {
let list = [] let list = []
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
list.push({}) list.push({})
......
...@@ -42,7 +42,8 @@ export default { ...@@ -42,7 +42,8 @@ export default {
this.$u.vuex('openId', res.openId) this.$u.vuex('openId', res.openId)
this.$u.vuex('userInfo', userInfo) this.$u.vuex('userInfo', userInfo)
this.$u.route({ this.$u.route({
type: 'back', url: '/pages/index/index',
type: 'tab',
}) })
}) })
} }
......
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