蓝色 贷款产品助手

mine.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. userInfo: {},
  7. hasUserInfo: false,
  8. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  9. avatar_url: 'http://m.henhaojie.com/images/KX0004.png',
  10. nick_name: '点击授权登录'
  11. },
  12. onLoad: function () {
  13. if (app.globalData.userInfo) {
  14. this.setData({
  15. userInfo: app.globalData.userInfo,
  16. hasUserInfo: true,
  17. avatar_url: app.globalData.userInfo.avatar_url,
  18. nick_name: app.globalData.userInfo.nick_name
  19. })
  20. } else if (this.data.canIUse){
  21. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  22. // 所以此处加入 callback 以防止这种情况
  23. app.userInfoReadyCallback = res => {
  24. this.setData({
  25. userInfo: res.userInfo,
  26. hasUserInfo: true
  27. })
  28. }
  29. } else {
  30. // 在没有 open-type=getUserInfo 版本的兼容处理
  31. wx.getUserInfo({
  32. success: res => {
  33. wx.setStorageSync('userInfo', res.userInfo);
  34. app.globalData.userInfo = res.userInfo
  35. this.setData({
  36. userInfo: res.userInfo,
  37. hasUserInfo: true
  38. })
  39. }
  40. })
  41. }
  42. },
  43. getUserInfo: function(e) {
  44. const that = this, userInfo = {};
  45. console.log();
  46. userInfo.encryptedData = e.detail.encryptedData;
  47. userInfo.iv = e.detail.iv;
  48. // console.log(e.detail.userInfo);
  49. userInfo.avatar_url = e.detail.userInfo.avatarUrl;
  50. userInfo.nick_name = e.detail.userInfo.nickName;
  51. app.globalData.userInfo = userInfo;
  52. wx.setStorageSync('userInfo', userInfo);
  53. app.login(that);
  54. this.setData({
  55. userInfo: e.detail.userInfo,
  56. hasUserInfo: true,
  57. avatar_url: e.detail.userInfo.avatarUrl,
  58. nick_name: e.detail.userInfo.nickName
  59. })
  60. },
  61. initInfo() {
  62. var token = wx.getStorageSync('user').token, data = {}, that = this;
  63. console.log(token);
  64. if (token) {
  65. that.getInfo(token)
  66. } else {
  67. app.login(that, that.getInfo);
  68. }
  69. },
  70. getInfo(token) {
  71. var that = this, token = token || wx.getStorageSync('user').token, data = null;
  72. wx.request({
  73. url: app.globalData.HOST + '/user/wx/personalCenter',
  74. method: 'POST',
  75. data: { token: token },
  76. success: function (res) {
  77. if (res.data.errno == '0') {
  78. data = res.data.rst
  79. that.setData({ userInfo: data, avatar_url: data.user.avatar_url, nick_name: data.user.nick_name})
  80. } else if (res.data.errno == '90001') {
  81. }
  82. }
  83. });
  84. },
  85. goApplication() {
  86. var tel = wx.getStorageSync('tel') || '0', user_id = wx.getStorageSync('user').user_id || '0';
  87. console.log(user_id);
  88. console.log(tel);
  89. if (tel != '0' || user_id != '0') {
  90. wx.navigateTo({
  91. url: "/pages/application/application"
  92. })
  93. } else {
  94. wx.navigateTo({
  95. url: "/pages/getPhone/getPhone?from=mine"
  96. })
  97. }
  98. },
  99. goFeedback: function (e) {
  100. var tel = wx.getStorageSync('tel') || '0', user_id = wx.getStorageSync('user').user_id || '0';
  101. if (tel != '0' || user_id != '0') {
  102. wx.navigateTo({
  103. url: "/pages/feedback/feedback"
  104. })
  105. } else {
  106. wx.navigateTo({
  107. url: "/pages/getPhone/getPhone?from=mineFeedback"
  108. })
  109. }
  110. },
  111. onShareAppMessage: function () {
  112. return {
  113. title: app.globalData.title,
  114. imageUrl: app.globalData.img,
  115. path: '/pages/index/index',
  116. success: function(res) {
  117. app.noticeModal('分享成功')
  118. },
  119. fail: function(res) {
  120. app.noticeModal('您取消了分享')
  121. }
  122. }
  123. }
  124. })