学习课程记录

This commit is contained in:
2025-11-17 16:35:18 +08:00
parent d2e554c715
commit ba0f14489e
6 changed files with 73 additions and 14 deletions

View File

@@ -98,10 +98,10 @@
<!-- 文章资源 -->
<div v-if="currentNode.nodeType === 0 && articleData" class="article-content">
<ArticleShowView
<ArticleShow
:as-dialog="false"
:article-data="articleData"
:category-list="[]"
:article-data="articleData"
:show-back-button="false"
@videos-completed="handleArticleVideosCompleted"
/>
</div>
@@ -195,7 +195,7 @@ import {
Download,
InfoFilled
} from '@element-plus/icons-vue';
import { ArticleShowView } from '@/views/public/article';
import { ArticleShow } from '@/views/public/article';
import { courseApi } from '@/apis/study';
import { learningRecordApi, learningHistoryApi } from '@/apis/study';
import { resourceApi } from '@/apis/resource';
@@ -516,6 +516,12 @@ async function loadNodeContent() {
if (!activeChapters.value.includes(currentChapterIndex.value)) {
activeChapters.value.push(currentChapterIndex.value);
}
// 等待DOM更新后检查是否需要自动标记完成针对内容太短没有滚动条的情况
await nextTick();
setTimeout(() => {
checkAutoComplete();
}, 500); // 延迟500ms等待ArticleShow初始化完成
}
// 选择节点
@@ -706,6 +712,48 @@ function hasScrollbar(): boolean {
return contentAreaRef.value.scrollHeight > contentAreaRef.value.clientHeight;
}
// 检查是否需要自动标记完成(针对内容太短没有滚动条的情况)
async function checkAutoComplete() {
// 如果当前节点已完成,跳过
if (isCurrentNodeCompleted.value) {
return;
}
if (!currentNode.value) return;
// 对富文本类型nodeType === 1立即检查
if (currentNode.value.nodeType === 1) {
if (!hasScrollbar()) {
console.log('📄 富文本内容较短无需滚动,自动标记为完成');
const nodeKey = `${currentChapterIndex.value}-${currentNodeIndex.value}`;
await markNodeComplete(nodeKey);
}
}
// 对文章类型nodeType === 0延迟检查等待ArticleShow初始化视频监听器
// 如果文章有视频会在视频播放完成时emit事件不会走到这里
// 如果文章没有视频且没有滚动条,需要自动标记完成
if (currentNode.value.nodeType === 0) {
// 保存当前节点信息,避免延迟后节点已改变
const chapterIdx = currentChapterIndex.value;
const nodeIdx = currentNodeIndex.value;
const nodeKey = `${chapterIdx}-${nodeIdx}`;
// 延迟1秒再检查给ArticleShow足够时间初始化
setTimeout(async () => {
// 再次检查是否已完成(可能已通过视频完成事件标记)
// 且确认当前还在同一个节点
if (!completedNodes.value.has(nodeKey) &&
currentChapterIndex.value === chapterIdx &&
currentNodeIndex.value === nodeIdx &&
!hasScrollbar()) {
console.log('📄 文章内容较短无需滚动且无视频,自动标记为完成');
await markNodeComplete(nodeKey);
}
}, 1000);
}
}
// 处理内容区域滚动
function handleContentScroll(event: Event) {
const target = event.target as HTMLElement;