lesson.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. currentContent = [];
  67. });
  68. }
  69. },
  70. playAudio: function (e) {
  71. var that = this;
  72. var id = Number(e.currentTarget.dataset.id) + 1;
  73. currentContent.push(id);
  74. if (id < 10)
  75. id = "0" + id;
  76. this.setData({
  77. IsPause: false,
  78. LessonPage: Number(id),
  79. AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a",
  80. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  81. });
  82. backgroundAudioManager.title = this.data.ArrTirtle[Number(e.currentTarget.dataset.id)].Title;
  83. backgroundAudioManager.src = this.data.AudioSrc;
  84. },
  85. bindEnded: function () {
  86. var id = this.data.LessonPage;
  87. if (id < this.data.ArrTirtle.length)
  88. this.playAudio({ currentTarget: { dataset: { id: id } } });
  89. if(currentContent.length>3)
  90. this.InsertMiaoguoUserLesson();
  91. else{
  92. this.setData({
  93. IsPause: true,
  94. });
  95. this.InsertMiaoguoUserLesson();
  96. }
  97. },
  98. audioPlay: function () {
  99. var that=this;
  100. if (this.data.IsPause){
  101. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  102. backgroundAudioManager.src = that.data.AudioSrc;
  103. this.setData({
  104. IsPause: false,
  105. });
  106. }
  107. else{
  108. backgroundAudioManager.pause();
  109. this.setData({
  110. IsPause: true,
  111. });
  112. }
  113. },
  114. previewImage:function(e){
  115. var url=e.currentTarget.dataset.url;
  116. wx.previewImage({
  117. current: url,
  118. urls: [url]
  119. });
  120. },
  121. onShareAppMessage: function () {
  122. var title ="秒过学习法";
  123. var imageUrl = '../images/program_screenshot_l' + this.data.LessonID + '.png';
  124. if (this.data.LessonPage>0){
  125. title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
  126. imageUrl=this.data.ImageUrl;
  127. }
  128. return {
  129. title: title,
  130. path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  131. imageUrl: imageUrl,
  132. }
  133. },
  134. });