|
|
@@ -16,13 +16,17 @@ const router = createRouter({
|
|
|
},
|
|
|
|
|
|
// 登录与注册
|
|
|
+ // {
|
|
|
+ // path: "/",
|
|
|
+ // redirect: () => {
|
|
|
+ // window.location.href = "https://p-nju.seec.seecoder.cn/login?from=https://air.seec.seecoder.cn/";
|
|
|
+ // // {本地门户首页地址}?from={本地eai首页地址}
|
|
|
+ // return "/"; // 占位返回值,实际不会执行
|
|
|
+ // },
|
|
|
+ // },
|
|
|
{
|
|
|
path: "/",
|
|
|
- redirect: () => {
|
|
|
- window.location.href = "https://p-nju.seec.seecoder.cn/login?from=https://air.seec.seecoder.cn/";
|
|
|
- // {本地门户首页地址}?from={本地eai首页地址}
|
|
|
- return "/"; // 占位返回值,实际不会执行
|
|
|
- },
|
|
|
+ redirect: "/login"
|
|
|
},
|
|
|
{
|
|
|
path: '/login',
|
|
|
@@ -180,54 +184,149 @@ const router = createRouter({
|
|
|
]
|
|
|
})
|
|
|
|
|
|
-/*
|
|
|
- 路由守卫
|
|
|
- */
|
|
|
- router.beforeEach(async (to) => {
|
|
|
- const store = useStore();
|
|
|
- const publicPaths = ['/login', '/register', '/passwordChange', '/admin/login'];
|
|
|
- // 1. 检查URL中的token
|
|
|
- const urlToken = new URLSearchParams(window.location.search).get('token');
|
|
|
- if (urlToken) {
|
|
|
- try {
|
|
|
- // 等待 token 验证完成
|
|
|
- const res = await authApis.authToken(urlToken || store.token);
|
|
|
- const data = res.data.data;
|
|
|
- // 存储用户状态
|
|
|
- store.setUser(data);
|
|
|
- store.setToken(data?.token);
|
|
|
- localStorage.setItem('Authorization', data?.token);
|
|
|
- localStorage.setItem('User', JSON.stringify(data));
|
|
|
- // 清除 URL 中的 token
|
|
|
- if (urlToken) {
|
|
|
- window.history.replaceState({}, '', to.path);
|
|
|
- }
|
|
|
+// /*
|
|
|
+// 路由守卫
|
|
|
+// */
|
|
|
+// router.beforeEach(async (to) => {
|
|
|
+// const store = useStore();
|
|
|
+// const publicPaths = ['/login', '/register', '/passwordChange', '/admin/login'];
|
|
|
+// // 1. 检查URL中的token
|
|
|
+// const urlToken = new URLSearchParams(window.location.search).get('token');
|
|
|
+// if (urlToken) {
|
|
|
+// try {
|
|
|
+// // 等待 token 验证完成
|
|
|
+// const res = await authApis.authToken(urlToken || store.token);
|
|
|
+// const data = res.data.data;
|
|
|
+// // 存储用户状态
|
|
|
+// store.setUser(data);
|
|
|
+// store.setToken(data?.token);
|
|
|
+// localStorage.setItem('Authorization', data?.token);
|
|
|
+// localStorage.setItem('User', JSON.stringify(data));
|
|
|
+// // 清除 URL 中的 token
|
|
|
+// if (urlToken) {
|
|
|
+// window.history.replaceState({}, '', to.path);
|
|
|
+// }
|
|
|
|
|
|
- // 如果当前路径是公开路径,允许继续;否则跳转到首页
|
|
|
- if (!publicPaths.includes(to.path)) {
|
|
|
- return '/home';
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('Token验证失败:', error);
|
|
|
- // 验证失败,清除无效的 token
|
|
|
- store.setUser(null);
|
|
|
- store.setToken(null);
|
|
|
- localStorage.removeItem('Authorization');
|
|
|
- localStorage.removeItem('User');
|
|
|
- }
|
|
|
- }
|
|
|
+// // 如果当前路径是公开路径,允许继续;否则跳转到首页
|
|
|
+// if (!publicPaths.includes(to.path)) {
|
|
|
+// return '/home';
|
|
|
+// }
|
|
|
+// } catch (error) {
|
|
|
+// console.error('Token验证失败:', error);
|
|
|
+// // 验证失败,清除无效的 token
|
|
|
+// store.setUser(null);
|
|
|
+// store.setToken(null);
|
|
|
+// localStorage.removeItem('Authorization');
|
|
|
+// localStorage.removeItem('User');
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- if (publicPaths.includes(to.path)) return true;
|
|
|
+// if (publicPaths.includes(to.path)) return true;
|
|
|
|
|
|
- if (!store.user?.role) {
|
|
|
- return '/login';
|
|
|
- }
|
|
|
+// if (!store.user?.role) {
|
|
|
+// return '/login';
|
|
|
+// }
|
|
|
|
|
|
- if (to.meta?.roles && !to.meta.roles.includes(store.user.role)) {
|
|
|
- return '/login';
|
|
|
- }
|
|
|
+// if (to.meta?.roles && !to.meta.roles.includes(store.user.role)) {
|
|
|
+// return '/login';
|
|
|
+// }
|
|
|
|
|
|
- return true;
|
|
|
- });
|
|
|
+// return true;
|
|
|
+// });
|
|
|
|
|
|
export default router
|
|
|
+
|
|
|
+// import { createRouter, createWebHistory } from 'vue-router'
|
|
|
+
|
|
|
+// const router = createRouter({
|
|
|
+// history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
+// routes: [
|
|
|
+// {
|
|
|
+// path: "/",
|
|
|
+// redirect: "/login"
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: '/login',
|
|
|
+// name: 'login',
|
|
|
+// component: () => import('../views/LoginPage/LoginPage.vue')
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: '/register',
|
|
|
+// name: 'register',
|
|
|
+// component: () => import('../views/LoginPage/RegisterPage.vue')
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: '/course',
|
|
|
+// name: 'course',
|
|
|
+// component: () => import('../views/CoursePage/CoursePage.vue')
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: '/home',
|
|
|
+// name: 'home',
|
|
|
+// redirect: '/home/courseSquare',
|
|
|
+// component: () => import('../layout/Layout/Layout.vue'),
|
|
|
+// children: [
|
|
|
+// {
|
|
|
+// path: 'courseSquare',
|
|
|
+// name: 'courseSquare',
|
|
|
+// component: () => import("../views/CourseSquare/index.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'courseDetail/:courseId',
|
|
|
+// name: 'courseDetail',
|
|
|
+// component: () => import("../views/CourseSquare/component/CourseDetails/index.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'moreCourse',
|
|
|
+// name: 'moreCourse',
|
|
|
+// component: () => import("../views/CourseSquare/component/AllCourse/MoreCourse.vue"),
|
|
|
+// props(route) {
|
|
|
+// return route.query
|
|
|
+// },
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'myCourse',
|
|
|
+// name: 'myCourse',
|
|
|
+// component: () => import("../views/CoursePage/CoursePage.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'myHomework',
|
|
|
+// name: 'myHomework',
|
|
|
+// component: () => import("@/views/HomeworkPage/index.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'homeworkDetail/:assignmentId',
|
|
|
+// name: 'homeworkDetail',
|
|
|
+// component: () => import("@/views/HomeworkPage/component/HomeworkDetail.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'assignment/:assignmentId/edit',
|
|
|
+// name: 'edit',
|
|
|
+// component: () => import('../views/EditPage/EditPage.vue')
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'assignment/:assignmentId/correct',
|
|
|
+// name: 'correct',
|
|
|
+// component: () => import('../views/CorrectPage/CorrectPage.vue')
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'myCorrect/course',
|
|
|
+// name: 'myCorrectWithCourse',
|
|
|
+// component: () => import("@/views/CorrectPage/CoursePage.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'myCorrect/assignment',
|
|
|
+// name: 'myCorrectWithAssignment',
|
|
|
+// component: () => import("@/views/CorrectPage/AssignmentPage.vue")
|
|
|
+// },
|
|
|
+// {
|
|
|
+// path: 'myCorrect/assignment/:assignmentId',
|
|
|
+// name: 'myCorrectWithAssignmentId',
|
|
|
+// component: () => import("@/views/CorrectPage/CorrectAssignmentPage.vue")
|
|
|
+// },
|
|
|
+// ]
|
|
|
+// },
|
|
|
+// ]
|
|
|
+// })
|
|
|
+
|
|
|
+// export default router
|