From c1f7cb902574420590ea23b6068c176092ba551b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=B0=91=E5=BA=B7?= Date: Fri, 27 Jun 2025 11:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BF=A1=E4=BB=A3=E7=A0=81=E5=BA=93-A?= =?UTF-8?q?I=E5=A4=A7=E6=A8=A1=E5=9E=8B=E6=8E=A5=E5=8F=A3=E6=94=B9?= =?UTF-8?q?=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Jyh/AI/Home/GuessYouWantToAsk.vue | 8 +- .../ViewHistoryAside/BatchManageModal.vue | 5 +- .../ViewHistoryAside/ViewHistoryAside.vue | 8 +- src/views/Jyh/AI/Home/index.vue | 141 +++++++++--------- 4 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/views/Jyh/AI/Home/GuessYouWantToAsk.vue b/src/views/Jyh/AI/Home/GuessYouWantToAsk.vue index ce7e4ac..b033ea1 100644 --- a/src/views/Jyh/AI/Home/GuessYouWantToAsk.vue +++ b/src/views/Jyh/AI/Home/GuessYouWantToAsk.vue @@ -52,7 +52,6 @@ onMounted(() => { const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST; // 猜你想问接口 const fetchFollowupQuestions = async (question,df_id,sql_id='') => { - debugger try { // 构造请求参数(需根据实际文档补充 df_id 和 sql_id,示例中使用空字符串占位) const params = { @@ -64,10 +63,9 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => { // `${VITE_AI_API_HOST}/api/v0/update_recommend_questions`, // params // ); - const response = await fetchUpdateRecommendQuestions(params); - const createRes = response.data; - if (createRes&&createRes.questions) { - questions.value = createRes.questions + const { data } = await fetchUpdateRecommendQuestions(params); + if(data.code===200) { + questions.value = data.data } else { // Message.error('创建会话失败,未获取到会话ID'); } diff --git a/src/views/Jyh/AI/Home/components/ViewHistoryAside/BatchManageModal.vue b/src/views/Jyh/AI/Home/components/ViewHistoryAside/BatchManageModal.vue index a26809f..01dc3a7 100644 --- a/src/views/Jyh/AI/Home/components/ViewHistoryAside/BatchManageModal.vue +++ b/src/views/Jyh/AI/Home/components/ViewHistoryAside/BatchManageModal.vue @@ -217,7 +217,7 @@ const getQuestionHistory = async () => { "search": searchText.value }); - if (data.data.conversationList) { + if (data.code===200) { dhlsList.value = data.data.conversationList; dhlsPagination.value.total = data.data.pagination.total || 0; } @@ -250,7 +250,7 @@ const getQuestionCollection = async () => { "search": searchText.value }); - if (data.data.conversationList) { + if (data.code===200) { collectionList.value = data.data.conversationList; collectionPagination.value.total = data.data.pagination.total || 0; } @@ -377,7 +377,6 @@ const toggleCollect = async (conversationIds) => { userId: props.username, conversationIdList: conversationIds }); - if (res.data.code === 200||res.data.code === 20000) { Message.success(res.data.message || '取消收藏成功'); // 刷新当前标签页的数据 diff --git a/src/views/Jyh/AI/Home/components/ViewHistoryAside/ViewHistoryAside.vue b/src/views/Jyh/AI/Home/components/ViewHistoryAside/ViewHistoryAside.vue index cd5ca0e..b40bca9 100644 --- a/src/views/Jyh/AI/Home/components/ViewHistoryAside/ViewHistoryAside.vue +++ b/src/views/Jyh/AI/Home/components/ViewHistoryAside/ViewHistoryAside.vue @@ -440,8 +440,8 @@ const getQuestionHistory = async () => { "search": searchText.value }); debugger - if(data.conversationList) { - dhlsList.value = data.conversationList + if(data.code===200) { + dhlsList.value = data.data } else { // Message.error(data.error||'接口异常!') } @@ -467,8 +467,8 @@ const getQuestionCollection = async () => { "size": page.value.size, "search": searchText.value }); - if(data.conversationList) { - collectionList.value = data.conversationList + if(data.code===200) { + collectionList.value = data.data } else { // Message.error(data.error||'接口异常!') } diff --git a/src/views/Jyh/AI/Home/index.vue b/src/views/Jyh/AI/Home/index.vue index 863a843..acef61c 100644 --- a/src/views/Jyh/AI/Home/index.vue +++ b/src/views/Jyh/AI/Home/index.vue @@ -351,71 +351,72 @@ const getAIAnswer = async (content) => { // conversationId: CONV_ID.value, // question: content, // }); - const response = await fetchChatUseSql({ + const {data} = await fetchChatUseSql({ userId: username, // 使用 username 作为 userId conversationId: CONV_ID.value, question: content, }); + if(data.code===200) { + debugger + const row = data.data + if(row.type) { + const {text,type,id,table_name=[], states={}} = row; + messages.value[messages.value.length - 1].id = id; + // 处理思考过程 + const { thinkProcess,steps } = processThinkStates(states); + messages.value[messages.value.length - 1].thinkProcess = thinkProcess; + messages.value[messages.value.length - 1].steps = steps; + messages.value[messages.value.length - 1].thinkExpanded = true; - debugger - const row = response.data - if(row.type) { - const {text,type,id,table_name=[], states={}} = row; - messages.value[messages.value.length - 1].id = id; - // 处理思考过程 - const { thinkProcess,steps } = processThinkStates(states); - messages.value[messages.value.length - 1].thinkProcess = thinkProcess; - messages.value[messages.value.length - 1].steps = steps; - messages.value[messages.value.length - 1].thinkExpanded = true; + if(type==='text') { + messages.value[messages.value.length - 1].content = text; + messages.value[messages.value.length - 1].loading = false; + messages.value[messages.value.length - 1].type = 'text'; + } else if(type==='df') { + messages.value[messages.value.length - 1].content = row[type]; + messages.value[messages.value.length - 1].loading = false; + messages.value[messages.value.length - 1].type = 'df'; - if(type==='text') { - messages.value[messages.value.length - 1].content = text; - messages.value[messages.value.length - 1].loading = false; - messages.value[messages.value.length - 1].type = 'text'; - } else if(type==='df') { - messages.value[messages.value.length - 1].content = row[type]; - messages.value[messages.value.length - 1].loading = false; - messages.value[messages.value.length - 1].type = 'df'; - - // 判断是否软件详情 - if(table_name.length===1&&table_name[0]==='critical_software_info') { - let arr = JSON.parse(row[type]); - if(arr&&arr.length===1) { - messages.value[messages.value.length - 1].type = 'critical_software_info'; - messages.value[messages.value.length - 1].id = arr[0]?.id || arr[0]?.ID; - messages.value[messages.value.length - 1].software_name = arr[0]?.software_name || arr[0]['软件名称']; + // 判断是否软件详情 + if(table_name.length===1&&table_name[0]==='critical_software_info') { + let arr = JSON.parse(row[type]); + if(arr&&arr.length===1) { + messages.value[messages.value.length - 1].type = 'critical_software_info'; + messages.value[messages.value.length - 1].id = arr[0]?.id || arr[0]?.ID; + messages.value[messages.value.length - 1].software_name = arr[0]?.software_name || arr[0]['软件名称']; + } } + } else if(type==='sql_error') { + messages.value[messages.value.length - 1].content = row.error; + messages.value[messages.value.length - 1].loading = false; + messages.value[messages.value.length - 1].type = 'error'; } - } else if(type==='sql_error') { - messages.value[messages.value.length - 1].content = row.error; - messages.value[messages.value.length - 1].loading = false; - messages.value[messages.value.length - 1].type = 'error'; + fetchFollowupQuestions(content,id) + } else { + Message.warning('接口异常!') } - fetchFollowupQuestions(content,id) - } else { - Message.warning('接口异常!') - } - // messages.value.push({ - // from: 'ai-model', - // content: '', - // avatarPosition: 'side-left', - // avatarConfig: { ...aiModelAvatar }, - // loading: true, - // }); + // messages.value.push({ + // from: 'ai-model', + // content: '', + // avatarPosition: 'side-left', + // avatarConfig: { ...aiModelAvatar }, + // loading: true, + // }); - // /* 模拟流式数据返回 */ - // setTimeout(async () => { - // messages.value.at(-1).loading = false; - // for (let i = 0; i < content.length;) { - // await new Promise(r => setTimeout(r, 300 * Math.random())); - // messages.value[messages.value.length - 1].content = content.slice(0, i += Math.random() * 10); - // nextTick(() => { - // conversationRef.value?.scrollTo({ - // top: conversationRef.value.scrollHeight - // }); - // }); - // } - // }, 1000); + // /* 模拟流式数据返回 */ + // setTimeout(async () => { + // messages.value.at(-1).loading = false; + // for (let i = 0; i < content.length;) { + // await new Promise(r => setTimeout(r, 300 * Math.random())); + // messages.value[messages.value.length - 1].content = content.slice(0, i += Math.random() * 10); + // nextTick(() => { + // conversationRef.value?.scrollTo({ + // top: conversationRef.value.scrollHeight + // }); + // }); + // } + // }, 1000); + } } else { // Message.error('请先创建会话!'); } @@ -470,19 +471,16 @@ const createConversation = async () => { // const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, { // userId: username, // }); - const response = await fetchCreateConversation({ + const {data} = await fetchCreateConversation({ userId: username, }); - const createRes = response.data; - debugger - if (createRes&&createRes.conversationId) { - debugger - CONV_ID.value = createRes.conversationId; + if(data.code===200) { + CONV_ID.value = data.data.conversationId; console.log('创建会话成功,会话ID:', CONV_ID.value); nextTick(() => { // 刷新会话列表 if (viewHistoryRef.value) { - viewHistoryRef.value.getQuestionHistory(); // 调用子组件方法 + viewHistoryRef.value.getQuestionHistory(); // 调用子组件方法 } }) } else { @@ -506,10 +504,14 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => { // `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`, // params // ); - const response = await FetchFollowupQuestions(params); - const createRes = response.data; - if (createRes&&createRes.questions) { - followupQuestions.value = createRes.questions + const {data} = await FetchFollowupQuestions(params); + if(data.code===200) { + const createRes = data.data; + if (createRes&&createRes.questions) { + followupQuestions.value = createRes.questions + } else { + // Message.error('创建会话失败,未获取到会话ID'); + } } else { // Message.error('创建会话失败,未获取到会话ID'); } @@ -558,10 +560,11 @@ const getConversationDetail = async (convId: string) => { userId: username, conversationId: convId, }); - if(response.data?.error) { + debugger + if(response.data.code!==200) { // Message.error(response.data?.error); } else { - const detail = response.data.messages; + const detail = response.data.data; // 处理详情数据(如回显消息列表) handleDetailResponse(detail); } @@ -582,7 +585,7 @@ const handleDetailResponse = (detail: any) => { let type = i.type; let table_name = i.table_name; if(type==='text') { - messages.content = i.text; + messages.content = i.text || i.content; messages.loading = false; messages.type = 'text'; } else if(type==='df') {