Merge remote-tracking branch 'origin/Chester' into merge/1
# Conflicts: # package-lock.json # package.json # src/assets/avatar.jpg # src/router/authentication.js # src/services/authenticationService.js # src/store/authentication.js # src/views/authentication/Login.vue # src/views/authentication/Profile.vue # src/views/authentication/Register.vue
This commit is contained in:
commit
4dc09d2983
BIN
public/background1.jpg
Normal file
BIN
public/background1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 300 KiB |
BIN
public/background2.jpg
Normal file
BIN
public/background2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue';
|
||||||
|
|
||||||
const count = ref(0)
|
const count = ref(0);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -13,7 +13,7 @@ const count = ref(0)
|
|||||||
<img src="../assets/vue.svg" class="logo vue" alt="Vue logo" />
|
<img src="../assets/vue.svg" class="logo vue" alt="Vue logo" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<h1>{{ this.$route.meta.msg }}</h1>
|
<h1>{{ $route.meta.msg }}</h1>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<el-button type="success" @click="count++">count is {{ count }}</el-button>
|
<el-button type="success" @click="count++">count is {{ count }}</el-button>
|
||||||
@ -25,19 +25,24 @@ const count = ref(0)
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
Check out
|
Check out
|
||||||
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank">create-vue</a>, the official Vue + Vite starter
|
||||||
>create-vue</a
|
|
||||||
>, the official Vue + Vite starter
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Learn more about IDE Support for Vue in the
|
Learn more about IDE Support for Vue in the
|
||||||
<a
|
<a href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support" target="_blank">Vue Docs Scaling up Guide</a>.
|
||||||
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
|
|
||||||
target="_blank"
|
|
||||||
>Vue Docs Scaling up Guide</a
|
|
||||||
>.
|
|
||||||
</p>
|
</p>
|
||||||
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
||||||
|
|
||||||
|
<!-- 添加导航链接 -->
|
||||||
|
<ul>
|
||||||
|
<li><router-link to="/login">Login</router-link></li>
|
||||||
|
<li><router-link to="/register">Register</router-link></li>
|
||||||
|
<li><router-link to="/courseList">Courses</router-link></li>
|
||||||
|
<li><router-link to="/meetings">Meetings</router-link></li>
|
||||||
|
<li><router-link to="/news">News</router-link></li>
|
||||||
|
<li><router-link to="/organizations">Organizations</router-link></li>
|
||||||
|
<li><router-link to="/users">Users</router-link></li>
|
||||||
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@ -56,4 +61,4 @@ const count = ref(0)
|
|||||||
.read-the-docs {
|
.read-the-docs {
|
||||||
color: #888;
|
color: #888;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -1,9 +1,23 @@
|
|||||||
// import CourseList from '../views/course-management/CourseList.vue'
|
import Course from '../views/course-management/Course.vue';
|
||||||
// import CourseDetail from '../views/course-management/CourseDetail.vue'
|
import CourseList from '../views/course-management/CourseList.vue';
|
||||||
// import CourseEdit from '../views/course-management/CourseEdit.vue'
|
import BackgroundWrapper from "@views/course-management/BackgroundWrapper.vue";
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
// { path: '/courses', component: CourseList },
|
{
|
||||||
// { path: '/courses/:id', component: CourseDetail },
|
path: '/course',
|
||||||
// { path: '/courses/:id/edit', component: CourseEdit }
|
name: 'Course',
|
||||||
]
|
component: Course
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '/courseList',
|
||||||
|
name: 'CourseList',
|
||||||
|
component: CourseList
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '/backgroundWrapper',
|
||||||
|
name: 'BackgroundWrapper',
|
||||||
|
component: BackgroundWrapper
|
||||||
|
}
|
||||||
|
];
|
||||||
17
src/views/course-management/BackgroundWrapper.vue
Normal file
17
src/views/course-management/BackgroundWrapper.vue
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<template>
|
||||||
|
<div class="background-wrapper">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.background-wrapper {
|
||||||
|
background: url('@public/background2.jpg') no-repeat center center fixed;
|
||||||
|
background-size: cover;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
425
src/views/course-management/Course.vue
Normal file
425
src/views/course-management/Course.vue
Normal file
@ -0,0 +1,425 @@
|
|||||||
|
<script setup>
|
||||||
|
import {onMounted, ref, computed} from 'vue';
|
||||||
|
import {
|
||||||
|
ElButton,
|
||||||
|
ElForm,
|
||||||
|
ElFormItem,
|
||||||
|
ElInput,
|
||||||
|
ElMessage,
|
||||||
|
ElMessageBox,
|
||||||
|
ElUpload
|
||||||
|
} from 'element-plus';
|
||||||
|
|
||||||
|
import {Delete, Plus, Refresh, ZoomIn} from "@element-plus/icons-vue";
|
||||||
|
import {useRoute, useRouter} from "vue-router";
|
||||||
|
import {useStore} from "vuex";
|
||||||
|
import axios from "axios";
|
||||||
|
import BackgroundWrapper from './BackgroundWrapper.vue'; // 导入 BackgroundWrapper
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
const store = useStore();
|
||||||
|
const token = ref('')
|
||||||
|
const form = ref({
|
||||||
|
token: '',
|
||||||
|
title: '',
|
||||||
|
description: '',
|
||||||
|
orderNo: '',
|
||||||
|
author: '',
|
||||||
|
videoPath: '',
|
||||||
|
imagePath: ''
|
||||||
|
});
|
||||||
|
const createMode = ref(false);
|
||||||
|
const modeTitle = ref('');
|
||||||
|
|
||||||
|
const videoFileList = ref([]); // 用于存储上传视频文件的列表
|
||||||
|
const imageFileList = ref([]); // 用于存储上传图片文件的列表
|
||||||
|
const basePath = '/api/courses'
|
||||||
|
const videoUploadUrl = basePath + '/upload'; // 上传视频的后端地址
|
||||||
|
const imageUploadUrl = videoUploadUrl; // 上传图片的后端地址
|
||||||
|
const dialogImageUrl = ref('');
|
||||||
|
const dialogVisible = ref(false); // 用于图片放大预览
|
||||||
|
|
||||||
|
//下面是编辑模式需要的一些变量
|
||||||
|
const id = ref('');
|
||||||
|
|
||||||
|
const beforeVideoUpload = (file) => {
|
||||||
|
const isMp4 = file.type === 'video/mp4';
|
||||||
|
if (!isMp4) {
|
||||||
|
ElMessage.error('只能上传 mp4 格式的视频文件!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLt500M = file.size / 1024 / 1024 < 500;
|
||||||
|
if (!isLt500M) {
|
||||||
|
ElMessage.error('上传视频大小不能超过 500MB!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const beforeImageUpload = (file) => {
|
||||||
|
const isImage = file.type === 'image/png' || file.type === 'image/jpg' || file.type === 'image/jpeg';
|
||||||
|
if (!isImage) {
|
||||||
|
ElMessage.error('只能上传 png/jpg/jpeg 格式的图片文件!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLt5M = file.size / 1024 / 1024 < 5;
|
||||||
|
if (!isLt5M) {
|
||||||
|
ElMessage.error('上传文件大小不能超过 5MB!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVideoSuccess = (response, file, fileList) => {
|
||||||
|
file.url = response.url;
|
||||||
|
form.value.videoPath = response.url; // 确保设置到表单中
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImageSuccess = (response, file, fileList) => {
|
||||||
|
file.url = response.url;
|
||||||
|
form.value.imagePath = response.url; // 确保设置到表单中
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVideoError = (error, file, fileList) => {
|
||||||
|
ElMessage.error('视频上传失败,请重试!');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImageError = (error, file, fileList) => {
|
||||||
|
ElMessage.error('图片上传失败,请重试!');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVideoChange = (file, fileList) => {
|
||||||
|
if (fileList.length > 1) {
|
||||||
|
fileList.splice(0, fileList.length - 1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleImageChange = (file, fileList) => {
|
||||||
|
if (fileList.length > 1) {
|
||||||
|
fileList.splice(0, fileList.length - 1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePictureCardPreview = (file) => {
|
||||||
|
dialogImageUrl.value = file.url
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
const handleRemoveImage = (file) => {
|
||||||
|
imageFileList.value = imageFileList.value.filter((item) => item.uid !== file.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRemoveVideo = (file) => {
|
||||||
|
videoFileList.value = videoFileList.value.filter((item) => item.uid !== file.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCommit = async () => {
|
||||||
|
if (form.value.title === '' || form.value.description === '' || form.value.orderNo === '' || form.value.author === '') {
|
||||||
|
await ElMessageBox.alert('请填写完整信息!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isNaN(form.value.orderNo)) {
|
||||||
|
await ElMessageBox.alert('排序必须是一个数字!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (imageFileList.value.length === 0 || videoFileList.value.length === 0) {
|
||||||
|
await ElMessageBox.alert('请选择封面图片和课程视频!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
form.value.imagePath = imageFileList.value[0].url;
|
||||||
|
form.value.videoPath = videoFileList.value[0].url;
|
||||||
|
if (createMode.value) {
|
||||||
|
try {
|
||||||
|
const response = await axios.post(basePath, form.value);
|
||||||
|
ElMessage.success('添加成功!');
|
||||||
|
router.push('/courseList');
|
||||||
|
} catch (e) {
|
||||||
|
await ElMessageBox.alert(e.response.data.message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const response = await axios.put(`${basePath}/${id.value}`, form.value);
|
||||||
|
ElMessage.success('修改成功!');
|
||||||
|
router.push('/courseList');
|
||||||
|
} catch (e) {
|
||||||
|
await ElMessageBox.alert(e.response.data.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isLayoutReady = ref(false);
|
||||||
|
|
||||||
|
const fetchCourseDetail = async () => {
|
||||||
|
let params = {
|
||||||
|
token: token.value,
|
||||||
|
}
|
||||||
|
const res = await axios.get(basePath + '/' + id.value, {params});
|
||||||
|
form.value.title = res.data.title;
|
||||||
|
form.value.description = res.data.description;
|
||||||
|
form.value.orderNo = res.data.orderNo;
|
||||||
|
form.value.author = res.data.author;
|
||||||
|
form.value.videoPath = res.data.videoPath;
|
||||||
|
form.value.imagePath = res.data.imagePath;
|
||||||
|
imageFileList.value.push({url: res.data.imagePath});
|
||||||
|
videoFileList.value.push({url: res.data.videoPath});
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderNo = computed({
|
||||||
|
get() {
|
||||||
|
return form.value.orderNo;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
form.value.orderNo = value.replace(/\D/g, ''); // 只保留数字
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
token.value = store.getters['authentication/token'];
|
||||||
|
form.value.token = token.value;
|
||||||
|
if (route.query.mode === 'create' || route.params.mode === 'create') {
|
||||||
|
createMode.value = true;
|
||||||
|
modeTitle.value = '添加课程';
|
||||||
|
}
|
||||||
|
if (route.query.mode === 'edit' || route.params.mode === 'edit') {
|
||||||
|
id.value = route.params.id === undefined ? route.query.id : route.params.id;
|
||||||
|
createMode.value = false;
|
||||||
|
modeTitle.value = '修改课程';
|
||||||
|
fetchCourseDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BackgroundWrapper class="background-wrapper">
|
||||||
|
<div class="form-container">
|
||||||
|
<ElForm :model="form" label-width="120px" @submit.prevent="handleCommit">
|
||||||
|
<h2>{{ modeTitle }}</h2>
|
||||||
|
<ElFormItem label="课程名称" required>
|
||||||
|
<ElInput v-model="form.title" placeholder="请输入课程名称" required></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="课程封面" required>
|
||||||
|
<el-upload
|
||||||
|
:action="imageUploadUrl"
|
||||||
|
:limit="2"
|
||||||
|
:before-upload="beforeImageUpload"
|
||||||
|
:on-success="handleImageSuccess"
|
||||||
|
:on-error="handleImageError"
|
||||||
|
:on-change="handleImageChange"
|
||||||
|
:file-list="imageFileList"
|
||||||
|
list-type="picture-card"
|
||||||
|
auto-upload
|
||||||
|
v-model:file-list="imageFileList"
|
||||||
|
>
|
||||||
|
<template #file="{ file }">
|
||||||
|
<div>
|
||||||
|
<img class="el-upload-list__item-thumbnail" :src="file.url" alt=""/>
|
||||||
|
<span class="el-upload-list__item-actions">
|
||||||
|
<span
|
||||||
|
class="el-upload-list__item-preview"
|
||||||
|
@click="handlePictureCardPreview(file)"
|
||||||
|
>
|
||||||
|
<el-icon><zoom-in/></el-icon>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="el-upload-list__item-delete"
|
||||||
|
@click="handleRemoveImage(file)"
|
||||||
|
>
|
||||||
|
<el-icon><Delete/></el-icon>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-icon v-if="imageFileList.length === 0">
|
||||||
|
<Plus/>
|
||||||
|
</el-icon>
|
||||||
|
<el-icon v-else>
|
||||||
|
<Refresh/>
|
||||||
|
</el-icon>
|
||||||
|
</el-upload>
|
||||||
|
<div class="tip">
|
||||||
|
请上传大小不超过 <span style="color: red;">5MB</span> 格式为 <span style="color: red;">png/jpg/jpeg</span> 的文件
|
||||||
|
</div>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="课程视频" required>
|
||||||
|
<el-upload
|
||||||
|
:action="videoUploadUrl"
|
||||||
|
:limit="2"
|
||||||
|
:before-upload="beforeVideoUpload"
|
||||||
|
:on-success="handleVideoSuccess"
|
||||||
|
:on-error="handleVideoError"
|
||||||
|
:on-change="handleVideoChange"
|
||||||
|
:file-list="videoFileList"
|
||||||
|
list-type="picture-card"
|
||||||
|
auto-upload
|
||||||
|
v-model:file-list="videoFileList"
|
||||||
|
>
|
||||||
|
<template #file="{ file }">
|
||||||
|
<div>
|
||||||
|
<video class="el-upload-list__item-thumbnail" :src="file.url" controls></video>
|
||||||
|
<span class="el-upload-list__item-actions">
|
||||||
|
<span
|
||||||
|
class="el-upload-list__item-delete"
|
||||||
|
@click="handleRemoveVideo(file)"
|
||||||
|
>
|
||||||
|
<el-icon><Delete/></el-icon>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-icon v-if="videoFileList.length === 0">
|
||||||
|
<Plus/>
|
||||||
|
</el-icon>
|
||||||
|
<el-icon v-else>
|
||||||
|
<Refresh/>
|
||||||
|
</el-icon>
|
||||||
|
</el-upload>
|
||||||
|
<div class="tip">
|
||||||
|
请上传大小不超过 <span style="color: red;">500MB</span> 格式为 <span style="color: red;">mp4</span> 的文件
|
||||||
|
</div>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="课程简介" required>
|
||||||
|
<ElInput v-model="form.description" placeholder="请输入课程简介" required></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="课程排序" required>
|
||||||
|
<ElInput v-model="orderNo" placeholder="请输入课程排序(数字)" required></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem label="作者" required>
|
||||||
|
<ElInput v-model="form.author" placeholder="请输入作者" required></ElInput>
|
||||||
|
</ElFormItem>
|
||||||
|
<ElFormItem>
|
||||||
|
<ElButton type="primary" native-type="submit">确定</ElButton>
|
||||||
|
<ElButton @click="router.push('/courseList')">取消</ElButton>
|
||||||
|
</ElFormItem>
|
||||||
|
</ElForm>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-dialog v-model="dialogVisible" class="image-preview">
|
||||||
|
<img w-full :src="dialogImageUrl" alt="Preview Image"/>
|
||||||
|
</el-dialog>
|
||||||
|
</BackgroundWrapper>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background-wrapper {
|
||||||
|
position: fixed; /* 确保背景覆盖整个视口 */
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto; /* 只在内容溢出时允许滚动 */
|
||||||
|
/* 自定义滚动条样式 */
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: #007bff #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 针对 Webkit 浏览器的自定义滚动条 */
|
||||||
|
.background-wrapper::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background-wrapper::-webkit-scrollbar-track {
|
||||||
|
background: #f0f0f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background-wrapper::-webkit-scrollbar-thumb {
|
||||||
|
background-color: #007bff;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 3px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto; /* 使容器在内容溢出时出现滚动条 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-preview {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-preview img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tip {
|
||||||
|
margin-top: 8px;
|
||||||
|
color: #727272;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form {
|
||||||
|
background: white;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
width: 65%; /* 增加宽度 */
|
||||||
|
max-height: 90vh; /* 确保表单不会超过视口高度 */
|
||||||
|
overflow-y: auto; /* 使表单在内容溢出时出现滚动条 */
|
||||||
|
/* 自定义滚动条样式 */
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: #007bff #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 针对 Webkit 浏览器的自定义滚动条 */
|
||||||
|
.el-form::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form::-webkit-scrollbar-track {
|
||||||
|
background: #f0f0f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form::-webkit-scrollbar-thumb {
|
||||||
|
background-color: #007bff;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 3px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form-item {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-form-item label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-input,
|
||||||
|
.el-select {
|
||||||
|
width: calc(100% - 12px); /* 设置文本框宽度,使其与滚动条保持一定距离 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-button--primary {
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-button--primary:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dynamic-width-select {
|
||||||
|
min-width: 30%;
|
||||||
|
max-width: 100%;
|
||||||
|
width: auto; /* 使宽度根据内容调整 */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
333
src/views/course-management/CourseList.vue
Normal file
333
src/views/course-management/CourseList.vue
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
<script setup>
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
import { ElButton, ElForm, ElFormItem, ElInput, ElMessage, ElMessageBox, ElPagination, ElTable, ElTableColumn } from 'element-plus';
|
||||||
|
import axios from "axios";
|
||||||
|
import { useStore } from "vuex";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
import Course from "@views/course-management/Course.vue";
|
||||||
|
import BackgroundWrapper from './BackgroundWrapper.vue';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import { write, utils } from 'xlsx';
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const store = useStore();
|
||||||
|
const token = store.getters['authentication/token'];
|
||||||
|
|
||||||
|
const searchTitle = ref('');
|
||||||
|
const searchAuthor = ref('');
|
||||||
|
const searchDescription = ref('');
|
||||||
|
const sortOrder = ref('');
|
||||||
|
|
||||||
|
const allCoursesData = ref([]);
|
||||||
|
const coursesData = ref([]);
|
||||||
|
|
||||||
|
const currentPage = ref(1);
|
||||||
|
const pageSize = ref(10);
|
||||||
|
const coursesCount = ref(0);
|
||||||
|
const firstTimeLoad = ref(true);
|
||||||
|
|
||||||
|
const selections = ref([]);
|
||||||
|
|
||||||
|
const loadCourses = async (forceReload = false) => {
|
||||||
|
if (forceReload) {
|
||||||
|
firstTimeLoad.value = true;
|
||||||
|
allCoursesData.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstTimeLoad.value || allCoursesData.value.length < (currentPage.value * pageSize.value) && (currentPage.value * pageSize.value) <= coursesCount.value) {
|
||||||
|
let params = {
|
||||||
|
token: token,
|
||||||
|
start: allCoursesData.value.length,
|
||||||
|
end: allCoursesData.value.length + pageSize.value * 2
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await axios.get('/api/courses', { params });
|
||||||
|
const data = response.data;
|
||||||
|
coursesCount.value = data.courseCount;
|
||||||
|
allCoursesData.value.push(...data.courseList);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
firstTimeLoad.value = false;
|
||||||
|
}
|
||||||
|
coursesData.value = allCoursesData.value.slice((currentPage.value - 1) * pageSize.value, currentPage.value * pageSize.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadCourses();
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSearch = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('/api/courses/search', {
|
||||||
|
params: {
|
||||||
|
token: token,
|
||||||
|
title: searchTitle.value || '',
|
||||||
|
author: searchAuthor.value || '',
|
||||||
|
description: searchDescription.value || '',
|
||||||
|
sortOrder: sortOrder.value || '',
|
||||||
|
start: 0,
|
||||||
|
end: pageSize.value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = response.data;
|
||||||
|
coursesCount.value = data.courseCount;
|
||||||
|
allCoursesData.value = data.courseList;
|
||||||
|
coursesData.value = allCoursesData.value.slice(0, pageSize.value);
|
||||||
|
currentPage.value = 1;
|
||||||
|
firstTimeLoad.value = false;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReset = async () => {
|
||||||
|
searchTitle.value = '';
|
||||||
|
searchAuthor.value = '';
|
||||||
|
searchDescription.value = '';
|
||||||
|
sortOrder.value = '';
|
||||||
|
await loadCourses(true); // 强制重新加载课程数据
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSort = async () => {
|
||||||
|
// 将所有课程的排序字段转换成数值
|
||||||
|
const sortedCourses = _.cloneDeep(allCoursesData.value).map(course => ({
|
||||||
|
...course,
|
||||||
|
orderNo: Number(course.orderNo)
|
||||||
|
})).sort((a, b) => a.orderNo - b.orderNo);
|
||||||
|
|
||||||
|
// 更新所有课程的数据
|
||||||
|
allCoursesData.value = sortedCourses;
|
||||||
|
|
||||||
|
// 计算当前分页的数据
|
||||||
|
const start = (currentPage.value - 1) * pageSize.value;
|
||||||
|
const end = start + pageSize.value;
|
||||||
|
coursesData.value = allCoursesData.value.slice(start, end);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
// 创建一个新的工作簿
|
||||||
|
const workbook = utils.book_new();
|
||||||
|
|
||||||
|
// 创建工作表数据,提取 allCoursesData
|
||||||
|
const sheetData = allCoursesData.value.map(course => ({
|
||||||
|
'课程名称': course.title,
|
||||||
|
'作者': course.author,
|
||||||
|
'课程简介': course.description,
|
||||||
|
'排序': course.orderNo
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 将数据放入工作表
|
||||||
|
const worksheet = utils.json_to_sheet(sheetData);
|
||||||
|
|
||||||
|
// 将工作表添加到工作簿中
|
||||||
|
utils.book_append_sheet(workbook, worksheet, 'Courses');
|
||||||
|
|
||||||
|
// 生成 Excel 文件
|
||||||
|
const wbout = write(workbook, { bookType: 'xlsx', type: 'array' });
|
||||||
|
|
||||||
|
// 使用 file-saver 保存文件
|
||||||
|
saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '课程信息.xlsx');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditButton = () => {
|
||||||
|
if (selections.value.length === 1) {
|
||||||
|
// 只有一个课程被选中,导航到编辑页面
|
||||||
|
const selectedCourse = selections.value[0];
|
||||||
|
router.push({ name: 'Course', query: { mode: 'edit', id: selectedCourse.id } });
|
||||||
|
} else if (selections.value.length > 1) {
|
||||||
|
// 选中了多个课程,弹出提示
|
||||||
|
ElMessage.warning('无法同时修改多个目标');
|
||||||
|
} else {
|
||||||
|
// 没有选中任何课程,弹出提示
|
||||||
|
ElMessage.warning('请先选择要修改的课程');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteButton = async () => {
|
||||||
|
if (selections.value.length === 0) {
|
||||||
|
ElMessage.warning('请先选择要删除的课程');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElMessageBox.confirm(
|
||||||
|
'是否确认删除选中的课程?此操作不可撤销。',
|
||||||
|
'确认删除',
|
||||||
|
{
|
||||||
|
confirmButtonText: '确认',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
}
|
||||||
|
).then(async () => {
|
||||||
|
try {
|
||||||
|
const deletePromises = selections.value.map(selection =>
|
||||||
|
axios.delete(`/api/courses/${selection.id}`, { params: { token: token } })
|
||||||
|
);
|
||||||
|
await Promise.all(deletePromises);
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
selections.value = []; // 清空选中项
|
||||||
|
await loadCourses(true); // 强制重新加载课程数据
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error('删除失败');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
ElMessage.info('已取消删除操作');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectionChange = (newSelections) => {
|
||||||
|
selections.value = newSelections;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditInTable = (index) => {
|
||||||
|
router.push({ name: 'Course', query: { mode: 'edit', id: coursesData.value[index].id } });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteInTable = async (index) => {
|
||||||
|
ElMessageBox.confirm(
|
||||||
|
'是否确认删除该课程?此操作不可撤销。',
|
||||||
|
'确认删除',
|
||||||
|
{
|
||||||
|
confirmButtonText: '确认',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
}
|
||||||
|
).then(async () => {
|
||||||
|
try {
|
||||||
|
await axios.delete(`/api/courses/${coursesData.value[index].id}`, { params: { token: token } });
|
||||||
|
coursesData.value.splice(index, 1);
|
||||||
|
allCoursesData.value.splice(index, 1);
|
||||||
|
coursesCount.value--;
|
||||||
|
await loadCourses(true); // 强制重新加载课程数据
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error('删除失败');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
ElMessage.info('已取消删除操作');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BackgroundWrapper class="background-wrapper">
|
||||||
|
<div class="center-wrapper">
|
||||||
|
<div class="container">
|
||||||
|
<div class="search-container">
|
||||||
|
<el-form inline>
|
||||||
|
<el-form-item label="课程名称">
|
||||||
|
<el-input v-model="searchTitle" placeholder="请输入课程名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="排序">
|
||||||
|
<el-input v-model="sortOrder" placeholder="请输入排序" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="作者">
|
||||||
|
<el-input v-model="searchAuthor" placeholder="请输入作者" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="课程简介">
|
||||||
|
<el-input v-model="searchDescription" placeholder="请输入简介" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleReset">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button-container">
|
||||||
|
<el-button type="success" @click="router.push('/course?mode=create')">新增</el-button>
|
||||||
|
<el-button type="warning" @click="handleEditButton">修改</el-button>
|
||||||
|
<el-button type="danger" @click="handleDeleteButton">删除</el-button>
|
||||||
|
<el-button type="info" @click="handleSort">排序</el-button>
|
||||||
|
<el-button type="primary" @click="handleExport">导出</el-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-table :data="coursesData" style="width: 100%;" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="55"></el-table-column>
|
||||||
|
<el-table-column prop="orderNo" label="排序" align="center"></el-table-column>
|
||||||
|
<el-table-column prop="title" label="课程名称" align="center"></el-table-column>
|
||||||
|
<el-table-column prop="author" label="作者" align="center"></el-table-column>
|
||||||
|
<el-table-column prop="description" label="课程简介" align="center"></el-table-column>
|
||||||
|
<el-table-column label="操作" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button @click="handleEditInTable(scope.$index)" type="text">修改</el-button>
|
||||||
|
<el-button @click="handleDeleteInTable(scope.$index)" type="text">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<div class="pagination-container">
|
||||||
|
<el-pagination
|
||||||
|
@size-change="pageSize = $event; loadCourses(true)"
|
||||||
|
@current-change="currentPage = $event; loadCourses(true)"
|
||||||
|
:current-page="currentPage"
|
||||||
|
:page-size="pageSize"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
:total="coursesCount"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
>
|
||||||
|
</el-pagination>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</BackgroundWrapper>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background-wrapper {
|
||||||
|
position: fixed; /* 确保背景覆盖整个视口 */
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto; /* 只在内容溢出时允许滚动 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.center-wrapper {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
padding: 20px;
|
||||||
|
background: rgba(255, 255, 255, 0.8); /* 为了让内容清晰,可加上一层半透明白色背景 */
|
||||||
|
border-radius: 15px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
max-width: 800px; /* 控制页面内容宽度 */
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-container {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-container {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-table {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-bottom: -10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
56
src/views/user-management/Profile.vue
Normal file
56
src/views/user-management/Profile.vue
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h2>Profile</h2>
|
||||||
|
<form @submit.prevent="updateProfile">
|
||||||
|
<div>
|
||||||
|
<label for="nickname">Nickname:</label>
|
||||||
|
<input type="text" v-model="user.nickname">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="phoneNumber">Phone Number:</label>
|
||||||
|
<input type="text" v-model="user.phoneNumber">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="gender">Gender:</label>
|
||||||
|
<input type="text" v-model="user.gender">
|
||||||
|
</div>
|
||||||
|
<button type="submit">Update Profile</button>
|
||||||
|
</form>
|
||||||
|
<form @submit.prevent="changePassword">
|
||||||
|
<div>
|
||||||
|
<label for="oldPassword">Old Password:</label>
|
||||||
|
<input type="password" v-model="oldPassword" required>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="newPassword">New Password:</label>
|
||||||
|
<input type="password" v-model="newPassword" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Change Password</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapActions, mapState } from 'vuex';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
oldPassword: '',
|
||||||
|
newPassword: ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(['user'])
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(['updateProfile', 'changePassword']),
|
||||||
|
async updateProfile() {
|
||||||
|
await this.updateProfile(this.user);
|
||||||
|
},
|
||||||
|
async changePassword() {
|
||||||
|
await this.changePassword({ oldPassword: this.oldPassword, newPassword: this.newPassword });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user