const app = getApp()
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
barHeight: "",
|
navBarHeight: "",
|
loading: false,
|
answerTitle: "", // 导航栏标题
|
bookId: "",
|
productLinkPath: "",
|
rootCmsItemId: "",
|
idPathList: [], // 题目列表
|
answerType: "", // 答题类型
|
submitStatus: false, // 提交状态
|
currentIndex: 0, // 当前答题数
|
collectList: [], // 收藏题目列表
|
subjectiveNum: 0, // 主观题得分
|
subjectiveGrade: 0, // 主观题总分
|
total: 0, // 题目总数
|
correctNum: 0, // 正确题目数量
|
cardList: [], // 提交项,
|
questionDataList: []
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad(options) {
|
const systInfo = wx.getSystemInfoSync();
|
const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
|
const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
|
this.setData({
|
barHeight: systInfo.statusBarHeight,
|
navBarHeight: navBarHeight,
|
answerTitle: options.answerTitle,
|
bookId: options.bookId,
|
productLinkPath: options.productLinkPath,
|
rootCmsItemId: options.rootCmsItemId,
|
idPathList: JSON.parse(options.idPathList),
|
answerType: options.answerType
|
});
|
this.init()
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload() {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh() {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom() {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage() {
|
},
|
// 返回
|
goBack() {
|
wx.navigateBack();
|
},
|
// 初始化函数
|
async init() {
|
if (this.data.answerType == 'option') {
|
// 测试答题
|
await this.getCollectIdList() // 获取收藏id列表
|
// await getErrorList() // 获取错题id列表
|
}
|
},
|
// 获取收藏题目列表id
|
getCollectIdList() {
|
app.MG.identity
|
.getUserKey({
|
domain: 'collectData',
|
keys: [this.data.rootCmsItemId]
|
})
|
.then(async (res) => {
|
try {
|
this.setData({
|
collectList: JSON.parse(res[0].value)
|
})
|
} catch (error) {
|
}
|
if (this.data.answerType == 'option') {
|
// 先获取用户答题记录
|
await this.getAnswerInfo((res) => {
|
if (res.length) {
|
// 有记录,不能答题,状态设为已提交
|
this.setData({
|
submitStatus: true
|
})
|
let value = JSON.parse(res[0].value)
|
// console.log('答题记录', JSON.parse(res[0].value))
|
// 有答题记录,得分赋值
|
if (value) {
|
value.dataList.forEach((item) => {
|
if (item.name == '客观题得分' && item.path == this.data.productLinkPath)
|
this.setData({
|
subjectiveNum: item.score
|
})
|
})
|
}
|
this.setData({
|
currentIndex: value.currentIndex
|
})
|
// 携带答题记录 获取题目
|
this.getQuestionList(value.dataList)
|
} else {
|
this.getQuestionList() // 获取题库题目
|
}
|
})
|
}
|
})
|
},
|
// 获取题库题目
|
getQuestionList(oldData) {
|
// 清空正确题数记录
|
this.setData({
|
correctNum: 0
|
})
|
let flag = 0
|
this.data.idPathList.forEach((pathitem) => {
|
const pathList = this.data.cardList
|
pathList.push({
|
name: pathitem.name,
|
path: pathitem.productLinkPath,
|
catalogName: pathitem.type,
|
infoList: []
|
})
|
this.setData({
|
cardList: pathList
|
})
|
// 获取题目
|
let questionArr = []
|
let query = {
|
path: '*',
|
queryType: '*',
|
productId: this.data.bookId,
|
cmsPath: pathitem.productLinkPath,
|
itemFields: {
|
// SysType: 'CmsFolder',
|
Embedded_QuestionBank_Stem: [],
|
Embedded_QuestionBank_AnalysisCon: [],
|
Embedded_QuestionBank_Answer: [],
|
Embedded_QuestionBank_Option: [],
|
Embedded_QuestionBank_QuestionType: [],
|
Embedded_QuestionBank_StemStyle: [],
|
Embedded_QuestionBank_OptionStyle: [],
|
Embedded_QuestionBank_KnowledgePoint: [],
|
Embedded_QuestionBank_Difficulty: []
|
},
|
pading: {
|
start: 0,
|
size: 999
|
}
|
}
|
app.MG.store.getProductDetail(query).then((res) => {
|
this.setData({
|
total: res.datas.cmsDatas[0].datas.length
|
})
|
// total.value += res.datas.cmsDatas[0].datas.length
|
let oldList
|
if (oldData) {
|
// 提交过,存在答题记录
|
oldList = oldData.find((item) => item.path == pathitem.productLinkPath).infoList
|
this.setData({
|
submitStatus: true
|
})
|
}
|
res.datas.cmsDatas[0].datas.forEach((item, index) => {
|
let oldObj = ''
|
if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id)
|
let questionObj = {
|
// num: index, // 题号
|
id: item.id,
|
stem:
|
item.Embedded_QuestionBank_QuestionType == 'completion'
|
? JSON.parse(item.Embedded_QuestionBank_Stem)
|
.stemTxt.replaceAll('<vacancy>', ',input,')
|
.split(',')
|
: JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
|
answer: item.Embedded_QuestionBank_Answer, // 答案
|
option: item.Embedded_QuestionBank_Option
|
? JSON.parse(item.Embedded_QuestionBank_Option)
|
: '', // 选择题选项
|
analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
|
questionType: item.Embedded_QuestionBank_QuestionType, // 题型
|
optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
|
stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
|
difficulty: item.Embedded_QuestionBank_Difficulty
|
? 4 - item.Embedded_QuestionBank_Difficulty
|
: 0, // 难度等级
|
userAnswer: oldObj
|
? oldObj.userAnswer
|
: item.Embedded_QuestionBank_QuestionType == 'completion' ||
|
item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
|
? []
|
: '',
|
isRight: oldObj ? oldObj.isRight : null,
|
isComplete: oldObj ? oldObj.isComplete : false,
|
isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
|
isUnfold: '' // 控制解析的折叠面板是否展开
|
}
|
// 多选和填空答案肯为数组,要转换JSON格式
|
if (
|
questionObj.questionType == 'completion' ||
|
questionObj.questionType == 'multipleChoice'
|
) {
|
try {
|
questionObj.answer = JSON.parse(questionObj.answer)
|
} catch (error) {
|
questionObj.answer = item.Embedded_QuestionBank_Answer
|
}
|
}
|
// 填空题改造
|
if (questionObj.questionType == 'completion') {
|
let index = 0
|
for (let i = 0; i < questionObj.stem.length; i++) {
|
const item = questionObj.stem[i]
|
if (item == 'input') {
|
questionObj.stem[i] = {
|
num: index,
|
data: 'input'
|
}
|
if (!oldObj) questionObj.userAnswer[index] = ''
|
index++
|
}
|
}
|
}
|
questionArr.push(questionObj)
|
// 旧数据里 题目已经作答,修改已答题目数量
|
// if (oldObj && oldObj.userAnswer.length > 0) countDownRef.value.changeAlready()
|
// 旧数据里 题目正确 记录正确数量
|
if (questionObj.isRight) {
|
this.setData({
|
correctNum: this.data.correctNum + 1
|
})
|
}
|
// if (pathitem.name == '判断题') {
|
// topicList.value.judge.data = questionArr
|
// topicList.value.judge.path = pathitem.productLinkPath
|
// if (oldData) subjectiveTotal.value += 1 // 有旧数据,计算主观题数
|
// } else if (pathitem.name == '填空题') {
|
// topicList.value.gap.data = questionArr
|
// topicList.value.gap.path = pathitem.productLinkPath
|
// if (oldData) subjectiveTotal.value += 1
|
// } else if (pathitem.name == '多选题') {
|
// topicList.value.check.data = questionArr
|
// topicList.value.check.path = pathitem.productLinkPath
|
// if (oldData) subjectiveTotal.value += 1
|
// } else if (pathitem.name == '单选题') {
|
// topicList.value.radio.data = questionArr
|
// topicList.value.radio.path = pathitem.productLinkPath
|
// if (oldData) subjectiveTotal.value += 1
|
// } else if (pathitem.name == '简答题') {
|
// topicList.value.short.data = questionArr
|
// topicList.value.short.path = pathitem.productLinkPath
|
// } else if (pathitem.name == '翻译题') {
|
// topicList.value.translate.data = questionArr
|
// topicList.value.translate.path = pathitem.productLinkPath
|
// } else if (pathitem.name == '听力题') {
|
// topicList.value.listen.data = questionArr
|
// topicList.value.listen.path = pathitem.productLinkPath
|
// if (oldData) subjectiveTotal.value += 1
|
// }
|
let infoList =
|
this.data.cardList[this.data.cardList.findIndex((item) => item.path == pathitem.productLinkPath)]
|
.infoList
|
infoList.push(questionObj)
|
flag++;
|
let questionList = []
|
// if (flag == this.data.idPathList.length) {
|
this.data.cardList.forEach(aitem => {
|
aitem.infoList.forEach(bitem => {
|
questionList.push(bitem)
|
bitem.number = questionList.length
|
})
|
})
|
this.setData({
|
questionDataList: questionList
|
})
|
// }
|
})
|
})
|
})
|
this.setData({
|
loading: false,
|
})
|
console.log('题目列表', this.data.questionDataList, this.data.cardList);
|
},
|
// 获取答题数据
|
getAnswerInfo(callback) {
|
app.MG.identity
|
.getUserKey({
|
domain: 'answerData',
|
keys: [this.data.productLinkPath]
|
})
|
.then((res) => {
|
if (callback) callback(res)
|
})
|
}
|
})
|