12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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'
- })
- },
- clipboar() {
- wx.setClipboardData({
- data: this.data.userInfo.user.eid,
- success: function (res) { //成功回调函数
- wx.showToast({
- title: '已复制',
- 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}`
- })
- }
- },
- })
|