lesson.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. else{
  90. this.setData({
  91. IsPause: true,
  92. });
  93. }
  94. },
  95. audioPlay: function () {
  96. var that=this;
  97. if (this.data.IsPause){
  98. backgroundAudioManager.title = that.data.ArrTirtle[that.data.LessonPage - 1].Title;
  99. backgroundAudioManager.src = that.data.AudioSrc;
  100. this.setData({
  101. IsPause: false,
  102. });
  103. }
  104. else{
  105. backgroundAudioManager.pause();
  106. this.setData({
  107. IsPause: true,
  108. });
  109. }
  110. },
  111. previewImage:function(e){
  112. var url=e.currentTarget.dataset.url;
  113. wx.previewImage({
  114. current: url,
  115. urls: [url]
  116. });
  117. },
  118. onShareAppMessage: function () {
  119. var title ="秒过学习法";
  120. if (this.data.LessonPage>0){
  121. title = this.data.ArrTirtle[this.data.LessonPage - 1].Title;
  122. }
  123. return {
  124. title: title,
  125. path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  126. imageUrl: '../images/program_screenshot_l' + this.data.LessonID+'.png',
  127. }
  128. },
  129. });