diff --git a/src/vue2/src/components/process/ModelAnalysis.vue b/src/vue2/src/components/process/ModelAnalysis.vue index 8a3a3e2..bfb3896 100644 --- a/src/vue2/src/components/process/ModelAnalysis.vue +++ b/src/vue2/src/components/process/ModelAnalysis.vue @@ -270,7 +270,8 @@ export default { sentimentAnalysis: [], keyEntities: [], logs: [] - } + }, + errorMessage: '' } }, @@ -312,37 +313,67 @@ export default { methods: { ...mapActions('process', [ - 'processAnalysis' + 'processAnalysis', + 'setStepStatus' ]), startAnalysis() { - this.isLoading = true - this.analysisStatus = 'running' - this.analysisProgress = 0 + this.analysisStatus = 'running'; + this.isLoading = true; + this.analysisProgress = 0; + this.errorMessage = ''; - // 模拟分析过程 - this.analysisTimer = setInterval(() => { - this.analysisProgress += Math.floor(Math.random() * 5) + 1 - - if (this.analysisProgress >= 100) { - clearInterval(this.analysisTimer) - this.analysisProgress = 100 - this.isLoading = false - this.analysisStatus = 'completed' - - // 生成模拟分析结果 - this.resultData = this.generateMockResult() - - // 通知处理流程管理器 - this.$emit('next') + // 模拟分析过程的进度 + this.progressTimer = setInterval(() => { + if (this.analysisProgress < 100) { + this.analysisProgress += Math.floor(Math.random() * 5) + 1; + if (this.analysisProgress > 100) { + this.analysisProgress = 100; + } + } else { + clearInterval(this.progressTimer); + this.completeAnalysis(); + } + }, 300); + + // 在真实场景中,这里应该调用API来执行大模型分析 + // 模拟API调用延迟 + setTimeout(() => { + try { + this.loadAnalysisResultData(); + this.analysisStatus = 'completed'; + this.setStepStatus({ step: 'analysis', status: 'completed' }); + } catch (error) { + console.error('分析过程出错:', error); + this.analysisStatus = 'error'; + this.errorMessage = '分析过程中发生错误:' + (error.message || '未知错误'); + clearInterval(this.progressTimer); } - }, 300) + }, 8000); + }, + + loadAnalysisResultData() { + console.log('加载分析结果数据'); + this.resultData = this.generateMockResult(); }, handleRetry() { - this.analysisStatus = 'pending' - this.analysisProgress = 0 - this.$emit('retry') + this.errorMessage = ''; + this.startAnalysis(); + }, + + completeAnalysis() { + this.isLoading = false; + this.isCompleted = true; + this.$emit('next'); + + // 使用路由实例的push方法时通过catch优雅处理NavigationDuplicated错误 + // 这样处理路由跳转,即使调用了多次相同的路由也不会报错 + this.$router.push('/statistics').catch(err => { + if (err.name !== 'NavigationDuplicated') { + throw err; + } + }); }, generateMockResult() { @@ -505,7 +536,10 @@ export default { beforeDestroy() { if (this.analysisTimer) { - clearInterval(this.analysisTimer) + clearInterval(this.analysisTimer); + } + if (this.progressTimer) { + clearInterval(this.progressTimer); } } } diff --git a/src/vue2/src/router/index.js b/src/vue2/src/router/index.js index 55afb29..f77259c 100644 --- a/src/vue2/src/router/index.js +++ b/src/vue2/src/router/index.js @@ -5,6 +5,14 @@ import StatisticsPage from '../views/Statistics.vue' Vue.use(VueRouter) +// 解决NavigationDuplicated错误 +const originalPush = VueRouter.prototype.push +VueRouter.prototype.push = function push(location) { + return originalPush.call(this, location).catch(err => { + if (err.name !== 'NavigationDuplicated') throw err + }) +} + const routes = [ { path: '/', diff --git a/src/vue2/src/views/Process.vue b/src/vue2/src/views/Process.vue index 0025c37..8a17c24 100644 --- a/src/vue2/src/views/Process.vue +++ b/src/vue2/src/views/Process.vue @@ -176,7 +176,11 @@ export default { completeProcess() { // 完成处理后跳转到分析页面 - this.$router.push('/analysis') + this.$router.push('/statistics').catch(err => { + if (err.name !== 'NavigationDuplicated') { + throw err + } + }) } } }