|
|
@ -13,7 +13,7 @@ Page({ |
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
data: { |
|
|
|
messageTotal: Number, |
|
|
|
canIUse: wx.canIUse('button.open-type.getUserInfo'), |
|
|
|
authType:0, |
|
|
@ -24,7 +24,7 @@ Page({ |
|
|
|
userInfo:{ |
|
|
|
type:Object, |
|
|
|
value:{} |
|
|
|
}, |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -37,13 +37,23 @@ Page({ |
|
|
|
onShow: function () { |
|
|
|
console.log('啦啦啦') |
|
|
|
this.getUserInfo() |
|
|
|
if (store.hasPhone()) { |
|
|
|
console.log('已经绑定手机号码') |
|
|
|
this.getUserInfo() |
|
|
|
} else { |
|
|
|
console.log('未绑定手机号码') |
|
|
|
wx.redirectTo({ |
|
|
|
url: '/pages/register/index', |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
isAuthUserInfo(){ |
|
|
|
isAuthUserInfo () { |
|
|
|
let that = this |
|
|
|
wx.showLoading() |
|
|
|
return new Promise(resolve =>{ |
|
|
|
console.log('未授权') |
|
|
|
return new Promise(resolve => { |
|
|
|
wx.getSetting({ |
|
|
|
success(res) { |
|
|
|
success (res) { |
|
|
|
if (res.authSetting['scope.userInfo']) { |
|
|
|
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
|
|
|
|
wx.getUserInfo({ |
|
|
@ -55,13 +65,13 @@ Page({ |
|
|
|
store.saveUserInfo({ |
|
|
|
nickName: nickName, |
|
|
|
avatarUrl: avatarUrl, |
|
|
|
phone:'' |
|
|
|
phone: '' |
|
|
|
}) |
|
|
|
|
|
|
|
if(nickName && avatarUrl){ |
|
|
|
if (nickName && avatarUrl) { |
|
|
|
that.setData({ |
|
|
|
isAuth:false |
|
|
|
},()=>{ |
|
|
|
isAuth: false |
|
|
|
}, () => { |
|
|
|
wx.hideLoading() |
|
|
|
}) |
|
|
|
} |
|
|
@ -73,9 +83,9 @@ Page({ |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
bindGetUserInfo(e) { |
|
|
|
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 |
|
|
@ -85,44 +95,43 @@ Page({ |
|
|
|
this.updateUserInfo(avatarUrl, city, country, gender, nickName, province) |
|
|
|
this.isAuthUserInfo() |
|
|
|
}, |
|
|
|
hasBindUserInfo(){ |
|
|
|
hasBindUserInfo () { |
|
|
|
return store.hasBindUserInfo(); |
|
|
|
}, |
|
|
|
updateUserInfo(avatarUrl, city, country, gender, nickName, province){ |
|
|
|
userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province,res=>{ |
|
|
|
|
|
|
|
updateUserInfo (avatarUrl, city, country, gender, nickName, province) { |
|
|
|
userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province, res => { |
|
|
|
|
|
|
|
}) |
|
|
|
}, |
|
|
|
getUserInfo(){ |
|
|
|
userModel.getUserInfo(res=>{ |
|
|
|
getUserInfo () { |
|
|
|
userModel.getUserInfo(res => { |
|
|
|
let nickName = res.result.nickName |
|
|
|
let avatarUrl = res.result.avatarUrl |
|
|
|
|
|
|
|
if (nickName && avatarUrl){ |
|
|
|
console.log('已授权') |
|
|
|
console.log(res.result) |
|
|
|
let userInfo = res.result |
|
|
|
this.setData({ |
|
|
|
userInfo: res.result, |
|
|
|
avatarUrl: res.result.avatarUrl, |
|
|
|
nickName: res.result.nickName, |
|
|
|
reAuth:true |
|
|
|
reAuth: true |
|
|
|
}) |
|
|
|
store.saveUserInfo({ |
|
|
|
nickName: res.result.nickName, |
|
|
|
avatarUrl: res.result.avatarUrl, |
|
|
|
phone: res.result.phone === null ? '' : res.result.phone |
|
|
|
phone: res.result.phone || '' |
|
|
|
}) |
|
|
|
} else { |
|
|
|
console.log('未授权') |
|
|
|
this.setData({ |
|
|
|
isAuth:true |
|
|
|
isAuth: true |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
getMsgStatus(){ |
|
|
|
userModel.getMyMessageTotal(res=>{ |
|
|
|
getMsgStatus () { |
|
|
|
userModel.getMyMessageTotal(res => { |
|
|
|
console.log(res.result.total) |
|
|
|
this.setData({ |
|
|
|
messageTotal: Number(res.result.total) |
|
|
@ -130,17 +139,13 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
onTapItem (e) { |
|
|
|
const {type} = e.currentTarget.dataset |
|
|
|
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 || ''}`, |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.navigateTo({ |
|
|
|
url: `/pages/user/${type}/index`, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |