与牧同行-小程序用户端
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.

52 lines
1.6 KiB

6 days ago
  1. // index.js
  2. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  3. Component({
  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. methods: {
  15. // 事件处理函数
  16. bindViewTap() {
  17. wx.navigateTo({
  18. url: '../logs/logs'
  19. })
  20. },
  21. onChooseAvatar(e) {
  22. const { avatarUrl } = e.detail
  23. const { nickName } = this.data.userInfo
  24. this.setData({
  25. "userInfo.avatarUrl": avatarUrl,
  26. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  27. })
  28. },
  29. onInputChange(e) {
  30. const nickName = e.detail.value
  31. const { avatarUrl } = this.data.userInfo
  32. this.setData({
  33. "userInfo.nickName": nickName,
  34. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  35. })
  36. },
  37. getUserProfile(e) {
  38. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  39. wx.getUserProfile({
  40. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  41. success: (res) => {
  42. console.log(res)
  43. this.setData({
  44. userInfo: res.userInfo,
  45. hasUserInfo: true
  46. })
  47. }
  48. })
  49. },
  50. },
  51. })