2025-06-16 14:42:26 +08:00
|
|
|
/*
|
2025-06-23 03:16:55 -04:00
|
|
|
* @Author: RenXiaoDong
|
|
|
|
|
* @Date: 2025-06-22 22:59:16
|
2025-06-16 14:42:26 +08:00
|
|
|
*/
|
2025-06-23 03:16:55 -04:00
|
|
|
import type { Router } from 'vue-router';
|
|
|
|
|
import NProgress from 'nprogress';
|
|
|
|
|
import { goUserLogin } from '@/utils/user';
|
2025-06-16 14:42:26 +08:00
|
|
|
|
|
|
|
|
import { useUserStore } from '@/stores/modules/user';
|
|
|
|
|
|
|
|
|
|
export default function setupUserLoginInfoGuard(router: Router) {
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
|
|
NProgress.start();
|
|
|
|
|
const userStore = useUserStore();
|
2025-06-23 03:16:55 -04:00
|
|
|
|
|
|
|
|
const requireLogin = to?.meta?.requireLogin || 0;
|
|
|
|
|
const isLogin = !!userStore.isLogin;
|
|
|
|
|
|
|
|
|
|
if (requireLogin === 1 && !isLogin) {
|
|
|
|
|
goUserLogin();
|
|
|
|
|
next();
|
|
|
|
|
return;
|
2025-06-16 14:42:26 +08:00
|
|
|
}
|
2025-06-23 03:16:55 -04:00
|
|
|
|
|
|
|
|
next();
|
2025-06-16 14:42:26 +08:00
|
|
|
});
|
|
|
|
|
}
|