get-user-info.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: '获取用户信息',
  5. path: 'packageAPI/pages/api/get-user-info/get-user-info'
  6. }
  7. },
  8. data: {
  9. theme: 'light',
  10. hasUserInfo: false,
  11. canIUseGetUserProfile: false
  12. },
  13. getUserInfo(info) {
  14. console.log('getUserInfo')
  15. const userInfo = info.detail.userInfo
  16. this.setData({
  17. userInfo,
  18. hasUserInfo: true
  19. })
  20. },
  21. handleGetUserProfile(e) {
  22. console.log('getUserProfile')
  23. wx.getUserProfile({
  24. desc: '用于演示 wx.getUserProfile', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  25. success: (res) => {
  26. console.log('wx.getUserProfile: ', res.userInfo)
  27. this.setData({
  28. userInfo: res.userInfo,
  29. hasUserInfo: true
  30. })
  31. }
  32. })
  33. },
  34. clear() {
  35. this.setData({
  36. hasUserInfo: false,
  37. userInfo: {}
  38. })
  39. },
  40. onLoad() {
  41. this.setData({
  42. theme: wx.getSystemInfoSync().theme || 'light'
  43. })
  44. if (wx.onThemeChange) {
  45. wx.onThemeChange(({theme}) => {
  46. this.setData({theme})
  47. })
  48. }
  49. if (wx.getUserProfile) {
  50. this.setData({
  51. canIUseGetUserProfile: true
  52. })
  53. }
  54. }
  55. })