2022-08-16 23:30:23 +08:00
|
|
|
|
import router from '@/routers/router';
|
|
|
|
|
import NProgress from '@/config/nprogress';
|
|
|
|
|
import { GlobalStore } from '@/store';
|
|
|
|
|
import { AxiosCanceler } from '@/api/helper/axios-cancel';
|
|
|
|
|
|
|
|
|
|
const axiosCanceler = new AxiosCanceler();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 路由拦截 beforeEach(路由配置无数种方法,个人觉得最简便)
|
|
|
|
|
* */
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
NProgress.start();
|
|
|
|
|
axiosCanceler.removeAllPending();
|
|
|
|
|
|
|
|
|
|
if (!to.matched.some((record) => record.meta.requiresAuth)) return next();
|
|
|
|
|
|
|
|
|
|
const globalStore = GlobalStore();
|
|
|
|
|
if (!globalStore.isLogin) {
|
|
|
|
|
next({
|
2023-04-14 18:54:34 +08:00
|
|
|
|
name: 'login',
|
|
|
|
|
params: { code: globalStore.entrance },
|
2022-08-16 23:30:23 +08:00
|
|
|
|
});
|
|
|
|
|
NProgress.done();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.afterEach(() => {
|
|
|
|
|
NProgress.done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|