index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var user = require('../../../services/user.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. userInfo: {},
  8. isLogin: false
  9. },
  10. onLoad: function(options) {
  11. // 页面初始化 options为页面跳转所带来的参数
  12. console.log(app.globalData)
  13. },
  14. onReady: function() {
  15. },
  16. onShow: function() {
  17. let userInfo = wx.getStorageSync('userInfo');
  18. let token = wx.getStorageSync('token');
  19. // 页面显示
  20. if (userInfo && token) {
  21. app.globalData.userInfo = userInfo;
  22. app.globalData.token = token;
  23. this.setData({
  24. isLogin: true
  25. });
  26. }
  27. this.setData({
  28. userInfo: app.globalData.userInfo,
  29. });
  30. },
  31. onHide: function() {
  32. // 页面隐藏
  33. },
  34. onUnload: function() {
  35. // 页面关闭
  36. },
  37. goLogin() {
  38. if (!this.data.isLogin) {
  39. wx.navigateTo({
  40. url: '/pages/auth/auth'
  41. })
  42. }else{
  43. wx.navigateTo({
  44. url: '/pages/user/user?userId=' + app.globalData.userInfo.openId,
  45. })
  46. }
  47. },
  48. exitLogin: function() {
  49. wx.showModal({
  50. title: '',
  51. confirmColor: '#b4282d',
  52. content: '退出登录?',
  53. success: function(res) {
  54. if (res.confirm) {
  55. wx.removeStorageSync('token');
  56. wx.removeStorageSync('userInfo');
  57. wx.switchTab({
  58. url: '/pages/index/index'
  59. });
  60. }
  61. }
  62. })
  63. }
  64. })