feat(student): 添加学习分析生成进度显示

- 在分析生成期间显示进度条和提示信息
- 引入 analyzeProgress 变量动态更新进度百分比
- 使用定时器模拟进度增长,达到 90% 后等待完成
- 分析完成后将进度设置为 100% 并清除定时器
- 调整模板逻辑,区分加载中和结果显示状态
This commit is contained in:
lbw
2025-12-29 14:50:27 +08:00
parent 340bc5b5e3
commit bddf6c0936

View File

@@ -56,7 +56,13 @@
生成学习分析
</el-button>
</div>
<template v-if="analysisHtml">
<template v-if="analyzeLoading">
<div class="space-y-2">
<el-progress :percentage="analyzeProgress" :stroke-width="10" />
<div class="text-sm text-gray-500 dark:text-gray-400">正在生成学习分析请稍候</div>
</div>
</template>
<template v-else-if="analysisHtml">
<div class="leading-7 text-gray-700 dark:text-gray-200" v-html="analysisHtml"></div>
</template>
<template v-else>
@@ -87,6 +93,8 @@ const detail = ref(null)
const route = useRoute()
const history = ref([])
const analyzeLoading = ref(false)
const analyzeProgress = ref(0)
let analyzeTimer = null
const analysisText = ref('')
const wordStat = ref(null)
const md = new MarkdownIt({
@@ -125,6 +133,16 @@ async function fetchStudyAnalyze() {
const id = route.params.id
if (!id) return
analyzeLoading.value = true
analyzeProgress.value = 0
if (analyzeTimer) {
clearInterval(analyzeTimer)
analyzeTimer = null
}
analyzeTimer = setInterval(() => {
const inc = Math.floor(Math.random() * 8) + 3
const next = analyzeProgress.value + inc
analyzeProgress.value = next >= 90 ? 90 : next
}, 300)
try {
const res = await getStudentStudyAnalyze({
studentId: Number(id)
@@ -133,6 +151,11 @@ async function fetchStudyAnalyze() {
const raw = typeof d?.data === 'string' ? d.data : ''
analysisText.value = raw.replace(/\\n/g, '\n')
} finally {
analyzeProgress.value = 100
if (analyzeTimer) {
clearInterval(analyzeTimer)
analyzeTimer = null
}
analyzeLoading.value = false
}
}