permission.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. let queryLoginName = to.query.loginName || null;
  6. if (queryLoginName) {
  7. localStorage.setItem('loginName', queryLoginName);
  8. }
  9. const username = localStorage.getItem('loginName');
  10. if (username) {
  11. /* has token*/
  12. if (!store.state.user.userInfo) {
  13. // 获取移动端获取用户信息接口
  14. store
  15. .dispatch('getUserInfo')
  16. .then(() => {
  17. next();
  18. })
  19. .catch(() => {
  20. next();
  21. });
  22. } else {
  23. next();
  24. }
  25. } else {
  26. // 测试使用 账户密码登录页面,正式环境禁用
  27. if (to.path == '/logincs' && process.env.NODE_ENV == 'production') {
  28. next('/');
  29. } else {
  30. next();
  31. }
  32. // // 没有token
  33. // if (whiteList.indexOf(to.path) !== -1) {
  34. // // 在免登录白名单,直接进入
  35. // next();
  36. // } else {
  37. // next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
  38. // NProgress.done();
  39. // }
  40. }
  41. });