me.js 607 B

123456789101112131415161718192021222324252627282930
  1. // pages/me/me.js
  2. import * as requestAPI from '../../models/dataModel'
  3. Page({
  4. data: {
  5. isLogin: false,
  6. userName: ''
  7. },
  8. onLoad: function (options) {
  9. },
  10. onShow() {
  11. if(wx.getStorageSync('token') && !this.data.userName) {
  12. requestAPI.getUserInfo().then(res => {
  13. wx.setStorageSync('userName', res.data.data.sysUser.username);
  14. this.setData({
  15. userName: res.data.data.sysUser.username,
  16. isLogin: true
  17. })
  18. })
  19. }
  20. },
  21. login() {
  22. if(!this.data.isLogin) {
  23. wx.navigateTo({
  24. url: '/pages/login/login',
  25. })
  26. }
  27. }
  28. })