CoursePage.vue 3.0 KB

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