lesson.js 4.0 KB

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