myworks.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. item.isActivity && (temp.activity = true);
  148. // recommendWorks.push(temp);
  149. this.data.videoList.push(temp);
  150. });
  151. this.setData({
  152. videoList: this.data.videoList,
  153. totalNo: res.data.data.totalNo
  154. })
  155. console.log('dangqian', this.data.videoList)
  156. })
  157. },
  158. /**
  159. * 生命周期函数--监听页面加载
  160. */
  161. onLoad: function (options) {
  162. // if (options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2') {
  163. if (options.uid === wx.getStorageSync('uid')) {
  164. this.setData({
  165. isMyself: true
  166. })
  167. }
  168. this.setData({
  169. uid: options.uid
  170. }, () => {
  171. console.log(options.uid);
  172. });
  173. // wx.showToast({
  174. // title: '加载中...',
  175. // icon: 'loading'
  176. // });
  177. this.getResults();
  178. },
  179. /**
  180. * 生命周期函数--监听页面初次渲染完成
  181. */
  182. onReady: function () {
  183. },
  184. /**
  185. * 生命周期函数--监听页面显示
  186. */
  187. onShow: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面隐藏
  191. */
  192. onHide: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面卸载
  196. */
  197. onUnload: function () {
  198. },
  199. /**
  200. * 页面相关事件处理函数--监听用户下拉动作
  201. */
  202. onPullDownRefresh: function () {
  203. },
  204. /**
  205. * 页面上拉触底事件的处理函数
  206. */
  207. onReachBottom: function () {
  208. this.setData({
  209. pageNo: this.data.pageNo + 1
  210. }, () => {
  211. if (this.data.pageNo <= this.data.totalNo) {
  212. this.getUserWorks();
  213. }
  214. })
  215. },
  216. collectTap: function (e) {
  217. const index = e.detail.index;
  218. let str = `videoList[${index}].isFavorite`;
  219. let str2 = `videoList[${index}].favoritesAmount`;
  220. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  221. this.setData({
  222. [str]: e.detail.isCollect,
  223. [str2]: favoritesAmount
  224. })
  225. },
  226. likeTap: function (e) {
  227. console.log('点赞', e)
  228. const index = e.detail.index;
  229. let likeStr = `videoList[${index}].isLike`;
  230. let likeNumStr = `videoList[${index}].likes`;
  231. this.setData({
  232. [likeStr]: true,
  233. [likeNumStr]: this.data.videoList[index].likes + 1
  234. })
  235. },
  236. openShare: function (e) {
  237. console.log('用户点击分享按钮', e)
  238. this.setData({
  239. shareTitle: e.detail.currentTarget.dataset.title,
  240. shareId: e.detail.currentTarget.dataset.id,
  241. shareImg: e.detail.currentTarget.dataset.shareimg,
  242. ifTapActivity: e.detail.currentTarget.dataset.activity
  243. })
  244. },
  245. /**
  246. * 用户点击右上角分享
  247. */
  248. onShareAppMessage: function (res) {
  249. console.log('点击分享按钮', res)
  250. console.log('点击分享按钮', this.data.shareTitle)
  251. console.log('点击分享按钮', this.data.shareId)
  252. console.log('点击分享按钮', this.data.shareImg)
  253. if (res.from === 'button') {
  254. return {
  255. title: '请欣赏我的课文朗读作品,点赞+评论。',
  256. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  257. imageUrl: this.data.shareImg
  258. }
  259. } else {
  260. return {
  261. title: '课文朗读,从未如此有趣。',
  262. path: '/pages/index/index',
  263. }
  264. }
  265. },
  266. addShareAmount: function (e) {
  267. console.log('+++++1', e)
  268. let str = `videoList[${e.detail.index}].shareAmount`;
  269. this.setData({
  270. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  271. })
  272. }
  273. })