// pages/homework_report/homework_report.js const app=getApp(); Page({ /** * 页面的初始数据 */ data: { baseImgUrl: app.globalData.baseImgUrl, thumbnail: app.globalData.thumbnail, yuwen: '../../image/yuwen4.0.png', math: '../../image/shuxue4.0.png', English: '../../image/yingyu4.0.png', physics: '../../image/wuli.png', chemistry: '../../image/huaxue.png', labelRed: '../../image/biao_qian_hong.png', labelGay: '../../image/biao_qian_hui.png', idx:0, isMohu:false, voiceKeyIndex:-1, imgNum:3, isPlay:0, times:0, isMusic:0, isEnd:0, learningState: [{ "name": "积极性", "type": 1 }, { "name": "自律性", "type": 2 }, { "name": "专注度", "type": 3 }, { "name": "作业速度", "type": 2 } ], subjectList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ options }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getHomeworkReport() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { let pages = getCurrentPages(); const {isMusic,voiceKeyList, voiceKeyIndex}=this.data console.log( '生命周期函数--监听页面隐藏'+isMusic) if(isMusic){ this.stopPlay() this.innerAudioContext.stop(); clearInterval(this.setIntervalAudio) this.pauseAudio(voiceKeyList, voiceKeyIndex) } }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { const {isMusic,voiceKeyList, voiceKeyIndex}=this.data console.log( '生命周期函数--监听页面卸载'+isMusic) if(isMusic){ this.stopPlay() this.innerAudioContext.stop(); clearInterval(this.setIntervalAudio) this.pauseAudio(voiceKeyList, voiceKeyIndex) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * 用户点击右上角分享 */ onShareAppMessage: function () { const { vipId, date } = this.data.options return { title: `作业反馈报告`, path: `pages/homework_report/homework_report?type=8&vipId=${vipId}&date=${date}`, success: res => { wx.showToast({ title: '转发成功', icon: 'success' }) }, fail: res => { wx.showToast({ title: '转发失败', icon: 'none' }) } } }, //查看图片 viewImageCtl: app.viewImageCtl, /** * 查看评语 */ getWords:function(e){ const {method} = e.currentTarget.dataset; wx.navigateTo({ url: `../remark/remark?method=${JSON.stringify(method)}`, success: res => { }, fail: res => { wx.showToast({ title: '跳转失败', icon: 'none' }) } }) }, // 获取作业报告 getHomeworkReport:function(){ const postData = { fn: this.getHomeworkReport, param: { ...arguments } } const { idx, options } = this.data const { vipId, date }=options; wx.showLoading({ title: '加载中', }) const fn = res => { const { abstractSituation = {}, correctList = [], learningState = [], isMainParent} = res.data; wx.hideLoading(); const {voiceKeyList}=abstractSituation const voiceListTemp = (res => { for (let i in res) { res[i].voiceType = 0 res[i].durationNum = 0; res[i].progress = 0; res[i].isHands = false; } return res })(voiceKeyList) const correctListTemp = (res => { for (let i in res) { const { homeworkList, homeworkCommentList } = res[i]; const arr = { homeworkList, homeworkCommentList } const homeworkListTemp = [], wrongItemListTemp = [] for (let j in homeworkList) { homeworkListTemp.push({ photoKey: homeworkList[j].homeworkPictureUrl, isVague: homeworkList[j].isVague, status: homeworkList[j].status }) } for (let j in homeworkCommentList) { wrongItemListTemp.push({ photoKey: homeworkCommentList[j].homeworkCommentUrl, compositionCommentModuleList: homeworkCommentList[j].compositionCommentModuleList, isComposition: homeworkCommentList[j].isComposition, }) } res[i]['homeworkList'] = homeworkListTemp res[i]['homeworkCommentList'] = wrongItemListTemp } return res })(correctList) this.setData({ abstractSituation, correctList, learningState, isMainParent,voiceKeyList:voiceListTemp}); // console.log(abstractSituation) this.clickSubject(idx); } app.post('/api/parents/parents/V2/homeworkReport4', { vipId, date}, 0, postData ).then(fn) }, cutItems:function(e){ const { idx } = e.target.dataset; this.setData({ idx }) this.clickSubject(idx) }, // 切换科目 clickSubject:function(idx){ const { correctList}=this.data; var temp={}; var workImg, mistakeImg = []; for (var i in correctList){ if (correctList[idx].subject == correctList[i].subject){ for (let j in correctList[i].homeworkList){ if (correctList[i].homeworkList[j].isVague == 0) { this.setData({ isMohu: true }) }else{ this.setData({ isMohu: false }) } } this.setData({ list: correctList[i] }) } } }, /** * 开始计时 */ startSetInter: function () { let time = 1000; var that = this; let { times,isEnd} = this.data; // console.log(times) var setTime = this.data.times + 1 console.log(setTime) that.setData({ times: setTime,imgNum:setTime }) that.data.setInter = setTimeout(this.startSetInter, time); if (setTime>2) { that.endSetInter(); if(setTime==3&&!isEnd){ setTimeout( function () { that.startSetInter() }, 1000) } } }, /** * 结束计时 */ endSetInter:function(){ var that = this; clearTimeout(that.data.setInter) that.setData({ times: 0}) }, /** * 结束计时 */ stopPlay:function(){ var that = this; that.endSetInter(); that.setData({ imgNum:3}) console.log('结束') }, /** * 音频控制按钮 */ audioCtl: function (e) { const { index } = e.currentTarget.dataset const { voiceKeyList, voiceKeyIndex} = this.data const { voiceType } = voiceKeyList[index]; this.setData({isMusic:1}) var that=this // console.log(index,voiceKeyIndex,voiceType) if (index == voiceKeyIndex) { if (voiceType == 1) { console.log('1---停止') that.stopPlay() if (this.innerAudioContext) this.innerAudioContext.stop() } else if (voiceType == 2) { console.log('1---播放') if (this.innerAudioContext) this.innerAudioContext.play() } else { this.audioManager() } } else { const temp = {} temp['voiceKeyIndex'] = index this.setData(temp) this.audioManager() } }, /** * 开始播放语音 */ playAudio: function (voiceKeyList, voiceKeyIndex) { const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex]; console.log('开始播放语音') this.startSetInter() const temp = {} temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 1; temp[`voiceKeyList[${voiceKeyIndex}].isHands`] = true; this.setData(temp) let d = voiceType == 2 ? durationNum - 1 : duration if (this.setIntervalAudio) { clearInterval(this.setIntervalAudio) } // console.log(d) this.setIntervalAudio = setInterval(() => { if (d > 0) { d-- temp[`voiceKeyList[${voiceKeyIndex}].durationNum`] = d temp[`voiceKeyList[${voiceKeyIndex}].progress`] = Math.floor((duration - d) / duration * 100) this.setData(temp) } else { clearInterval(this.setIntervalAudio) } }, 1000) }, /** * 暂停播放语音 */ pauseAudio: function (voiceKeyList, voiceKeyIndex) { console.log('2---停止') const {isEnd}=this.data this.setData({isEnd:!isEnd}) const temp = {} temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 2 this.setData(temp) }, /** * 结束播放语音 */ endAudio: function (voiceKeyList, voiceKeyIndex, listIndex) { console.log('3---停止') const {isEnd}=this.data this.setData({isEnd:!isEnd}) const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex] this.stopPlay() const temp = {} temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 0 temp[`voiceKeyList[${voiceKeyIndex}].duration`] = duration temp[`voiceKeyList[${voiceKeyIndex}].progress`] = 0 temp[`voiceKeyList[${voiceKeyIndex}].isHands`] = false; this.setData(temp) }, /** * 语音播放管理器 */ audioManager: function () { const { voiceKeyList, voiceKeyIndex, baseImgUrl } = this.data if (this.innerAudioContext) { this.innerAudioContext.destroy() clearInterval(this.setIntervalAudio) for (const i in voiceKeyList) { const temp = {}; temp[`voiceKeyList[${i}].voiceType`] = 0; this.setData(temp) } } const { voiceKey } = voiceKeyList[voiceKeyIndex] if (!voiceKey) return this.innerAudioContext = wx.createInnerAudioContext() this.innerAudioContext.autoplay = true this.innerAudioContext.src = baseImgUrl+voiceKey console.log(baseImgUrl + voiceKey) this.innerAudioContext.onPlay(() => { this.playAudio(voiceKeyList, voiceKeyIndex) }) this.innerAudioContext.onStop(() => { clearInterval(this.setIntervalAudio) this.pauseAudio(voiceKeyList, voiceKeyIndex) }) this.innerAudioContext.onEnded(() => { this.innerAudioContext.destroy() clearInterval(this.setIntervalAudio) this.endAudio(voiceKeyList, voiceKeyIndex) }) this.innerAudioContext.onError(res => { console.log(res) wx.showToast({ title: '播放语音失败', icon: 'none' }) }) }, /** * 结束语音 */ nextAudio: function () { const { voiceKeyList, voiceKeyIndex} = this.data; this.stopPlay() if (voiceKeyIndex != -1 && listIndex != -1) { const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex] const temp = {} temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 0 temp[`voiceKeyList[${voiceKeyIndex}].duration`] = duration temp[`voiceKeyList[${voiceKeyIndex}].progress`] = 0 if (this.innerAudioContext) this.innerAudioContext.pause() this.setData(temp) } }, })