lesson.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var imageUrlPrefix;
  5. var currentContent;
  6. var backgroundAudioManager;
  7. Page({
  8. data: {
  9. LessonID: 1,
  10. ArrTirtle: [],
  11. },
  12. onLoad: function (options) {
  13. var that = this;
  14. var LessonID = 1;
  15. var LessonPage = 1;
  16. if (options && options.LessonID) {
  17. LessonID = options.LessonID;
  18. var arrName=['','第一课', '第二课', '第三课', '第四课'];
  19. wx.setNavigationBarTitle({
  20. title: arrName[LessonID],
  21. });
  22. }
  23. if (options && options.LessonPage) {
  24. LessonPage = options.LessonPage;
  25. }
  26. else
  27. LessonPage=1;
  28. that.setData({
  29. Containnerheight: main.getWindowHeight(),
  30. LessonID: LessonID,
  31. LessonPage: LessonPage,
  32. });
  33. backgroundAudioManager = wx.getBackgroundAudioManager();
  34. backgroundAudioManager.onEnded(that.bindEnded);
  35. imageUrlPrefix = app.globalData.uploadImageUrl + "lesson/lesson" + LessonID + "/";
  36. main.getData("GetMiaoguoLesson?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) {
  37. var id = that.data.LessonPage;
  38. if (id < 10)
  39. id = "0" + id;
  40. var imageUrl = "../images/program_screenshot_lesson_a01.png";
  41. if (that.data.LessonID=="5")
  42. imageUrl ="../images/program_screenshot_lesson_b01.png";
  43. that.setData({
  44. ArrTirtle: data.List,
  45. IsPause: true,
  46. ShareImageUrl:imageUrl,
  47. AudioSrc: imageUrlPrefix + "sounds/"+that.data.LessonPage+".m4a",
  48. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id+".jpg",
  49. });
  50. if (that.data.LessonPage>1){
  51. that.setData({
  52. IsPause: false,
  53. });
  54. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  55. backgroundAudioManager.src = that.data.AudioSrc;
  56. }
  57. });
  58. currentContent = [];
  59. app.globalData.LessonID = 0;
  60. app.globalData.LessonPage = 0;
  61. },
  62. onUnload: function () {
  63. this.InsertMiaoguoUserLesson();
  64. },
  65. onHide: function () {
  66. this.InsertMiaoguoUserLesson();
  67. },
  68. InsertMiaoguoUserLesson: function () {
  69. if (currentContent.length > 0) {
  70. var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID;
  71. url += "&LessonID=" + this.data.LessonID;
  72. url += "&Content=" + currentContent.join(",");
  73. main.getData(url, function (data) {
  74. if (currentContent.length>0){
  75. var lastNum = currentContent[currentContent.length-1];
  76. currentContent=[];
  77. currentContent.push(lastNum);
  78. }
  79. });
  80. }
  81. },
  82. playAudio: function (e) {
  83. var that = this;
  84. var id = Number(e.currentTarget.dataset.id) + 1;
  85. currentContent.push(id);
  86. if (id < 10)
  87. id = "0" + id;
  88. this.setData({
  89. IsPause: false,
  90. LessonPage: Number(id),
  91. AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a",
  92. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  93. });
  94. backgroundAudioManager.title = this.data.ArrTirtle[Number(e.currentTarget.dataset.id)].Title;
  95. backgroundAudioManager.src = this.data.AudioSrc;
  96. },
  97. bindEnded: function () {
  98. var id = this.data.LessonPage;
  99. this.InsertMiaoguoUserLesson();
  100. if (id < this.data.ArrTirtle.length){
  101. this.playAudio({ currentTarget: { dataset: { id: id } } });
  102. }
  103. else{
  104. this.setData({
  105. IsPause: true,
  106. });
  107. }
  108. },
  109. audioPlay: function () {
  110. var that=this;
  111. if (this.data.IsPause){
  112. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  113. backgroundAudioManager.src = that.data.AudioSrc;
  114. this.setData({
  115. IsPause: false,
  116. });
  117. }
  118. else{
  119. backgroundAudioManager.pause();
  120. this.setData({
  121. IsPause: true,
  122. });
  123. }
  124. },
  125. previewImage:function(e){
  126. var url=e.currentTarget.dataset.url;
  127. wx.previewImage({
  128. current: url,
  129. urls: [url]
  130. });
  131. },
  132. onShareAppMessage: function () {
  133. var title ="《秒过学习法》课程";
  134. var imageUrl = this.data.ShareImageUrl;
  135. if (this.data.LessonID==5){
  136. title="《秒过学习法》结业致辞"
  137. }
  138. else if (this.data.LessonPage>0){
  139. title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
  140. }
  141. return {
  142. title: title,
  143. path: app.globalData.SharePath + '?type=lesson&LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  144. imageUrl: imageUrl,
  145. }
  146. },
  147. });