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

feat: 检查首页、全部课程、全部测试页面的数据,在vuex中添加isTeacher、isStudent

mjh 4 лет назад
Родитель
Сommit
403ab7cdbf

+ 8 - 1
src/store/modules/user.js

@@ -124,7 +124,14 @@ const user = {
     },
   },
 
-  getters: {}
+  getters: {
+    isTeacher(state){
+      return ["TEACHER"].indexOf(state.role) !== -1;
+    },
+    isStudent(state){
+      return ["STUDENT"].indexOf(state.role) !== -1;
+    }
+  }
 };
 
 export default user;

+ 24 - 8
src/views/CoursePage/CoursePage.vue

@@ -1,7 +1,8 @@
 <template>
   <el-row id="course-page-body">
     <el-col :span="3">
-      <el-menu background-color="#f8f9fb" default-active="1" style="position: fixed; width: 180px;" @select="handleSelect">
+      <el-menu background-color="#f8f9fb" default-active="1" style="position: fixed; width: 180px;"
+               @select="handleSelect">
         <el-menu-item index="0">
           <el-icon>
             <Back/>
@@ -33,9 +34,16 @@
         <div v-if="this.activeIndex === '1'" class="course-page-main">
           <CourseCard v-for="course in courses_all" :key="course.id" :courseVO="course"/>
         </div>
-        <div v-else class="course-page-main">
+        <div v-if="this.activeIndex === '2' && isStudent" class="course-page-main">
           <CourseCard v-for="course in courses_my" :key="course.id" :courseVO="course"/>
         </div>
+        <!--todo-->
+        <div v-if="this.activeIndex === '2' && isTeacher">
+          教师请前往
+          <span style="cursor: pointer;color: red"
+                @click="$router.push('/manage')">管理页面</span>
+          查看相关课程。
+        </div>
       </el-card>
     </el-col>
   </el-row>
@@ -44,12 +52,12 @@
 
 <script>
 import GlobalFooter from "@/components/GlobalFooter";
-import { Back, Document, DocumentChecked } from "@element-plus/icons-vue";
+import {Back, Document, DocumentChecked} from "@element-plus/icons-vue";
 import CourseCard from "@/components/CourseCard";
 
 export default {
   name: "CoursePage",
-  components: { Back, CourseCard, Document, DocumentChecked, GlobalFooter },
+  components: {Back, CourseCard, Document, DocumentChecked, GlobalFooter},
   data() {
     return {
       activeIndex: "1",
@@ -65,16 +73,24 @@ export default {
         return "我的课程";
       }
     },
+    isTeacher() {
+      return this.$store.getters.isTeacher;
+    },
+    isStudent() {
+      return this.$store.getters.isStudent;
+    },
   },
 
   mounted() {
     this.$apis.getAllCourses().then(res => {
       this.courses_all = res.data.data;
     });
-    if (this.$store.state.user.token) {
-      this.courses_my = this.$apis.getStudentCourses({ studentId: this.$store.state.user.id }).then(res => {
-        this.courses_my = res.data.data;
-      });
+    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 = res.data.data;
+        });
+      }
     }
   },
 

+ 26 - 20
src/views/PortalPage/PortalPage.vue

@@ -21,14 +21,14 @@
             <div style="font-size: small; font-weight: bold; color: #666666">登录以查看</div>
           </div>
 
-          <div v-if="isLogin && isStudent && myCourseList.length!==0" :style="{height: (courseRowHeight - 63) + 'px'}"
+          <div v-if="isLogin && isStudent && myCourseList!==null && myCourseList.length!==0" :style="{height: (courseRowHeight - 63) + 'px'}"
                class="portal-card-main">
             <div class="portal-my-card-main">
               <MyCourseCard v-for="course in myCourseList" :key="course.id" :courseVO="course"/>
             </div>
           </div>
 
-          <div v-if="isLogin && isStudent && myCourseList.length===0"
+          <div v-if="isLogin && isStudent && myCourseList!==null && myCourseList.length===0"
                :style="{height: (courseRowHeight - 63) + 'px', marginTop: (courseRowHeight / 2 - 100) + 'px'}"
                class="portal-card-main" style="cursor: pointer"
                @click="this.$router.push('/course')">
@@ -38,7 +38,7 @@
             <div style="font-size: small; font-weight: bold; color: #666666">去选择课程</div>
           </div>
 
-          <div v-if="isLogin && isTeacher"
+          <div v-show="isLogin && isTeacher"
                :style="{height: (courseRowHeight - 63) + 'px', marginTop: (courseRowHeight / 2 - 100) + 'px'}"
                class="portal-card-main" style="cursor: pointer"
                @click="this.$router.push('/manage')">
@@ -79,7 +79,7 @@
                 @click="$router.push('/manage')">管理页面</span>
           查看相关测试。
         </div>
-        <div v-else>
+        <div v-if="isTeacher">
           <div v-if="isLogin" :style="{height: (testRowHeight - 63) + 'px'}" class="portal-card-main">
             <div class="portal-my-card-main">
               <div v-if="myTestList.length !== 0">
@@ -171,7 +171,7 @@ export default {
       evalExamList: [],
       courseList: [],
       coderExamList: [],
-      myCourseList: [],
+      myCourseList: null,
       myEvalExamList: [],
       myCoderExamList: [],
       myTestList: [],
@@ -184,10 +184,10 @@ export default {
       return this.$store.state.user.token !== undefined;
     },
     isTeacher() {
-      return ["TEACHER", "SEEC", "ADMIN"].indexOf(this.$store.state.user.role) !== -1;
+      return this.$store.getters.isTeacher;
     },
     isStudent() {
-      return ["STUDENT", "SEEC", "ADMIN"].indexOf(this.$store.state.user.role) !== -1;
+      return this.$store.getters.isStudent;
     }
   },
 
@@ -203,31 +203,37 @@ export default {
       })();
     };
 
-    await this.$apis.getExampleCourses().then(res => {
+    this.$apis.getExampleCourses().then(res => {
       this.courseList = res.data.data;
     });
-
-    // await this.$apis.getAllEvalExams().then(res => {
-    //   this.coderExamList = res.data.data["examVOList"];
+    // this.$apis.getAllEvalExams().then(res => {
+    //   this.evalExamList = res.data.data["examVOList"];
     // });
+    // todo
     this.evalExamList = this.$apis.getAllEvalExams().data.data["examVOList"];
-
-    // await this.$apis.getAllCoderExams().then(res => {
+    // this.$apis.getAllCoderExams().then(res => {
     //   this.coderExamList = res.data.data.res;
     // });
-    this.coderExamList = this.$apis.getAllCoderExams().data.data["res"];
-
-    if (this.isLogin) {
+    // todo
+    this.coderExamList = this.$apis.getAllCoderExams().data.data.res;
+    if (this.isLogin && this.isStudent) {
       this.$apis.getStudentCourses(this.$store.state.user.id)
         .then(res => {
           this.myCourseList = res.data.data;
         })
         .catch(err => {
         });
-      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.$apis.getStudentEvalExams({state: 0})
+        .then(
+          res => {
+            this.myEvalExamList = res.data.data.examVOList;
+          })
+        .catch();
+      this.$apis.getStudentCoderExams({})
+        .then(res => {
+          this.myCoderExamList = res.data.data.res;
+        })
+        .catch();
       this.myTestList = [].concat(this.myEvalExamList).concat(this.myCoderExamList);
     }
 

+ 33 - 4
src/views/TestPage/TestPage.vue

@@ -1,7 +1,8 @@
 <template>
   <el-row id="test-page-body">
     <el-col :span="3">
-      <el-menu background-color="#f8f9fb" default-active="1" style="position: fixed; width: 180px;" @select="handleSelect">
+      <el-menu background-color="#f8f9fb" default-active="1" style="position: fixed; width: 180px;"
+               @select="handleSelect">
         <el-menu-item index="0">
           <el-icon>
             <Back/>
@@ -35,11 +36,18 @@
           <el-divider style="grid-column-start: 1; grid-column-end: 5"/>
           <CoderCard v-for="item in coderExamList" :key="item.id" :coderVO="item"/>
         </div>
-        <div v-else class="test-page-main">
+        <div v-if="this.activeIndex === '2' && isStudent" class="test-page-main">
           <EvalCard v-for="item in evalExamList_my" :key="item.id" :examVO="item"/>
           <el-divider style="grid-column-start: 1; grid-column-end: 5"/>
           <CoderCard v-for="item in coderExamList_my" :key="item.id" :coderVO="item"/>
         </div>
+        <!--todo-->
+        <div v-if="this.activeIndex === '2' && isTeacher">
+          教师请前往
+          <span style="cursor: pointer;color: red"
+                @click="$router.push('/manage')">管理页面</span>
+          查看相关测试。
+        </div>
       </el-card>
     </el-col>
   </el-row>
@@ -51,12 +59,12 @@
 import EvalCard from "@/components/EvalCard";
 import CoderCard from "@/components/CoderCard";
 import GlobalFooter from "@/components/GlobalFooter";
-import { Back, Document, DocumentChecked } from "@element-plus/icons-vue";
+import {Back, Document, DocumentChecked} from "@element-plus/icons-vue";
 
 
 export default {
   name: "TestPage",
-  components: { Back, Document, DocumentChecked, GlobalFooter, CoderCard, EvalCard, },
+  components: {Back, Document, DocumentChecked, GlobalFooter, CoderCard, EvalCard,},
   data() {
     return {
       activeIndex: "1",
@@ -74,6 +82,12 @@ export default {
         return "我的测试";
       }
     },
+    isTeacher() {
+      return this.$store.getters.isTeacher;
+    },
+    isStudent() {
+      return this.$store.getters.isStudent;
+    },
   },
 
 
@@ -81,12 +95,27 @@ export default {
     // await this.$apis.getAllEvalExams().then(res => {
     //   this.coderExamList = res.data.data["examVOList"];
     // });
+    // todo
     this.evalExamList = this.$apis.getAllEvalExams().data.data["examVOList"];
 
     // await this.$apis.getAllCoderExams().then(res => {
     //   this.coderExamList = res.data.data.res;
     // });
+    // todo
     this.coderExamList = this.$apis.getAllCoderExams().data.data["res"];
+    if (this.isStudent) {
+      this.$apis.getStudentEvalExams({state: 0})
+        .then(res => {
+          this.evalExamList_my = res.data.data.examVOList;
+
+          this.$apis.getStudentCoderExams({})
+            .then(res => {
+              this.coderExamList_my = res.data.data.res;
+            })
+            .catch();
+        })
+        .catch();
+    }
   },
 
   methods: {