permission.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. getDict(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. });
  33. const getDict = async function () {
  34. let gz_Option = await getDictOption({}, 'gz_customer_post'); //公装业务员岗位
  35. let jz_Option = await getDictOption({}, 'jz_post_name'); //家装业务员岗位
  36. let postName = store.state.user.userInfo.postName;
  37. if (gz_Option.indexof(postName) == -1 || jz_Option.indexof(postName) == -1) {
  38. localStorage.setItem('isGZorJZ', 'false');
  39. } else {
  40. localStorage.setItem('isGZorJZ', 'true');
  41. }
  42. next();
  43. };