permission.js 841 B

1234567891011121314151617181920212223242526272829303132333435
  1. import router from './router';
  2. import store from './store';
  3. const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
  4. router.beforeEach((to, from, next) => {
  5. const username = localStorage.getItem('loginName');
  6. if (username) {
  7. /* has token*/
  8. if (!store.state.user.userInfo) {
  9. // 获取移动端获取用户信息接口
  10. store
  11. .dispatch('getUserInfo')
  12. .then(() => {
  13. next();
  14. })
  15. .catch(() => {
  16. next();
  17. });
  18. } else {
  19. next();
  20. }
  21. } else {
  22. next();
  23. // // 没有token
  24. // if (whiteList.indexOf(to.path) !== -1) {
  25. // // 在免登录白名单,直接进入
  26. // next();
  27. // } else {
  28. // next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
  29. // NProgress.done();
  30. // }
  31. }
  32. });