You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.4 KiB
125 lines
3.4 KiB
// pages/user/index.js
|
|
import dayjs from '../../utils/dayjs/index.js'
|
|
import relativeTime from '../../utils/dayjs/relativeTime.js'
|
|
dayjs.extend(relativeTime);
|
|
import { store } from '../../utils/store.js'
|
|
import { UserModel } from '../../models/user.js'
|
|
let userModel = new UserModel()
|
|
import { AuthModel } from '../../models/auth.js'
|
|
let authModel = new AuthModel()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
messageTotal: Number,
|
|
isAuth:false,
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
|
|
},
|
|
onShow: function () {
|
|
if (store.hasBindUserInfo()) {
|
|
console.log("onshow");
|
|
|
|
this.getUserInfo()
|
|
this.setData({
|
|
isAuth: true
|
|
})
|
|
} else {
|
|
this.setData({
|
|
isAuth: false
|
|
})
|
|
// wx.redirectTo({
|
|
// url: '/pages/weChatAuth/index',
|
|
// })
|
|
}
|
|
},
|
|
|
|
// 获取用户信息
|
|
getUserInfo () {
|
|
userModel.getUserInfo(res => {
|
|
console.log("getUserInfo");
|
|
|
|
console.log(res)
|
|
let nickName = res.result.nickName
|
|
let avatarUrl = res.result.avatarUrl
|
|
|
|
if (nickName && avatarUrl){
|
|
//console.log('已授权')
|
|
this.setData({
|
|
userInfo: res.result,
|
|
avatarUrl: res.result.avatarUrl,
|
|
nickName: res.result.nickName,
|
|
isAuth:true,
|
|
},()=>{
|
|
if (store.hasPhone()) {
|
|
//console.log('已经绑定手机号码')
|
|
this.getMsgStatus()
|
|
} else {
|
|
//console.log('未绑定手机号码')
|
|
wx.showModal({
|
|
title: '温馨提示',
|
|
content: '是否前往验证手机号码?',
|
|
success(res) {
|
|
if (res.confirm) {
|
|
wx.redirectTo({
|
|
url: '/pages/register/index',
|
|
})
|
|
} else if (res.cancel) {
|
|
wx.switchTab({
|
|
url: '/pages/home/index',
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
store.saveUserInfo({
|
|
nickName: res.result.nickName,
|
|
avatarUrl: res.result.avatarUrl,
|
|
phone: res.result.phone || ''
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 获取未读消息
|
|
getMsgStatus () {
|
|
userModel.getMyMessageTotal(res => {
|
|
//console.log(res.result.total)
|
|
this.setData({
|
|
messageTotal: Number(res.result.total)
|
|
})
|
|
})
|
|
},
|
|
|
|
// cell点击
|
|
onTapItem (e) {
|
|
const { type } = e.currentTarget.dataset
|
|
console.log(type)
|
|
|
|
if(this.data.isAuth){
|
|
if (type === 'myInfo') {
|
|
wx.navigateTo({
|
|
url: `/pages/user/${type}/index?userIcon=${this.data.userInfo.avatarUrl}&userName=${this.data.userInfo.nickName}&userPhone=${this.data.userInfo.phone || ''}&company=${this.data.userInfo.company || ''}&position=${this.data.userInfo.position || ''}&street=${this.data.userInfo.departId || ''}&age=${this.data.userInfo.age || ''}&genderIndex=${this.data.userInfo.gender || ''}&education=${this.data.userInfo.education || ''}&professionalTitle=${this.data.userInfo.title || ''}&talentTitle=${this.data.userInfo.designation || ''}&prize=${this.data.userInfo.honor || ''}`,
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: `/pages/user/${type}/index`,
|
|
})
|
|
}
|
|
} else {
|
|
wx.redirectTo({
|
|
url: '/pages/weChatAuth/index',
|
|
})
|
|
}
|
|
}
|
|
})
|