mjh 4 лет назад
Родитель
Сommit
8e276454b0

+ 15 - 0
src/api/coder.js

@@ -0,0 +1,15 @@
+const prefix = "/coder";
+
+import mockAPIs from "@/api/mock";
+import {axios} from "@/requests/axios.config";
+
+function getAllCoderExams(data) {
+  // return axios.get(`${prefix}/exams`, data);
+  return mockAPIs.getAllCoderExams(data);
+}
+
+const coderAPIs = {
+  getAllCoderExams
+};
+
+export default coderAPIs;

+ 1 - 1
src/api/eval.js

@@ -3,7 +3,7 @@
 import mockAPIs from "@/api/mock";
 
 function getAllEvalExams(data) {
-  // return axios.get(`${prefix}`, data);
+  // return axios.get(`${prefix}/exams`, data);
   return mockAPIs.getAllEvalExams(data);
 }
 

+ 2 - 2
src/api/index.js

@@ -1,15 +1,15 @@
-import mockAPIs from "@/api/mock";
 import userAPIs from "@/api/user";
 import courseAPIs from "@/api/course";
 import courseSelectionAPIs from "@/api/courseSelection";
 import evalAPIs from "@/api/eval";
+import coderAPIs from "@/api/coder";
 
 const api = {
-  ...mockAPIs,
   ...userAPIs,
   ...courseAPIs,
   ...courseSelectionAPIs,
   ...evalAPIs,
+  ...coderAPIs,
 };
 
 export default api;

+ 206 - 0
src/api/mock.js

@@ -251,10 +251,216 @@ const getAllCourses = function () {
   };
 };
 
+const getAllCoderExams = function () {
+  return {
+    "data": {
+      "code": 0,
+      "data": {
+        "res": [
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1646636481,
+            "endAt": 1646755200,
+            "url": null,
+            "result": null,
+            "name": "作业3内测",
+            "course": "软件工程与计算-I-2022-内测",
+            "id": 1273,
+            "courseId": 2,
+            "startAt": 1646582400,
+            "status": "AVAILABLE",
+            "problems": [
+              {
+                "name": "ValidateInput",
+                "description": "ValidateInput",
+                "id": 11,
+                "type": "PYTHON"
+              },
+              {
+                "name": "LogoPlus",
+                "description": "LogoPlus",
+                "id": 10,
+                "type": "PYTHON"
+              }
+            ]
+          },
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1646065877,
+            "endAt": 1646582399,
+            "url": null,
+            "result": null,
+            "name": "作业2",
+            "course": "软件工程与计算-I-2022",
+            "id": 959,
+            "courseId": 3,
+            "startAt": 1646064000,
+            "status": "CLOSED",
+            "problems": [
+              {
+                "name": "MaximumDifference",
+                "description": "MaximumDifference",
+                "id": 8,
+                "type": "PYTHON"
+              },
+              {
+                "name": "Logo",
+                "description": "Logo",
+                "id": 9,
+                "type": "PYTHON"
+              }
+            ]
+          },
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1646034591,
+            "endAt": 1646150399,
+            "url": null,
+            "result": null,
+            "name": "作业2内测",
+            "course": "软件工程与计算-I-2022-内测",
+            "id": 948,
+            "courseId": 2,
+            "startAt": 1645977600,
+            "status": "CLOSED",
+            "problems": [
+              {
+                "name": "MaximumDifference",
+                "description": "MaximumDifference",
+                "id": 8,
+                "type": "PYTHON"
+              },
+              {
+                "name": "Logo",
+                "description": "Logo",
+                "id": 9,
+                "type": "PYTHON"
+              }
+            ]
+          },
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1645372587,
+            "endAt": 1645977600,
+            "url": null,
+            "result": null,
+            "name": "作业1",
+            "course": "软件工程与计算-I-2022",
+            "id": 437,
+            "courseId": 3,
+            "startAt": 1645286400,
+            "status": "CLOSED",
+            "problems": [
+              {
+                "name": "buy_lolipop",
+                "description": "buy_lolipop",
+                "id": 6,
+                "type": "PYTHON"
+              },
+              {
+                "name": "flight",
+                "description": "Flight",
+                "id": 7,
+                "type": "PYTHON"
+              }
+            ]
+          },
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1645337694,
+            "endAt": 1645372800,
+            "url": null,
+            "result": null,
+            "name": "lab0测试",
+            "course": "软件工程与计算-I-2022-内测",
+            "id": 418,
+            "courseId": 2,
+            "startAt": 1645286400,
+            "status": "CLOSED",
+            "problems": [
+              {
+                "name": "buy_lolipop",
+                "description": "buy_lolipop",
+                "id": 6,
+                "type": "PYTHON"
+              },
+              {
+                "name": "flight",
+                "description": "Flight",
+                "id": 7,
+                "type": "PYTHON"
+              }
+            ]
+          },
+          {
+            "creator": {
+              "id": 271,
+              "username": "kenny67nju"
+            },
+            "joined": false,
+            "created_at": 1645251063,
+            "endAt": 1645286400,
+            "url": null,
+            "result": null,
+            "name": "lab0内测",
+            "course": "软件工程与计算-I-2022-内测",
+            "id": 393,
+            "courseId": 2,
+            "startAt": 1645200000,
+            "status": "CLOSED",
+            "problems": [
+              {
+                "name": "buy_lolipop",
+                "description": "buy_lolipop",
+                "id": 6,
+                "type": "PYTHON"
+              },
+              {
+                "name": "flight",
+                "description": "Flight",
+                "id": 7,
+                "type": "PYTHON"
+              }
+            ]
+          }
+        ],
+        "err": 0,
+        "page": {
+          "total": 6,
+          "size": 6,
+          "limit": 10,
+          "page": 1
+        }
+      }
+    }
+  };
+};
+
 const mockAPIs = {
   example,
   getAllEvalExams,
   getAllCourses,
+  getAllCoderExams,
 };
 
 export default mockAPIs;

+ 109 - 0
src/components/CoderCard.vue

@@ -0,0 +1,109 @@
+<template>
+  <el-card class="coder" shadow="hover">
+    <el-row>
+      <el-col class="name" :span="16">
+        {{ coderVO.name }}
+      </el-col>
+      <el-col class="status" :span="8">
+        <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==='FINISHED'" size="small" type="success">已完成</el-tag>
+        <el-tag v-else-if="state==='OVER'" size="small" type="danger">已结束</el-tag>
+      </el-col>
+    </el-row>
+    <el-row class="teacher">
+      教师: {{ coderVO.creator.username }}
+    </el-row>
+    <el-row class="course">
+      所属课程: {{coderVO.course}}
+    </el-row>
+    <el-row class="time">
+      {{ timeToCHN(toDate(coderVO.startAt)) }} 至 {{ timeToCHN(toDate(coderVO.endAt)) }}
+    </el-row>
+    <el-row class="button">
+      <el-col :span="24">
+        <el-button v-if="state==='FINISHED'" size="small" type="success" plain>结果报告</el-button>
+        <el-button v-else size="small" type="primary" plain>查看详情</el-button>
+      </el-col>
+    </el-row>
+  </el-card>
+</template>
+
+<script>
+export default {
+  name: "CoderCard",
+  props: {
+    coderVO: {
+      type: Object,
+      default: () => {
+      },
+    }
+  },
+  computed: {
+    state: function () {
+      if (this.toDate(this.coderVO.endAt) < new Date()) {
+        return "OVER";
+      } else if (this.toDate(this.coderVO.startAt) > new Date()) {
+        return "NOT_STARTED";
+      // } else if (this.coderVO.status === "CLOSED") {
+      //   return "FINISHED";
+      } else {
+        return "RUNNING";
+      }
+    },
+  },
+  mounted() {
+  },
+  methods: {
+    timeToCHN: function (time) {
+      const date = new Date(time);
+      const hours = date.getHours() > 9 ? date.getHours() : "0" + date.getHours();
+      const minutes = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes();
+      return (date.getMonth() + 1) + "月" + date.getDate() + "日 " +
+        hours + ":" + minutes;
+    },
+
+    toDate(timeStamp) {
+      return new Date(Number(timeStamp + "000"));
+    },
+  },
+};
+</script>
+
+<style scoped>
+.coder {
+  background-color: #f8f9fb;
+  margin: 10px 0 0 10px;
+  border: 1px solid #e4e7ed;
+  border-radius: 8px;
+  height: calc(100% - 14px);
+}
+
+.name {
+  font-weight: bold;
+}
+
+.status {
+  text-align: right;
+}
+
+.teacher {
+  font-size: 10px;
+  margin-top: 10px;
+}
+
+.course {
+  font-size: 10px;
+  margin-top: 4px;
+}
+
+.time {
+  margin-top: 4px;
+  font-size: 10px;
+}
+
+.button {
+  margin-top: 12px;
+  text-align: center;
+}
+</style>

+ 13 - 0
src/components/CourseCard.vue

@@ -24,6 +24,12 @@
     <el-row class="description">
       {{ courseVO.description }}
     </el-row>
+    <el-row class="button">
+      <el-col :span="24">
+        <el-button v-if="state==='FINISHED'" size="small" type="success" plain>结果报告</el-button>
+        <el-button v-else size="small" type="primary" plain>查看详情</el-button>
+      </el-col>
+    </el-row>
   </el-card>
 </template>
 
@@ -41,6 +47,8 @@ export default {
         return "OVER";
       } else if (new Date(this.courseVO.startTime) > new Date()) {
         return "NOT_STARTED";
+      // } else if (this.examVO.finished) {
+      //   return "FINISHED";
       } else {
         return "RUNNING";
       }
@@ -122,4 +130,9 @@ export default {
   padding: 10px;
   font-size: 10px;
 }
+
+.button {
+  margin-top: 12px;
+  text-align: center;
+}
 </style>

+ 15 - 1
src/requests/axios.config.js

@@ -1,18 +1,32 @@
 import axios from "axios";
 import store from "@/store";
+import userAPIs from "@/api/user";
 
 const httpPrefix = "http";
 
 const instance = axios.create({
   baseURL: "/api"
 });
+//
+// const specialUrls = [
+//   "/eval",
+// ];
 
 instance.interceptors.request.use(
-  (config) => {
+  async (config) => {
     if(config.url.startsWith(httpPrefix)){
       config.baseURL = "";
     }
 
+    // if(specialUrls.indexOf(config.url) !== -1){
+    //   const res = await userAPIs.loginAPI({
+    //     phone: "17301585267",
+    //     password: "SEEC2020",
+    //   });
+    //   config.headers.authorization = res.data.data.token;
+    //   return config;
+    // }
+
     if (store.state.user.token) {
       config.headers.authorization = store.state.user.token;
     } else {

+ 22 - 7
src/views/PortalPage/PortalPage.vue

@@ -107,13 +107,19 @@
         <el-tabs v-model="activeTestName" @tab-click="changeTestPane">
           <el-tab-pane label="评测题" name="eval">
             <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="24">
+              <el-col v-for="item in evalExamList.slice(0, cardRowLength)" :key="item.id" :lg="7" :md="11" :sm="11"
+                      :xs="24">
                 <EvalCard :examVO="item"></EvalCard>
               </el-col>
             </el-row>
           </el-tab-pane>
           <el-tab-pane label="代码题" name="coder">
-            coder测试
+            <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="24">
+                <CoderCard :coder-v-o="item"></CoderCard>
+              </el-col>
+            </el-row>
           </el-tab-pane>
         </el-tabs>
       </el-card>
@@ -130,11 +136,12 @@ import InfoCard from "@/views/PortalPage/components/InfoCard";
 import CourseCard from "@/components/CourseCard";
 import GlobalFooter from "@/components/GlobalFooter";
 import EvalCard from "@/views/PortalPage/components/EvalCard";
+import CoderCard from "@/components/CoderCard";
 
 export default {
   //属性
   name: "PortalPage",
-  components: { GlobalFooter, CourseCard, InfoCard, CarouselCard, GlobalHeader, EvalCard },
+  components: {CoderCard, GlobalFooter, CourseCard, InfoCard, CarouselCard, GlobalHeader, EvalCard},
   data() {
     return {
       isLogin: this.$store.state.user.token !== undefined,
@@ -143,6 +150,7 @@ export default {
       activeTestName: "eval",
       evalExamList: [],
       courseList: [],
+      coderExamList: [],
       courseRowHeight: 0,
       testRowHeight: 0,
     };
@@ -162,17 +170,24 @@ export default {
 
     console.log(this.isLogin);
 
-    // const res = await this.$apis.getAllCourses();
-    // this.courseList = res.data.data;
+    // await this.$apis.getAllCourses().then(res => {
+    //   this.courseList = res.data.data;
+    // });
     this.courseList = this.$apis.getAllCourses().data.data;
     for (let i = 3 - this.courseList.length % 3; i !== 0; i--) {
       this.courseList.push(this.courseList[0]);
     }
 
-    // const res2 = await this.$apis.getAllEvalExams();
-    // this.evalExamList = res2.data.data["examVOList"];
+    // await this.$apis.getAllEvalExams().then(res => {
+    //   this.coderExamList = res.data.data["examVOList"];
+    // });
     this.evalExamList = this.$apis.getAllEvalExams().data.data["examVOList"];
 
+    // await this.$apis.getAllCoderExams().then(res => {
+    //   this.coderExamList = res.data.data.res;
+    // });
+    this.coderExamList = this.$apis.getAllCoderExams().data.data["res"];
+
     await this.$nextTick(() => {
       that.handleResize();
     });

+ 1 - 1
src/views/PortalPage/components/EvalCard.vue

@@ -17,7 +17,7 @@
     <el-row class="time">
       {{ timeToCHN(examVO.startTime) }} 至 {{ timeToCHN(examVO.endTime) }}
     </el-row>
-    <el-row class="comment">
+    <el-row class="comment" v-if="examVO.comment !== ''">
       {{ examVO.comment }}
     </el-row>
     <el-row class="button">