class.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. const app = getApp()
  6. Page({
  7. data: {
  8. fullScreenBtn: false,
  9. playBtn: true,
  10. gesture: true,
  11. centerBtn: true,
  12. controls: true,
  13. videoLoad: false,
  14. autoPlay: true,
  15. videoUrl: '',
  16. poster: '',
  17. works: [],
  18. total: '',
  19. title: '',
  20. id: '',
  21. iconImg: '',
  22. pageNo: 1,
  23. totalNo: 0,
  24. collectFlag: false,
  25. goBackHome: false,
  26. lazyVideoUrl: '',
  27. isIOS: app.globalData.isIOS,
  28. modalType: "text",
  29. modalText: [{
  30. text: '您还不是本课程的会员',
  31. type: 'bigOrange'
  32. },
  33. {
  34. text: '您可以开团,拼团成功获得使用权',
  35. type: 'normal'
  36. }
  37. ],
  38. modalBtnText: '去开团',
  39. isModalShow: false,
  40. productId: 0,
  41. videoPlayTime: 0
  42. },
  43. onLoad: function (option) {
  44. console.log(option);
  45. if (option.scene || option.shareCard) {
  46. this.setData({
  47. goBackHome: true
  48. })
  49. }
  50. this.setData({
  51. // title: option.title,
  52. id: option.id
  53. })
  54. this.uid = wx.getStorageSync('uid');;
  55. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  56. console.log(res);
  57. const classId = this.data.id;
  58. httpRequestApi.userIntoPage('pages/main/class/class', '官方课程页面').success((res) => {
  59. })
  60. this.setData({
  61. title: res.data.data.lesson.title,
  62. videoUrl: res.data.data.lesson.playUrl,
  63. iconImg: res.data.data.lesson.iconImg,
  64. productId: res.data.data.product.id
  65. })
  66. wx.setNavigationBarTitle({
  67. title: res.data.data.lesson.title //页面标题为路由参数
  68. })
  69. this.getReadInfo(1, 10);
  70. this.checkLike();
  71. // this.innerAudioContext = wx.createInnerAudioContext();
  72. // this.innerAudioContext.onPause((res) => {
  73. // // 播放音频失败的回调
  74. // console.log('音频暂停')
  75. // });
  76. // this.innerAudioContext.onPlay(res => {
  77. // console.log('class页面视频播放了')
  78. // })
  79. })
  80. },
  81. // video组件在获得url时迅速退出页面会导致小程序闪退,官方还没修复(11/28),处理办法:懒加载思路,在用户点击时再获取videoUrl
  82. // setVideoUrl: function(){
  83. // console.log('视频地址>>>>>>>>',this.data.lazyVideoUrl)
  84. // this.setData({
  85. // videoUrl: this.data.lazyVideoUrl,
  86. // })
  87. // },
  88. videoPlayHandler: function () {
  89. this.setData({
  90. videoLoad: true
  91. }, () => {
  92. this.videoClassCtx = wx.createVideoContext('classVideo', this);
  93. this.videoClassCtx.play();
  94. })
  95. },
  96. // 检查是否收藏
  97. checkLike: function () {
  98. httpRequestApi.classIsLike(this.uid, {
  99. targetCode: this.data.id
  100. }).success(res => {
  101. this.setData({
  102. collectFlag: res.data.data
  103. })
  104. })
  105. },
  106. goToReading: function () {
  107. let classId = this.data.id;
  108. // httpRequestApi.checkLesson(classId).success(res => {
  109. // const productId = res.data.data[0];
  110. // this.setData({
  111. // productId
  112. // })
  113. // });
  114. httpRequestApi.areYouSuper(this.data.productId).success(res => {
  115. if (res.data.success) {
  116. wx.navigateTo({
  117. url: `../../main/reading/reading?id=${this.data.id}`
  118. })
  119. } else {
  120. // ios用户 并且没有购买过此书
  121. // if (app.globalData.isIOS) {
  122. // wx.showModal({
  123. // title: '暂不支持',
  124. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  125. // success(res) {
  126. // if (res.confirm) {
  127. // console.log('用户点击确定')
  128. // } else if (res.cancel) {
  129. // console.log('用户点击取消')
  130. // }
  131. // }
  132. // })
  133. // return;
  134. // }
  135. this.setData({
  136. isModalShow: true
  137. })
  138. // wx.showModal({
  139. // title: '您未购买过本书,不能朗读',
  140. // content: '超值团购进行中,快去看看',
  141. // success(res) {
  142. // if (res.confirm) {
  143. // console.log('用户点击确定')
  144. // wx.navigateTo({
  145. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  146. // })
  147. // } else if (res.cancel) {
  148. // console.log('用户点击取消')
  149. // }
  150. // }
  151. // })
  152. }
  153. })
  154. },
  155. modalConfirmHandler: function () {
  156. this.setData({
  157. isModalShow: false
  158. })
  159. wx.navigateTo({
  160. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  161. })
  162. },
  163. modalCloseHandler: function () {
  164. this.setData({
  165. isModalShow: false
  166. })
  167. },
  168. openShare: function (e) {
  169. // this.setData({
  170. // shareFlag: !this.data.shareFlag
  171. // })
  172. this.shareDialog = this.selectComponent("#share-dialog");
  173. const data = {
  174. avatar: this.data.authorAvatar,
  175. author: this.data.author,
  176. iconImg: this.data.iconImg,
  177. title: this.data.title,
  178. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  179. // tip: this.data.tip,
  180. }
  181. this.shareDialog.share(data);
  182. },
  183. onShareAppMessage: function (res) {
  184. console.log(this.data.productId)
  185. if (res.from === 'button') {
  186. // 来自页面内转发按钮
  187. console.log(res.target)
  188. }
  189. return {
  190. title: '老师同学都在玩的配音show,你还在等什么?',
  191. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  192. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  193. }
  194. },
  195. goToWorks: function (e) {
  196. console.log(this.data.works)
  197. // this.videoClassCtx = wx.createVideoContext('myVideo', this);
  198. if (this.videoClassCtx) {
  199. this.videoClassCtx.stop();
  200. }
  201. console.log(e);
  202. let readId = e.currentTarget.dataset.id;
  203. let title = this.data.title;
  204. wx.navigateTo({
  205. url: `../../social/works/works?id=${readId}&title=${title}`
  206. })
  207. },
  208. collect: function (e) {
  209. // let uid = wx.getStorageSync('uid');
  210. let data = {
  211. targetCode: this.data.id,
  212. // title: this.data.title,
  213. // iconImg: this.data.iconImg
  214. }
  215. httpRequestApi.collectClass(this.uid, data).success(res => {
  216. this.setData({
  217. collectFlag: !this.data.collectFlag
  218. })
  219. })
  220. },
  221. getReadInfo: function (pageNo, pageSize) {
  222. // const uid = wx.getStorageSync('uid');
  223. const data = {
  224. lessonId: this.data.id,
  225. pageNo: this.data.pageNo,
  226. pageSize: 10
  227. };
  228. httpRequestApi.getClassRead(this.uid, data).success(res => {
  229. const readInfo = res.data.data.list;
  230. const readTemp = [];
  231. readInfo.forEach(item => {
  232. const temp = {};
  233. temp.nickName = item.user.wechatName;
  234. temp.time = formatDate(item.userRead.gmtCreated, 3);
  235. temp.avatar = item.user.avatar;
  236. temp.likes = item.userRead.playAmount ? item.userRead.playAmount : 0;
  237. temp.uid = item.userRead.uid;
  238. temp.id = item.userRead.id;
  239. this.data.works.push(temp);
  240. });
  241. this.setData({
  242. totalNo: res.data.data.totalNo,
  243. total: res.data.data.totalSize,
  244. works: this.data.works
  245. })
  246. });
  247. },
  248. // 下拉加载
  249. onReachBottom: function (e) {
  250. console.log(this.data.totalNo);
  251. this.setData({
  252. pageNo: this.data.pageNo + 1
  253. })
  254. if (this.data.pageNo <= this.data.totalNo) {
  255. this.getReadInfo();
  256. }
  257. },
  258. // 视频时间变动
  259. videoTimeChange: function (e) {
  260. this.videoPlayTime = e.detail.currentTime;
  261. },
  262. onHide: function () {
  263. let videoClassCtx = wx.createVideoContext('classVideo', this);
  264. videoClassCtx.stop();
  265. },
  266. onUnload: function () {
  267. if (this.videoPlayTime) {
  268. const data = {
  269. "title": this.data.title,
  270. "lessonId": this.data.id,
  271. "productId": this.data.productId,
  272. "playStopTime": this.videoPlayTime || 0,
  273. "type": 'EXAMPLE',
  274. }
  275. httpRequestApi.playLogReport(data).success(res => {
  276. console.log(res)
  277. })
  278. }
  279. }
  280. })