import { getPublicImage } from "../../../../assets/js/middleGround/tool"; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { barHeight: "", navBarHeight: "", loading: false, answerTitle: "", // 导航栏标题 countdownInterval: null, // 计时器 isCountdownRunning: true, // 是否倒计时 countdownTime: 0, // 倒计时时间 storeInfo: '', jslx: '', bookId: "", productLinkPath: "", rootCmsItemId: "", idPathList: [], // 题目列表 answerType: "", // 答题模式 submitStatus: false, // 提交状态 currentIndex: 0, // 当前显示的题号 collectList: [], // 收藏题目列表 errorList: [], // 错题列表 subjectiveTotal: 0, // 客观题总数 subjectiveNum: 0, // 客观题得分 subjectiveGrade: 0, // 客观题总分 correctNum: 0, // 正确题目数量 total: 0, // 题目总数 cardList: [], // 提交项, questionDataList: [], // 显示题目列表 noData: false, mockid: 0, uuid: 0, mockData: { // 组卷信息 state: "0", score: 0, // 总分 sumTime: 0, time: 0, // 答题剩余时间 datas: [], // 所有模考记录数据(题目列表,用户答题,考试报告) answer: [], }, saveTime: 20, isNight: false, sliderValue: 0, // 字体滑块 startTime: "", //进入页面当前时间 pauseTime: 0, //暂停时间 showDialog: false, // 未提交退出拦截弹窗 showId: '' }, /** * 生命周期函数--监听页面加载 */ 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 ? options.productLinkPath : "", rootCmsItemId: options.rootCmsItemId, idPathList: options.idPathList ? JSON.parse(options.idPathList) : [], answerType: options.answerType, storeInfo: options.storeInfo, jslx: options.jslx, }); wx.setNavigationBarTitle({ title: options.answerTitle, }) if (this.data.answerType == "mock") { this.setData({ uuid: options.uuid, mockid: options.mockid, }); } this.init(); }, /** * 生命周期函数--监听页面初次渲染完成 */ 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() {}, // 监听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 = /