index.js 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. getUserInfo,
  3. setFans
  4. } from '~/api/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. userInfo: {}
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.getUserInfo()
  17. },
  18. async getUserInfo() {
  19. let res = await getUserInfo({
  20. uid: '16c02342a44f45d78bb25b52ae6082ae'
  21. })
  22. console.log(res);
  23. this.setData({
  24. userInfo: res
  25. })
  26. },
  27. // 关注
  28. async setFans() {
  29. let newLike = !this.data.userInfo.like
  30. await setFans({
  31. uid: this.data.userInfo.user.uid
  32. }, 'put')
  33. this.setData({
  34. ['userInfo.like']: newLike
  35. })
  36. wx.showToast({
  37. title: newLike ? '已关注' : '取消关注',
  38. icon: 'none'
  39. })
  40. },
  41. toPkPage({
  42. currentTarget
  43. }) {
  44. wx.navigateTo({
  45. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  46. })
  47. },
  48. })