CoursePage.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <el-row id="course-page-body">
  3. <el-col :span="3">
  4. <el-menu background-color="#f8f9fb" default-active="1" @select="handleSelect">
  5. <el-menu-item index="0">
  6. <el-icon>
  7. <Back/>
  8. </el-icon>
  9. <span style="padding-left: 20px">返回首页</span>
  10. </el-menu-item>
  11. <el-menu-item index="1">
  12. <el-icon>
  13. <Document/>
  14. </el-icon>
  15. <span style="padding-left: 20px">全部课程</span>
  16. </el-menu-item>
  17. <el-menu-item index="2">
  18. <el-icon>
  19. <DocumentChecked/>
  20. </el-icon>
  21. <span style="padding-left: 20px">我的课程</span>
  22. </el-menu-item>
  23. </el-menu>
  24. </el-col>
  25. <el-col :span="1"/>
  26. <el-col :span="18">
  27. <el-card>
  28. <template #header>
  29. <span style="font-weight: bold; font-size: larger">
  30. {{ activeName }}
  31. </span>
  32. </template>
  33. <div v-if="this.activeIndex === '1'" class="course-page-main">
  34. <CourseCard v-for="course in courses_all" :key="course.id" :courseVO="course"/>
  35. </div>
  36. <div v-else class="course-page-main">
  37. <CourseCard v-for="course in courses_my" :key="course.id" :courseVO="course"/>
  38. </div>
  39. </el-card>
  40. </el-col>
  41. </el-row>
  42. <GlobalFooter/>
  43. </template>
  44. <script>
  45. import GlobalFooter from "@/components/GlobalFooter";
  46. import { Back, Document, DocumentChecked } from "@element-plus/icons-vue";
  47. import CourseCard from "@/components/CourseCard";
  48. export default {
  49. name: "CoursePage",
  50. components: { Back, CourseCard, Document, DocumentChecked, GlobalFooter },
  51. data() {
  52. return {
  53. activeIndex: "1",
  54. courses_all: [],
  55. courses_my: [],
  56. };
  57. },
  58. computed: {
  59. activeName() {
  60. if (this.activeIndex === "1") {
  61. return "全部课程";
  62. } else {
  63. return "我的课程";
  64. }
  65. },
  66. },
  67. mounted() {
  68. this.$apis.getAllCourses().then(res => {
  69. this.courses_all = res.data.data;
  70. });
  71. if (this.$store.state.user.token) {
  72. this.courses_my = this.$apis.getStudentCourses({ studentId: this.$store.state.user.id }).then(res => {
  73. this.courses_my = res.data.data;
  74. });
  75. }
  76. },
  77. methods: {
  78. handleSelect(index) {
  79. if (index === "0") {
  80. this.$router.push("portal");
  81. }
  82. this.activeIndex = index;
  83. },
  84. },
  85. };
  86. </script>
  87. <style scoped>
  88. #course-page-body {
  89. margin: 40px 60px 80px 60px;
  90. min-height: calc(100vh - 340px);
  91. position: relative;
  92. }
  93. .course-page-main {
  94. display: grid;
  95. grid-template-columns: 1fr 1fr 1fr 1fr;
  96. grid-gap: 20px;
  97. }
  98. </style>