permission.js 933 B

12345678910111213141516171819202122232425262728293031323334353637
  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. // 测试使用 账户密码登录页面,正式环境禁用
  11. if (to.path == '/logincs' && process.env.NODE_ENV == 'production') {
  12. next('/');
  13. } else {
  14. if (username) {
  15. /* has token*/
  16. if (!store.state.user.userInfo) {
  17. // 获取移动端获取用户信息接口
  18. store
  19. .dispatch('getUserInfo')
  20. .then(() => {
  21. next();
  22. })
  23. .catch(() => {
  24. next();
  25. });
  26. } else {
  27. next();
  28. }
  29. } else {
  30. alert('获取签名失败');
  31. next();
  32. }
  33. }
  34. });