Browse Source

fix:bug修复

廖彦舟 1 year ago
parent
commit
21a54be15e

+ 1 - 1
src/apis/axios.config.ts

@@ -1,7 +1,7 @@
 import axios from "axios";
 import axios from "axios";
 
 
 // const BASEURL = 'http://47.111.23.171:8081'
 // const BASEURL = 'http://47.111.23.171:8081'
-// const BASEURL = 'http://localhost:8080'
+// const BASEURL = 'http://localhost:8082'
 // const BASEURL = 'http://8.130.126.86:8080'
 // const BASEURL = 'http://8.130.126.86:8080'
 const BASEURL = 'https://air.seec.seecoder.cn/'
 const BASEURL = 'https://air.seec.seecoder.cn/'
 
 

+ 53 - 151
src/router/index.ts

@@ -16,17 +16,14 @@ 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: "/",
       path: "/",
-      redirect: "/login"
+      redirect: () => {
+        // window.location.href = "https://p-nju.seec.seecoder.cn/login?from=https://air.seec.seecoder.cn/";
+        window.location.href = "http://localhost:8000/login?from=http://localhost:4000/";
+        // {本地门户首页地址}?from={本地eai首页地址}
+        return "/"; // 占位返回值,实际不会执行
+    },
     },
     },
     {
     {
       path: '/login',
       path: '/login',
@@ -35,7 +32,7 @@ const router = createRouter({
     },
     },
     {
     {
       path: '/register',
       path: '/register',
-      name: 'register', 
+      name: 'register',
       component: () => import('../views/LoginPage/RegisterPage.vue')
       component: () => import('../views/LoginPage/RegisterPage.vue')
     },
     },
     {
     {
@@ -184,149 +181,54 @@ 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 true;
-  
-//     if (!store.user?.role) {
-//       return '/login';
-//     }
-  
-//     if (to.meta?.roles && !to.meta.roles.includes(store.user.role)) {
-//       return '/login';
-//     }
-  
-//     return true;
-//   });
+        // 如果当前路径是公开路径,允许继续;否则跳转到首页
+        // 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');
+    }
+    }
 
 
-export default router
+    if (publicPaths.includes(to.path)) return true;
 
 
-// import { createRouter, createWebHistory } from 'vue-router'
+    if (!store.user?.role) {
+      return '/login';
+    }
 
 
-// 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")
-//         },
-//       ]
-//     },
-//   ]
-// })
+    if (to.meta?.roles && !(to.meta.roles as string[]).includes(store.user.role)) {
+      return '/login';
+    }
 
 
-// export default router
+    return true;
+  });
+
+export default router

+ 3 - 3
src/views/CorrectPage/CorrectAssignmentPage.vue

@@ -123,7 +123,7 @@ import {Refresh, ZoomIn, ArrowLeft} from "@element-plus/icons-vue";
   }
   }
 
 
   const handleCorrect = (assignmentId:number, studentId:number) => {
   const handleCorrect = (assignmentId:number, studentId:number) => {
-    if(assignmentInfo.type === '写作'){
+    if(assignmentInfo.type === '写作' || assignmentInfo.type === 'writing'){
       router.push(`/home/myCorrect/assignment/${assignmentId}`)
       router.push(`/home/myCorrect/assignment/${assignmentId}`)
       //第二次路由跳转至教师批改界面,并传递了该作业的srudentId
       //第二次路由跳转至教师批改界面,并传递了该作业的srudentId
       router.push({
       router.push({
@@ -133,7 +133,7 @@ import {Refresh, ZoomIn, ArrowLeft} from "@element-plus/icons-vue";
           studentId: studentId
           studentId: studentId
         }
         }
       })
       })
-    } else if(assignmentInfo.type == 'AI口语'){
+    } else if(assignmentInfo.type == 'AI口语' || assignmentInfo.type === 'speaking'){
       router.push({
       router.push({
       path: `/home/assignment/${assignmentId}/airecord`,
       path: `/home/assignment/${assignmentId}/airecord`,
       query:{
       query:{
@@ -144,7 +144,7 @@ import {Refresh, ZoomIn, ArrowLeft} from "@element-plus/icons-vue";
         window.location.reload() // 强制刷新页面
         window.location.reload() // 强制刷新页面
       })
       })
     }
     }
-    
+
     // alert(studentId)
     // alert(studentId)
   }
   }
 
 

+ 1 - 1
src/views/CorrectPage/CoursePage.vue

@@ -93,7 +93,7 @@
     studentId:null,
     studentId:null,
     courseName:null,
     courseName:null,
     semester:null,
     semester:null,
-    teacherPid:null
+    teacherPid:Number(store.user.pid)
   })
   })
 
 
   let courseName = ref('')
   let courseName = ref('')

+ 1 - 0
src/views/CoursePage/CoursePage.vue

@@ -337,6 +337,7 @@
       Object.assign(query, {
       Object.assign(query, {
         courseId:null,
         courseId:null,
         teacherId:store.user.id,
         teacherId:store.user.id,
+        teacherPid:Number(store.user.pid),
         studentId:null,
         studentId:null,
         courseName:null,
         courseName:null,
         semester:null,
         semester:null,

+ 5 - 4
src/views/HomeworkPage/component/HomeworkDetail.vue

@@ -23,7 +23,7 @@
         <div class="item">
         <div class="item">
           <el-link type="primary" @click="downloadFile(data.descriptionFile, `${data.assignmentName}-描述文件`)">相关文件下载</el-link>
           <el-link type="primary" @click="downloadFile(data.descriptionFile, `${data.assignmentName}-描述文件`)">相关文件下载</el-link>
           <div class="button-container">
           <div class="button-container">
-            <el-button style="margin-left: 600px" color="#597D3B" @click="handleBack">返回</el-button>
+            <el-button style="margin-left: 550px" color="#597D3B" @click="handleBack">返回</el-button>
             <el-button color="#597D3B" @click="handleStart()" :disabled="new Date() > new Date(data.endTime)">
             <el-button color="#597D3B" @click="handleStart()" :disabled="new Date() > new Date(data.endTime)">
               开始{{ data.type }}
               开始{{ data.type }}
             </el-button>
             </el-button>
@@ -84,11 +84,12 @@ let data = reactive<IAssignment>({
 
 
 function handleStart(){
 function handleStart(){
   getEngagement()
   getEngagement()
-  if(data.type == '写作'){
+  console.log(data.type)
+  if(data.type == 'writing'){
     router.push(`/home/assignment/${assignmentId}/edit`)
     router.push(`/home/assignment/${assignmentId}/edit`)
-  } else if(data.type == 'AI口语'){
+  } else if(data.type == 'speaking'){
     router.push(`/home/assignment/${assignmentId}/aispeaking`)
     router.push(`/home/assignment/${assignmentId}/aispeaking`)
-  } 
+  }
 }
 }
 
 
 function downloadFile(url:string, fileName:string) {
 function downloadFile(url:string, fileName:string) {