setting.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const types = ['default', 'primary', 'warn']
  2. //获取应用实例
  3. const app = getApp()
  4. const pageObject = {
  5. data: {
  6. userInfo: {},
  7. hasUserInfo: false,
  8. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  9. defaultSize: 'default',
  10. primarySize: 'default',
  11. warnSize: 'default',
  12. disabled: false,
  13. plain: false,
  14. loading: false
  15. },
  16. onLoad: function () {
  17. // console.log("****************onLoad setting******************");
  18. if (app.globalData.userInfo) {
  19. this.setData({
  20. userInfo: app.globalData.userInfo,
  21. hasUserInfo: true
  22. })
  23. } else if (this.data.canIUse) {
  24. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  25. // 所以此处加入 callback 以防止这种情况
  26. app.userInfoReadyCallback = res => {
  27. this.setData({
  28. userInfo: res.userInfo,
  29. hasUserInfo: true
  30. })
  31. }
  32. } else {
  33. // 在没有 open-type=getUserInfo 版本的兼容处理
  34. wx.getUserInfo({
  35. success: res => {
  36. app.globalData.userInfo = res.userInfo
  37. this.setData({
  38. userInfo: res.userInfo,
  39. hasUserInfo: true
  40. })
  41. }
  42. })
  43. }
  44. console.log("user info:" + app.globalData.userInfo);
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. // console.log("onReady setting @@@@@@@@@@@@@@@@@");
  51. },
  52. /**
  53. * 生命周期函数--监听页面显示
  54. */
  55. onShow: function () {
  56. // console.log("*************onShow setting****************");
  57. if (app.globalData.userInfo) {
  58. this.setData({
  59. userInfo: app.globalData.userInfo,
  60. hasUserInfo: true
  61. })
  62. } else if (this.data.canIUse) {
  63. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  64. // 所以此处加入 callback 以防止这种情况
  65. app.userInfoReadyCallback = res => {
  66. this.setData({
  67. userInfo: res.userInfo,
  68. hasUserInfo: true
  69. })
  70. }
  71. } else {
  72. // 在没有 open-type=getUserInfo 版本的兼容处理
  73. wx.getUserInfo({
  74. success: res => {
  75. app.globalData.userInfo = res.userInfo
  76. this.setData({
  77. userInfo: res.userInfo,
  78. hasUserInfo: true
  79. })
  80. }
  81. })
  82. }
  83. // console.log("user info:" + app.globalData.userInfo);
  84. },
  85. }
  86. Page(pageObject)