style: 💄 代碼統一格式化
Former-commit-id: 7639f722803b80a3e1391f9652430d8e759e1a64
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import router from '@/router';
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
import { usePermissionStoreHook } from '@/store/modules/permission';
|
||||
import router from "@/router";
|
||||
import { useUserStoreHook } from "@/store/modules/user";
|
||||
import { usePermissionStoreHook } from "@/store/modules/permission";
|
||||
|
||||
import NProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
import NProgress from "nprogress";
|
||||
import "nprogress/nprogress.css";
|
||||
NProgress.configure({ showSpinner: false }); // 进度条
|
||||
|
||||
const permissionStore = usePermissionStoreHook();
|
||||
|
||||
// 白名单路由
|
||||
const whiteList = ['/login'];
|
||||
const whiteList = ["/login"];
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start();
|
||||
const hasToken = localStorage.getItem('accessToken');
|
||||
const hasToken = localStorage.getItem("accessToken");
|
||||
if (hasToken) {
|
||||
if (to.path === '/login') {
|
||||
if (to.path === "/login") {
|
||||
// 如果已登录,跳转首页
|
||||
next({ path: '/' });
|
||||
next({ path: "/" });
|
||||
NProgress.done();
|
||||
} else {
|
||||
const userStore = useUserStoreHook();
|
||||
@@ -25,7 +25,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (hasRoles) {
|
||||
// 未匹配到任何路由,跳转404
|
||||
if (to.matched.length === 0) {
|
||||
from.name ? next({ name: from.name }) : next('/404');
|
||||
from.name ? next({ name: from.name }) : next("/404");
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
try {
|
||||
const { roles } = await userStore.getInfo();
|
||||
const accessRoutes = await permissionStore.generateRoutes(roles);
|
||||
accessRoutes.forEach(route => {
|
||||
accessRoutes.forEach((route) => {
|
||||
router.addRoute(route);
|
||||
});
|
||||
next({ ...to, replace: true });
|
||||
|
||||
Reference in New Issue
Block a user