index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. },
  9. onLoad: function (options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. console.log(app.globalData)
  12. },
  13. onReady: function () {
  14. },
  15. onShow: function () {
  16. // 页面显示
  17. if (app.globalData.userInfo) {
  18. this.setData({
  19. userInfo: app.globalData.userInfo
  20. });
  21. }
  22. },
  23. onHide: function () {
  24. // 页面隐藏
  25. },
  26. onUnload: function () {
  27. // 页面关闭
  28. },
  29. goLogin(){
  30. user.loginByWeixin().then(res => {
  31. this.setData({
  32. userInfo: res.data.userInfo
  33. });
  34. app.globalData.userInfo = res.data.userInfo;
  35. app.globalData.token = res.data.token;
  36. }).catch((err) => {
  37. console.log(err)
  38. });
  39. },
  40. exitLogin: function () {
  41. wx.showModal({
  42. title: '',
  43. confirmColor: '#b4282d',
  44. content: '退出登录?',
  45. success: function (res) {
  46. if (res.confirm) {
  47. wx.removeStorageSync('token');
  48. wx.removeStorageSync('userInfo');
  49. wx.switchTab({
  50. url: '/pages/index/index'
  51. });
  52. }
  53. }
  54. })
  55. }
  56. })