import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); var imageUrlPrefix; var currentContent; var backgroundAudioManager; Page({ data: { LessonID: 1, ArrTirtle: [], }, onLoad: function (options) { var that = this; var LessonID = 1; var LessonPage = 1; if (options && options.LessonID) { LessonID = options.LessonID; } if (options && options.LessonPage) { LessonPage = options.LessonPage; } else LessonPage=1; that.setData({ Containnerheight: main.getWindowHeight(), LessonID: LessonID, LessonPage: LessonPage, }); backgroundAudioManager = wx.getBackgroundAudioManager(); backgroundAudioManager.onEnded(that.bindEnded); imageUrlPrefix = app.globalData.uploadImageUrl + "lesson/lesson" + LessonID + "/"; main.getData("GetMiaoguoLesson?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) { var id = that.data.LessonPage; if (id < 10) id = "0" + id; that.setData({ ArrTirtle: data.List, IsPause: true, AudioSrc: imageUrlPrefix + "sounds/"+that.data.LessonPage+".m4a", ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id+".jpg", }); if (that.data.LessonPage>1){ that.setData({ IsPause: false, }); backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title; backgroundAudioManager.src = that.data.AudioSrc; } }); currentContent = []; app.globalData.LessonID = 0; app.globalData.LessonPage = 0; }, onUnload: function () { this.InsertMiaoguoUserLesson(); }, onHide: function () { this.InsertMiaoguoUserLesson(); }, InsertMiaoguoUserLesson: function () { if (currentContent.length > 0) { var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID; url += "&LessonID=" + this.data.LessonID; url += "&Content=" + currentContent.join(","); main.getData(url, function (data) { if (currentContent.length>0){ var lastNum = currentContent[currentContent.length-1]; currentContent=[]; currentContent.push(lastNum); } }); } }, playAudio: function (e) { var that = this; var id = Number(e.currentTarget.dataset.id) + 1; currentContent.push(id); if (id < 10) id = "0" + id; this.setData({ IsPause: false, LessonPage: Number(id), AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a", ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg", }); backgroundAudioManager.title = this.data.ArrTirtle[Number(e.currentTarget.dataset.id)].Title; backgroundAudioManager.src = this.data.AudioSrc; }, bindEnded: function () { var id = this.data.LessonPage; this.InsertMiaoguoUserLesson(); if (id < this.data.ArrTirtle.length){ this.playAudio({ currentTarget: { dataset: { id: id } } }); } else{ this.setData({ IsPause: true, }); } }, audioPlay: function () { var that=this; if (this.data.IsPause){ backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title; backgroundAudioManager.src = that.data.AudioSrc; this.setData({ IsPause: false, }); } else{ backgroundAudioManager.pause(); this.setData({ IsPause: true, }); } }, previewImage:function(e){ var url=e.currentTarget.dataset.url; wx.previewImage({ current: url, urls: [url] }); }, onShareAppMessage: function () { var title ="秒过学习法"; var imageUrl = '../images/program_screenshot_l' + this.data.LessonID + '.png'; if (this.data.LessonPage>0){ title = this.data.ArrTirtle[this.data.LessonPage - 1].Title; } return { title: title, path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID, imageUrl: imageUrl, } }, });