myworks.js 7.8 KB

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