index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // index.js
  2. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  3. Page({
  4. data: {
  5. motto: 'Hello World',
  6. userInfo: {
  7. avatarUrl: defaultAvatarUrl,
  8. nickName: '',
  9. },
  10. hasUserInfo: false,
  11. canIUseGetUserProfile: wx.canIUse('getUserProfile'),
  12. canIUseNicknameComp: wx.canIUse('input.type.nickname'),
  13. },
  14. bindViewTap() {
  15. wx.navigateTo({
  16. url: '../logs/logs'
  17. })
  18. },
  19. onChooseAvatar(e) {
  20. const { avatarUrl } = e.detail
  21. const { nickName } = this.data.userInfo
  22. console.log("获取头像",e,this.data.userInfo)
  23. this.setData({
  24. "userInfo.avatarUrl": avatarUrl,
  25. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  26. })
  27. },
  28. onInputChange(e) {
  29. const nickName = e.detail.value
  30. const { avatarUrl } = this.data.userInfo
  31. console.log("获取名称",e,this.data.userInfo)
  32. this.setData({
  33. "userInfo.nickName": nickName,
  34. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  35. })
  36. },
  37. getUserProfile(e) {
  38. console.log("获取信息",e)
  39. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  40. debugger
  41. wx.getUserProfile({
  42. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  43. success: (res) => {
  44. debugger
  45. console.log("getUserProfile : "+res)
  46. this.setData({
  47. userInfo: res.userInfo,
  48. hasUserInfo: true
  49. })
  50. }
  51. })
  52. },
  53. })