mycollection.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.grade=item.userRead.grade;
  67. temp.videoShow = false;
  68. this.data.videoList.push(temp);
  69. });
  70. this.setData({
  71. videoList: this.data.videoList
  72. }, () => {
  73. console.log(this.data.videoList)
  74. })
  75. },
  76. goToReading: function (e) {
  77. console.log('去朗读', e)
  78. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  79. wx.navigateTo({
  80. url: `../../pages/reading/reading?id=${id}`
  81. });
  82. },
  83. // 评论区点击
  84. commentTap: function (e) {
  85. console.log('点击评论区', e)
  86. if (e.target.dataset.type === 'blank') {
  87. this.setData({
  88. commentShow: false
  89. })
  90. }
  91. },
  92. // 打开评论
  93. openComment: function (e) {
  94. //
  95. console.log('id', e.detail.activeId)
  96. this.setData({
  97. commentShow: !this.data.commentShow,
  98. commentId: e.detail.activeId,
  99. // commentList: []
  100. });
  101. // this.getReply(e.detail.activeId);
  102. },
  103. // 发布回复
  104. sendReply: function (e) {
  105. console.log('triger', e.detail.content);
  106. let data = {
  107. columnId: this.data.commentId,
  108. colunmNames: 'what',
  109. detailDesc: e.detail.content,
  110. // productId: this.data.productId
  111. }
  112. httpRequestApi.postReply(this.uid, data).success(res => {
  113. console.log(res)
  114. this.setData({
  115. pageNo: 1,
  116. commentList: []
  117. }, () => {
  118. this.getReply(this.data.commentId);
  119. })
  120. });
  121. },
  122. commentTouchMove: function (e) {
  123. return;
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload: function () {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh: function () {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function () {
  154. },
  155. collectTap: function(e){
  156. console.log('点击收藏',e)
  157. const index = e.detail.index;
  158. let str = `videoList[${index}].isFavorite`
  159. this.setData({
  160. [str]: e.detail.isCollect
  161. })
  162. },
  163. likeTap:function(e){
  164. console.log('点赞',e)
  165. const index = e.detail.index;
  166. let likeStr = `videoList[${index}].isLike`;
  167. let likeNumStr = `videoList[${index}].likes`;
  168. this.setData({
  169. [likeStr]: true,
  170. [likeNumStr]: this.data.videoList[index].likes + 1
  171. })
  172. },
  173. openShare: function (e) {
  174. console.log('用户点击分享按钮', e)
  175. this.setData({
  176. shareTitle: e.detail.currentTarget.dataset.title,
  177. shareId: e.detail.currentTarget.dataset.id,
  178. shareImg: e.detail.currentTarget.dataset.img
  179. })
  180. },
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function (res) {
  185. console.log('用户点分享',res)
  186. if (res.from === 'button') {
  187. return {
  188. title: '请欣赏我的课文朗读作品,点赞+评论。',
  189. path: `/pages/index/index?readId=${this.data.shareId}`,
  190. imageUrl: '../../static/index/share_icon.png'
  191. }
  192. } else {
  193. return {
  194. title: '课文朗读,从未如此有趣。',
  195. path: '/pages/index/index',
  196. }
  197. }
  198. }
  199. })