class.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. })
  72. },
  73. // video组件在获得url时迅速退出页面会导致小程序闪退,官方还没修复(11/28),处理办法:懒加载思路,在用户点击时再获取videoUrl
  74. // setVideoUrl: function(){
  75. // console.log('视频地址>>>>>>>>',this.data.lazyVideoUrl)
  76. // this.setData({
  77. // videoUrl: this.data.lazyVideoUrl,
  78. // })
  79. // },
  80. videoPlayHandler: function () {
  81. this.setData({
  82. videoLoad: true
  83. }, () => {
  84. this.videoCtx = wx.createVideoContext('classVideo', this);
  85. this.videoCtx.play();
  86. })
  87. },
  88. // 检查是否收藏
  89. checkLike: function () {
  90. httpRequestApi.classIsLike(this.uid, {
  91. targetCode: this.data.id
  92. }).success(res => {
  93. this.setData({
  94. collectFlag: res.data.data
  95. })
  96. })
  97. },
  98. goToReading: function () {
  99. let classId = this.data.id;
  100. // httpRequestApi.checkLesson(classId).success(res => {
  101. // const productId = res.data.data[0];
  102. // this.setData({
  103. // productId
  104. // })
  105. // });
  106. httpRequestApi.areYouSuper(this.data.productId).success(res => {
  107. if (res.data.success) {
  108. wx.navigateTo({
  109. url: `../../main/reading/reading?id=${this.data.id}`
  110. })
  111. } else {
  112. // ios用户 并且没有购买过此书
  113. // if (app.globalData.isIOS) {
  114. // wx.showModal({
  115. // title: '暂不支持',
  116. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  117. // success(res) {
  118. // if (res.confirm) {
  119. // console.log('用户点击确定')
  120. // } else if (res.cancel) {
  121. // console.log('用户点击取消')
  122. // }
  123. // }
  124. // })
  125. // return;
  126. // }
  127. this.setData({
  128. isModalShow: true
  129. })
  130. // wx.showModal({
  131. // title: '您未购买过本书,不能朗读',
  132. // content: '超值团购进行中,快去看看',
  133. // success(res) {
  134. // if (res.confirm) {
  135. // console.log('用户点击确定')
  136. // wx.navigateTo({
  137. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  138. // })
  139. // } else if (res.cancel) {
  140. // console.log('用户点击取消')
  141. // }
  142. // }
  143. // })
  144. }
  145. })
  146. },
  147. modalConfirmHandler: function () {
  148. this.setData({
  149. isModalShow: false
  150. })
  151. wx.navigateTo({
  152. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  153. })
  154. },
  155. modalCloseHandler: function () {
  156. this.setData({
  157. isModalShow: false
  158. })
  159. },
  160. openShare: function (e) {
  161. // this.setData({
  162. // shareFlag: !this.data.shareFlag
  163. // })
  164. this.shareDialog = this.selectComponent("#share-dialog");
  165. const data = {
  166. avatar: this.data.authorAvatar,
  167. author: this.data.author,
  168. iconImg: this.data.iconImg,
  169. title: this.data.title,
  170. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  171. // tip: this.data.tip,
  172. }
  173. this.shareDialog.share(data);
  174. },
  175. onShareAppMessage: function (res) {
  176. console.log(this.data.productId)
  177. if (res.from === 'button') {
  178. // 来自页面内转发按钮
  179. console.log(res.target)
  180. }
  181. return {
  182. title: '老师同学都在玩的配音show,你还在等什么?',
  183. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  184. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  185. }
  186. },
  187. goToWorks: function (e) {
  188. console.log(this.data.works)
  189. // this.videoCtx = wx.createVideoContext('myVideo', this);
  190. if (this.videoCtx) {
  191. this.videoCtx.stop();
  192. }
  193. console.log(e);
  194. let readId = e.currentTarget.dataset.id;
  195. let title = this.data.title;
  196. wx.navigateTo({
  197. url: `../../social/works/works?id=${readId}&title=${title}`
  198. })
  199. },
  200. collect: function (e) {
  201. // let uid = wx.getStorageSync('uid');
  202. let data = {
  203. targetCode: this.data.id,
  204. // title: this.data.title,
  205. // iconImg: this.data.iconImg
  206. }
  207. httpRequestApi.collectClass(this.uid, data).success(res => {
  208. this.setData({
  209. collectFlag: !this.data.collectFlag
  210. })
  211. })
  212. },
  213. getReadInfo: function (pageNo, pageSize) {
  214. // const uid = wx.getStorageSync('uid');
  215. const data = {
  216. lessonId: this.data.id,
  217. pageNo: this.data.pageNo,
  218. pageSize: 10
  219. };
  220. httpRequestApi.getClassRead(this.uid, data).success(res => {
  221. const readInfo = res.data.data.list;
  222. const readTemp = [];
  223. readInfo.forEach(item => {
  224. const temp = {};
  225. temp.nickName = item.user.wechatName;
  226. temp.time = formatDate(item.userRead.gmtModified, 3);
  227. temp.avatar = item.user.avatar;
  228. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  229. temp.uid = item.userRead.uid;
  230. temp.id = item.userRead.id;
  231. console.log(item.userRead)
  232. this.data.works.push(temp);
  233. });
  234. this.setData({
  235. totalNo: res.data.data.totalNo,
  236. total: res.data.data.totalSize,
  237. works: this.data.works
  238. })
  239. });
  240. },
  241. // 下拉加载
  242. onReachBottom: function (e) {
  243. console.log(this.data.totalNo);
  244. this.setData({
  245. pageNo: this.data.pageNo + 1
  246. })
  247. if (this.data.pageNo <= this.data.totalNo) {
  248. this.getReadInfo();
  249. }
  250. },
  251. // 视频时间变动
  252. videoTimeChange: function (e) {
  253. this.videoPlayTime = e.detail.currentTime;
  254. },
  255. onHide: function () {
  256. let videoCtx = wx.createVideoContext('classVideo', this);
  257. videoCtx.stop();
  258. },
  259. onUnload: function () {
  260. if (this.videoPlayTime) {
  261. const data = {
  262. "title": this.data.title,
  263. "lessonId": this.data.id,
  264. "productId": this.data.productId,
  265. "playStopTime": this.videoPlayTime || 0,
  266. "type": 'EXAMPLE',
  267. }
  268. httpRequestApi.playLogReport(data).success(res => {
  269. console.log(res)
  270. })
  271. }
  272. }
  273. })