|
|
@@ -7,17 +7,17 @@
|
|
|
<div class="course-type-selector">
|
|
|
<el-select v-model="courseType" class="m-2" placeholder="课程类型">
|
|
|
<el-option
|
|
|
- v-for="item in courseTypeOptions"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
+ v-for="item in courseTypeOptions"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
/>
|
|
|
</el-select>
|
|
|
<el-button class="ml-16" plain type="primary" @click="dialogVisible=true">{{ dialogTitle }}</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="course-card-list-container mt-16">
|
|
|
- <div v-for="(item,index) in courseListExample" :key="index" class="cItem">
|
|
|
+ <div v-for="(item,index) in myCourseList" :key="index" class="cItem">
|
|
|
<CourseCard :courseVO="item"></CourseCard>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -25,383 +25,259 @@
|
|
|
</el-card>
|
|
|
</div>
|
|
|
<el-dialog v-model="dialogVisible" :before-close="handleFormCancel" :width="600" title="新增课程">
|
|
|
- <el-form ref="formRef" :model="form" label-width="120px">
|
|
|
- <el-form-item label="课程名称">
|
|
|
+ <el-form ref="formRef" :model="form" label-width="100px" :rules="formRules">
|
|
|
+ <el-form-item label="课程名称" prop="name">
|
|
|
<el-input v-model="form.name" placeholder="请输入课程名称"></el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="所在学期">
|
|
|
- <el-select v-model="form.semester.year" placeholder="年份">
|
|
|
- <el-option v-for="item in Array.from(Array(100),(v,k)=>k+2022)" :key="item" :label="item"
|
|
|
- :value="item"></el-option>
|
|
|
- </el-select>
|
|
|
- -
|
|
|
- <el-select v-model="form.semester.season" placeholder="季节">
|
|
|
- <el-option key="1" label="春" value="春"></el-option>
|
|
|
- <el-option key="2" label="夏" value="夏"></el-option>
|
|
|
- <el-option key="3" label="秋" value="秋"></el-option>
|
|
|
- <el-option key="4" label="冬" value="冬"></el-option>
|
|
|
- </el-select>
|
|
|
+ <el-form-item label="所在学期" required>
|
|
|
+ <el-col :span="11">
|
|
|
+ <el-form-item prop="year">
|
|
|
+ <el-select v-model="form.year" placeholder="年份" style="width: 100%">
|
|
|
+ <el-option v-for="item in Array.from(Array(100),(v,k)=>k+2022)" :key="item" :label="item"
|
|
|
+ :value="item"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="2">-</el-col>
|
|
|
+ <el-col :span="11">
|
|
|
+ <el-form-item prop="season">
|
|
|
+ <el-select v-model="form.season" placeholder="季节" style="width: 100%">
|
|
|
+ <el-option key="1" label="春" value="春"></el-option>
|
|
|
+ <el-option key="2" label="夏" value="夏"></el-option>
|
|
|
+ <el-option key="3" label="秋" value="秋"></el-option>
|
|
|
+ <el-option key="4" label="冬" value="冬"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="课程简介">
|
|
|
+ <el-form-item label="课程简介" prop="description">
|
|
|
<el-input v-model="form.description" placeholder="请输入课程简介"></el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="课程时间">
|
|
|
+ <el-form-item label="课程时间" prop="time">
|
|
|
<el-date-picker v-model="form.courseTime" end-placeholder="结束时间" range-separator="至" start-placeholder="开始时间"
|
|
|
type="datetimerange">
|
|
|
</el-date-picker>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="课程邀请码">
|
|
|
+ <el-form-item label="课程邀请码" prop="invitationCode">
|
|
|
<el-input v-model="form.invitationCode" placeholder="请输入课程邀请码"></el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="课程价格">
|
|
|
+ <el-form-item label="课程价格" prop="price">
|
|
|
<el-input v-model="form.price" placeholder="请输入课程价格">
|
|
|
<template #append>元</template>
|
|
|
</el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="MOOC链接">
|
|
|
+ <el-form-item label="MOOC链接" prop="mooc">
|
|
|
<el-input v-model="form.moocUrl" placeholder="请输入MOOC链接"></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="课程图片">
|
|
|
- <!--todo: -->
|
|
|
+ <el-upload
|
|
|
+ class="upload-demo"
|
|
|
+ action=""
|
|
|
+ :limit="1"
|
|
|
+ list-type="picture"
|
|
|
+ :file-list="form.fileList"
|
|
|
+ :on-change="handleChange"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ :on-exceed="handleExceed"
|
|
|
+ :http-request="httpRequest">
|
|
|
+ <el-button type="primary" plain size="small">点击上传</el-button>
|
|
|
+ </el-upload>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
-
|
|
|
<div style="margin: auto;width: fit-content">
|
|
|
<el-button type="primary" @click="handleFormConfirm">确定</el-button>
|
|
|
<el-button @click="handleFormCancel">取消</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
- <div class="confirm-cancel-dialog">
|
|
|
- <el-dialog v-model="confirmFormCancel" center top="25vh" width="20%">
|
|
|
- <p>是否退出?退出将不保存信息</p>
|
|
|
- <div style="margin: auto;width: fit-content">
|
|
|
- <el-button plain size="small" type="warning" @click="handleConfirmFormCancel">退出</el-button>
|
|
|
- <el-button plain size="small" type="primary" @click="confirmFormCancel=false">取消</el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
- </div>
|
|
|
<GlobalFooter/>
|
|
|
</template>
|
|
|
|
|
|
-<script setup>
|
|
|
+<script>
|
|
|
import CourseCard from "@/components/CourseCard";
|
|
|
-import {reactive, ref} from "vue";
|
|
|
-import {getCurrentInstance} from "vue";
|
|
|
-import {ElMessage} from "element-plus";
|
|
|
+import {ElMessage, ElMessageBox} from "element-plus";
|
|
|
import GlobalFooter from "@/components/GlobalFooter";
|
|
|
+import client from "@/utils/oss";
|
|
|
|
|
|
-const _this = getCurrentInstance().appContext.config.globalProperties;
|
|
|
-
|
|
|
-let dialogVisible = ref(false);
|
|
|
-const dialogTitle = ref("新增课程");
|
|
|
-
|
|
|
-const form = reactive({
|
|
|
- name: "",
|
|
|
- semester: {
|
|
|
- year: "",
|
|
|
- season: "",
|
|
|
+export default {
|
|
|
+ name: "ManagePage",
|
|
|
+ components: {
|
|
|
+ CourseCard,
|
|
|
+ GlobalFooter,
|
|
|
},
|
|
|
- description: "",
|
|
|
- courseTime: [
|
|
|
- null,
|
|
|
- null,
|
|
|
- ],
|
|
|
- invitationCode: "",
|
|
|
- price: "0",//input均会将Number类型转化成为字符串类型
|
|
|
- moocUrl: null,
|
|
|
- imageUrl: null,
|
|
|
-});
|
|
|
-
|
|
|
-const courseListExample = [
|
|
|
- {
|
|
|
- "id": 37,
|
|
|
- "name": "2022-2",
|
|
|
- "teacher": {
|
|
|
- "id": 3117,
|
|
|
- "phone": "13382405535",
|
|
|
- "username": "PortalTestTeacher",
|
|
|
- "name": "PortalTestTeacher",
|
|
|
- "email": "m15256072859@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "TEACHER",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2022-02-21T13:21:26.171+08:00",
|
|
|
- "valid": true
|
|
|
- },
|
|
|
- "semester": "2022春",
|
|
|
- "imageUrl": null,
|
|
|
- "description": "minim eu sit Lorem",
|
|
|
- "startTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "endTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "invitationCode": "3117-4",
|
|
|
- "moocUrl": null,
|
|
|
- "evalId": null,
|
|
|
- "coderId": 12,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-20T11:54:34.084+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
+ data() {
|
|
|
+ const validateName = async (rule, value, callback) => {
|
|
|
+ const res = await this.$apis.checkCourseNameUnique(value);
|
|
|
+ const isNameUnique = res.data.data;
|
|
|
+ if (value === "") {
|
|
|
+ callback(new Error("请输入课程名称"));
|
|
|
+ } else if (!isNameUnique) {
|
|
|
+ callback(new Error("课程名称重复"));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const validateTime = (rule, value, callback) => {
|
|
|
+ if (this.form.courseTime[0] === null || this.form.courseTime[1] === null) {
|
|
|
+ callback(new Error("请选择课程始末时间"));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const validateMooc = (rule, value, callback) => {
|
|
|
+ if (value !== "") {
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return {
|
|
|
+ //
|
|
|
+ dialogVisible: false,
|
|
|
+ dialogTitle: "新增课程",
|
|
|
+ form: {
|
|
|
+ name: "",
|
|
|
+ year: "",
|
|
|
+ season: "",
|
|
|
+ description: "",
|
|
|
+ courseTime: [
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ ],
|
|
|
+ invitationCode: "",
|
|
|
+ price: "0",//input均会将Number类型转化成为字符串类型
|
|
|
+ moocUrl: null,
|
|
|
+ fileList: [],
|
|
|
+ imageUrl: "",
|
|
|
+ },
|
|
|
+ formRules: {
|
|
|
+ name: {
|
|
|
+ required: true, validator: validateName, trigger: "blur",
|
|
|
+ },
|
|
|
+ year: {
|
|
|
+ required: true, message: "请选择年份", trigger: "change",
|
|
|
+ },
|
|
|
+ season: {
|
|
|
+ required: true, message: "请选择季节", trigger: "change",
|
|
|
+ },
|
|
|
+ description: {
|
|
|
+ required: true, message: "请输入课程简介", trigger: "blur",
|
|
|
+ },
|
|
|
+ time: {
|
|
|
+ required: true, validator: validateTime, trigger: "change",
|
|
|
+ },
|
|
|
+ invitationCode: {
|
|
|
+ required: true, message: "请输入课程邀请码", trigger: "blur",
|
|
|
+ },
|
|
|
+ price: {
|
|
|
+ required: true, message: "请输入课程价格", trigger: "blur",
|
|
|
+ },
|
|
|
+ mooc: {
|
|
|
+ required: false, validator: validateMooc, trigger: "blur",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ //
|
|
|
+ myCourseList: [],
|
|
|
+ //
|
|
|
+ courseType: "all",
|
|
|
+ courseTypeOptions: [
|
|
|
+ {value: "all", label: "全部课程"},
|
|
|
+ {value: "pending", label: "未开始"},
|
|
|
+ {value: "start", label: "正在进行"},
|
|
|
+ {value: "end", label: "已结束"},
|
|
|
+ ],
|
|
|
+ };
|
|
|
},
|
|
|
- {
|
|
|
- "id": 37,
|
|
|
- "name": "2022-2",
|
|
|
- "teacher": {
|
|
|
- "id": 3117,
|
|
|
- "phone": "13382405535",
|
|
|
- "username": "PortalTestTeacher",
|
|
|
- "name": "PortalTestTeacher",
|
|
|
- "email": "m15256072859@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "TEACHER",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2022-02-21T13:21:26.171+08:00",
|
|
|
- "valid": true
|
|
|
- },
|
|
|
- "semester": "2022春",
|
|
|
- "imageUrl": null,
|
|
|
- "description": "minim eu sit Lorem",
|
|
|
- "startTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "endTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "invitationCode": "3117-4",
|
|
|
- "moocUrl": null,
|
|
|
- "evalId": null,
|
|
|
- "coderId": 12,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-20T11:54:34.084+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
+ computed: {},
|
|
|
+ mounted() {
|
|
|
+ this.$apis.getTeacherCourses(this.$store.state.user.id).then(res => {
|
|
|
+ this.myCourseList = res.data.data;
|
|
|
+ }).catch();
|
|
|
},
|
|
|
- {
|
|
|
- "id": 37,
|
|
|
- "name": "2022-2",
|
|
|
- "teacher": {
|
|
|
- "id": 3117,
|
|
|
- "phone": "13382405535",
|
|
|
- "username": "PortalTestTeacher",
|
|
|
- "name": "PortalTestTeacher",
|
|
|
- "email": "m15256072859@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "TEACHER",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2022-02-21T13:21:26.171+08:00",
|
|
|
- "valid": true
|
|
|
+ methods: {
|
|
|
+ handleFormConfirm() {
|
|
|
+ this.$refs.formRef.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.form.fileList.length === 0) {
|
|
|
+ this.form.imageUrl = "https://mjh1.oss-cn-hangzhou.aliyuncs.com/hci/no-image.png";
|
|
|
+ this.formatAndCreateCourse();
|
|
|
+ } else {
|
|
|
+ client.put("/seecoder/image-" + this.form.name + ".jpg", this.form.fileList[0].raw)
|
|
|
+ .then(res => {
|
|
|
+ this.form.imageUrl = res.res.requestUrls[0];
|
|
|
+ this.formatAndCreateCourse();
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ ElMessage.error(err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
- "semester": "2022春",
|
|
|
- "imageUrl": null,
|
|
|
- "description": "minim eu sit Lorem",
|
|
|
- "startTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "endTime": "2022-02-28T11:08:07.608+08:00",
|
|
|
- "invitationCode": "3117-4",
|
|
|
- "moocUrl": null,
|
|
|
- "evalId": null,
|
|
|
- "coderId": 12,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-20T11:54:34.084+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
- },
|
|
|
- {
|
|
|
- "id": 42,
|
|
|
- "name": "redrew",
|
|
|
- "teacher": {
|
|
|
- "id": 3117,
|
|
|
- "phone": "13382405535",
|
|
|
- "username": "PortalTestTeacher",
|
|
|
- "name": "PortalTestTeacher",
|
|
|
- "email": "m15256072859@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "TEACHER",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2022-02-21T13:21:26.171+08:00",
|
|
|
- "valid": true
|
|
|
+ handleFormCancel() {
|
|
|
+ ElMessageBox.confirm("是否确认退出?退出后将不保存表格信息。", "提示", {
|
|
|
+ confirmButtonText: "确认退出",
|
|
|
+ cancelButtonText: "我再想想",
|
|
|
+ type: "warning",
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.$refs.formRef.resetFields();
|
|
|
+ this.form.courseTime = [null,null];
|
|
|
+ })
|
|
|
+ .catch(action => {
|
|
|
+ });
|
|
|
},
|
|
|
- "semester": "2023春",
|
|
|
- "imageUrl": null,
|
|
|
- "description": "redrew",
|
|
|
- "startTime": "2022-02-28T16:52:27.67+08:00",
|
|
|
- "endTime": "2022-02-28T16:52:27.67+08:00",
|
|
|
- "invitationCode": "fd sfs",
|
|
|
- "moocUrl": "",
|
|
|
- "evalId": null,
|
|
|
- "coderId": 17,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-28T16:52:06.235+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
- },
|
|
|
- {
|
|
|
- "id": 44,
|
|
|
- "name": "rewrite",
|
|
|
- "teacher": {
|
|
|
- "id": 3117,
|
|
|
- "phone": "13382405535",
|
|
|
- "username": "PortalTestTeacher",
|
|
|
- "name": "PortalTestTeacher",
|
|
|
- "email": "m15256072859@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "TEACHER",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2022-02-21T13:21:26.171+08:00",
|
|
|
- "valid": true
|
|
|
+ formatAndCreateCourse() {
|
|
|
+ this.$apis.createCourse({
|
|
|
+ name: this.form.name,
|
|
|
+ teacher: {
|
|
|
+ id: this.$store.state.user.id,
|
|
|
+ },
|
|
|
+ semester: this.form.year + this.form.season,
|
|
|
+ imageUrl: this.form.imageUrl,
|
|
|
+ description: this.form.description,
|
|
|
+ startTime: this.form.courseTime[0],
|
|
|
+ endTime: this.form.courseTime[1],
|
|
|
+ invitationCode: this.form.invitationCode,
|
|
|
+ moocUrl: this.form.moocUrl,
|
|
|
+ createdTime: new Date(),
|
|
|
+ price: Number(this.form.price),
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.$refs.formRef.resetFields();
|
|
|
+ ElMessage.success("新建课程成功");
|
|
|
+ this.form.courseTime = [null,null];
|
|
|
+ this.myCourseList.push(res.data.data);
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ ElMessage.error(err);
|
|
|
+ });
|
|
|
},
|
|
|
- "semester": "2022春",
|
|
|
- "imageUrl": null,
|
|
|
- "description": "rewriter",
|
|
|
- "startTime": "2022-02-28T21:46:24.307+08:00",
|
|
|
- "endTime": "2022-02-28T21:46:24.307+08:00",
|
|
|
- "invitationCode": "rewriterule",
|
|
|
- "moocUrl": null,
|
|
|
- "evalId": null,
|
|
|
- "coderId": 19,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-28T21:46:24.008+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
- },
|
|
|
- {
|
|
|
- "id": 3,
|
|
|
- "name": "提象何角众交",
|
|
|
- "teacher": {
|
|
|
- "id": 1481,
|
|
|
- "phone": "17301585267",
|
|
|
- "username": "seecoder",
|
|
|
- "name": "root",
|
|
|
- "email": "seecoder@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "ADMIN",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2021-08-26T14:24:37.859+08:00",
|
|
|
- "valid": true
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- "id": 3,
|
|
|
- "name": "提象何角众交",
|
|
|
- "teacher": {
|
|
|
- "id": 1481,
|
|
|
- "phone": "17301585267",
|
|
|
- "username": "seecoder",
|
|
|
- "name": "root",
|
|
|
- "email": "seecoder@163.com",
|
|
|
- "photo": null,
|
|
|
- "role": "ADMIN",
|
|
|
- "signature": "无",
|
|
|
- "createdTime": "2021-08-26T14:24:37.859+08:00",
|
|
|
- "valid": true
|
|
|
+ // el-upload相关的方法
|
|
|
+ handleChange(file, fileList) {
|
|
|
+ this.form.fileList = fileList;
|
|
|
},
|
|
|
- "semester": "2022春",
|
|
|
- "imageUrl": "https://lain.bgm.tv/pic/cover/l/60/4d/325585_HHZpF.jpg",
|
|
|
- "description": "minim eu sit Lorem",
|
|
|
- "startTime": "2022-02-24T10:24:18.129+08:00",
|
|
|
- "endTime": "2022-02-24T10:24:18.129+08:00",
|
|
|
- "invitationCode": "15",
|
|
|
- "moocUrl": null,
|
|
|
- "evalId": null,
|
|
|
- "coderId": null,
|
|
|
- "helperId": null,
|
|
|
- "createdTime": "2022-02-20T11:54:34.084+08:00",
|
|
|
- "price": 0,
|
|
|
- "courseState": "NORMAL"
|
|
|
- }
|
|
|
-];
|
|
|
-
|
|
|
-const handleFormConfirm = async () => {
|
|
|
- const checkRes = checkForm();
|
|
|
- if (!checkRes.res) {
|
|
|
- ElMessage({
|
|
|
- message: checkRes.msg,
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- const res = await _this.$apis.createCourse({
|
|
|
- name: form.name,
|
|
|
- teacher: {
|
|
|
- id: _this.$store.state.user.id,
|
|
|
+ handleExceed(files, fileList) {
|
|
|
+ ElMessage.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
|
|
|
},
|
|
|
- semester: form.semester.year + form.semester.season,
|
|
|
- imageUrl: form.imageUrl,
|
|
|
- description: form.description,
|
|
|
- startTime: form.courseTime[0],
|
|
|
- endTime: form.courseTime[1],
|
|
|
- invitationCode: form.invitationCode,
|
|
|
- moocUrl: form.moocUrl,
|
|
|
- createdTime: new Date(),
|
|
|
- price: Number(form.price),
|
|
|
- });
|
|
|
- console.log(res);
|
|
|
- if (res.code === 0) {
|
|
|
- ElMessage({
|
|
|
- message: "新建课程成功!",
|
|
|
- type: "success",
|
|
|
- });
|
|
|
- clearForm();
|
|
|
- dialogVisible.value = false;
|
|
|
- // todo: 刷新课程列表
|
|
|
- } else {
|
|
|
- ElMessage({
|
|
|
- message: res.data.message,
|
|
|
- type: "error",
|
|
|
- });
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-const courseType = ref("all");
|
|
|
-const courseTypeOptions = ref([
|
|
|
- {value: "all", label: "全部课程"},
|
|
|
- {value: "pending", label: "未开始"},
|
|
|
- {value: "start", label: "正在进行"},
|
|
|
- {value: "end", label: "已结束"},
|
|
|
-]);
|
|
|
-
|
|
|
-
|
|
|
-//取消新增课程,弹窗确认
|
|
|
-let confirmFormCancel = ref(false);
|
|
|
-const handleFormCancel = function () {
|
|
|
- confirmFormCancel.value = true;
|
|
|
-};
|
|
|
-
|
|
|
-//确认取消新增课程
|
|
|
-const handleConfirmFormCancel = function () {
|
|
|
- confirmFormCancel.value = false;
|
|
|
- dialogVisible.value = false;
|
|
|
- clearForm();
|
|
|
-};
|
|
|
-
|
|
|
-//点击确定新增课程按钮时检查填写内容是否合法
|
|
|
-const checkForm = function () {
|
|
|
- const nameValid = form.name.length > 0;
|
|
|
- if (!nameValid) return {res: false, msg: "请输入课程名称!"};
|
|
|
- const yearValid = form.semester.year !== "";
|
|
|
- if (!yearValid) return {res: false, msg: "请选择课程所在年份!"};
|
|
|
- const seasonValid = form.semester.season !== "";
|
|
|
- if (!seasonValid) return {res: false, msg: "请选择课程所在季节!"};
|
|
|
- const descriptionValid = form.description.length > 0;
|
|
|
- if (!descriptionValid) return {res: false, msg: "请输入课程简介!"};
|
|
|
- const courseTimeValid = form.courseTime[0] !== null && form.courseTime[1] !== null;
|
|
|
- if (!courseTimeValid) return {res: false, msg: "请选择课程时间!"};
|
|
|
- const invitationCodeValid = form.invitationCode.length > 0;
|
|
|
- if (!invitationCodeValid) return {res: false, msg: "请输入课程邀请码!"};
|
|
|
- const priceValid = form.price.length > 0 && (parseInt(form.price) >= 0);
|
|
|
- if (!priceValid) return {res: false, msg: "请正确输入课程价格!"};
|
|
|
- //moocUrl和imgUrl可以为null
|
|
|
- // todo: 对moocUrl的检验,查询该链接是否有效
|
|
|
- return {res: true, msg: "表格填写完成!"};
|
|
|
-};
|
|
|
-//
|
|
|
-const clearForm = function () {
|
|
|
- form.name = "";
|
|
|
- form.semester.year = "";
|
|
|
- form.semester.season = "";
|
|
|
- form.description = "";
|
|
|
- form.courseTime[0] = form.courseTime[1] = null;
|
|
|
- form.invitationCode = "";
|
|
|
- form.price = "0";
|
|
|
- form.moocUrl = null;
|
|
|
- form.imageUrl = null;
|
|
|
+ httpRequest(event) {
|
|
|
+ },
|
|
|
+ beforeUpload(file) {
|
|
|
+ const isJPG = file.type === "image/jpeg";
|
|
|
+ const isLt10M = file.size / 1024 / 1024 < 10;
|
|
|
+ const isPNG = file.type === "image/png";
|
|
|
+ if (!(isJPG || isPNG)) {
|
|
|
+ ElMessage.error("上传头像图片只能是 JPG/PNG 格式!");
|
|
|
+ }
|
|
|
+ if (!isLt10M) {
|
|
|
+ ElMessage.error("上传图片大小不能超过 10MB!");
|
|
|
+ }
|
|
|
+ return (isJPG || isPNG) && isLt10M;
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|