myworks.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // pages/user/myworks/myworks.js
  2. import APIClient from '../../utils/APIClient.js'
  3. import {
  4. formatDate
  5. } from '../../utils/util.js'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. wareCards: {},
  12. pageNo: 1,
  13. totalNo: 0,
  14. uid: '',
  15. videoList: [],
  16. isFans: false,
  17. isMyself: false,
  18. commentId: '',
  19. pageSize: 3
  20. },
  21. // 打开评论
  22. openComment: function (e) {
  23. console.log('id', e.detail.activeId)
  24. this.setData({
  25. commentShow: !this.data.commentShow,
  26. commentId: e.detail.activeId,
  27. });
  28. },
  29. toMyWorks: function (e) {
  30. let id = e.currentTarget.dataset.readid;
  31. let title = e.currentTarget.dataset.title;
  32. wx.navigateTo({
  33. url: `../../social/works/works?id=${id}&title=${title}`
  34. });
  35. },
  36. commentTap: function (e) {
  37. console.log('点击评论区', e)
  38. if (e.target.dataset.type === 'blank') {
  39. this.setData({
  40. commentShow: false
  41. })
  42. }
  43. },
  44. touchMove: function(e){
  45. return
  46. },
  47. goToReading: function (e) {
  48. console.log('去朗读', e)
  49. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  50. wx.navigateTo({
  51. url: `../../pages/reading/reading?id=${id}`
  52. });
  53. },
  54. // 关注用户
  55. follow: function () {
  56. let followUid = this.data.uid;
  57. const uid = wx.getStorageSync('uid');
  58. if (this.data.isFans) {
  59. APIClient.cancerFollow(uid, followUid).success((res) => {
  60. this.setData({
  61. isFans: false
  62. })
  63. wx.showToast({
  64. title: '取消关注',
  65. icon: 'success',
  66. duration: 1000
  67. })
  68. });
  69. } else {
  70. APIClient.followUser(uid, followUid).success((res) => {
  71. this.setData({
  72. isFans: true
  73. })
  74. wx.showToast({
  75. title: '关注啦',
  76. icon: 'success',
  77. duration: 1000
  78. })
  79. });
  80. }
  81. },
  82. getResults() {
  83. let pageNo = this.data.pageNo;
  84. let pageSize = 3;
  85. let uid = this.data.uid;
  86. console.log('用户身份', uid);
  87. APIClient.getUserMsg(uid, pageNo, pageSize).success(res => {
  88. console.log(res)
  89. res.data.data.user.birthday = formatDate(res.data.data.user.birthday, 4)
  90. this.setData({
  91. wareCards: res.data.data,
  92. isFans: res.data.data.like
  93. });
  94. console.log(this.data.wareCards)
  95. // wx.hideToast();
  96. this.getUserWorks(uid, pageNo, pageSize)
  97. }).fail(err => {
  98. console.log(err);
  99. });
  100. },
  101. getUserWorks(uid, pageNo, pageSize) {
  102. APIClient.userWorks(this.data.uid, this.data.pageNo, this.data.pageSize).success(res => {
  103. console.log(res)
  104. const recommendRes = res.data.data.list;
  105. if (recommendRes.length === 0) return;
  106. recommendRes.forEach(item => {
  107. const temp = {};
  108. temp.title = item.userRead.title;
  109. temp.summary = item.userRead.summary;
  110. temp.img = item.userRead.iconImg;
  111. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  112. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  113. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  114. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  115. temp.time = formatDate(item.userRead.gmtCreated, 3);
  116. temp.avatar = item.user.avatar;
  117. temp.profession = item.user.profession;
  118. temp.uid = item.user.uid;
  119. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  120. temp.id = item.userRead.id;
  121. temp.type = item.userRead.type;
  122. // temp.avatar = item.user.avatar;
  123. temp.nickName = item.user.wechatName;
  124. temp.isLike = item.isLike;
  125. temp.isFavorite = item.isFavorites;
  126. temp.isFans = true;
  127. // recommendWorks.push(temp);
  128. this.data.videoList.push(temp);
  129. });
  130. this.setData({
  131. videoList: this.data.videoList,
  132. totalNo: res.data.data.totalNo
  133. })
  134. console.log('dangqian', this.data.videoList)
  135. })
  136. },
  137. /**
  138. * 生命周期函数--监听页面加载
  139. */
  140. onLoad: function (options) {
  141. // if (options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2') {
  142. if (options.uid === wx.getStorageSync('uid')) {
  143. this.setData({
  144. isMyself: true
  145. })
  146. }
  147. this.setData({
  148. uid: options.uid
  149. }, () => {
  150. console.log(options.uid);
  151. });
  152. // wx.showToast({
  153. // title: '加载中...',
  154. // icon: 'loading'
  155. // });
  156. this.getResults();
  157. },
  158. /**
  159. * 生命周期函数--监听页面初次渲染完成
  160. */
  161. onReady: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面显示
  165. */
  166. onShow: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面隐藏
  170. */
  171. onHide: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面卸载
  175. */
  176. onUnload: function () {
  177. },
  178. /**
  179. * 页面相关事件处理函数--监听用户下拉动作
  180. */
  181. onPullDownRefresh: function () {
  182. },
  183. /**
  184. * 页面上拉触底事件的处理函数
  185. */
  186. onReachBottom: function () {
  187. this.setData({
  188. pageNo: this.data.pageNo + 1
  189. },()=>{
  190. if (this.data.pageNo <= this.data.totalNo) {
  191. this.getUserWorks();
  192. }
  193. })
  194. },
  195. /**
  196. * 用户点击右上角分享
  197. */
  198. onShareAppMessage: function () {
  199. }
  200. })