index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {
  2. getUserInfo,
  3. setFans,
  4. getUserRead
  5. } from '~/api/user'
  6. import share from '~/mixins/share'
  7. import event from '~/mixins/event'
  8. import reachBottom from '~/mixins/reachBottom'
  9. Page({
  10. behaviors: [reachBottom, share,event],
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. uid: '',
  16. userInfo: {},
  17. // type为pk,顶部显示为pk时样式,user为默认样式
  18. type: 'user',
  19. uid: '',
  20. localUid: wx.getStorageSync('uid')
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. if (wx.getStorageSync('uid') == options.uid) {
  27. wx.setNavigationBarTitle({
  28. title: '我的主页'
  29. })
  30. }
  31. this.setData({
  32. type: options.type || 'user',
  33. uid: options.uid
  34. })
  35. },
  36. onShow() {
  37. this.getUserInfo()
  38. },
  39. async getUserInfo() {
  40. let res = await getUserInfo({
  41. uid: this.data.uid
  42. })
  43. this.setData({
  44. userInfo: res
  45. })
  46. this.resetData()
  47. },
  48. loadMore() {
  49. this.getData(getUserRead, {
  50. uid: this.data.userInfo.user.uid,
  51. pageSize: 20
  52. })
  53. },
  54. // 关注
  55. async setFans() {
  56. if (wx.getStorageSync('uid') == this.data.uid) {
  57. return wx.showToast({
  58. title: '不可以关注自己哦~',
  59. icon: 'none'
  60. })
  61. }
  62. let newLike = !this.data.userInfo.like
  63. let res = await setFans({
  64. uid: this.data.userInfo.user.uid,
  65. }, 'put')
  66. this.setData({
  67. ['userInfo.like']: newLike
  68. })
  69. wx.showToast({
  70. title: newLike ? '已关注' : '取消关注',
  71. icon: 'none'
  72. })
  73. },
  74. clipboar() {
  75. wx.setClipboardData({
  76. data: this.data.userInfo.user.eid,
  77. success: function (res) { //成功回调函数
  78. wx.showToast({
  79. title: '已复制',
  80. icon: "none"
  81. })
  82. }
  83. })
  84. },
  85. toPkPage({
  86. currentTarget
  87. }) {
  88. if (this.data.userInfo.user.profession == '官方' || wx.getStorageSync('uid') == this.data.uid) {
  89. wx.navigateTo({
  90. url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
  91. })
  92. } else {
  93. wx.navigateTo({
  94. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  95. })
  96. }
  97. },
  98. sendMsg({
  99. currentTarget
  100. }) {
  101. let user = this.data.userInfo.user
  102. let {
  103. nickName,
  104. eid,
  105. uid
  106. } = user
  107. if (this.data.localUid == uid) {
  108. return wx.showToast({
  109. title: '不可以给自己发私信哦~',
  110. icon: 'none'
  111. })
  112. }
  113. wx.navigateTo({
  114. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  115. })
  116. },
  117. })