Files
hsa/Html/static/js/dashboard.js
2024-12-28 17:11:24 +08:00

124 lines
4.8 KiB
JavaScript

// dashboard.js
function openCourseProgress(courseId) {
const courseData = {
'algorithm': {
title: '算法分析与设计',
progress: '50%',
chapters: [
{
title: '第一章: 算法基础',
subChapters: [
{ title: '子章节1: 算法介绍', path: 'introduction' },
{ title: '子章节2: 时间复杂度分析', path: 'time-complexity' }
]
},
{
title: '第二章: 排序与查找',
subChapters: [
{ title: '子章节1: 排序算法', path: 'sorting-algorithms' },
{ title: '子章节2: 查找算法', path: 'searching-algorithms' }
]
},
{
title: '第三章: 图算法',
subChapters: [
{ title: '子章节1: 图的表示', path: 'graph-representation' },
{ title: '子章节2: DFS 与 BFS', path: 'dfs-bfs' }
]
}
]
},
'data-structures': {
title: '数据结构与算法',
progress: '30%',
chapters: [
{
title: '第一章: 数组与链表',
subChapters: [
{ title: '子章节1: 数组基础', path: 'array-basics' },
{ title: '子章节2: 链表实现', path: 'linked-list' }
]
},
{
title: '第二章: 栈与队列',
subChapters: [
{ title: '子章节1: 栈的实现', path: 'stack-implementation' },
{ title: '子章节2: 队列的应用', path: 'queue-application' }
]
},
{
title: '第三章: 二叉树',
subChapters: [
{ title: '子章节1: 二叉树的遍历', path: 'binary-tree-traversal' },
{ title: '子章节2: 二叉查找树', path: 'binary-search-tree' }
]
}
]
}
// 可以继续添加其他课程的数据
};
// 获取对应课程的数据
const course = courseData[courseId];
if (!course) return;
// 更新右侧滑出卡片的内容
document.getElementById('course-title').textContent = course.title;
document.getElementById('progress').textContent = course.progress;
// 更新章节列表
const chapterList = document.getElementById('chapter-list');
chapterList.innerHTML = ''; // 清空之前的章节
course.chapters.forEach(chapter => {
const chapterItem = document.createElement('li');
chapterItem.classList.add('chapter-item');
const chapterTitle = document.createElement('div');
chapterTitle.classList.add('chapter-title');
chapterTitle.textContent = chapter.title;
chapterItem.appendChild(chapterTitle);
// 创建子章节
if (chapter.subChapters && chapter.subChapters.length > 0) {
const subChapterList = document.createElement('ul');
subChapterList.classList.add('sub-chapter-list');
chapter.subChapters.forEach(subChapter => {
const subChapterItem = document.createElement('li');
subChapterItem.classList.add('sub-chapter-item');
subChapterItem.textContent = subChapter.title;
// 添加点击事件跳转到学习页面
subChapterItem.addEventListener('click', () => {
const userId = 'userid'; // 这里可以动态传入当前用户ID
const courseName = encodeURIComponent(course.title); // 对课程名称进行编码
const subChapterPath = subChapter.path; // 子章节路径
const url = `/desktop/${userId}/${courseName}/${subChapterPath}`;
window.location.href = url; // 跳转到该学习页面
});
subChapterList.appendChild(subChapterItem);
});
chapterItem.appendChild(subChapterList);
// 添加点击事件切换子章节显示
chapterItem.addEventListener('click', () => {
chapterItem.classList.toggle('open');
});
}
chapterList.appendChild(chapterItem);
});
// 打开滑出卡片
document.getElementById('courseProgress').classList.add('open');
}
function closeCourseProgress() {
// 关闭滑出卡片
document.getElementById('courseProgress').classList.remove('open');
}