class.js 6.2 KB

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