| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- 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;
- var arrName=['','第一课', '第二课', '第三课', '第四课'];
- wx.setNavigationBarTitle({
- title: arrName[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 + "/";
-
- that.getData(LessonID,function(data){
- if (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;
- },
- getData:function(LessonID,callback){
- var list = wx.getStorageSync("LessonList");
- if (list){
- callback(list[LessonID-1]);
- }
- else{
- main.getData("GetMiaoguoLesson2?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) {
- if (data)
- callback(data[LessonID-1]);
- else
- callback();
- });
- }
- },
- 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 = "";
- if (this.data.LessonID == 5) {
- title = "《秒过学习法》结业致辞";
- imageUrl = this.data.ArrTirtle[0].ImageUrl;
- }
- else if (this.data.LessonPage>0){
- title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
- imageUrl = this.data.ArrTirtle[this.data.LessonPage - 1].ImageUrl;
- if (this.data.LessonID==1)
- imageUrl = this.data.ArrTirtle[0].ImageUrl;
- }
- imageUrl=app.globalData.uploadImageUrl+"web/"+imageUrl;
- return {
- title: title,
- path: app.globalData.SharePath + '?type=lesson&LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
- imageUrl: imageUrl,
- }
- },
- });
|