class.js 5.9 KB

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