index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.isLogin) {
  39. wx.navigateTo({
  40. url: '/pages/auth/auth'
  41. })
  42. }
  43. },
  44. exitLogin: function() {
  45. wx.showModal({
  46. title: '',
  47. confirmColor: '#b4282d',
  48. content: '退出登录?',
  49. success: function(res) {
  50. if (res.confirm) {
  51. wx.removeStorageSync('token');
  52. wx.removeStorageSync('userInfo');
  53. wx.switchTab({
  54. url: '/pages/index/index'
  55. });
  56. }
  57. }
  58. })
  59. }
  60. })