class.js 8.5 KB

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