myworks.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. statusbarobj: {
  21. isshowbtn: false, //是否显示按钮
  22. title: "小学语文朗读配音", //标题
  23. },
  24. },
  25. // 打开评论
  26. openComment: function (e) {
  27. console.log('id', e.detail.activeId)
  28. this.setData({
  29. commentShow: !this.data.commentShow,
  30. commentId: e.detail.activeId,
  31. });
  32. },
  33. toMyWorks: function (e) {
  34. let id = e.currentTarget.dataset.readid;
  35. let title = e.currentTarget.dataset.title;
  36. wx.navigateTo({
  37. url: `../../social/works/works?id=${id}&title=${title}`
  38. });
  39. },
  40. commentTap: function (e) {
  41. console.log('点击评论区', e)
  42. if (e.target.dataset.type === 'blank') {
  43. this.setData({
  44. commentShow: false
  45. })
  46. }
  47. },
  48. touchMove: function(e){
  49. return
  50. },
  51. goToReading: function (e) {
  52. console.log('去朗读', e)
  53. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  54. wx.navigateTo({
  55. url: `../../pages/reading/reading?id=${id}`
  56. });
  57. },
  58. // 关注用户
  59. follow: function () {
  60. let followUid = this.data.uid;
  61. const uid = wx.getStorageSync('uid');
  62. if (this.data.isFans) {
  63. APIClient.cancerFollow(uid, followUid).success((res) => {
  64. this.setData({
  65. isFans: false
  66. })
  67. wx.showToast({
  68. title: '取消关注',
  69. icon: 'success',
  70. duration: 1000
  71. })
  72. });
  73. } else {
  74. APIClient.followUser(uid, followUid).success((res) => {
  75. this.setData({
  76. isFans: true
  77. })
  78. wx.showToast({
  79. title: '关注啦',
  80. icon: 'success',
  81. duration: 1000
  82. })
  83. });
  84. }
  85. },
  86. getResults() {
  87. let pageNo = this.data.pageNo;
  88. let pageSize = 3;
  89. let uid = this.data.uid;
  90. console.log('用户身份', uid);
  91. APIClient.getUserMsg(uid, pageNo, pageSize).success(res => {
  92. console.log(res)
  93. res.data.data.user.birthday = formatDate(res.data.data.user.birthday, 4)
  94. this.setData({
  95. wareCards: res.data.data,
  96. isFans: res.data.data.like
  97. });
  98. console.log(this.data.wareCards)
  99. // wx.hideToast();
  100. this.getUserWorks(uid, pageNo, pageSize)
  101. }).fail(err => {
  102. console.log(err);
  103. });
  104. },
  105. getUserWorks(uid, pageNo, pageSize) {
  106. APIClient.userWorks(this.data.uid, this.data.pageNo, this.data.pageSize).success(res => {
  107. console.log(res)
  108. const recommendRes = res.data.data.list;
  109. if (recommendRes.length === 0) return;
  110. recommendRes.forEach(item => {
  111. const temp = {};
  112. temp.title = item.userRead.title;
  113. temp.summary = item.userRead.summary;
  114. temp.img = item.userRead.iconImg;
  115. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  116. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  117. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  118. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  119. temp.time = formatDate(item.userRead.gmtCreated, 3);
  120. temp.avatar = item.user.avatar;
  121. temp.profession = item.user.profession;
  122. temp.uid = item.user.uid;
  123. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  124. temp.id = item.userRead.id;
  125. temp.type = item.userRead.type;
  126. // temp.avatar = item.user.avatar;
  127. temp.nickName = item.user.wechatName;
  128. temp.isLike = item.isLike;
  129. temp.isFavorite = item.isFavorites;
  130. temp.isFans = true;
  131. temp.videoShow = false;
  132. temp.coverImg = item.userRead.coverImg;
  133. // recommendWorks.push(temp);
  134. this.data.videoList.push(temp);
  135. });
  136. this.setData({
  137. videoList: this.data.videoList,
  138. totalNo: res.data.data.totalNo
  139. })
  140. console.log('dangqian', this.data.videoList)
  141. })
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. onLoad: function (options) {
  147. // if (options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2') {
  148. if (options.uid === wx.getStorageSync('uid')) {
  149. this.setData({
  150. isMyself: true
  151. })
  152. }
  153. this.setData({
  154. uid: options.uid
  155. }, () => {
  156. console.log(options.uid);
  157. });
  158. // wx.showToast({
  159. // title: '加载中...',
  160. // icon: 'loading'
  161. // });
  162. this.getResults();
  163. },
  164. /**
  165. * 生命周期函数--监听页面初次渲染完成
  166. */
  167. onReady: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面显示
  171. */
  172. onShow: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面隐藏
  176. */
  177. onHide: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面卸载
  181. */
  182. onUnload: function () {
  183. },
  184. /**
  185. * 页面相关事件处理函数--监听用户下拉动作
  186. */
  187. onPullDownRefresh: function () {
  188. },
  189. /**
  190. * 页面上拉触底事件的处理函数
  191. */
  192. onReachBottom: function () {
  193. this.setData({
  194. pageNo: this.data.pageNo + 1
  195. },()=>{
  196. if (this.data.pageNo <= this.data.totalNo) {
  197. this.getUserWorks();
  198. }
  199. })
  200. },
  201. collectTap: function(e){
  202. console.log('点击收藏',e)
  203. const index = e.detail.index;
  204. let str = `videoList[${index}].isFavorite`
  205. this.setData({
  206. [str]: e.detail.isCollect
  207. })
  208. },
  209. likeTap:function(e){
  210. console.log('点赞',e)
  211. const index = e.detail.index;
  212. let likeStr = `videoList[${index}].isLike`;
  213. let likeNumStr = `videoList[${index}].likes`;
  214. this.setData({
  215. [likeStr]: true,
  216. [likeNumStr]: this.data.videoList[index].likes + 1
  217. })
  218. },
  219. /**
  220. * 用户点击右上角分享
  221. */
  222. onShareAppMessage: function (res) {
  223. console.log('点击分享按钮', res)
  224. console.log('点击分享按钮', this.data.shareTitle)
  225. console.log('点击分享按钮', this.data.shareId)
  226. console.log('点击分享按钮', this.data.shareImg)
  227. if (res.from === 'button') {
  228. return {
  229. title: '请欣赏我的课文朗读作品,点赞+评论。',
  230. path: `/pages/index/index?readId=${this.data.shareId}`,
  231. imageUrl: '../../static/index/share_icon.png'
  232. }
  233. } else {
  234. return {
  235. title: '课文朗读,从未如此有趣。',
  236. path: '/pages/index/index',
  237. }
  238. }
  239. },
  240. })