Commit 982f5295 authored by Damon's avatar Damon

feat: 答题分页数据对接

parent 559c4fe3
const UNI_APP = {
apiUrl: 'http://192.168.0.208:8760',
apiUrl: 'http://192.168.0.204:8760',
qn_base_url: 'https://qn-static.banshouhui.com/study/',
qn_asset_url: 'http://deudn.c.pp.cc/',
uUrl: 'http://rest-u.yunya.com/',
......
import { commonApiFun } from './common.js'
import { learnApiFun } from './learn.js'
const apiFun = function(vm) {
let commonApi = commonApiFun(vm)
let learnApi = learnApiFun(vm)
let apiUrl = {
...commonApi,
...learnApi
}
return apiUrl
}
......
let learnApiFun = function(vm) {
const globalUrl = process.uniEnv || {}
let ucenterApiUrl = globalUrl.uUrl
let getQuestion = async (params = {}) => await vm.$u.post('/rest/question/query/getQuestion', params)
let getQuestionTotal = async (params = {}) => await vm.$u.post('/rest/question/query/getQuestionTotal', params)
const learnApi = {
getQuestion,
getQuestionTotal
}
return learnApi
}
module.exports = {
learnApiFun,
}
......@@ -7,6 +7,7 @@ const install = (Vue, vm) => {
baseUrl: systemApiUrl,
header: {
'channel': 'Applets',
'tenant': 'weixiuhui',
'content-type': 'application/json; charset=utf-8',
},
loadingTime: 0,
......
......@@ -189,6 +189,7 @@ export default {
swiperList[current] = currentItem
swiperList[this.getLastSwiperChangeIndex(current)] = this.getLastSwiperNeedItem(currentItem, list)
swiperList[this.getNextSwiperChangeIndex(current)] = this.getNextSwiperNeedItem(currentItem, list)
console.log("swiperList", swiperList)
return swiperList;
},
/**
......
This diff is collapsed.
// 分页为如下格式:
// {
// "total": 300,
// "currentPage": 1,
// "list": []
// }
const TOTAL = 100
const lists = [
{
type: 1,
title: '采用QS1电桥测量tanδ的接线方式一般有差接线及和接线。',
answerList: [
{
sort: 'A',
text: '正确',
},
{
sort: 'B',
text: '错误',
},
],
answer: 'A',
explain:
'极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。',
index: 0,
rightKey: ['A'],
},
{
type: 2,
title:
'空气间隙的操作冲击击穿电压数值大小不仅与间隙距离、电极形状、电极极性有关,而且与操作冲击电压波的波前时间的长短有关。',
answerList: [
{
sort: 'A',
text: '正确',
},
{
sort: 'B',
text: '错误',
},
],
answer: 'B',
explain:
'极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。',
index: 1,
rightKey: ['B'],
},
{
type: 3,
title: '西林电桥采用正接线及反接线时,其测试原理相同',
answerList: [
{
sort: 'A',
text: '影响',
},
{
sort: 'B',
text: '影响很小',
},
{
sort: 'C',
text: '影响很大',
},
{
sort: 'D',
text: '无影响',
},
],
answer: 'B,C',
explain:
'双臂电桥是在单臂电桥的基础上增加特殊机构,以消除测试时连接线和接线柱接触电阻对测量结果的影响。',
index: 2,
rightKey: ['B', 'C'],
},
{
type: 2,
title: '测试标题测试标题测试标题测试标题',
answerList: [
{
sort: 'A',
text: '是',
},
{
sort: 'B',
text: '否',
},
],
answer: 'B',
explain: '测试内容测试内容测试内容测试内容测试内容测试内容',
index: 3,
rightKey: ['B'],
},
]
// 请求一页数据
function request({ currentPage, size, onSuccess, onFailed }, vm) {
const params = {
current: currentPage,
size: size,
model: {
questionWarehouseId: vm.questionWarehouseId,
recordId: vm.recordId,
source: vm.source
}
}
vm.$u.api.getQuestion(params).then(res => {
const list = res.records
let data = {}
data.total = res.total
data.currentPage = currentPage
let questionList = []
for (let i = 0; i < size; i++) {
const info = list[i]
const content = JSON.parse(info.content)
const answerList = content.choiceList.map(v => {
return {
sort: v.value,
text: v.label
}
})
let type
switch (info.echoMap.questionTypeId) {
case '单选题':
type = 1
break;
case '判断题':
type = 2
break;
case '多选题':
type = 3
break;
}
let item = {
index: i + (currentPage - 1) * size,
currentPage: currentPage,
total: data.total,
title: content.title,
answerList: answerList,
answer: info.answer,
rightKey: info.answer.split(','),
explain: info.analysis,
type: type
}
questionList.push(item)
}
data.questionList = questionList
onSuccess(data)
})
}
// 同时请求多页数据
function requestMulti({ pageList, size, onSuccess, onFailed }, vm) {
console.log('请求哪几页数据?', pageList)
uni.showLoading({
title: '加载中',
})
let promise = Promise.all(
pageList.map(function(pageNum) {
return new Promise(function(resolve, reject) {
request({
currentPage: pageNum,
size: size,
onSuccess: function(res) {
resolve(res)
},
onFailed: function(msg) {
reject(new Error('failed to request'))
},
},vm)
})
})
)
promise
.then(function(results) {
uni.hideLoading()
onSuccess(results)
})
.catch(function(err) {
uni.hideLoading()
onFailed(err)
})
}
// 根据初始index和每页item的数量获取当前是第几页
const getInitcurrentPage = function(index, size) {
let pageNum = parseInt((index + 1) / size)
let remain = (index + 1) % size
return remain == 0 ? pageNum : pageNum + 1
}
// 获取初始的pageList, 可能一页,可能两页
const getInitPageList = function(currentIndex, size, currentPage, total) {
if ((currentIndex + 1) % size == 1 && currentIndex != 0) {
return [currentPage - 1, currentPage]
}
if ((currentIndex + 1) % size == 0 && currentIndex != total - 1) {
return [currentPage, currentPage + 1]
}
return [currentPage]
}
function initAnswerCardList(total, vm) {
if (!vm.questionList) {
let list = []
for (let i = 0; i < total; i++) {
list.push({})
}
vm.$u.vuex('questionList', list)
}
}
module.exports = {
TOTAL: TOTAL,
request: request,
requestMulti: requestMulti,
getInitcurrentPage: getInitcurrentPage,
getInitPageList: getInitPageList,
initAnswerCardList: initAnswerCardList,
}
......@@ -12,7 +12,7 @@ try{
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['userInfo', 'vuex_token', 'openId', 'searchHistory', 'questionList'];
let saveStateKeys = ['userInfo', 'vuex_token', 'openId', 'searchHistory', 'questionList', 'lastIndex'];
// 保存变量到本地存储中
const saveLifeData = function(key, value){
......@@ -37,6 +37,7 @@ const store = new Vuex.Store({
openId: lifeData.openId ? lifeData.openId : '',
searchHistory: lifeData.searchHistory ? lifeData.searchHistory : [], // 搜索历史记录
questionList: lifeData.questionList ? lifeData.questionList : [], // 练习列表
lastIndex: lifeData.lastIndex ? lifeData.lastIndex : 0, // 上次做到第几题
// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
vuex_version: '1.0.0',
},
......
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