市北人才赋能平台 --小程序端
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.
 

151 lines
3.9 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,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
authType:0,
reAuth:false,
isAuth:false,
nickName:'',
avatarUrl:'',
userInfo:{
type:Object,
value:{}
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onShow: function () {
console.log('啦啦啦')
this.getUserInfo()
if (store.hasPhone()) {
console.log('已经绑定手机号码')
this.getUserInfo()
} else {
console.log('未绑定手机号码')
wx.redirectTo({
url: '/pages/register/index',
})
}
},
isAuthUserInfo () {
let that = this
wx.showLoading()
console.log('未授权')
return new Promise(resolve => {
wx.getSetting({
success (res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success: function (res) {
let nickName = res.userInfo.nickName
let avatarUrl = res.userInfo.avatarUrl
store.saveUserInfo({
nickName: nickName,
avatarUrl: avatarUrl,
phone: ''
})
if (nickName && avatarUrl) {
that.setData({
isAuth: false
}, () => {
wx.hideLoading()
})
}
that.getUserInfo()
}
})
}
}
})
})
},
bindGetUserInfo (e) {
console.log(e.detail.userInfo)
let avatarUrl = e.detail.userInfo.avatarUrl
let city = e.detail.userInfo.city
let country = e.detail.userInfo.country
let gender = e.detail.userInfo.gender
let nickName = e.detail.userInfo.nickName
let province = e.detail.userInfo.province
this.updateUserInfo(avatarUrl, city, country, gender, nickName, province)
this.isAuthUserInfo()
},
hasBindUserInfo () {
return store.hasBindUserInfo();
},
updateUserInfo (avatarUrl, city, country, gender, nickName, province) {
userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province, res => {
})
},
getUserInfo () {
userModel.getUserInfo(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,
reAuth: true
})
store.saveUserInfo({
nickName: res.result.nickName,
avatarUrl: res.result.avatarUrl,
phone: res.result.phone || ''
})
} else {
console.log('未授权')
this.setData({
isAuth: true
})
}
})
},
getMsgStatus () {
userModel.getMyMessageTotal(res => {
console.log(res.result.total)
this.setData({
messageTotal: Number(res.result.total)
})
})
},
onTapItem (e) {
const { type } = e.currentTarget.dataset
console.log(type)
console.log(this.data.userInfo)
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 || ''}`,
})
}
}
})