提交 913fed4c authored 作者: 张伊明's avatar 张伊明

优化智能写报

上级 a1df7e9b
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
state: () => ({ state: () => ({
...@@ -92,11 +92,43 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -92,11 +92,43 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
this.abortController = null; this.abortController = null;
}, },
backToInputAndClear() {
this.resetGenerateState();
this.reportContent = '';
this.writtingTitle = '';
this.descText = '';
this.uploadFileList = [];
this.routeQuery = {};
this._isDisableTemplate = false;
this.curTempTitle = '政令';
this.tempActiveIndex = 0;
},
updateTempActiveIndex(index, title) { updateTempActiveIndex(index, title) {
this.tempActiveIndex = index; this.tempActiveIndex = index;
this.curTempTitle = title; this.curTempTitle = title;
}, },
_keepStepsViewOnError() {
this.isGenerating = false;
this.isShowProcess = true;
this.isShowSteps = true;
this.abortController?.abort();
this.abortController = null;
},
async _showErrorDialog(message) {
await ElMessageBox.alert(message || '写报生成失败', '提示', {
confirmButtonText: '确认',
type: 'error'
});
},
async _handleGenerateError(message) {
this._keepStepsViewOnError();
await this._showErrorDialog(message);
},
// ========== 路由参数处理 ========== // ========== 路由参数处理 ==========
async setRouteParams(query) { async setRouteParams(query) {
this.routeQuery = { ...query }; this.routeQuery = { ...query };
...@@ -157,8 +189,7 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -157,8 +189,7 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
} }
} catch (error) { } catch (error) {
console.error(`获取${typeName}数据异常:`, error); console.error(`获取${typeName}数据异常:`, error);
ElMessage.error(`获取${typeName}数据失败: ${error.message}`); await this._handleGenerateError(`获取${typeName}数据失败: ${error.message}`);
this.resetGenerateState();
} }
}, },
...@@ -309,15 +340,20 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -309,15 +340,20 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
}); });
} }
break; break;
case 'error':
await this._handleGenerateError(jsonData.message);
break;
default: default:
console.debug('未处理的SSE事件类型', event.event); console.debug('未处理的SSE事件类型', event.event);
break; break;
} }
}, },
onerror: (error) => { onerror: async (error) => {
console.error('SSE连接错误', error); console.error('SSE连接错误', error);
ElMessage.warning('写报生成报错!'); if (error.name !== 'AbortError') {
if (error.name !== 'AbortError') return true; await this._handleGenerateError('写报生成报错!');
return true;
}
this.resetGenerateState(); this.resetGenerateState();
}, },
onclose: () => { onclose: () => {
...@@ -327,8 +363,9 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -327,8 +363,9 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
}); });
} catch (error) { } catch (error) {
if (error.name !== 'AbortError') { if (error.name !== 'AbortError') {
ElMessage.error(`PDF解析请求失败:${error.message}`);
console.error('PDF SSE请求异常', error); console.error('PDF SSE请求异常', error);
await this._handleGenerateError(`PDF解析请求失败:${error.message}`);
throw error;
} }
this.resetGenerateState(); this.resetGenerateState();
throw error; throw error;
...@@ -435,8 +472,7 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -435,8 +472,7 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
} else if ((msgData.event_type || '').toLowerCase().includes('error')) { } else if ((msgData.event_type || '').toLowerCase().includes('error')) {
// 优先从 data.error 获取详细错误描述 // 优先从 data.error 获取详细错误描述
const errorMsg = msgData.data?.error || str || '生成失败'; const errorMsg = msgData.data?.error || str || '生成失败';
ElMessage.error('生成失败:' + errorMsg); this._handleGenerateError('生成失败:' + errorMsg);
this.resetGenerateState();
} else { } else {
// 老版 --index.vue 行为:步骤栏直接追加服务端发来的完整步骤内容,不加时间戳、不强行换行 // 老版 --index.vue 行为:步骤栏直接追加服务端发来的完整步骤内容,不加时间戳、不强行换行
// 这样可以避免 SSE 分片导致的“步骤破碎”(一条步骤被拆成多条显示) // 这样可以避免 SSE 分片导致的“步骤破碎”(一条步骤被拆成多条显示)
...@@ -446,15 +482,17 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -446,15 +482,17 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
this.curAgentTool = msgData.tool || '无'; this.curAgentTool = msgData.tool || '无';
} }
}, },
onerror: (error) => { onerror: async (error) => {
ElMessage.warning('写报生成报错!'); await this._handleGenerateError('写报生成报错!');
this.resetGenerateState();
throw new Error(error); throw new Error(error);
} }
}); });
} catch (error) { } catch (error) {
ElMessage.warning('写报生成报错!'); if (error.name !== 'AbortError') {
this.resetGenerateState(); await this._handleGenerateError(error.message || '写报生成报错!');
} else {
this.resetGenerateState();
}
throw error; throw error;
} }
}, },
......
...@@ -163,6 +163,9 @@ ...@@ -163,6 +163,9 @@
<div class="left-box translation-box" :class="{ 'has-back-btn': store.isGenerating }" <div class="left-box translation-box" :class="{ 'has-back-btn': store.isGenerating }"
v-if="store.isShowClauseTranslation"> v-if="store.isShowClauseTranslation">
<div class="translation-main-box"> <div class="translation-main-box">
<div class="translation-actions" v-if="!store.isGenerating">
<div class="back-input-btn" @click="store.backToInputAndClear">返回输入栏</div>
</div>
<!-- 政令标题卡片 --> <!-- 政令标题卡片 -->
<div class="metadata-card" v-if="store.pdfMetadata"> <div class="metadata-card" v-if="store.pdfMetadata">
<div class="card-header"> <div class="card-header">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论