index.js 2.5 KB

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