index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. })