| | |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | // wx.enableAlertBeforeUnload({ |
| | | // message: "未提交,是否退出答题?", |
| | | // success: function (res) { |
| | | // console.log('确定', res); |
| | | // }, |
| | | // fail: function (err) { |
| | | // console.log("失败:", err); |
| | | // }, |
| | | // }); |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | |
| | | * 生命周期函数--监听页面初次渲染完成 |
| | | */ |
| | | onReady() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | |
| | | * 生命周期函数--监听页面隐藏 |
| | | */ |
| | | onHide() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | onUnload() { |
| | | onUnload(e) { |
| | | if (this.data.countdownInterval !== null) { |
| | | clearInterval(this.data.countdownInterval) |
| | | } |
| | |
| | | */ |
| | | onShareAppMessage() { |
| | | }, |
| | | |
| | | // 监听watch |
| | | watch(context, variableName, callback) { |
| | | let value = context.data[variableName]; // 获取被监听属性的当前值 |
| | | |
| | | // 使用 Object.defineProperty 方法在数据对象上定义属性的 getter 和 setter |
| | | Object.defineProperty(context.data, variableName, { |
| | | configurable: true, // 可配置 |
| | | enumerable: true, // 可枚举 |
| | | get: function () { |
| | | return value; // 返回属性的当前值 |
| | | }, |
| | | set: function (newVal) { |
| | | const oldVal = value; // 记录属性的旧值 |
| | | value = newVal; // 更新属性的值 |
| | | callback.call(context, newVal, oldVal); // 调用回调函数,传递新值和旧值 |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 返回 |
| | | goBack() { |
| | | console.log(this.data.submitStatus); |
| | | wx.navigateBack(); |
| | | }, |
| | | //设置背景色 |
| | |
| | | this.setData({ |
| | | currentIndex: e.detail.index |
| | | }) |
| | | let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0 |
| | | let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer) |
| | | if (flag) this.handleQuestion(e.detail.index) |
| | | |
| | | if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') { |
| | | let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0 |
| | | let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer) |
| | | if (flag) this.handleQuestion(e.detail.index) |
| | | } |
| | | }, |
| | | // 点击答题卡跳转题目 |
| | | goQuestion(e) { |
| | |
| | | } else { |
| | | return false |
| | | } |
| | | } else { |
| | | } else if (typeof data == 'object') { |
| | | const answer = data.find((item) => item.length > 0) |
| | | if (answer) { |
| | | return true |
| | | } else { |
| | | return false |
| | | } |
| | | } else { |
| | | return false |
| | | } |
| | | }, |
| | | // 提交逻辑 |
| | | submitPaper() { |
| | | // 关闭退出页面监听 |
| | | wx.disableAlertBeforeUnload() |
| | | this.setData({ |
| | | submitStatus: true |
| | | }) |
| | |
| | | let value = JSON.parse(res[0].value) |
| | | // 有答题记录,得分赋值 |
| | | if (value) { |
| | | wx.disableAlertBeforeUnload() |
| | | this.setData({ |
| | | submitStatus: true |
| | | }) |
| | |
| | | this.setData({ |
| | | currentIndex: value.currentIndex |
| | | }) |
| | | console.log(this.data.submitStatus); |
| | | // 携带答题记录 获取题目 |
| | | await this.getQuestionList(value.dataList) |
| | | } else { |
| | |
| | | loading: false, |
| | | }) |
| | | }, |
| | | // 批改题目 (练习,我的错题,我的收藏) |
| | | // 批改题目 (练习,我的错题,我的收藏,,组卷) |
| | | handleQuestion(num) { |
| | | const questionList = this.data.questionDataList |
| | | const index = num - 1 >= 0 ? num - 1 : 0 |
| | |
| | | }, |
| | | // 获取组卷题目列表 |
| | | async getMockDataList(questionList, oldList) { |
| | | console.log(questionList, oldList); |
| | | const questionDataList = this.data.questionDataList |
| | | questionList.forEach(async (pathitem, pathindex) => { |
| | | let itemIds = [] |
| | |
| | | }) |
| | | let questionList = [] |
| | | const cardUpdatedList = this.data.cardList |
| | | // if (flag == this.data.idPathList.length) { |
| | | cardUpdatedList.forEach(aitem => { |
| | | aitem.infoList.forEach((bitem, bindex) => { |
| | | questionList.push(bitem) |
| | |
| | | questionDataList: questionList, |
| | | cardList: cardUpdatedList |
| | | }) |
| | | console.log('组卷题目列表', this.data.questionDataList); |
| | | }) |
| | | }) |
| | | }) |