autoLogin.js 834 B

123456789101112131415161718192021222324252627
  1. import util from './util.js';
  2. import { login } from '../api/user.js';
  3. import { logout } from '../api/api.js';
  4. export default function authLogin(login_type) {
  5. return new Promise((reslove, reject) => {
  6. util.autoLogin().then(userInfo => {
  7. if (login_type !== undefined) {
  8. userInfo.login_type = 'routine';
  9. }
  10. login(userInfo).then(res => {
  11. getApp().globalData.token = res.data.token;
  12. getApp().globalData.userInfo = res.data.userInfo;
  13. getApp().globalData.isLog = true;
  14. getApp().globalData.expiresTime = res.data.expires_time;
  15. if (res.data.cache_key) {
  16. wx.setStorage({ key: 'cache_key', data: res.data.cache_key });
  17. }
  18. reslove();
  19. }).catch(err => {
  20. reject();
  21. });
  22. }).catch(err=>{
  23. reject();
  24. });
  25. })
  26. }