myworks.js 5.1 KB

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