lesson.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. }
  19. if (options && options.LessonPage) {
  20. LessonPage = options.LessonPage;
  21. }
  22. else
  23. LessonPage=1;
  24. that.setData({
  25. Containnerheight: main.getWindowHeight(),
  26. LessonID: LessonID,
  27. LessonPage: LessonPage,
  28. });
  29. backgroundAudioManager = wx.getBackgroundAudioManager();
  30. backgroundAudioManager.onEnded(that.bindEnded);
  31. imageUrlPrefix = app.globalData.uploadImageUrl + "lesson/lesson" + LessonID + "/";
  32. main.getData("GetMiaoguoLesson?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) {
  33. var id = that.data.LessonPage;
  34. if (id < 10)
  35. id = "0" + id;
  36. that.setData({
  37. ArrTirtle: data.List,
  38. IsPause: true,
  39. AudioSrc: imageUrlPrefix + "sounds/"+that.data.LessonPage+".m4a",
  40. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id+".jpg",
  41. });
  42. if (that.data.LessonPage>1){
  43. that.setData({
  44. IsPause: false,
  45. });
  46. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  47. backgroundAudioManager.src = that.data.AudioSrc;
  48. }
  49. });
  50. currentContent = [];
  51. app.globalData.LessonID = 0;
  52. app.globalData.LessonPage = 0;
  53. },
  54. onUnload: function () {
  55. this.InsertMiaoguoUserLesson();
  56. },
  57. onHide: function () {
  58. this.InsertMiaoguoUserLesson();
  59. },
  60. InsertMiaoguoUserLesson: function () {
  61. if (currentContent.length > 0) {
  62. var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID;
  63. url += "&LessonID=" + this.data.LessonID;
  64. url += "&Content=" + currentContent.join(",");
  65. main.getData(url, function (data) {
  66. if (currentContent.length>0){
  67. var lastNum = currentContent[currentContent.length-1];
  68. currentContent=[];
  69. currentContent.push(lastNum);
  70. }
  71. });
  72. }
  73. },
  74. playAudio: function (e) {
  75. var that = this;
  76. var id = Number(e.currentTarget.dataset.id) + 1;
  77. currentContent.push(id);
  78. if (id < 10)
  79. id = "0" + id;
  80. this.setData({
  81. IsPause: false,
  82. LessonPage: Number(id),
  83. AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a",
  84. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  85. });
  86. backgroundAudioManager.title = this.data.ArrTirtle[Number(e.currentTarget.dataset.id)].Title;
  87. backgroundAudioManager.src = this.data.AudioSrc;
  88. },
  89. bindEnded: function () {
  90. var id = this.data.LessonPage;
  91. this.InsertMiaoguoUserLesson();
  92. if (id < this.data.ArrTirtle.length){
  93. this.playAudio({ currentTarget: { dataset: { id: id } } });
  94. }
  95. else{
  96. this.setData({
  97. IsPause: true,
  98. });
  99. }
  100. },
  101. audioPlay: function () {
  102. var that=this;
  103. if (this.data.IsPause){
  104. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  105. backgroundAudioManager.src = that.data.AudioSrc;
  106. this.setData({
  107. IsPause: false,
  108. });
  109. }
  110. else{
  111. backgroundAudioManager.pause();
  112. this.setData({
  113. IsPause: true,
  114. });
  115. }
  116. },
  117. previewImage:function(e){
  118. var url=e.currentTarget.dataset.url;
  119. wx.previewImage({
  120. current: url,
  121. urls: [url]
  122. });
  123. },
  124. onShareAppMessage: function () {
  125. var title ="秒过学习法";
  126. var imageUrl = '../images/program_screenshot_l' + this.data.LessonID + '.png';
  127. if (this.data.LessonPage>0){
  128. title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
  129. }
  130. return {
  131. title: title,
  132. path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  133. imageUrl: imageUrl,
  134. }
  135. },
  136. });