permission.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import router from './router'
  2. import { MessageBox } from 'element-ui';
  3. import { getToken, setToken } from '@/utils/auth' // getToken from cookie
  4. import { lockStatus,unlock } from "@/api/allApi";
  5. //路由跳转之前
  6. router.beforeEach((to, _from, next) => {
  7. const path = to.path;
  8. const Authorization = to.query.Authorization
  9. if (path.indexOf('auth') != -1 && Authorization) {
  10. setToken(Authorization);
  11. // console.log(Authorization);
  12. next({ path: '/' });
  13. }else{
  14. const token = getToken();
  15. if( token && token != 'undefined' ){
  16. lockStatus().then(response=>{
  17. let lockStatus = response.data.data;
  18. if(lockStatus==0){
  19. MessageBox.alert('欢迎来到DGT积分商城系统,以为您发放工龄年限积分,请前往个人中心查看。', '积分发放通知', {
  20. confirmButtonText: '确定',
  21. showClose:false,
  22. callback: action => {
  23. unlock().then(response=>{
  24. next();
  25. })
  26. }
  27. });
  28. }else{
  29. next();
  30. }
  31. })
  32. }else{
  33. const prodHref = 'http://dgtcloud.dgtis.com/oneportal/login';//发布地址
  34. const devHref = 'http://192.168.100.208:8080/oneportal/login';//测试地址
  35. location.href = process.env.NODE_ENV === 'production' ? prodHref : devHref;
  36. }
  37. }
  38. })
  39. router.afterEach(() => {})