autoLogin.js 991 B

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