class.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. },
  29. onLoad: function (option) {
  30. console.log(option);
  31. if (option.scene || option.shareCard) {
  32. this.setData({
  33. goBackHome: true
  34. })
  35. }
  36. this.setData({
  37. // title: option.title,
  38. id: option.id
  39. })
  40. this.uid = wx.getStorageSync('uid');;
  41. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  42. console.log(res);
  43. this.setData({
  44. title: res.data.data.title,
  45. videoUrl: res.data.data.playUrl,
  46. iconImg: res.data.data.iconImg
  47. })
  48. wx.setNavigationBarTitle({
  49. title: res.data.data.title //页面标题为路由参数
  50. })
  51. this.getReadInfo(1, 10);
  52. this.checkLike();
  53. })
  54. },
  55. // video组件在获得url时迅速退出页面会导致小程序闪退,官方还没修复(11/28),处理办法:懒加载思路,在用户点击时再获取videoUrl
  56. // setVideoUrl: function(){
  57. // console.log('视频地址>>>>>>>>',this.data.lazyVideoUrl)
  58. // this.setData({
  59. // videoUrl: this.data.lazyVideoUrl,
  60. // })
  61. // },
  62. videoPlayHandler: function () {
  63. this.setData({
  64. videoLoad: true
  65. }, () => {
  66. this.videoCtx = wx.createVideoContext('classVideo', this);
  67. this.videoCtx.play();
  68. })
  69. },
  70. // 检查是否收藏
  71. checkLike: function () {
  72. httpRequestApi.classIsLike(this.uid, {
  73. targetCode: this.data.id
  74. }).success(res => {
  75. this.setData({
  76. collectFlag: res.data.data
  77. })
  78. })
  79. },
  80. goToReading: function () {
  81. let classId = this.data.id;
  82. httpRequestApi.checkLesson(classId).success(res => {
  83. const productId = res.data.data[0];
  84. // wx.navigateTo({
  85. // url: `../../main/reading/reading?id=${classId}`
  86. // })
  87. // return;
  88. httpRequestApi.areYouSuper(res.data.data).success(res => {
  89. if (res.data.success) {
  90. wx.navigateTo({
  91. url: `../../main/reading/reading?id=${classId}`
  92. })
  93. } else {
  94. // ios用户 并且没有购买过此书
  95. // if (app.globalData.isIOS) {
  96. // wx.showModal({
  97. // title: '暂不支持',
  98. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  99. // success(res) {
  100. // if (res.confirm) {
  101. // console.log('用户点击确定')
  102. // } else if (res.cancel) {
  103. // console.log('用户点击取消')
  104. // }
  105. // }
  106. // })
  107. // return;
  108. // }
  109. wx.showModal({
  110. title: '您未购买过本书,不能朗读',
  111. content: '超值团购进行中,快去看看',
  112. success(res) {
  113. if (res.confirm) {
  114. console.log('用户点击确定')
  115. wx.navigateTo({
  116. url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  117. })
  118. } else if (res.cancel) {
  119. console.log('用户点击取消')
  120. }
  121. }
  122. })
  123. }
  124. })
  125. });
  126. },
  127. openShare: function (e) {
  128. // this.setData({
  129. // shareFlag: !this.data.shareFlag
  130. // })
  131. this.shareDialog = this.selectComponent("#share-dialog");
  132. const data = {
  133. avatar: this.data.authorAvatar,
  134. author: this.data.author,
  135. iconImg: this.data.iconImg,
  136. title: this.data.title,
  137. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  138. // tip: this.data.tip,
  139. }
  140. this.shareDialog.share(data);
  141. },
  142. onShareAppMessage: function (res) {
  143. if (res.from === 'button') {
  144. // 来自页面内转发按钮
  145. console.log(res.target)
  146. }
  147. return {
  148. title: '老师同学都在玩的配音show,你还在等什么?',
  149. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  150. imageUrl: '../../../static/share/class_icon.jpg'
  151. }
  152. },
  153. goToWorks: function (e) {
  154. console.log(this.data.works)
  155. // this.videoCtx = wx.createVideoContext('myVideo', this);
  156. if (this.videoCtx) {
  157. this.videoCtx.stop();
  158. }
  159. console.log(e);
  160. let readId = e.currentTarget.dataset.id;
  161. let title = this.data.title;
  162. wx.navigateTo({
  163. url: `../../social/works/works?id=${readId}&title=${title}`
  164. })
  165. },
  166. collect: function (e) {
  167. // let uid = wx.getStorageSync('uid');
  168. let data = {
  169. targetCode: this.data.id,
  170. // title: this.data.title,
  171. // iconImg: this.data.iconImg
  172. }
  173. httpRequestApi.collectClass(this.uid, data).success(res => {
  174. this.setData({
  175. collectFlag: !this.data.collectFlag
  176. })
  177. })
  178. },
  179. getReadInfo: function (pageNo, pageSize) {
  180. // const uid = wx.getStorageSync('uid');
  181. const data = {
  182. lessonId: this.data.id,
  183. pageNo: this.data.pageNo,
  184. pageSize: 10
  185. };
  186. httpRequestApi.getClassRead(this.uid, data).success(res => {
  187. const readInfo = res.data.data.list;
  188. const readTemp = [];
  189. readInfo.forEach(item => {
  190. const temp = {};
  191. temp.nickName = item.user.wechatName;
  192. temp.time = formatDate(item.userRead.gmtModified, 3);
  193. temp.avatar = item.user.avatar;
  194. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  195. temp.uid = item.userRead.uid;
  196. temp.id = item.userRead.id;
  197. console.log(item.userRead)
  198. this.data.works.push(temp);
  199. });
  200. this.setData({
  201. totalNo: res.data.data.totalNo,
  202. total: res.data.data.totalSize,
  203. works: this.data.works
  204. })
  205. });
  206. },
  207. // 下拉加载
  208. onReachBottom: function (e) {
  209. console.log(this.data.totalNo);
  210. this.setData({
  211. pageNo: this.data.pageNo + 1
  212. })
  213. if (this.data.pageNo <= this.data.totalNo) {
  214. this.getReadInfo();
  215. }
  216. },
  217. onHide: function () {
  218. let videoCtx = wx.createVideoContext('classVideo', this);
  219. videoCtx.stop();
  220. },
  221. })