|
|
@@ -0,0 +1,200 @@
|
|
|
+<!--
|
|
|
+ Description: 我的课程页面
|
|
|
+ Author: BaiQi
|
|
|
+ Created Date: 2024-7-2
|
|
|
+-->
|
|
|
+<template>
|
|
|
+ <el-card style="margin: 10px auto 0;height: 625px; width: 80%" shadow="never">
|
|
|
+ <el-button :icon="Refresh" circle></el-button>
|
|
|
+ <template v-if="role == 'teachers'">
|
|
|
+ <el-button @click="visible = !visible" color="#597d3b">新增课程</el-button>
|
|
|
+ </template>
|
|
|
+ <el-select
|
|
|
+ v-model="state"
|
|
|
+ placeholder="状态"
|
|
|
+ size="default"
|
|
|
+ style="width: 150px; margin-left: 10px;"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in stateOptions"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+
|
|
|
+ <el-table :data="dataForm.records" height="500" style="width: 100%">
|
|
|
+ <el-table-column type="index"/>
|
|
|
+ <el-table-column prop="courseName" label="课程名称"/>
|
|
|
+ <el-table-column prop="description" label="描述"/>
|
|
|
+ <el-table-column prop="endTime" label="截止时间" sortable/>
|
|
|
+ <el-table-column>
|
|
|
+ <template #default="scope">
|
|
|
+ <el-button text @click="handleShowDetail(scope.row.courseId)" style="margin-right: 0; margin-left: 0;padding-left: 5px; padding-right: 5px">
|
|
|
+ <el-icon style="margin-right: 3px"><ZoomIn/></el-icon>
|
|
|
+ 详情
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-card>
|
|
|
+
|
|
|
+ <el-dialog v-model="visible">
|
|
|
+ <el-form :model="newCourse">
|
|
|
+ <el-form-item label="课程名称">
|
|
|
+ <el-input v-model="newCourse.courseName" placeholder="请输入名称"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="面向年级">
|
|
|
+ <el-input v-model="newCourse.targetGrade" placeholder="请输入年级"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="描述">
|
|
|
+ <el-input v-model="newCourse.description" placeholder="请输入描述"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="选课码">
|
|
|
+ <el-input v-model="newCourse.enrollCode" placeholder="请输入选课码"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="开始时间">
|
|
|
+ <el-date-picker v-model="newCourse.startTime" type="datetime" placeholder="截止时间" style="width: 180px"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="截止时间">
|
|
|
+ <el-date-picker v-model="newCourse.endTime" type="datetime" placeholder="截止时间" style="width: 180px"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button @click="visible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="handleSubmit()">确定</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+ import useApis from "@/apis";
|
|
|
+ import {useStore} from "@/store";
|
|
|
+ import {onMounted, reactive, ref} from "vue";
|
|
|
+ import type {CourseVO} from "@/types/vo";
|
|
|
+ import {Refresh, ZoomIn} from "@element-plus/icons-vue";
|
|
|
+ import router from "@/router";
|
|
|
+ import type {CourseDTO} from "@/types/dto";
|
|
|
+ import {ElNotification} from "element-plus";
|
|
|
+
|
|
|
+ const apis = useApis()
|
|
|
+ const store = useStore()
|
|
|
+ const role:'teachers' | 'student' = store.user.role === 'STUDENT' ? 'student':'teachers';
|
|
|
+
|
|
|
+ let visible = ref(false)
|
|
|
+
|
|
|
+ let dataForm = reactive<{
|
|
|
+ records: CourseVO[],
|
|
|
+ current: number,// 当前页码
|
|
|
+ size: number, // 分页大小
|
|
|
+ pages: number, // 总页数
|
|
|
+ total: number
|
|
|
+ }>({
|
|
|
+ records: null,
|
|
|
+ current: null,
|
|
|
+ size: null,
|
|
|
+ pages: null,
|
|
|
+ total: null,
|
|
|
+ })
|
|
|
+
|
|
|
+ let newCourse = reactive<CourseDTO>({
|
|
|
+ courseName: "",
|
|
|
+ teacherIds: [store.user.id],
|
|
|
+ courseImages: [],
|
|
|
+ targetGrade: "",
|
|
|
+ startTime: "",
|
|
|
+ endTime: "",
|
|
|
+ description: "",
|
|
|
+ enrollCode: ""
|
|
|
+ })
|
|
|
+
|
|
|
+ function formatDate(date) {
|
|
|
+ const d = new Date(date);
|
|
|
+ const year = d.getFullYear();
|
|
|
+ const month = String(d.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(d.getDate()).padStart(2, '0');
|
|
|
+ const hours = String(d.getHours()).padStart(2, '0');
|
|
|
+ const minutes = String(d.getMinutes()).padStart(2, '0');
|
|
|
+ const seconds = String(d.getSeconds()).padStart(2, '0');
|
|
|
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleSubmit = () => {
|
|
|
+ newCourse.endTime = formatDate(newCourse.endTime)
|
|
|
+ newCourse.startTime = formatDate(newCourse.startTime)
|
|
|
+ apis.createCourse(newCourse)
|
|
|
+ .then((res:any) => {
|
|
|
+ if(res.data.code===200) {
|
|
|
+ ElNotification({
|
|
|
+ title: '添加成功',
|
|
|
+ type: 'success',
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ console.log(res.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ visible.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleShowDetail = (value:number) => {
|
|
|
+ // router.push(`/home/courseDetail/${value}`)
|
|
|
+ router.replace(`/home/courseDetail/${value}`);
|
|
|
+ // location.reload()
|
|
|
+ }
|
|
|
+
|
|
|
+ const fetchCourseByUserId = () => {
|
|
|
+ if (role === 'student') {
|
|
|
+ apis.getCourseByStudentId(store.user.id)
|
|
|
+ .then((res: any) => {
|
|
|
+ let data = res.data.data
|
|
|
+ console.log(data)
|
|
|
+ Object.assign(dataForm, {...data})
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ });
|
|
|
+ } else if (role === "teachers") {
|
|
|
+ apis.getCourseByTeacherId(store.user.id)
|
|
|
+ .then((res: any) => {
|
|
|
+ let data = res.data.data
|
|
|
+ console.log(data)
|
|
|
+ Object.assign(dataForm, {...data})
|
|
|
+ })
|
|
|
+ .catch((err: any) => {
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ fetchCourseByUserId()
|
|
|
+ })
|
|
|
+
|
|
|
+ // TODO:状态选择
|
|
|
+ let state = ref(null)
|
|
|
+ const stateOptions = [
|
|
|
+ {
|
|
|
+ value: 0,
|
|
|
+ label: "已结课"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 1,
|
|
|
+ label: "未结课"
|
|
|
+ },
|
|
|
+ ]
|
|
|
+</script>
|
|
|
+
|
|
|
+<script lang="ts">
|
|
|
+export default {
|
|
|
+ name: "CoursePage"
|
|
|
+}
|
|
|
+</script>
|