lesson.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var imageUrlPrefix;
  5. var currentContent;
  6. Page({
  7. data: {
  8. LessonID: 1,
  9. ArrTirtle: [],
  10. },
  11. onReady: function (e) {
  12. this.audioCtx = wx.createAudioContext('myAudio')
  13. },
  14. onLoad: function (options) {
  15. var that = this;
  16. var LessonID = 1;
  17. var LessonPage = 1;
  18. if (options && options.LessonID) {
  19. LessonID = options.LessonID;
  20. }
  21. if (options && options.LessonPage) {
  22. LessonPage = options.LessonPage;
  23. }
  24. that.setData({
  25. Containnerheight: main.getWindowHeight(),
  26. LessonID: LessonID,
  27. LessonPage: LessonPage,
  28. });
  29. imageUrlPrefix = app.globalData.uploadImageUrl + "lesson/lesson" + LessonID + "/";
  30. main.getData("GetMiaoguoLesson?Lesson=" + LessonID + "&time=" + new Date().getTime(), function (data) {
  31. var id = that.data.LessonPage;
  32. if (id < 10)
  33. id = "0" + id;
  34. that.setData({
  35. ArrTirtle: data.List,
  36. IsPause: true,
  37. AudioSrc: imageUrlPrefix + "sounds/"+that.data.LessonPage+".m4a",
  38. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id+".jpg",
  39. });
  40. });
  41. currentContent = [];
  42. app.globalData.LessonID = 0;
  43. app.globalData.LessonPage = 0;
  44. },
  45. onUnload: function () {
  46. this.InsertMiaoguoUserLesson();
  47. },
  48. onHide: function () {
  49. this.InsertMiaoguoUserLesson();
  50. },
  51. InsertMiaoguoUserLesson: function () {
  52. if (currentContent.length > 0) {
  53. var url = "InsertMiaoguoUserLesson?UserID=" + app.globalData.userInfo.UserID;
  54. url += "&LessonID=" + this.data.LessonID;
  55. url += "&Content=" + currentContent.join(",");
  56. main.getData(url, function (data) {
  57. currentContent = [];
  58. });
  59. }
  60. },
  61. playAudio: function (e) {
  62. var that = this;
  63. var id = Number(e.currentTarget.dataset.id) + 1;
  64. if (id < 10)
  65. id = "0" + id;
  66. this.setData({
  67. IsPause: false,
  68. LessonPage: Number(id),
  69. AudioSrc: imageUrlPrefix + "sounds/" + Number(id) + ".m4a",
  70. ImageUrl: imageUrlPrefix + "%E5%B9%BB%E7%81%AF%E7%89%87" + id + ".jpg",
  71. });
  72. setTimeout(function () {
  73. that.audioCtx.play();
  74. }, 1000);
  75. },
  76. bindEnded: function () {
  77. var id = this.data.LessonPage;
  78. currentContent.push(id);
  79. if (id < this.data.ArrTirtle.length)
  80. this.playAudio({ currentTarget: { dataset: { id: id } } });
  81. },
  82. audioPlay: function () {
  83. if (this.data.IsPause){
  84. this.audioCtx.play();
  85. this.setData({
  86. IsPause: false,
  87. });
  88. }
  89. else{
  90. this.audioCtx.pause();
  91. this.setData({
  92. IsPause: true,
  93. });
  94. }
  95. },
  96. previewImage:function(e){
  97. var url=e.currentTarget.dataset.url;
  98. wx.previewImage({
  99. current: url,
  100. urls: [url]
  101. });
  102. },
  103. onShareAppMessage: function () {
  104. return {
  105. title: "秒过学习法",
  106. path: app.globalData.SharePath + '?LessonID=' + this.data.LessonID + '&LessonPage=' + this.data.LessonPage+'&UserID=' + app.globalData.userInfo.UserID,
  107. imageUrl: '../images/program_screenshot_l' + this.data.LessonID+'.png',
  108. }
  109. },
  110. });