class.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. if(this.data.isIOS){
  147. wx.navigateTo({
  148. url: `../../vipPage/wechat/wechat`
  149. })
  150. }else{
  151. this.setData({
  152. modalType: 'androidVIP',
  153. isModalShow: true
  154. })
  155. }
  156. }
  157. })
  158. }, (error) => {
  159. this.setData({
  160. hide: !this.data.hide
  161. })
  162. if (this.videoClassCtx) {
  163. this.videoClassCtx.stop();
  164. }
  165. return;
  166. });
  167. },
  168. modalConfirmHandler: function () {
  169. this.setData({
  170. isModalShow: false
  171. })
  172. if(this.data.isIOS){
  173. // wx.navigateTo({
  174. // url: `../../vipPage/vipCode/vipCode`
  175. // })
  176. wx.navigateTo({
  177. url: `../../vipPage/wechat/wechat`
  178. })
  179. }else{
  180. wx.navigateTo({
  181. url: `../../vipPage/vip/vip`
  182. })
  183. }
  184. },
  185. modalCloseHandler: function () {
  186. this.setData({
  187. isModalShow: false
  188. })
  189. },
  190. openShare: function (e) {
  191. // this.setData({
  192. // shareFlag: !this.data.shareFlag
  193. // })
  194. this.shareDialog = this.selectComponent("#share-dialog");
  195. const data = {
  196. avatar: this.data.authorAvatar,
  197. author: this.data.author,
  198. iconImg: this.data.iconImg,
  199. title: this.data.title,
  200. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  201. // tip: this.data.tip,
  202. }
  203. this.shareDialog.share(data);
  204. },
  205. onShareAppMessage: function (res) {
  206. console.log(this.data.productId)
  207. if (res.from === 'button') {
  208. // 来自页面内转发按钮
  209. console.log(res.target)
  210. }
  211. return {
  212. title: '老师同学都在玩的配音show,你还在等什么?',
  213. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  214. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  215. }
  216. },
  217. goToWorks: function (e) {
  218. console.log(this.data.works)
  219. // this.videoClassCtx = wx.createVideoContext('myVideo', this);
  220. if (this.videoClassCtx) {
  221. this.videoClassCtx.stop();
  222. }
  223. console.log(e);
  224. let readId = e.currentTarget.dataset.id;
  225. let title = this.data.title;
  226. wx.navigateTo({
  227. url: `../../social/works/works?id=${readId}&title=${title}`
  228. })
  229. },
  230. collect: function (e) {
  231. // let uid = wx.getStorageSync('uid');
  232. let data = {
  233. targetCode: this.data.id,
  234. // title: this.data.title,
  235. // iconImg: this.data.iconImg
  236. }
  237. httpRequestApi.collectClass(this.uid, data).success(res => {
  238. this.setData({
  239. collectFlag: !this.data.collectFlag
  240. })
  241. })
  242. },
  243. getReadInfo: function (pageNo, pageSize) {
  244. // const uid = wx.getStorageSync('uid');
  245. const data = {
  246. lessonId: this.data.id,
  247. pageNo: this.data.pageNo,
  248. pageSize: 10
  249. };
  250. httpRequestApi.getClassRead(this.uid, data).success(res => {
  251. const readInfo = res.data.data.list;
  252. const readTemp = [];
  253. readInfo.forEach(item => {
  254. const temp = {};
  255. temp.nickName = item.user.wechatName;
  256. temp.time = formatDate(item.userRead.gmtCreated, 3);
  257. temp.avatar = item.user.avatar;
  258. temp.likes = item.userRead.playAmount ? item.userRead.playAmount : 0;
  259. temp.uid = item.userRead.uid;
  260. temp.id = item.userRead.id;
  261. this.data.works.push(temp);
  262. });
  263. this.setData({
  264. totalNo: res.data.data.totalNo,
  265. total: res.data.data.totalSize,
  266. works: this.data.works
  267. })
  268. });
  269. },
  270. // 下拉加载
  271. onReachBottom: function (e) {
  272. console.log(this.data.totalNo);
  273. this.setData({
  274. pageNo: this.data.pageNo + 1
  275. })
  276. if (this.data.pageNo <= this.data.totalNo) {
  277. this.getReadInfo();
  278. }
  279. },
  280. // 视频时间变动
  281. videoTimeChange: function (e) {
  282. this.videoPlayTime = e.detail.currentTime;
  283. },
  284. onHide: function () {
  285. let videoClassCtx = wx.createVideoContext('classVideo', this);
  286. videoClassCtx.stop();
  287. },
  288. onUnload: function () {
  289. if (this.videoPlayTime) {
  290. const data = {
  291. "title": this.data.title,
  292. "lessonId": this.data.id,
  293. "productId": this.data.productId,
  294. "playStopTime": this.videoPlayTime || 0,
  295. "type": 'EXAMPLE',
  296. }
  297. httpRequestApi.playLogReport(data).success(res => {
  298. console.log(res)
  299. })
  300. }
  301. }
  302. })