index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. this.getUserInfo()
  36. },
  37. /* onShow() {
  38. this.getUserInfo()
  39. }, */
  40. async getUserInfo() {
  41. let res = await getUserInfo({
  42. uid: this.data.uid
  43. })
  44. this.setData({
  45. userInfo: res
  46. })
  47. this.resetData()
  48. },
  49. loadMore() {
  50. this.getData(getUserRead, {
  51. uid: this.data.userInfo.user.uid,
  52. pageSize: 20
  53. })
  54. },
  55. // 关注
  56. async setFans() {
  57. if (wx.getStorageSync('uid') == this.data.uid) {
  58. return wx.showToast({
  59. title: '不可以关注自己哦~',
  60. icon: 'none'
  61. })
  62. }
  63. let newLike = !this.data.userInfo.like
  64. let res = await setFans({
  65. uid: this.data.userInfo.user.uid,
  66. }, 'put')
  67. this.setData({
  68. ['userInfo.like']: newLike
  69. })
  70. wx.showToast({
  71. title: newLike ? '已关注' : '取消关注',
  72. icon: 'none'
  73. })
  74. },
  75. clipboar() {
  76. wx.setClipboardData({
  77. data: this.data.userInfo.user.eid,
  78. success: function (res) { //成功回调函数
  79. wx.showToast({
  80. title: '已复制',
  81. icon: "none"
  82. })
  83. }
  84. })
  85. },
  86. toPkPage({
  87. currentTarget
  88. }) {
  89. if (this.data.userInfo.user.profession == '官方' || wx.getStorageSync('uid') == this.data.uid) {
  90. wx.navigateTo({
  91. url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
  92. })
  93. } else {
  94. wx.navigateTo({
  95. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  96. })
  97. }
  98. },
  99. sendMsg({
  100. currentTarget
  101. }) {
  102. let user = this.data.userInfo.user
  103. let {
  104. nickName,
  105. eid,
  106. uid
  107. } = user
  108. if (this.data.localUid == uid) {
  109. return wx.showToast({
  110. title: '不可以给自己发私信哦~',
  111. icon: 'none'
  112. })
  113. }
  114. wx.navigateTo({
  115. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  116. })
  117. },
  118. })