app.js 820 B

123456789101112131415161718192021222324252627282930313233
  1. // app.js
  2. App({
  3. onLaunch() {
  4. // 展示本地存储能力
  5. const logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. // 登录
  9. let token = wx.getStorageSync('token')
  10. let time = wx.getStorageSync('time')//登录时间
  11. let Time = new Date()//当前时间
  12. //console.log('时间差为' + parseInt(Time - time)/1000)
  13. let currentTime = wx.getStorageSync('currentTime')//过期时间
  14. if(token != ''){
  15. if(parseInt(Time - time)/1000 < currentTime){
  16. wx.switchTab({
  17. url: 'pages/scene/scene',
  18. })
  19. }
  20. else{
  21. }
  22. }
  23. wx.login({
  24. success: res => {
  25. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  26. }
  27. })
  28. },
  29. globalData: {
  30. userInfo: null
  31. },
  32. })