Files
hsa/Html/apps/static/js/dashboard.js
2025-09-06 21:27:28 +08:00

139 lines
6.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// dashboard.js
let courseData;
function show_user_data(user_data, course_brief_data_list){
courseData = {}
for (let i=0;i<course_brief_data_list.length;i++){
courseData[course_brief_data_list[i]._id] = {}
}
for (let i=0;i<course_brief_data_list.length;i++){
course_brief_data = course_brief_data_list[i]
console.log(course_brief_data)
courseData[course_brief_data._id]._id = course_brief_data._id;
courseData[course_brief_data._id].title = course_brief_data.name;
courseData[course_brief_data._id].chapters = course_brief_data.chapters;
courseData[course_brief_data._id].image_url = course_brief_data.image_url;
courseData[course_brief_data._id].description = course_brief_data.description;
courseData[course_brief_data._id].created_at = course_brief_data.created_at;
courseData[course_brief_data._id].updated_at = course_brief_data.updated_at;
}
for (var course in courseData){
courseData[course].chapters = courseData[course].chapters
console.log(courseData[course])
}
}
function openCourseProgress(courseId) {
console.log(courseId)
const course = courseData[courseId];
if (!course) return;
fetch(`/dashboard/get_course_progress`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({course_id: courseId})
}).then(response => response.json())
.then(data => {
console.log(data)
/*
course_last_study_date: "2025-09-06"
course_put_in_date: "2025-09-06"
course_total_study_time:0
lesson_processs:Array(1):
(3) [Array(0), '基础算法', '二分']
material_id:"68bacdfadf5aeae0912f7f18"
user_uuid: $binary: {base64: 'r4hz5J1JSWe1hKJqXnAgwQ==', subType: '04'}
*/
course.course_last_study_date = data.data.course_last_study_date;
course.course_put_in_date = data.data.course_put_in_date;
course.course_total_study_time = data.data.course_total_study_time;
course.lesson_processs = data.data.lesson_processs;
course.material_id = data.data.material_id;
course.user_uuid = data.data.user_uuid;
document.getElementById('course-title').textContent = course.title;
///////////////////////// course.progress;还没有计算
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.chapter_name;
chapterItem.appendChild(chapterTitle);
// 创建子章节
if (chapter.lessons && chapter.lessons.length > 0) {
const subChapterList = document.createElement('ul');
subChapterList.classList.add('sub-chapter-list');
chapter.lessons.forEach(subChapter => {
const subChapterItem = document.createElement('li');//课时层级
subChapterItem.classList.add('sub-chapter-item');
subChapterItem.textContent = subChapter.lesson_name;
console.log('-------------------')
console.log(course)
// 查找学生进度
for(let i = 0; i < course.lesson_processs.length; i++) {
if (course.lesson_processs[i][2] == subChapter.lesson_name && course.lesson_processs[i][1] == chapter.chapter_name) {//确定lesson_id对应正确
///////////////////////////////////////////
//这里之后要做lesson的各个step的进度和得分
////////////////////////////////////////////
console.log('-------------------')
console.log(course.lesson_processs[i][0])
lesson_chapters_progress = course.lesson_processs[i][0];//寻找对应的每一个章节的进度
for (let j=0; j<lesson_chapters_progress.length;j++){
chapter_progress = lesson_chapters_progress[j]
if(chapter_progress.title == subChapter){
subChapterItem.textContent += ("(已"+(chapter_progress.is_rebuttal?"申辩" : "完成")+" 得分"+ (chapter_progress.is_rebuttal?chapter_progress.rebuttal_score : chapter_progress.score) +"");
}
}
if (course.lesson_processs[i][0].length === 1) {
subChapterItem.classList.add('completed');
}
break;
}
}
// 添加点击事件跳转到学习页面
subChapterItem.addEventListener('click', () => {
const courseId = encodeURIComponent(course._id); // 对课程名称进行编码
const url = `/desktop_nouser/${courseId}/${chapter.chapter_name}/${subChapter.lesson_name}`;
window.location.href = url; // 跳转到该学习页面
});
subChapterList.appendChild(subChapterItem);
});
chapterItem.appendChild(subChapterList);
// 添加点击事件切换子章节显示
chapterItem.addEventListener('click', () => {
chapterItem.classList.toggle('open');
});
}
chapterList.appendChild(chapterItem);
});
})
.catch(error => {
console.error('Error:', error);
});
// 打开滑出卡片
document.getElementById('courseProgress').classList.add('open');
}
function closeCourseProgress() {
// 关闭滑出卡片
document.getElementById('courseProgress').classList.remove('open');
}