permission.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Vue from 'vue';
  2. import router from './router';
  3. import store from './store';
  4. // 微信JSSDK实例
  5. const wx = Vue.prototype.wx;
  6. const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
  7. router.beforeEach((to, from, next) => {
  8. const username = localStorage.getItem('loginName');
  9. if (username) {
  10. /* has token*/
  11. if (!store.state.user.userInfo) {
  12. // 获取移动端获取用户信息接口
  13. store
  14. .dispatch('getUserInfo')
  15. .then(() => {
  16. next();
  17. })
  18. .catch(() => {
  19. next();
  20. });
  21. } else {
  22. next();
  23. }
  24. } else {
  25. // 测试使用 账户密码登录页面,正式环境禁用
  26. if (to.path == '/login') {
  27. next();
  28. } else {
  29. alert('当前用户没有权限');
  30. wx.closeWindow();
  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. });