mjh hace 4 años
padre
commit
b32aa80598

+ 5 - 9
src/api/announcement.js

@@ -11,27 +11,23 @@ function getAnnouncementsByCourseId(courseId) {
 }
 
 function getAnnouncementById(id) {
-  return axios.get(`${prefix}`, {params: {id,}});
+  return axios.get(`${prefix}`, {params: {id}});
 }
 
 function updateAnnouncement(data) {
   return axios.put(`${prefix}`, data);
 }
 
-function deleteAnnouncement(id, userId) {
+function deleteAnnouncement(id) {
   return axios.delete(`${prefix}`, {
     params: {
-      id, userId,
+      id
     }
   });
 }
 
-function getUnreadAnnouncements(userId) {
-  return axios.get(`${prefix}/getUnreadByUserId`, {
-    params: {
-      userId
-    }
-  });
+function getUnreadAnnouncements() {
+  return axios.get(`${prefix}/getUnreadByUserId`);
 }
 
 const announcementAPIs = {

+ 14 - 8
src/api/coder.js

@@ -1,24 +1,30 @@
 const prefix = "/coder";
 
-import { axios } from "@/requests/axios.config";
+import {axios} from "@/requests/axios.config";
 
-function getAllCoderExams(data) {
-  return axios.get(`${prefix}/exams`, data);
+function getStudentCoderExams({page, limit}) {
+  return axios.get(`${prefix}/exam/student`, {
+    // page和limit非必需
+    params: {
+      page,
+      limit,
+    }
+  });
 }
 
-function getStudentCoderExams({ page, limit }) {
-  return axios.get(`${prefix}/exams`, {
-    // page和limit非必需
+function getExampleCoderExams({page, limit, status}) {
+  return axios.get(`${prefix}/exam/recommend`, {
     params: {
       page,
-      limit
+      limit,
+      status,
     }
   });
 }
 
 const coderAPIs = {
-  getAllCoderExams,
   getStudentCoderExams,
+  getExampleCoderExams,
 };
 
 export default coderAPIs;

+ 5 - 15
src/api/course/course.js

@@ -15,21 +15,12 @@ function getExampleCourses() {
   return axios.get(`${prefix}/example`);
 }
 
-function getTeacherCourses(teacherId) {
-  return axios.get(`${prefix}/teacher`, {
-      params: {
-        teacherId,
-      },
-    }
-  );
+function getTeacherCourses() {
+  return axios.get(`${prefix}/teacher`);
 }
 
-function getStudentCourses(studentId) {
-  return axios.get(`${prefix}/student`, {
-    params: {
-      studentId,
-    },
-  });
+function getStudentCourses() {
+  return axios.get(`${prefix}/student`);
 }
 
 function getCourseById(id) {
@@ -44,11 +35,10 @@ function updateCourse(data) {
   return axios.put(`${prefix}/update`, data);
 }
 
-function deleteCourse(courseId, userId) {
+function deleteCourse(courseId) {
   return axios.delete(`${prefix}/delete`, {
     params: {
       courseId,
-      userId
     }
   });
 }

+ 18 - 5
src/components/GlobalHeader.vue

@@ -92,14 +92,27 @@ export default {
     },
     unreadNum() {
       return this.myUnReadAnnouncements.length + this.myUnReadMessages.length > 99 ? "99+" : this.myUnReadAnnouncements.length + this.myUnReadMessages.length;
+    },
+  },
+
+  watch:{
+    isLogin(newData, oldData){
+      if(newData){
+        this.$apis.getUnreadAnnouncements()
+          .then(res => {
+            this.myUnReadAnnouncements = res.data.data;
+          });
+      }
     }
   },
 
-  created() {
-    this.$apis.getUnreadAnnouncements(this.$store.state.user.id)
-      .then(res => {
-        this.myUnReadAnnouncements = res.data.data;
-      });
+  mounted() {
+    if (this.isLogin) {
+      this.$apis.getUnreadAnnouncements()
+        .then(res => {
+          this.myUnReadAnnouncements = res.data.data;
+        });
+    }
   },
 
   methods: {

+ 1 - 1
src/components/TestCard.vue

@@ -111,7 +111,7 @@ export default {
   },
   async mounted() {
     if (this.type === "eval") {
-      const res = await this.$apis.getUserAPI(this.testVO.creatorId);
+      const res = await this.$apis.getUserAPI(this.testVO.course.teacherId);
       this.teacher = res.data.data;
     } else {
       const res = await this.$apis.getUserAPI(this.testVO.creator.id);

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

@@ -384,7 +384,7 @@ export default {
         center: true,
       })
         .then(() => {
-          this.$apis.deleteAnnouncement(item.id, this.$store.state.user.id)
+          this.$apis.deleteAnnouncement(item.id)
             .then(() => {
               this.announcementList.splice(index, 1);
             })

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

@@ -87,7 +87,7 @@ export default {
     });
     if (this.isStudent) {
       if (this.$store.state.user.token) {
-        this.courses_my = this.$apis.getStudentCourses(this.$store.state.user.id).then(res => {
+        this.courses_my = this.$apis.getStudentCourses().then(res => {
           this.courses_my = res.data.data;
         });
       }

+ 2 - 2
src/views/ManagePage/ManagePage.vue

@@ -260,7 +260,7 @@ export default {
   },
   computed: {},
   mounted() {
-    this.$apis.getTeacherCourses(this.$store.state.user.id).then(res => {
+    this.$apis.getTeacherCourses().then(res => {
       this.myCourseList = res.data.data;
     });
 
@@ -428,7 +428,7 @@ export default {
       if (item.state === "EXAMPLE") {
         ElMessage.error("无法删除示例课程");
       } else {
-        this.$apis.deleteCourse(item.id, this.$store.state.user.id)
+        this.$apis.deleteCourse(item.id)
           .then(res => {
             for (let i = 0; i < this.myCourseList.length; i++) {
               if (this.myCourseList[i].id === item.id) {

+ 1 - 1
src/views/MessagePage/MessagePage.vue

@@ -14,7 +14,7 @@ export default {
   },
 
   created() {
-    this.$apis.getUnreadAnnouncements(this.$store.state.user.id)
+    this.$apis.getUnreadAnnouncements()
       .then(res => {
         this.myUnReadAnnouncement = res.data.data;
       });

+ 4 - 6
src/views/PortalPage/PortalPage.vue

@@ -144,7 +144,7 @@ import CarouselCard from "@/views/PortalPage/components/CarouselCard";
 import CourseCard from "@/components/CourseCard";
 import MyCourseCard from "@/views/PortalPage/components/MyCourseCard";
 import MyTestCard from "@/views/PortalPage/components/MyTestCard";
-import { Lock, SetUp, ShoppingCart } from "@element-plus/icons-vue";
+import {Lock, SetUp, ShoppingCart} from "@element-plus/icons-vue";
 import TestCard from "@/components/TestCard";
 
 export default {
@@ -208,17 +208,15 @@ export default {
 
     this.courseList = (await this.$apis.getExampleCourses()).data.data;
     this.evalExamList = (await this.$apis.getExampleEvalExams()).data.data;
-    // todo ERROR: 缺少 token 就无法请求
-    // this.coderExamList = (await this.$apis.getAllCoderExams()).data.data;
-    this.coderExamList = this.$apis.getAllCoderExams().data.data.res;
+    this.coderExamList = (await this.$apis.getExampleCoderExams({})).data.data.res;
 
     if (this.isLogin && this.isStudent) {
-      this.$apis.getStudentCourses(this.$store.state.user.id).then(res => {
+      this.$apis.getStudentCourses().then(res => {
         this.myCourseList = res.data.data;
         this.myCourseLoading = false;
         that.handleResize();
       });
-      this.$apis.getStudentEvalExams({ state: 0 }).then(res => {
+      this.$apis.getStudentEvalExams({state: 0}).then(res => {
         this.myEvalExamList = res.data.data.examVOList;
         this.myTestLoading = false;
         that.handleResize();