class.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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.authorize({
  130. scope: 'scope.record',
  131. success () {
  132. // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
  133. console.log('成功')
  134. wx.navigateTo({
  135. url: `../../main/reading/reading?id=${this.data.id}`
  136. })
  137. },
  138. fail () {
  139. wx.showModal({
  140. title: '无法开启您的录音权限',
  141. content: '点击右上角浮点按钮->设置,进行授权',
  142. confirmText: '我知道了',
  143. showCancel: false,
  144. success(res) {
  145. console.log('用户点击确定')
  146. dialogFlag = false;
  147. }
  148. })
  149. }
  150. })
  151. } else {
  152. // ios用户 并且没有购买过此书
  153. // if (app.globalData.isIOS) {
  154. // wx.showModal({
  155. // title: '暂不支持',
  156. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  157. // success(res) {
  158. // if (res.confirm) {
  159. // console.log('用户点击确定')
  160. // } else if (res.cancel) {
  161. // console.log('用户点击取消')
  162. // }
  163. // }
  164. // })
  165. // return;
  166. // }
  167. this.setData({
  168. isModalShow: true
  169. })
  170. // wx.showModal({
  171. // title: '您未购买过本书,不能朗读',
  172. // content: '超值团购进行中,快去看看',
  173. // success(res) {
  174. // if (res.confirm) {
  175. // console.log('用户点击确定')
  176. // wx.navigateTo({
  177. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  178. // })
  179. // } else if (res.cancel) {
  180. // console.log('用户点击取消')
  181. // }
  182. // }
  183. // })
  184. }
  185. })
  186. }, (error) => {
  187. this.setData({
  188. hide: !this.data.hide
  189. })
  190. if (this.videoClassCtx) {
  191. this.videoClassCtx.stop();
  192. }
  193. return;
  194. });
  195. },
  196. modalConfirmHandler: function () {
  197. this.setData({
  198. isModalShow: false
  199. })
  200. wx.navigateTo({
  201. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  202. })
  203. },
  204. modalCloseHandler: function () {
  205. this.setData({
  206. isModalShow: false
  207. })
  208. },
  209. openShare: function (e) {
  210. // this.setData({
  211. // shareFlag: !this.data.shareFlag
  212. // })
  213. this.shareDialog = this.selectComponent("#share-dialog");
  214. const data = {
  215. avatar: this.data.authorAvatar,
  216. author: this.data.author,
  217. iconImg: this.data.iconImg,
  218. title: this.data.title,
  219. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  220. // tip: this.data.tip,
  221. }
  222. this.shareDialog.share(data);
  223. },
  224. onShareAppMessage: function (res) {
  225. console.log(this.data.productId)
  226. if (res.from === 'button') {
  227. // 来自页面内转发按钮
  228. console.log(res.target)
  229. }
  230. return {
  231. title: '老师同学都在玩的配音show,你还在等什么?',
  232. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  233. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  234. }
  235. },
  236. goToWorks: function (e) {
  237. console.log(this.data.works)
  238. // this.videoClassCtx = wx.createVideoContext('myVideo', this);
  239. if (this.videoClassCtx) {
  240. this.videoClassCtx.stop();
  241. }
  242. console.log(e);
  243. let readId = e.currentTarget.dataset.id;
  244. let title = this.data.title;
  245. wx.navigateTo({
  246. url: `../../social/works/works?id=${readId}&title=${title}`
  247. })
  248. },
  249. collect: function (e) {
  250. // let uid = wx.getStorageSync('uid');
  251. let data = {
  252. targetCode: this.data.id,
  253. // title: this.data.title,
  254. // iconImg: this.data.iconImg
  255. }
  256. httpRequestApi.collectClass(this.uid, data).success(res => {
  257. this.setData({
  258. collectFlag: !this.data.collectFlag
  259. })
  260. })
  261. },
  262. getReadInfo: function (pageNo, pageSize) {
  263. // const uid = wx.getStorageSync('uid');
  264. const data = {
  265. lessonId: this.data.id,
  266. pageNo: this.data.pageNo,
  267. pageSize: 10
  268. };
  269. httpRequestApi.getClassRead(this.uid, data).success(res => {
  270. const readInfo = res.data.data.list;
  271. const readTemp = [];
  272. readInfo.forEach(item => {
  273. const temp = {};
  274. temp.nickName = item.user.wechatName;
  275. temp.time = formatDate(item.userRead.gmtCreated, 3);
  276. temp.avatar = item.user.avatar;
  277. temp.likes = item.userRead.playAmount ? item.userRead.playAmount : 0;
  278. temp.uid = item.userRead.uid;
  279. temp.id = item.userRead.id;
  280. this.data.works.push(temp);
  281. });
  282. this.setData({
  283. totalNo: res.data.data.totalNo,
  284. total: res.data.data.totalSize,
  285. works: this.data.works
  286. })
  287. });
  288. },
  289. // 下拉加载
  290. onReachBottom: function (e) {
  291. console.log(this.data.totalNo);
  292. this.setData({
  293. pageNo: this.data.pageNo + 1
  294. })
  295. if (this.data.pageNo <= this.data.totalNo) {
  296. this.getReadInfo();
  297. }
  298. },
  299. // 视频时间变动
  300. videoTimeChange: function (e) {
  301. this.videoPlayTime = e.detail.currentTime;
  302. },
  303. onHide: function () {
  304. let videoClassCtx = wx.createVideoContext('classVideo', this);
  305. videoClassCtx.stop();
  306. },
  307. onUnload: function () {
  308. if (this.videoPlayTime) {
  309. const data = {
  310. "title": this.data.title,
  311. "lessonId": this.data.id,
  312. "productId": this.data.productId,
  313. "playStopTime": this.videoPlayTime || 0,
  314. "type": 'EXAMPLE',
  315. }
  316. httpRequestApi.playLogReport(data).success(res => {
  317. console.log(res)
  318. })
  319. }
  320. }
  321. })