Procházet zdrojové kódy

feat: 添加了coder卡片和eval卡片的跳转,但是跳转当中暂时还没有考虑到评测的一个状态。

mjh před 4 roky
rodič
revize
79316cdaee

+ 2 - 2
src/api/coder.js

@@ -9,9 +9,9 @@ function getAllCoderExams(data) {
 }
 }
 
 
 // page和limit非必需
 // page和limit非必需
-function getStudentCoderExams({page, limit}){
+function getStudentCoderExams({page, limit}) {
   return axios.get(`${prefix}/exams`, {
   return axios.get(`${prefix}/exams`, {
-    params:{
+    params: {
       page,
       page,
       limit
       limit
     }
     }

+ 9 - 0
src/api/course.js

@@ -43,6 +43,14 @@ function deleteCourse(data) {
   return axios.post(`${prefix}/delete`, data.id);
   return axios.post(`${prefix}/delete`, data.id);
 }
 }
 
 
+function getCourseByCoderId(coderId) {
+  return axios.get(`${prefix}/getCourseByCoderId`, {
+    params: {
+      coderId,
+    }
+  });
+}
+
 
 
 const courseAPIs = {
 const courseAPIs = {
   createCourse,
   createCourse,
@@ -53,6 +61,7 @@ const courseAPIs = {
   deleteCourse,
   deleteCourse,
   updateCourse,
   updateCourse,
   getExampleCourses,
   getExampleCourses,
+  getCourseByCoderId,
 };
 };
 
 
 export default courseAPIs;
 export default courseAPIs;

+ 56 - 14
src/components/CoderCard.vue

@@ -15,8 +15,8 @@
       <el-col :span="8" class="status">
       <el-col :span="8" class="status">
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
-        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已完成</el-tag>
-        <el-tag v-else-if="state==='OVER'" size="small" type="danger">已结束</el-tag>
+        <el-tag v-else-if="state==='CLOSED'" size="small" type="danger">已关闭</el-tag>
+        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已结束</el-tag>
       </el-col>
       </el-col>
     </el-row>
     </el-row>
     <el-row class="teacher">
     <el-row class="teacher">
@@ -38,7 +38,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import {List} from "@element-plus/icons-vue";
+import {ElMessageBox} from "element-plus";
 
 
 export default {
 export default {
   name: "CoderCard",
   name: "CoderCard",
@@ -51,19 +51,16 @@ export default {
   },
   },
   computed: {
   computed: {
     state: function () {
     state: function () {
-      if (this.coderVO.endAt * 1000 < new Date()) {
-        return "OVER";
+      if (this.coderVO.status === "CLOSED") {
+        return "CLOSED";
       } else if (this.coderVO.startAt * 1000 > new Date()) {
       } else if (this.coderVO.startAt * 1000 > new Date()) {
         return "NOT_STARTED";
         return "NOT_STARTED";
-      } else if (this.coderVO.status === "CLOSED") {
+      } else if (this.coderVO.endAt * 1000 < new Date()) {
         return "FINISHED";
         return "FINISHED";
       } else {
       } else {
         return "RUNNING";
         return "RUNNING";
       }
       }
     },
     },
-    coderURL() {
-      return this.$store.state.user.token ? "https://coder.seec.seecoder.cn?id_token=" + this.$store.state.user.token : "https://coder.seec.seecoder.cn";
-    },
   },
   },
   mounted() {
   mounted() {
   },
   },
@@ -76,12 +73,57 @@ export default {
       return Y + M + D;
       return Y + M + D;
     },
     },
     async toTestInfo() {
     async toTestInfo() {
+      if (!this.$store.state.user.token) {
+        await this.$router.push("/auth");
+        return;
+      }
+      let messageBoxContent = "";
+      let messageBoxTitle = "Coder";
+      let confirmButtonText = "";
+      let cancelButtonText = "让我想想";
+      let nextURL = "";
+      // todo: 跳转流程中还需要考虑CoderExam的状态
       const res = await this.$apis.getStudentCoderExams({});
       const res = await this.$apis.getStudentCoderExams({});
-      const userCoderExamsId = res.data.data.res.map(exam => {
-        return exam.id;
-      });
-      console.log(this.coderVO.id in userCoderExamsId);
-      // window.open(this.coderURL);
+      const userCoderExams = res.data.data.res;
+      for (let userCoderExam of userCoderExams) {
+        if (this.coderVO.id === userCoderExam.id) {
+          if (userCoderExam.joined) {
+            nextURL = "https://coder.seec.seecoder.cn/exam/" + this.coderVO.id + "?id_token=" + this.$store.state.user.token;
+            window.open(nextURL);
+            return;
+          } else {
+            messageBoxContent = "尚未参加该测试,是否立即参加?";
+            confirmButtonText = "立即参加";
+            nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
+          }
+        }
+      }
+      if (messageBoxContent === "") {
+        const res = await this.$apis.getCourseByCoderId(this.coderVO.courseId);
+        if (res.data.data === null) {
+          nextURL = "https://coder.seec.seecoder.cn/course/select?id_token=" + this.$store.state.user.token;
+          messageBoxContent = "尚未选择该Coder课程,是否前往Coder系统?";
+          confirmButtonText = "前往选课";
+        } else {
+          nextURL = "/course/" + res.data.data.id;
+          messageBoxContent = "尚未选择该课程,是否前往选课?";
+          confirmButtonText = "前往选课";
+        }
+      }
+      ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
+        distinguishCancelAndClose: true,
+        confirmButtonText,
+        cancelButtonText,
+      })
+        .then(() => {
+          if (nextURL.startsWith("http")) {
+            window.open(nextURL);
+          } else {
+            this.$router.push(nextURL);
+          }
+        })
+        .catch(action => {
+        });
     },
     },
   },
   },
 };
 };

+ 2 - 4
src/components/CourseCard.vue

@@ -9,7 +9,7 @@
       <el-col :span="8" class="status">
       <el-col :span="8" class="status">
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
-        <el-tag v-else-if="state==='OVER'" size="small" type="danger">已结束</el-tag>
+        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已结束</el-tag>
       </el-col>
       </el-col>
     </el-row>
     </el-row>
     <el-row class="teacher">
     <el-row class="teacher">
@@ -44,11 +44,9 @@ export default {
   computed: {
   computed: {
     state: function () {
     state: function () {
       if (new Date(this.courseVO.endTime) < new Date()) {
       if (new Date(this.courseVO.endTime) < new Date()) {
-        return "OVER";
+        return "FINISHED";
       } else if (new Date(this.courseVO.startTime) > new Date()) {
       } else if (new Date(this.courseVO.startTime) > new Date()) {
         return "NOT_STARTED";
         return "NOT_STARTED";
-      } else if (this.courseVO.finished) {
-        return "FINISHED";
       } else {
       } else {
         return "RUNNING";
         return "RUNNING";
       }
       }

+ 48 - 14
src/components/EvalCard.vue

@@ -1,22 +1,21 @@
 <template>
 <template>
   <el-card class="eval" shadow="hover" @click="toTestInfo">
   <el-card class="eval" shadow="hover" @click="toTestInfo">
 
 
-    <div style="border-bottom: 30px solid #f5b86e; float: right; width: 0; height: 0; position: absolute;right: 0;bottom: 0;border-left: 30px solid transparent;">
+    <div
+      style="border-bottom: 30px solid #f5b86e; float: right; width: 0; height: 0; position: absolute;right: 0;bottom: 0;border-left: 30px solid transparent;">
       <div style="padding: 0 4px 0 4px; position: absolute; right: 0; bottom: -30px; color: white">
       <div style="padding: 0 4px 0 4px; position: absolute; right: 0; bottom: -30px; color: white">
         E
         E
       </div>
       </div>
     </div>
     </div>
 
 
     <el-row>
     <el-row>
-      <el-col :span="17" class="name">
+      <el-col :span="16" class="name">
         {{ examVO.examName }}
         {{ examVO.examName }}
       </el-col>
       </el-col>
-      <el-col :span="1"/>
-      <el-col :span="6" class="status">
+      <el-col :span="8" class="status">
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
-        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已完成</el-tag>
-        <el-tag v-else-if="state==='OVER'" size="small" type="danger">已结束</el-tag>
+        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已结束</el-tag>
       </el-col>
       </el-col>
     </el-row>
     </el-row>
     <el-row class="teacher">
     <el-row class="teacher">
@@ -38,6 +37,8 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import {ElMessageBox} from "element-plus";
+
 export default {
 export default {
   name: "EvalCard",
   name: "EvalCard",
   props: {
   props: {
@@ -58,11 +59,9 @@ export default {
   computed: {
   computed: {
     state: function () {
     state: function () {
       if (new Date(this.examVO.endTime) < new Date()) {
       if (new Date(this.examVO.endTime) < new Date()) {
-        return "OVER";
+        return "FINISHED";
       } else if (new Date(this.examVO.startTime) > new Date()) {
       } else if (new Date(this.examVO.startTime) > new Date()) {
         return "NOT_STARTED";
         return "NOT_STARTED";
-      } else if (this.examVO.finished) {
-        return "FINISHED";
       } else {
       } else {
         return "RUNNING";
         return "RUNNING";
       }
       }
@@ -84,12 +83,47 @@ export default {
       return Y + M + D;
       return Y + M + D;
     },
     },
     async toTestInfo() {
     async toTestInfo() {
+      if (!this.$store.state.user.token) {
+        await this.$router.push("/auth");
+        return;
+      }
+      let messageBoxContent = "";
+      let messageBoxTitle = "Eval";
+      let confirmButtonText = "";
+      let cancelButtonText = "让我想想";
+      let nextURL = "";
+      // todo: 跳转流程还需要考虑EvalExam的状态
       const res = await this.$apis.getStudentEvalExams({state: 0});
       const res = await this.$apis.getStudentEvalExams({state: 0});
-      const userEvalExamsId = res.data.data.examVOList.map(exam => {
-        return exam.examId;
-      });
-      console.log(this.examVO.id in userEvalExamsId);
-      // window.open(this.evalURL);
+      const userEvalExams = res.data.data.examVOList;
+      for (let userEvalExam of userEvalExams) {
+        if (userEvalExam.examId === this.examVO.examId) {
+          if (this.examVO.isJoined) {
+            nextURL = "https://eval.seec.seecoder.cn?id_token=" + this.$store.state.user.token;
+            window.open(nextURL);
+            return;
+          } else {
+            // todo: eval系统暂时应该不存在参加了评测但是isJoined字段为false的情况。
+          }
+        }
+      }
+      if (messageBoxContent === "") {
+        messageBoxContent = "尚未参加该测试,是否立即参加?";
+        confirmButtonText = "立即参加";
+        nextURL = "https://eval.seec.seecoder.cn?id_token=" + this.$store.state.user.token;
+      }
+      ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
+        distinguishCancelAndClose: true,
+        confirmButtonText,
+        cancelButtonText,
+      }).then(() => {
+        if (nextURL.startsWith("http")) {
+          window.open(nextURL);
+        } else {
+          this.$router.push(nextURL);
+        }
+      })
+        .catch(action => {
+        });
     },
     },
   }
   }
 };
 };

+ 18 - 8
src/views/PortalPage/PortalPage.vue

@@ -2,7 +2,7 @@
   <GlobalHeader/>
   <GlobalHeader/>
   <div id="portal-body">
   <div id="portal-body">
 
 
-<!--    <InfoCard/>-->
+    <!--    <InfoCard/>-->
 
 
     <CarouselCard id="portal-carousel-card"/>
     <CarouselCard id="portal-carousel-card"/>
 
 
@@ -17,7 +17,8 @@
             <MyCourseCard :courseVO="course" v-for="course in myCourseList" :key="course.id"/>
             <MyCourseCard :courseVO="course" v-for="course in myCourseList" :key="course.id"/>
           </div>
           </div>
         </div>
         </div>
-        <div v-else :style="{height: (courseRowHeight - 63) + 'px', marginTop: (courseRowHeight / 2 - 120) + 'px'}" class="portal-card-main">
+        <div v-else :style="{height: (courseRowHeight - 63) + 'px', marginTop: (courseRowHeight / 2 - 120) + 'px'}"
+             class="portal-card-main">
           <div>
           <div>
             <svg class="icon" height="128" viewBox="0 0 1024 1024" width="128" xmlns="http://www.w3.org/2000/svg">
             <svg class="icon" height="128" viewBox="0 0 1024 1024" width="128" xmlns="http://www.w3.org/2000/svg">
               <path
               <path
@@ -60,7 +61,8 @@
             <MyTestCard :testVO="test" v-for="test in myTestList" :key="test.id"/>
             <MyTestCard :testVO="test" v-for="test in myTestList" :key="test.id"/>
           </div>
           </div>
         </div>
         </div>
-        <div v-else :style="{height: (testRowHeight - 63) + 'px', marginTop: (testRowHeight / 2 - 120) + 'px'}" class="portal-card-main">
+        <div v-else :style="{height: (testRowHeight - 63) + 'px', marginTop: (testRowHeight / 2 - 120) + 'px'}"
+             class="portal-card-main">
           <div>
           <div>
             <svg class="icon" height="128" viewBox="0 0 1024 1024" width="128" xmlns="http://www.w3.org/2000/svg">
             <svg class="icon" height="128" viewBox="0 0 1024 1024" width="128" xmlns="http://www.w3.org/2000/svg">
               <path
               <path
@@ -87,14 +89,16 @@
         <el-tabs v-model="activeTestName" @tab-click="changeTestPane">
         <el-tabs v-model="activeTestName" @tab-click="changeTestPane">
           <el-tab-pane label="评测题" name="eval">
           <el-tab-pane label="评测题" name="eval">
             <el-row justify="space-around">
             <el-row justify="space-around">
-              <el-col v-for="item in evalExamList.slice(0, cardRowLength)" :key="item.id" :lg="7" :md="11" :sm="11" :xs="11">
+              <el-col v-for="item in evalExamList.slice(0, cardRowLength)" :key="item.id" :lg="7" :md="11" :sm="11"
+                      :xs="11">
                 <EvalCard :examVO="item"></EvalCard>
                 <EvalCard :examVO="item"></EvalCard>
               </el-col>
               </el-col>
             </el-row>
             </el-row>
           </el-tab-pane>
           </el-tab-pane>
           <el-tab-pane label="代码题" name="coder">
           <el-tab-pane label="代码题" name="coder">
             <el-row justify="space-around">
             <el-row justify="space-around">
-              <el-col v-for="item in coderExamList.slice(0, cardRowLength)" :key="item.id" :lg="7" :md="11" :sm="11" :xs="11">
+              <el-col v-for="item in coderExamList.slice(0, cardRowLength)" :key="item.id" :lg="7" :md="11" :sm="11"
+                      :xs="11">
                 <CoderCard :coder-v-o="item"></CoderCard>
                 <CoderCard :coder-v-o="item"></CoderCard>
               </el-col>
               </el-col>
             </el-row>
             </el-row>
@@ -121,7 +125,7 @@ import MyTestCard from "@/views/PortalPage/components/MyTestCard";
 export default {
 export default {
   //属性
   //属性
   name: "PortalPage",
   name: "PortalPage",
-  components: { MyTestCard, CoderCard, GlobalFooter, CourseCard, CarouselCard, GlobalHeader, EvalCard, MyCourseCard },
+  components: {MyTestCard, CoderCard, GlobalFooter, CourseCard, CarouselCard, GlobalHeader, EvalCard, MyCourseCard},
   data() {
   data() {
     return {
     return {
       isLogin: this.$store.state.user.token !== undefined,
       isLogin: this.$store.state.user.token !== undefined,
@@ -132,6 +136,8 @@ export default {
       courseList: [],
       courseList: [],
       coderExamList: [],
       coderExamList: [],
       myCourseList: [],
       myCourseList: [],
+      myEvalExamList: [],
+      myCoderExamList: [],
       myTestList: [],
       myTestList: [],
       courseRowHeight: 0,
       courseRowHeight: 0,
       testRowHeight: 0,
       testRowHeight: 0,
@@ -165,10 +171,14 @@ export default {
     this.coderExamList = this.$apis.getAllCoderExams().data.data["res"];
     this.coderExamList = this.$apis.getAllCoderExams().data.data["res"];
 
 
     if (this.isLogin) {
     if (this.isLogin) {
-      this.myCourseList = this.$apis.getStudentCourses({ "studentId": this.$store.state.user.id }).then(res => {
+      this.myCourseList = this.$apis.getStudentCourses({"studentId": this.$store.state.user.id}).then(res => {
         this.myCourseList = res.data.data;
         this.myCourseList = res.data.data;
       });
       });
-      this.myTestList = [].concat(this.evalExamList).concat(this.coderExamList);
+      const evalRes = await this.$apis.getStudentEvalExams({state: 0});
+      this.myEvalExamList = evalRes.data.data.examVOList;
+      const coderRes = await this.$apis.getStudentCoderExams({});
+      this.myCoderExamList = coderRes.data.data.res;
+      this.myTestList = [].concat(this.myEvalExamList).concat(this.myCoderExamList);
     }
     }
 
 
     await this.$nextTick(() => {
     await this.$nextTick(() => {

+ 62 - 14
src/views/PortalPage/components/MyTestCard.vue

@@ -12,7 +12,7 @@
     </div>
     </div>
 
 
     <el-row>
     <el-row>
-      <el-col :span="20">
+      <el-col :span="16">
         <el-col v-if="type==='eval'" class="title">
         <el-col v-if="type==='eval'" class="title">
           {{ testVO.examName }}
           {{ testVO.examName }}
         </el-col>
         </el-col>
@@ -20,11 +20,11 @@
           {{ testVO.name }}
           {{ testVO.name }}
         </el-col>
         </el-col>
       </el-col>
       </el-col>
-      <el-col :span="4">
+      <el-col :span="8" style="text-align: center;">
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
         <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
-        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已完成</el-tag>
-        <el-tag v-else-if="state==='OVER'" size="small" type="danger">已结束</el-tag>
+        <el-tag v-else-if="state==='FINISHED'" size="small" type="success">已结束</el-tag>
+        <el-tag v-else-if="state==='CLOSED'" size="small" type="danger">已关闭</el-tag>
       </el-col>
       </el-col>
     </el-row>
     </el-row>
 
 
@@ -60,6 +60,8 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import {ElMessageBox} from "element-plus";
+
 export default {
 export default {
   name: "MyTestCard",
   name: "MyTestCard",
   props: {
   props: {
@@ -84,14 +86,24 @@ export default {
       }
       }
     },
     },
     state() {
     state() {
-      if (new Date(this.testVO.endTime) < new Date() || new Date(this.testVO.endAt) < new Date()) {
-        return "OVER";
-      } else if (new Date(this.testVO.startTime) > new Date() || new Date(this.testVO.startAt) > new Date()) {
-        return "NOT_STARTED";
-      } else if (this.testVO.finished) {
-        return "FINISHED";
+      if (this.type === "eval") {
+        if (new Date(this.testVO.endTime) < new Date()) {
+          return "FINISHED";
+        } else if (new Date(this.testVO.startTime) > new Date()) {
+          return "NOT_STARTED";
+        } else {
+          return "RUNNING";
+        }
       } else {
       } else {
-        return "RUNNING";
+        if (this.testVO.status === "CLOSED") {
+          return "CLOSED";
+        } else if (this.testVO.startAt * 1000 > new Date()) {
+          return "NOT_STARTED";
+        } else if (this.testVO.endAt * 1000 < new Date()) {
+          return "FINISHED";
+        } else {
+          return "RUNNING";
+        }
       }
       }
     },
     },
     evalURL() {
     evalURL() {
@@ -120,11 +132,47 @@ export default {
       return Y + M + D + h + m;
       return Y + M + D + h + m;
     },
     },
     toTestInfo() {
     toTestInfo() {
-      if (this.testVO.examId) {
-        window.open(this.evalURL);
+      let messageBoxContent = "";
+      let messageBoxTitle = "";
+      let confirmButtonText = "";
+      let cancelButtonText = "让我想想";
+      let nextURL = "";
+
+      if (this.type === "eval") {
+        if (this.testVO.isJoined) {
+          messageBoxTitle = "Eval";
+          nextURL = "https://eval.seec.seecoder.cn?id_token=" + this.$store.state.user.token;
+          window.open(this.evalURL);
+          return;
+        } else {
+          // todo: eval系统暂时应该不存在参加了评测但是isJoined字段为false的情况。
+        }
       } else {
       } else {
-        window.open(this.coderURL);
+        messageBoxTitle = "Coder";
+        if (this.testVO.joined) {
+          nextURL = "https://coder.seec.seecoder.cn/exam/" + this.testVO.id + "?id_token=" + this.$store.state.user.token;
+          window.open(nextURL);
+          return;
+        } else {
+          messageBoxContent = "尚未参加该测试,是否立即参加?";
+          confirmButtonText = "立即参加";
+          nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
+        }
       }
       }
+
+      ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
+        distinguishCancelAndClose: true,
+        confirmButtonText,
+        cancelButtonText,
+      }).then(() => {
+        if (nextURL.startsWith("http")) {
+          window.open(nextURL);
+        } else {
+          this.$router.push(nextURL);
+        }
+      })
+        .catch(action => {
+        });
     },
     },
   }
   }
 };
 };