|
|
@@ -0,0 +1,166 @@
|
|
|
+<template>
|
|
|
+ <div class="course-content">
|
|
|
+ <div class="course-content-container">
|
|
|
+ <div class="course-content-title">
|
|
|
+ {{ props.title }}
|
|
|
+ </div>
|
|
|
+ <div class="course-items-container">
|
|
|
+ <el-card v-for="item in getCoursesSlice(0, 5)" :key="item.courseId" class="course-item active" @click="handleClick(item.courseId)">
|
|
|
+ <div style="width: 200px; height: 120px">
|
|
|
+ <img :src="item.courseImages[0]" :alt="item.courseName" class="course-item-img">
|
|
|
+ </div>
|
|
|
+ <div class="course-item-content">
|
|
|
+ <div style="font-weight: bold">{{item.courseName}}</div>
|
|
|
+ <div>{{item.description}}</div>
|
|
|
+ <div>{{item.teacherIds.join("\n")}}</div>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+
|
|
|
+ <template v-if="getCoursesSlice(0, 5).length < 5">
|
|
|
+ <el-card v-for="item in 5 - getCoursesSlice(0, 5).length" :key="item" class="course-item-hidden">
|
|
|
+ </el-card>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </div>
|
|
|
+ <div class="course-items-container">
|
|
|
+ <el-card v-for="item in getCoursesSlice(5, 10)" :key="item.courseId" class="course-item active" @click="handleClick(item.courseId)">
|
|
|
+ <div style="width: 200px; height: 120px">
|
|
|
+ <img :src="item.courseImages[0]" :alt="item.courseName" class="course-item-img">
|
|
|
+ </div>
|
|
|
+ <div class="course-item-content">
|
|
|
+ <div style="font-weight: bold">{{item.courseName}}</div>
|
|
|
+ <div>{{item.description}}</div>
|
|
|
+ <div>{{item.teacherIds.join("\n")}}</div>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+
|
|
|
+ <template v-if="getCoursesSlice(5, 10).length < 5">
|
|
|
+ <el-card v-for="item in 5 - getCoursesSlice(5, 10).length" :key="item" class="course-item-hidden">
|
|
|
+ </el-card>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <el-pagination
|
|
|
+ small
|
|
|
+ style="font-size: 16px;margin-top: 10px;margin-left: 450px"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ :current-page="queryInfo.pageNow"
|
|
|
+ :page-size="queryInfo.pageSize"
|
|
|
+ layout="total, prev, pager, next, jumper"
|
|
|
+ :total="pageInfo.total">
|
|
|
+ </el-pagination>
|
|
|
+
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import './MoreCourse.scss'
|
|
|
+import {defineProps, onMounted, reactive} from "vue";
|
|
|
+import useApis from "@/apis";
|
|
|
+import type {CourseQuery} from "@/types/query";
|
|
|
+import router from "@/router";
|
|
|
+import {useStore} from "@/store";
|
|
|
+
|
|
|
+const apis = useApis()
|
|
|
+const store = useStore()
|
|
|
+const role:'teachers' | 'student' = store.user.role === 'STUDENT' ? 'student':'teachers';
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ title: string;
|
|
|
+ type: 'all' | 'my'
|
|
|
+}>()
|
|
|
+
|
|
|
+const queryInfo = reactive({
|
|
|
+ pageNow: 1,
|
|
|
+ pageSize: 10,
|
|
|
+})
|
|
|
+
|
|
|
+let pageInfo = reactive({
|
|
|
+ total: 0,
|
|
|
+ courseData: []
|
|
|
+})
|
|
|
+
|
|
|
+// 处理课程卡片的点击事件
|
|
|
+const handleClick = (value:number) => {
|
|
|
+ router.push(`/home/courseDetail/${value}`)
|
|
|
+}
|
|
|
+
|
|
|
+const handleCurrentChange =(index:number)=>{
|
|
|
+ queryInfo.pageNow=index;
|
|
|
+ fetchData();
|
|
|
+}
|
|
|
+
|
|
|
+const fetchData = () => {
|
|
|
+ if(props.type === 'all'){
|
|
|
+ fetchAllCourse()
|
|
|
+ } else if(props.type === 'my'){
|
|
|
+ fetchCourseByUserId()
|
|
|
+ }else{
|
|
|
+ alert("获取课程失败")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const fetchAllCourse = () => {
|
|
|
+ const query = reactive<CourseQuery>({
|
|
|
+ courseId:null,
|
|
|
+ teacherId:null,
|
|
|
+ studentId:null,
|
|
|
+ courseName:null,
|
|
|
+ semester:null,
|
|
|
+ })
|
|
|
+ apis.getAllCourse(query, queryInfo.pageNow, queryInfo.pageSize)
|
|
|
+ .then((res: any) => {
|
|
|
+ console.log(res)
|
|
|
+ pageInfo.courseData = res.data.data.records
|
|
|
+ pageInfo.total = res.data.data.total
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.error("错误信息",err);
|
|
|
+ })
|
|
|
+ .finally(() => {});
|
|
|
+}
|
|
|
+
|
|
|
+const fetchCourseByUserId = () => {
|
|
|
+ if(role === 'student'){
|
|
|
+ apis.getCourseByStudentId(store.user.id, queryInfo.pageNow, queryInfo.pageSize)
|
|
|
+ .then((res: any) => {
|
|
|
+ console.log(res)
|
|
|
+ pageInfo.courseData = res.data.data.records
|
|
|
+ pageInfo.total = res.data.data.total
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
+ .finally(() => {});
|
|
|
+ } else if(role === "teachers"){
|
|
|
+ apis.getCourseByTeacherId(store.user.id, queryInfo.pageNow, queryInfo.pageSize)
|
|
|
+ .then((res: any) => {
|
|
|
+ console.log(res.data.data)
|
|
|
+ pageInfo.courseData = res.data.data.records
|
|
|
+ pageInfo.total = res.data.data.total
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
+ .finally(() => {});
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//只获取前五个课程
|
|
|
+const getCoursesSlice = (start:number, end:number) => {
|
|
|
+ return pageInfo.courseData.slice(start, end)
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(()=>{
|
|
|
+ fetchData()
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<script lang="ts">
|
|
|
+export default {
|
|
|
+ name: "AllCourse"
|
|
|
+}
|
|
|
+</script>
|