me.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import http from '../../base/httputil'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isShowAccoutDialog : false
  9. },
  10. init_userInfo() {
  11. let that = this
  12. if (app.globalToken == null) {
  13. http.showLoading()
  14. wx.getUserProfile({
  15. desc: 'desc',
  16. success: (res) => {
  17. this.getSysUserInfo(res.userInfo)
  18. },
  19. fail: res => {
  20. console.log(res)
  21. },
  22. })
  23. }
  24. },
  25. getSysUserInfo(info) {
  26. let that = this
  27. wx.login({
  28. success(res) {
  29. var code = res.code
  30. var data = {
  31. wxCode: code,
  32. wxNickName: info.nickName,
  33. wxAvatarUrl: info.avatarUrl
  34. }
  35. http.send_post("/auth/applogin", data, that.loginSuccess)
  36. },
  37. fail(res) {
  38. console.log("ffff", res)
  39. }
  40. })
  41. },
  42. loginSuccess(res) {
  43. console.log("rrrr",res)
  44. if (res.data.code != 200) {
  45. wx.showToast({
  46. title: res.data.msg,
  47. icon: "none"
  48. })
  49. this.setData({
  50. isShowAccoutDialog : true
  51. })
  52. } else {
  53. app.globalToken = res.data.data.access_token
  54. console.log("我的令牌:",app.globalToken )
  55. //登录成功,获取首页数据
  56. http.hideLoading()
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad(options) {
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady() {
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide() {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload() {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh() {
  88. },
  89. /**
  90. * 页面上拉触底事件的处理函数
  91. */
  92. onReachBottom() {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage() {
  98. }
  99. })