permission.js 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // 测试使用 账户密码登录页面,正式环境禁用
  23. if (to.path == '/logincs' && process.env.NODE_ENV == 'production') {
  24. next('/');
  25. } else {
  26. next();
  27. }
  28. // // 没有token
  29. // if (whiteList.indexOf(to.path) !== -1) {
  30. // // 在免登录白名单,直接进入
  31. // next();
  32. // } else {
  33. // next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
  34. // NProgress.done();
  35. // }
  36. }
  37. });