mycollection.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import httpRequestApi from '../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../utils/util';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. collection_data: [],
  11. line1: '您还没有收藏过哦',
  12. line2: '快去收藏自己喜欢的吧',
  13. videoList: [],
  14. commentShow: false,
  15. statusbarobj: {
  16. isshowbtn: false, //是否显示按钮
  17. title: "小学语文朗读配音", //标题
  18. },
  19. },
  20. toClass: function (e) {
  21. let targetCode = e.currentTarget.dataset.targetcode;
  22. let title = e.currentTarget.dataset.title;
  23. // wx.navigateTo({
  24. // url: `../../main/class/class?id=${targetCode}&title=${title}`
  25. // });
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (option) {
  31. console.log(option.title);
  32. if (option.title) {
  33. wx.setNavigationBarTitle({
  34. title: '我的收藏' //页面标题为路由参数
  35. });
  36. this.setData({
  37. title: option.title
  38. });
  39. }
  40. httpRequestApi.myFavorites().success(res => {
  41. this.formatWorksList(res.data.data.list)
  42. });
  43. },
  44. formatWorksList(list) {
  45. list.forEach(item => {
  46. const temp = {};
  47. temp.title = item.userRead.title;
  48. temp.summary = item.userRead.summary;
  49. temp.img = item.userRead.iconImg;
  50. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  51. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  52. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  53. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  54. temp.time = formatDate(item.userRead.gmtCreated, 3);
  55. temp.avatar = item.user.avatar;
  56. temp.profession = item.user.profession;
  57. temp.uid = item.user.uid;
  58. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  59. temp.id = item.userRead.id;
  60. temp.type = item.userRead.type;
  61. temp.nickName = item.user.wechatName;
  62. temp.isLike = item.isLike;
  63. temp.isFans = true;
  64. temp.isFavorite = true;
  65. temp.coverImg = item.userRead.coverImg;
  66. temp.shareImg = item.userRead.shareImg;
  67. temp.grade=item.userRead.grade;
  68. temp.videoShow = false;
  69. this.data.videoList.push(temp);
  70. });
  71. this.setData({
  72. videoList: this.data.videoList
  73. }, () => {
  74. console.log(this.data.videoList)
  75. })
  76. },
  77. goToReading: function (e) {
  78. console.log('去朗读', e)
  79. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  80. wx.navigateTo({
  81. url: `../../pages/reading/reading?id=${id}`
  82. });
  83. },
  84. // 评论区点击
  85. commentTap: function (e) {
  86. console.log('点击评论区', e)
  87. if (e.target.dataset.type === 'blank') {
  88. this.setData({
  89. commentShow: false
  90. })
  91. }
  92. },
  93. // 打开评论
  94. openComment: function (e) {
  95. //
  96. console.log('id', e.detail.activeId)
  97. this.setData({
  98. commentShow: !this.data.commentShow,
  99. commentId: e.detail.activeId,
  100. // commentList: []
  101. });
  102. // this.getReply(e.detail.activeId);
  103. },
  104. // 发布回复
  105. sendReply: function (e) {
  106. console.log('triger', e.detail.content);
  107. let data = {
  108. columnId: this.data.commentId,
  109. colunmNames: 'what',
  110. detailDesc: e.detail.content,
  111. // productId: this.data.productId
  112. }
  113. httpRequestApi.postReply(this.uid, data).success(res => {
  114. console.log(res)
  115. this.setData({
  116. pageNo: 1,
  117. commentList: []
  118. }, () => {
  119. this.getReply(this.data.commentId);
  120. })
  121. });
  122. },
  123. commentTouchMove: function (e) {
  124. return;
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload: function () {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh: function () {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom: function () {
  155. },
  156. collectTap: function(e){
  157. console.log('点击收藏',e)
  158. const index = e.detail.index;
  159. let str = `videoList[${index}].isFavorite`
  160. this.setData({
  161. [str]: e.detail.isCollect
  162. })
  163. },
  164. likeTap:function(e){
  165. console.log('点赞',e)
  166. const index = e.detail.index;
  167. let likeStr = `videoList[${index}].isLike`;
  168. let likeNumStr = `videoList[${index}].likes`;
  169. this.setData({
  170. [likeStr]: true,
  171. [likeNumStr]: this.data.videoList[index].likes + 1
  172. })
  173. },
  174. openShare: function (e) {
  175. console.log('用户点击分享按钮', e)
  176. this.setData({
  177. shareTitle: e.detail.currentTarget.dataset.title,
  178. shareId: e.detail.currentTarget.dataset.id,
  179. shareImg: e.detail.currentTarget.dataset.shareimg
  180. })
  181. },
  182. /**
  183. * 用户点击右上角分享
  184. */
  185. onShareAppMessage: function (res) {
  186. console.log('用户点分享',res)
  187. if (res.from === 'button') {
  188. return {
  189. title: '请欣赏我的课文朗读作品,点赞+评论。',
  190. path: `/pages/index/index?readId=${this.data.shareId}`,
  191. imageUrl: this.data.shareImg
  192. }
  193. } else {
  194. return {
  195. title: '课文朗读,从未如此有趣。',
  196. path: '/pages/index/index',
  197. }
  198. }
  199. }
  200. })