1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /*
- * @Author: jixiang
- * @Date: 2021-07-07 16:47:54
- * @Description: 权限
- * @FilePath: /suqian_account_new/src/permission.ts
- * One World One Drefeel(56580223@qq.com)
- */
- import router from './router';
- import { configure, start, done } from 'nprogress';
- import { RouteRecordRaw } from 'vue-router';
- import { getToken, setToken } from './utils/cookie';
- import { decode, encode, useLocal } from './utils/tools';
- import useLayoutStore from './store';
- configure({ showSpinner: false });
- const loginRoutePath = '/toCasLogin';
- const loginRoutePath2 = '/casLogin';
- const defaultRoutePath = '/bookManage';
- // const packagePath = '/bookManage';
- router.beforeEach(async (to, from) => {
- start();
- if (
- to.path.toLocaleLowerCase() === loginRoutePath.toLocaleLowerCase() ||
- to.path.toLocaleLowerCase() === loginRoutePath2.toLocaleLowerCase()
- ) {
- done();
- if (getToken())
- return typeof to.query.from === 'string' ? decode(to.query.from) : defaultRoutePath;
- return;
- }
- console.log(to.path.toLocaleLowerCase(), 'ddddd');
- // debugger;
- //判断是否是首页
- console.log('eeee', to.path.toLocaleLowerCase() == defaultRoutePath.toLocaleLowerCase());
- if (to.path.toLocaleLowerCase() == defaultRoutePath.toLocaleLowerCase()) {
- done();
- return;
- }
- console.log(getToken(), '是否登录');
- // 判断是否登录
- if (!getToken()) {
- router.push(loginRoutePath);
- // window.location.href = import.meta.env.VITE_APP_BOOK_STORE_URL as string;
- // return loginRoutePath + (to.fullPath ? `?from=${encode(to.fullPath)}` : '');
- }
- // 前端检查token是否失效
- // useLocal('token').then((d) => setToken(d.ACCESS_TOKEN));
- // .catch(() => logout());
- });
- router.afterEach(() => {
- done();
- });
|