lesson.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. that.getData(LessonID,function(data){
  37. if (data){
  38. var id = that.data.LessonPage;
  39. if (id < 10)
  40. id = "0" + id;
  41. that.setData({
  42. ArrTirtle: data.List,
  43. IsPause: true,
  44. AudioSrc: imageUrlPrefix + "sounds/" + that.data.LessonPage + ".m4a",
  45. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  46. });
  47. if (that.data.LessonPage > 1) {
  48. that.setData({
  49. IsPause: false,
  50. });
  51. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  52. backgroundAudioManager.src = that.data.AudioSrc;
  53. }
  54. }
  55. });
  56. currentContent = [];
  57. app.globalData.LessonID = 0;
  58. app.globalData.LessonPage = 0;
  59. },
  60. getData:function(LessonID,callback){
  61. var list = wx.getStorageSync("LessonList");
  62. if (list){
  63. callback(list[LessonID-1]);
  64. }
  65. else{
  66. main.getData("GetMiaoguoLesson2?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) {
  67. if (data)
  68. callback(data[LessonID-1]);
  69. else
  70. callback();
  71. });
  72. }
  73. },
  74. onUnload: function () {
  75. this.InsertMiaoguoUserLesson();
  76. },
  77. onHide: function () {
  78. this.InsertMiaoguoUserLesson();
  79. },
  80. InsertMiaoguoUserLesson: function () {
  81. if (currentContent.length > 0) {
  82. var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID;
  83. url += "&LessonID=" + this.data.LessonID;
  84. url += "&Content=" + currentContent.join(",");
  85. main.getData(url, function (data) {
  86. if (currentContent.length>0){
  87. var lastNum = currentContent[currentContent.length-1];
  88. currentContent=[];
  89. currentContent.push(lastNum);
  90. }
  91. });
  92. }
  93. },
  94. playAudio: function (e) {
  95. var that = this;
  96. var id = Number(e.currentTarget.dataset.id) + 1;
  97. currentContent.push(id);
  98. if (id < 10)
  99. id = "0" + id;
  100. this.setData({
  101. IsPause: false,
  102. LessonPage: Number(id),
  103. AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a",
  104. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  105. });
  106. backgroundAudioManager.title = this.data.ArrTirtle[Number(e.currentTarget.dataset.id)].Title;
  107. backgroundAudioManager.src = this.data.AudioSrc;
  108. },
  109. bindEnded: function () {
  110. var id = this.data.LessonPage;
  111. this.InsertMiaoguoUserLesson();
  112. if (id < this.data.ArrTirtle.length){
  113. this.playAudio({ currentTarget: { dataset: { id: id } } });
  114. }
  115. else{
  116. this.setData({
  117. IsPause: true,
  118. });
  119. }
  120. },
  121. audioPlay: function () {
  122. var that=this;
  123. if (this.data.IsPause){
  124. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  125. backgroundAudioManager.src = that.data.AudioSrc;
  126. this.setData({
  127. IsPause: false,
  128. });
  129. }
  130. else{
  131. backgroundAudioManager.pause();
  132. this.setData({
  133. IsPause: true,
  134. });
  135. }
  136. },
  137. previewImage:function(e){
  138. var url=e.currentTarget.dataset.url;
  139. wx.previewImage({
  140. current: url,
  141. urls: [url]
  142. });
  143. },
  144. onShareAppMessage: function () {
  145. var title ="课程";
  146. var imageUrl = "";
  147. if (this.data.LessonID == 5) {
  148. title = "结业致辞";
  149. imageUrl = this.data.ArrTirtle[0].ImageUrl;
  150. }
  151. else if (this.data.LessonPage>0){
  152. title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
  153. imageUrl = this.data.ArrTirtle[this.data.LessonPage - 1].ImageUrl;
  154. if (this.data.LessonID==1)
  155. imageUrl = this.data.ArrTirtle[0].ImageUrl;
  156. }
  157. imageUrl=app.globalData.uploadImageUrl+"web/"+imageUrl;
  158. return {
  159. title: title,
  160. path: app.globalData.SharePath + '?type=lesson&LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  161. imageUrl: imageUrl,
  162. }
  163. },
  164. });