import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); var imageUrlPrefix; var currentContent; Page({ data: { LessonID: 1, ArrTirtle: [], }, onReady: function (e) { this.audioCtx = wx.createAudioContext('myAudio') }, 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; } that.setData({ Containnerheight: main.getWindowHeight(), LessonID: LessonID, LessonPage: LessonPage, }); 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", }); }); 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) { currentContent = []; }); } }, playAudio: function (e) { var that = this; var id = Number(e.currentTarget.dataset.id) + 1; 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", }); setTimeout(function () { that.audioCtx.play(); }, 1000); }, bindEnded: function () { var id = this.data.LessonPage; currentContent.push(id); if (id < this.data.ArrTirtle.length) this.playAudio({ currentTarget: { dataset: { id: id } } }); }, audioPlay: function () { if (this.data.IsPause){ this.audioCtx.play(); this.setData({ IsPause: false, }); } else{ this.audioCtx.pause(); this.setData({ IsPause: true, }); } }, previewImage:function(e){ var url=e.currentTarget.dataset.url; wx.previewImage({ current: url, urls: [url] }); }, onShareAppMessage: function () { return { title: "秒过学习法", path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID, imageUrl: '../images/program_screenshot_l' + this.data.LessonID+'.png', } }, });