permission.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * @Author: jixiang
  3. * @Date: 2021-07-07 16:47:54
  4. * @Description: 权限
  5. * @FilePath: /suqian_account_new/src/permission.ts
  6. * One World One Drefeel(56580223@qq.com)
  7. */
  8. import router from './router';
  9. import { configure, start, done } from 'nprogress';
  10. import { RouteRecordRaw } from 'vue-router';
  11. import { getToken, setToken } from './utils/cookie';
  12. import { decode, encode, useLocal } from './utils/tools';
  13. import useLayoutStore from './store';
  14. configure({ showSpinner: false });
  15. const loginRoutePath = '/toCasLogin';
  16. const loginRoutePath2 = '/casLogin';
  17. const defaultRoutePath = '/bookManage';
  18. // const packagePath = '/bookManage';
  19. router.beforeEach(async (to, from) => {
  20. start();
  21. if (
  22. to.path.toLocaleLowerCase() === loginRoutePath.toLocaleLowerCase() ||
  23. to.path.toLocaleLowerCase() === loginRoutePath2.toLocaleLowerCase()
  24. ) {
  25. done();
  26. if (getToken())
  27. return typeof to.query.from === 'string' ? decode(to.query.from) : defaultRoutePath;
  28. return;
  29. }
  30. console.log(to.path.toLocaleLowerCase(), 'ddddd');
  31. // debugger;
  32. //判断是否是首页
  33. console.log('eeee', to.path.toLocaleLowerCase() == defaultRoutePath.toLocaleLowerCase());
  34. if (to.path.toLocaleLowerCase() == defaultRoutePath.toLocaleLowerCase()) {
  35. done();
  36. return;
  37. }
  38. console.log(getToken(), '是否登录');
  39. // 判断是否登录
  40. if (!getToken()) {
  41. router.push(loginRoutePath);
  42. // window.location.href = import.meta.env.VITE_APP_BOOK_STORE_URL as string;
  43. // return loginRoutePath + (to.fullPath ? `?from=${encode(to.fullPath)}` : '');
  44. }
  45. // 前端检查token是否失效
  46. // useLocal('token').then((d) => setToken(d.ACCESS_TOKEN));
  47. // .catch(() => logout());
  48. });
  49. router.afterEach(() => {
  50. done();
  51. });