Просмотр исходного кода

feat: 增加课程信息展示

weijin 4 лет назад
Родитель
Сommit
868887f3fb

+ 7 - 0
src/api/course.ts

@@ -0,0 +1,7 @@
+import axios from 'axios'
+import { COURSE_MODULE } from './prefix'
+import { ReceivedData, CourseSerializer } from '@/api/types'
+
+export const getCoursesByTeacher = () => {
+  return axios.get<ReceivedData<Array<CourseSerializer>>>(`${COURSE_MODULE}`)
+}

+ 1 - 0
src/api/prefix.ts

@@ -1,5 +1,6 @@
 const BASE_URL = '/api'
 
+export const COURSE_MODULE = BASE_URL + '/course'
 export const EXAM_MODULE = BASE_URL + '/exam'
 export const QUESTION_MODULE = BASE_URL + '/question'
 export const USER_MODULE = BASE_URL + '/user'

+ 19 - 1
src/api/types.d.ts

@@ -40,7 +40,15 @@ export interface Pageable {
 //yyyy-MM-dd HH:mm:ss
 export type LocalDateTime = string
 
-export type UserRole = 'STUDENT' | 'TEACHER'
+export type UserRole =
+  | 'STUDENT'
+  | 'TEACHER'
+  | 'ADMIN'
+  | 'HR'
+  | 'STAFF'
+  | 'ASSISTANT'
+  | 'SEEC'
+  | 'SEECX'
 
 export interface ExamSerializer {
   antiCheating: boolean
@@ -54,6 +62,8 @@ export interface ExamSerializer {
   examName: string
   isPublic: boolean
   isHidden: boolean
+  courseId?: ID
+  course?: CourseSerializer
   // 上边是创建评测所需的信息
   examId?: number
   inviteCode?: string
@@ -219,3 +229,11 @@ export interface AnalysisInfo {
 export interface AnalysisInfoItem {
   [key: string]: number
 }
+
+export interface CourseSerializer {
+  id: ID
+  name: string
+  code: string
+  isPublic: boolean
+  isJoined: boolean
+}

+ 10 - 2
src/store/index.ts

@@ -27,8 +27,16 @@ export const mutations: MutationTree<RootState> = {
 }
 
 export const getters: GetterTree<RootState, RootState> = {
-  isStudent: (state) => state.user.role === 'STUDENT',
-  isTeacher: (state) => state.user.role === 'TEACHER',
+  isStudent: (state) =>
+    state.user.role === 'STUDENT' ||
+    state.user.role === 'STAFF' ||
+    state.user.role === 'ASSISTANT' ||
+    state.user.role === 'SEEC' ||
+    state.user.role === 'SEECX',
+  isTeacher: (state) =>
+    state.user.role === 'TEACHER' ||
+    state.user.role === 'HR' ||
+    state.user.role === 'ADMIN',
   getId: (state) => state.user.id,
   isLogin: (state) => Boolean(state.token),
   getExamAnswers: (state) => state.examAnswers,

+ 10 - 5
src/views/student/components/StudentExamInfoCard.vue

@@ -78,18 +78,18 @@
         >
       </v-col>
     </v-row>
-    <v-row justify="space-between" dense>
-      <v-col>
+    <v-row dense>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-5"
           >开始时间: {{ examInfo.startTime }}</v-card-text
         >
       </v-col>
-      <v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-5"
           >结束时间: {{ examInfo.endTime }}</v-card-text
         >
       </v-col>
-      <v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-5"
           >评测时长:
           {{ getExamLength(examInfo.startTime, examInfo.endTime) }}
@@ -97,7 +97,12 @@
       </v-col>
     </v-row>
     <v-row no-gutters>
-      <v-col>
+      <v-col :cols="4">
+        <v-card-text class="pa-0 pb-5"
+          >所属课程: {{ examInfo.course.name }}</v-card-text
+        >
+      </v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-4"
           >监考:{{ examInfo.antiCheating ? '是' : '否' }}</v-card-text
         >

+ 23 - 2
src/views/teacher/ExamCreate.vue

@@ -22,6 +22,16 @@
           :rules="nameRules"
         ></v-text-field>
 
+        <v-select
+          v-model="course"
+          :items="courseList"
+          :item-text="'name'"
+          :item-value="'id'"
+          label="所属课程"
+          class="ma-4"
+          :rules="courseRules"
+        ></v-select>
+
         <v-text-field
           v-model="position"
           :counter="20"
@@ -229,10 +239,11 @@
 import Vue from 'vue'
 import PageHeader from '@/views/components/PageHeader.vue'
 import { createExam } from '@/api/exam'
-import { ExamSerializer, ID } from '@/api/types'
+import { ExamSerializer } from '@/api/types'
 import { mapGetters } from 'vuex'
 import dayjs, { Dayjs } from 'dayjs'
 import { TIME_FORMAT } from '@/utils/common'
+import { getCoursesByTeacher } from '@/api/course'
 
 export default Vue.extend({
   name: 'ExamCreate',
@@ -259,6 +270,8 @@ export default Vue.extend({
           href: '/'
         }
       ],
+      courseList: [] as any[],
+      course: '',
       skillList: [
         'Java',
         'C++',
@@ -292,6 +305,7 @@ export default Vue.extend({
         (v: string) => !!v || '该项为必填项',
         (v: string) => v.length <= 25 || '字数过多'
       ],
+      courseRules: [(v: string) => !!v || '该项为必填项'],
       arrayRules: [(v: [] | string) => v.length > 0 || '该项为必填项'],
       examLengthTicks: [
         '0.5 小时',
@@ -358,6 +372,11 @@ export default Vue.extend({
   },
 
   methods: {
+    getCourses() {
+      getCoursesByTeacher().then(({ data }) => {
+        this.courseList = data.result
+      })
+    },
     onCreateExam() {
       const obj = {
         creatorId: this.getId,
@@ -370,7 +389,8 @@ export default Vue.extend({
         comment: this.comment,
         antiCheating: this.antiCheating,
         isPublic: !this.isPrivate,
-        isHidden: false
+        isHidden: false,
+        courseId: this.course
       } as ExamSerializer
       console.log('创建评测', obj)
       createExam(obj).then(({ data }) => {
@@ -386,6 +406,7 @@ export default Vue.extend({
     }
   },
   mounted() {
+    this.getCourses()
     this.nowDatetime = dayjs()
     this.nowDateTimeFormatted = this.nowDatetime.format(TIME_FORMAT)
     this.startDate = this.nowDateTimeFormatted.substr(0, 10)

+ 11 - 8
src/views/teacher/components/TeacherExamInfoCard.vue

@@ -56,27 +56,30 @@
       </v-col>
     </v-row>
     <v-row justify="space-between" dense>
-      <v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-4"
           >开始时间: {{ examInfo.startTime }}</v-card-text
         >
         <v-card-text class="pa-0 pb-4"
-          >监考: {{ examInfo.antiCheating ? '是' : '否' }}
-        </v-card-text>
+          >所属课程: {{ examInfo.course.name }}</v-card-text
+        >
       </v-col>
-      <v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-4"
           >结束时间: {{ examInfo.endTime }}</v-card-text
         >
-        <v-card-text class="pa-0 pb-4" v-if="examInfo.inviteCode"
-          >邀请码: {{ examInfo.inviteCode }}</v-card-text
-        >
+        <v-card-text class="pa-0 pb-4"
+          >监考: {{ examInfo.antiCheating ? '是' : '否' }}
+        </v-card-text>
       </v-col>
-      <v-col>
+      <v-col :cols="4">
         <v-card-text class="pa-0 pb-4"
           >评测时长:
           {{ getExamLength(examInfo.startTime, examInfo.endTime) }}
         </v-card-text>
+        <v-card-text class="pa-0 pb-4" v-if="examInfo.inviteCode"
+          >邀请码: {{ examInfo.inviteCode }}</v-card-text
+        >
       </v-col>
     </v-row>
     <v-dialog v-model="extendTimeDialog" max-width="500" attach="">