| | |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | 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) { |
| | |
| | | }, |
| | | // 提交逻辑 |
| | | 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 { |