// packageBookService/pages/psychologyAnswer/psychologyAnswer.js import { loginInfo } from '../../../assets/js/login'; const app = getApp(); var pastData = require('./testdata/index') Page({ /** * 页面的初始数据 */ data: { isBuy: false, // 是否需要购买 questuionName: "", //试卷名称 dataList: "", barHeight: "", navBarHeight: "", loading: true, answerTitle: "", // 导航栏标题 submitStatus: false, // 提交状态 currentIndex: 0, // 当前显示的题号 total: 0, // 题目总数 totalScore: 0, //题目总分 scoreDataList: [], // 特殊分数 cardList: [], // 提交项, questionDataList: [], // 显示题目列表 questionDataTitle: "", //显示题目的提示信息 jumpQuestionList: [], //存储被删除的题目 noData: false, isNight: false, sliderValue: 0, // 字体滑块 showDialog: false, // 未提交退出拦截弹窗 showId: '', uuid: "", isShowDialog: false, // 测试报告弹窗是否显示 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { // 在此进行是否购买的查询 const questionId = options.listId; const bookId = options.bookId const bookName = options.bookName const formPath = options.formPath const query = { "cmsItemId": Number(questionId) }; app.MG.file.checkCmsItem(query) .then((res) => { const isBuys = res; this.setData({ isBuy: isBuys }); if (!isBuys) { wx.showModal({ icon: 'error', title: '温馨提示', content: '请购买题库,即将返回购买页', confirmText: '确定', showCancel: false, // 关闭取消按钮 success: function (res) { if (res.confirm) { wx.navigateTo({ url: '/packageBookService/pages/bookServices/detail/index?id=' + bookId + '&name=' + bookName + '&tabValue=' + formPath, }) } } }); return; // 直接返回,避免执行后续代码 } // 其他逻辑 const questuionName = options.listName; this.setData({ questionName: questuionName }); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 const token = wx.getStorageSync(app.config.tokenKey); if (!token) { loginInfo(app, (data) => { if (data) { this.init(); } else { this.init(); } }); } else { this.init(); } }) .catch((err) => { console.error('检查题库失败:', err); wx.showToast({ icon: 'error', title: '加载失败,请重试' }); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() { if (this.data.answerType != "mock") { if (wx.timer) { clearInterval(wx.timer); } } if (this.data.answerType == "mock") { if (wx.timer) { clearInterval(wx.timer); } wx.timer = setInterval(() => { this.setData({ saveTime: this.data.saveTime - 1, }); if (this.data.saveTime == 0) { this.saveMockData(); } }, 1000); } this.setData({ startTime: Date.now(), }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { if (wx.timer) { clearInterval(wx.timer); } this.setData({ pauseTime: Date.now(), }); if (wx.getStorageSync(app.config.tokenKey)) { let duration = this.data.pauseTime - this.data.startTime; this.count(duration); } }, /** * 生命周期函数--监听页面卸载 */ onUnload(e) { if (wx.timer) { clearInterval(wx.timer); } if (this.data.countdownInterval !== null) { clearInterval(this.data.countdownInterval); } this.setData({ pauseTime: Date.now(), }); if (wx.getStorageSync(app.config.tokenKey)) { let duration = this.data.pauseTime - this.data.startTime; this.count(duration); } }, count(timeStr) { const data = { appRefCode: app.config.appRefCode, type: "LearningTime", //统计类型--阅读时长 data: timeStr + "", //统计内容--时长毫秒 event: "LearningTime", sysType: "App", }; //阅读商品的id if (this.data.bookId) { data.productId = this.data.bookId; } //阅读资源的id // if (product.cmsItemId) { // data.cmsItemId = product.cmsItemId // } app.MG.job.newJobWithApiNewEvent(data).then((res) => {}); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {}, onShareTimeline() {}, // 监听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); // 调用回调函数,传递新值和旧值 }, }); }, // 修改nav颜色 changeNavBarColor(e) { if (type == 'night') { wx.setNavigationBarColor({ backgroundColor: '#000000', frontColor: '#ffffff', }) } else { wx.setNavigationBarColor({ backgroundColor: '#ffffff', frontColor: '#000000', }) } }, // 正则找出听力src extractSourceSrc(htmlString) { // 正则表达式匹配标签中的src属性值 var srcRegex = /