class.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. getOpenidSessionKey((res) => {
  120. httpRequestApi.getUserAuth().success(res => {
  121. if (res.data.success) {
  122. const that = this;
  123. wx.authorize({
  124. scope: 'scope.record',
  125. success () {
  126. // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
  127. console.log('成功')
  128. wx.navigateTo({
  129. url: `../../main/reading/reading?id=${that.data.id}`
  130. })
  131. },
  132. fail () {
  133. wx.showModal({
  134. title: '录音前请打开麦克风权限',
  135. content: '点击右上角浮点...,选择:设置-麦克风,点击/打开。',
  136. confirmText: '我知道了',
  137. showCancel: false,
  138. success(res) {
  139. console.log('用户点击确定')
  140. }
  141. })
  142. }
  143. })
  144. } else {
  145. console.log('chulaiba')
  146. this.setData({
  147. modalType: this.data.isIOS ? 'iosCode' : 'androidVIP',
  148. isModalShow: true
  149. })
  150. }
  151. })
  152. }, (error) => {
  153. this.setData({
  154. hide: !this.data.hide
  155. })
  156. if (this.videoClassCtx) {
  157. this.videoClassCtx.stop();
  158. }
  159. return;
  160. });
  161. },
  162. modalConfirmHandler: function () {
  163. this.setData({
  164. isModalShow: false
  165. })
  166. wx.navigateTo({
  167. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  168. })
  169. },
  170. modalCloseHandler: function () {
  171. this.setData({
  172. isModalShow: false
  173. })
  174. },
  175. openShare: function (e) {
  176. // this.setData({
  177. // shareFlag: !this.data.shareFlag
  178. // })
  179. this.shareDialog = this.selectComponent("#share-dialog");
  180. const data = {
  181. avatar: this.data.authorAvatar,
  182. author: this.data.author,
  183. iconImg: this.data.iconImg,
  184. title: this.data.title,
  185. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  186. // tip: this.data.tip,
  187. }
  188. this.shareDialog.share(data);
  189. },
  190. onShareAppMessage: function (res) {
  191. console.log(this.data.productId)
  192. if (res.from === 'button') {
  193. // 来自页面内转发按钮
  194. console.log(res.target)
  195. }
  196. return {
  197. title: '老师同学都在玩的配音show,你还在等什么?',
  198. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  199. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  200. }
  201. },
  202. goToWorks: function (e) {
  203. console.log(this.data.works)
  204. // this.videoClassCtx = wx.createVideoContext('myVideo', this);
  205. if (this.videoClassCtx) {
  206. this.videoClassCtx.stop();
  207. }
  208. console.log(e);
  209. let readId = e.currentTarget.dataset.id;
  210. let title = this.data.title;
  211. wx.navigateTo({
  212. url: `../../social/works/works?id=${readId}&title=${title}`
  213. })
  214. },
  215. collect: function (e) {
  216. // let uid = wx.getStorageSync('uid');
  217. let data = {
  218. targetCode: this.data.id,
  219. // title: this.data.title,
  220. // iconImg: this.data.iconImg
  221. }
  222. httpRequestApi.collectClass(this.uid, data).success(res => {
  223. this.setData({
  224. collectFlag: !this.data.collectFlag
  225. })
  226. })
  227. },
  228. getReadInfo: function (pageNo, pageSize) {
  229. // const uid = wx.getStorageSync('uid');
  230. const data = {
  231. lessonId: this.data.id,
  232. pageNo: this.data.pageNo,
  233. pageSize: 10
  234. };
  235. httpRequestApi.getClassRead(this.uid, data).success(res => {
  236. const readInfo = res.data.data.list;
  237. const readTemp = [];
  238. readInfo.forEach(item => {
  239. const temp = {};
  240. temp.nickName = item.user.wechatName;
  241. temp.time = formatDate(item.userRead.gmtCreated, 3);
  242. temp.avatar = item.user.avatar;
  243. temp.likes = item.userRead.playAmount ? item.userRead.playAmount : 0;
  244. temp.uid = item.userRead.uid;
  245. temp.id = item.userRead.id;
  246. this.data.works.push(temp);
  247. });
  248. this.setData({
  249. totalNo: res.data.data.totalNo,
  250. total: res.data.data.totalSize,
  251. works: this.data.works
  252. })
  253. });
  254. },
  255. // 下拉加载
  256. onReachBottom: function (e) {
  257. console.log(this.data.totalNo);
  258. this.setData({
  259. pageNo: this.data.pageNo + 1
  260. })
  261. if (this.data.pageNo <= this.data.totalNo) {
  262. this.getReadInfo();
  263. }
  264. },
  265. // 视频时间变动
  266. videoTimeChange: function (e) {
  267. this.videoPlayTime = e.detail.currentTime;
  268. },
  269. onHide: function () {
  270. let videoClassCtx = wx.createVideoContext('classVideo', this);
  271. videoClassCtx.stop();
  272. },
  273. onUnload: function () {
  274. if (this.videoPlayTime) {
  275. const data = {
  276. "title": this.data.title,
  277. "lessonId": this.data.id,
  278. "productId": this.data.productId,
  279. "playStopTime": this.videoPlayTime || 0,
  280. "type": 'EXAMPLE',
  281. }
  282. httpRequestApi.playLogReport(data).success(res => {
  283. console.log(res)
  284. })
  285. }
  286. }
  287. })