add:教师端新增删除课程,增加并更换footer-brief模板
This commit is contained in:
@@ -485,6 +485,20 @@ label[for="course-description"] {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete-course-btn {
|
||||||
|
background-color: #e74c3c;
|
||||||
|
color: white;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-course-btn:hover {
|
||||||
|
background-color: #c0392b;
|
||||||
|
}
|
||||||
|
|
||||||
/* 编辑弹窗 */
|
/* 编辑弹窗 */
|
||||||
.edit-modal {
|
.edit-modal {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -292,6 +292,43 @@ function closeAddCourseModal() {
|
|||||||
document.getElementById('add-course-modal').style.display = 'none';
|
document.getElementById('add-course-modal').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 显示删除课程确认弹窗
|
||||||
|
function showDeleteCourseConfirmation() {
|
||||||
|
if (!material_id) {
|
||||||
|
alert('无法删除课程:未找到课程ID');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confirm('确定要删除这个课程吗?此操作无法撤销!')) {
|
||||||
|
deleteCourse(material_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除课程
|
||||||
|
function deleteCourse(courseId) {
|
||||||
|
fetch(`/materials/${courseId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.message) {
|
||||||
|
alert(data.message);
|
||||||
|
if (data.success) {
|
||||||
|
// 关闭侧边栏并刷新页面
|
||||||
|
closeCourseDetails();
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('删除课程时出错:', error);
|
||||||
|
alert('删除课程失败,请稍后再试!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onTeacherboardPageLoad(){
|
function onTeacherboardPageLoad(){
|
||||||
// 提交表单处理
|
// 提交表单处理
|
||||||
document.getElementById('add-course-form').addEventListener('submit', function(event) {
|
document.getElementById('add-course-form').addEventListener('submit', function(event) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% include 'foot.html' %}
|
{% include 'footer-brief.html' %}
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
var course_id = "{{course_id}}";
|
var course_id = "{{course_id}}";
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'navbar.html' %} <!-- 引入navbar.html -->
|
{% include 'navbar.html' %} <!-- 引入navbar.html -->
|
||||||
{% include 'learning-path.html' %} <!-- 引入learning-path.html -->
|
|
||||||
<section class="search-section">
|
<section class="search-section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
@@ -81,7 +80,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include 'foot.html' %}
|
{% include 'footer-brief.html' %}
|
||||||
|
|
||||||
<script src="/static/js/dashboard.js"></script>
|
<script src="/static/js/dashboard.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
11
Html/apps/templates/footer-brief.html
Normal file
11
Html/apps/templates/footer-brief.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<link rel="stylesheet" href="/static/css/footer.css">
|
||||||
|
<footer class="hs-footer">
|
||||||
|
<div class="footer-main">
|
||||||
|
|
||||||
|
<div class="footer-bottom">
|
||||||
|
<div class="footer-bottom-right">
|
||||||
|
<span>© 2025 华实学伴. 保留所有权利</span>
|
||||||
|
<a href="https://beian.miit.gov.cn" target="_blank">沪ICP备2025142149号</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|
||||||
{% include 'foot.html' %}
|
{% include 'footer-brief.html' %}
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
window.appData = {
|
window.appData = {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
<button class="add-chapter-btn" onclick="showInputForNewChapter()">新增章节</button>
|
<button class="add-chapter-btn" onclick="showInputForNewChapter()">新增章节</button>
|
||||||
|
<button class="delete-course-btn" onclick="showDeleteCourseConfirmation()">删除课程</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 编辑章节或课时弹窗 -->
|
<!-- 编辑章节或课时弹窗 -->
|
||||||
@@ -121,6 +121,6 @@
|
|||||||
<script src="/static/js/course_current.js"></script>
|
<script src="/static/js/course_current.js"></script>
|
||||||
<script src="/static/js/teacherboard.js"></script>
|
<script src="/static/js/teacherboard.js"></script>
|
||||||
<script src="/static/js/teacher_course_setting.js"></script>
|
<script src="/static/js/teacher_course_setting.js"></script>
|
||||||
{% include 'foot.html' %}
|
{% include 'footer-brief.html' %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from flask import Blueprint, request, jsonify, current_app, session, render_template, session
|
from flask import Blueprint, request, jsonify, current_app, session, render_template, session
|
||||||
|
from bson import ObjectId
|
||||||
from ..services.course_service import create_material, update_material, get_materials_by_teacher, load_material, get_materials_by_teacher_dict, add_material_chapter, add_material_chapter_lesson, delete_material_chapter_lesson, reorder_material_structure, rename_material_structure
|
from ..services.course_service import create_material, update_material, get_materials_by_teacher, load_material, get_materials_by_teacher_dict, add_material_chapter, add_material_chapter_lesson, delete_material_chapter_lesson, reorder_material_structure, rename_material_structure
|
||||||
from ..auth.decorators import require_role
|
from ..auth.decorators import require_role
|
||||||
from ..services.cos_service import upload_file
|
from ..services.cos_service import upload_file
|
||||||
@@ -37,24 +38,60 @@ def create_new_material():
|
|||||||
material_id = create_material(teacher_id, material_name, description, chapters, image_url)
|
material_id = create_material(teacher_id, material_name, description, chapters, image_url)
|
||||||
return jsonify({"message": "教材创建成功", "material_id": material_id}), 201
|
return jsonify({"message": "教材创建成功", "material_id": material_id}), 201
|
||||||
|
|
||||||
@bp.route('/materials/<material_id>', methods=['GET'])
|
@bp.route('/materials/<material_id>', methods=['GET', 'PUT', 'DELETE'])
|
||||||
@require_role(roles="teacher")
|
@require_role(roles="teacher")
|
||||||
def get_material(material_id):
|
def handle_material(material_id):
|
||||||
if material_id is None:
|
|
||||||
return jsonify({"message": "教材名称不能为空"}), 400
|
|
||||||
material = load_material(material_id)
|
|
||||||
print(material)
|
|
||||||
return jsonify( material.model_dump()), 200
|
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
@bp.route('/materials/<material_id>', methods=['PUT'])
|
if material_id is None:
|
||||||
@require_role(roles="teacher")
|
return jsonify({"message": "教材名称不能为空"}), 400
|
||||||
def update_existing_material(material_id):
|
material = load_material(material_id)
|
||||||
data = request.get_json()
|
print(material)
|
||||||
chapters = data.get('chapters')
|
return jsonify(material.model_dump()), 200
|
||||||
if update_material(material_id, chapters):
|
|
||||||
return jsonify({"message": "教材更新成功"}), 200
|
elif request.method == 'PUT':
|
||||||
return jsonify({"message": "教材未找到"}), 404
|
data = request.get_json()
|
||||||
|
chapters = data.get('chapters')
|
||||||
|
if update_material(material_id, chapters):
|
||||||
|
return jsonify({"message": "教材更新成功"}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({"message": "教材更新失败"}), 500
|
||||||
|
|
||||||
|
elif request.method == 'DELETE':
|
||||||
|
# 获取当前教师信息
|
||||||
|
teacher_uuid = session.get("user_uuid")
|
||||||
|
teacher_id = current_app.extensions["uuid2username"][teacher_uuid]
|
||||||
|
|
||||||
|
# 检查材料是否存在,并且是否为当前教师创建
|
||||||
|
mongo = current_app.extensions["mongo"]
|
||||||
|
print(f"尝试删除课程ID: {material_id}, 当前教师ID: {teacher_id}")
|
||||||
|
try:
|
||||||
|
material = mongo.db.materials.find_one({'_id': ObjectId(material_id)})
|
||||||
|
print(f"找到的材料: {material}")
|
||||||
|
|
||||||
|
if not material:
|
||||||
|
return jsonify({"message": "课程不存在", "success": False}), 404
|
||||||
|
|
||||||
|
# 验证是否为当前教师创建的课程
|
||||||
|
if material.get('teacher_id') != teacher_id:
|
||||||
|
return jsonify({"message": "权限不足,无法删除他人课程", "success": False}), 403
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"查询材料时出错: {e}")
|
||||||
|
return jsonify({"message": f"查询课程时出错: {str(e)}", "success": False}), 500
|
||||||
|
|
||||||
|
# 执行删除操作
|
||||||
|
try:
|
||||||
|
result = mongo.db.materials.delete_one({'_id': ObjectId(material_id), 'teacher_id': teacher_id})
|
||||||
|
print(f"删除操作结果: {result.deleted_count}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"删除材料时出错: {e}")
|
||||||
|
return jsonify({"message": f"删除课程时出错: {str(e)}", "success": False}), 500
|
||||||
|
|
||||||
|
if result.deleted_count > 0:
|
||||||
|
return jsonify({"message": "课程删除成功", "success": True}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({"message": "删除失败", "success": False}), 500
|
||||||
|
|
||||||
@bp.route('/materials/addchapter/<material_id>', methods=['POST'])
|
@bp.route('/materials/addchapter/<material_id>', methods=['POST'])
|
||||||
@require_role(roles="teacher")
|
@require_role(roles="teacher")
|
||||||
|
|||||||
Reference in New Issue
Block a user