1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import {
- getUserInfo,
- setFans,
- getUserRead
- } from '~/api/user'
- import share from '~/mixins/share'
- import reachBottom from '~/mixins/reachBottom'
- Page({
- behaviors: [reachBottom, share],
- /**
- * 页面的初始数据
- */
- data: {
- uid: '',
- userInfo: {},
- // type为pk,顶部显示为pk时样式,user为默认样式
- type: 'user',
- uid: '',
- localUid: wx.getStorageSync('uid')
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (wx.getStorageSync('uid') == options.uid) {
- wx.setNavigationBarTitle({
- title: '我的主页'
- })
- }
- this.setData({
- type: options.type || 'user',
- uid: options.uid
- })
- },
- onShow() {
- this.getUserInfo()
- },
- async getUserInfo() {
- let res = await getUserInfo({
- uid: this.data.uid
- })
- this.setData({
- userInfo: res
- })
- this.resetData()
- },
- loadMore() {
- this.getData(getUserRead, {
- uid: this.data.userInfo.user.uid,
- pageSize: 20
- })
- },
- // 关注
- async setFans() {
- if (wx.getStorageSync('uid') == this.data.uid) {
- return wx.showToast({
- title: '不可以关注自己哦~',
- icon: 'none'
- })
- }
- let newLike = !this.data.userInfo.like
- let res = await setFans({
- uid: this.data.userInfo.user.uid,
- }, 'put')
- this.setData({
- ['userInfo.like']: newLike
- })
- wx.showToast({
- title: newLike ? '已关注' : '取消关注',
- icon: 'none'
- })
- },
- toPkPage({
- currentTarget
- }) {
- if (this.data.userInfo.user.profession == '官方' || wx.getStorageSync('uid') == this.data.uid) {
- wx.navigateTo({
- url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
- })
- } else {
- wx.navigateTo({
- url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
- })
- }
- },
- })
|