From db2339e341668d14506c114ee88d6d143d4813b0 Mon Sep 17 00:00:00 2001 From: xuyonghao <898441624@qq.com> Date: 星期三, 27 十一月 2024 15:33:16 +0800 Subject: [PATCH] 图标修改 --- src/views/sessionManager/components/agentSession.vue | 160 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 93 insertions(+), 67 deletions(-) diff --git a/src/views/sessionManager/components/agentSession.vue b/src/views/sessionManager/components/agentSession.vue index 59f1821..e10748a 100644 --- a/src/views/sessionManager/components/agentSession.vue +++ b/src/views/sessionManager/components/agentSession.vue @@ -70,11 +70,7 @@ /> </template> <template #content> - <!-- <a-card :class="{ chatItemAnswer: theme === 'light' }">--> - <!-- <div :class="{ light: theme === 'light' }"--> - <!-- >{{ sessionDetail.content }}--> - <!-- </div>--> - <!-- </a-card>--> + <a-textarea readonly auto-size @@ -86,6 +82,7 @@ style="border: none" > </a-textarea> + </template> <template #actions> <span @@ -102,6 +99,7 @@ > <icon-refresh /> 閲嶆柊鐢熸垚 </span> + <!-- <span class="action"><icon-to-bottom />涓嬭浇 </span> --> </template> </a-comment> <a-comment v-else-if="sessionDetail.role === 'last'"> @@ -176,19 +174,7 @@ <icon-send size="32" style="color: #0960bd" /> </a-button> </div> - <!-- <div class="btn-send">--> - <!-- <!– <icon-send size="32" /> –>--> - <!-- <a-button--> - <!-- :disabled="chatDis"--> - <!-- @click="sentClick"--> - <!-- type="text"--> - <!-- style="border-radius: 24px"--> - <!-- :loading="loading"--> - <!-- >--> - <!-- <icon-send size="32" style="color: #0960bd;"/>--> - <!-- </a-button--> - <!-- >--> - <!-- </div>--> + </div> <a-modal v-model:visible="visible" @@ -237,8 +223,8 @@ import { agentResetApi, agentSetApi, - getAgentSessionDetailsApi, - } from '@/api/agentSession'; + getAgentSessionDetailsApi, updateAgentConversation + } from "@/api/agentSession"; import EventBus from '@/utils/EventBus'; import useClipboard from 'vue-clipboard3'; import { addSessionApi, getSessionDetailsApi } from '@/api/session'; @@ -269,7 +255,7 @@ const selectValue = ref(''); const sectionList = ref({}); let chatObj = reactive({}); - const isStopChat = ref(false); + let isStopChat = false; const appStore = useAppStore(); const theme = computed(() => { return appStore.theme; @@ -281,7 +267,9 @@ const visible = ref(false); let isHistory = ref(false); //鏄惁鏄巻鍙茶褰� let dsl = reactive({}); - const chatDataMeg = reactive({}); + + + let toStop = false; const rules = { name: [ @@ -364,7 +352,9 @@ 'Content-Type': 'application/json', }, body: JSON.stringify({ + converson_id: conversation_id.value, id: agentObj.id, + dsl:agentObj.dsl, }), }); @@ -406,12 +396,25 @@ const { code, data } = await getAgentSessionDetailsApi(id); if (code == 0) { console.log(data, 'agent浼氳瘽璇︽儏'); - Object.assign(chatObj, data); - sessionDetailList.value = data.dsl.messages; + let l = data.dsl.messages.length; + if (l > 1) { + chatObj.dsl.messages[chatObj.dsl.messages.length-1] = data.dsl.messages[l - 1]; + await updateAgentConversation({ + converson_id: conversation_id.value, + dsl: chatObj.dsl + }); + } else { + chatObj.dsl = data.dsl; + } + sessionDetailList.value = chatObj.dsl.messages; agentTitle.value = `${data.title}` || '鏈懡鍚嶄細璇�'; from.name = `${data.title}` || '鏈懡鍚嶄細璇�'; refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� } + }; + + const copyText = (text) => { + inputMsg.value = text; }; // 鍘嗗彶璁板綍璺宠浆鑾峰彇agent浼氳瘽璇︽儏 @@ -420,12 +423,18 @@ from.name = session.name; const { code, data } = await getSessionDetailsApi(session.id); if (code == 200) { - sessionDetailList.value = data.message.messages; const res = await getAgentSessionDetailsApi(session.dialog_id); if (res.code == 0) { - console.log(res.data, 'agent浼氳瘽璇︽儏'); + console.log(res.data, "agent浼氳瘽璇︽儏"); Object.assign(agentObj, res.data); - Object.assign(chatObj, res.data); + if (data?.message?.messages) { + sessionDetailList.value = data.message.messages; + let dsl = data.message; + Object.assign(chatObj, { "dsl": dsl }); + } else { + Object.assign(chatObj, res.data); + sessionDetailList.value = res.data.dsl.messages; + } Object.assign(dsl, res.data.dsl); refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� } @@ -456,18 +465,6 @@ event.preventDefault(); // 闃绘榛樿琛屼负锛屽嵆涓嶆崲琛� } - // chatDis.value = true; - // loading.value = true; - // if (!agentObj.id) { - // Message.warning('璇烽�夋嫨浼氳瘽'); - // chatDis.value = false; - // loading.value = false; - // return; - // } - - // if (displayedText.value) { - // querySessionList(); - // } if (inputMsg.value) { startChat(inputMsg.value); @@ -481,7 +478,11 @@ } }; + let message_stop = []; + let message_id = ""; const startChat = async (valMsg) => { + isStopChat = false; + displayedText.value = ''; sessionDetailList.value.push({ content: valMsg, role: 'user', @@ -490,6 +491,7 @@ refreshScroll(); let chatStr = { id: agentObj.id, + converson_id: conversation_id.value, message: valMsg, }; if (isHistory.value) { @@ -510,6 +512,10 @@ .getReader(); currIndex.value = 0; while (true) { + if (isStopChat) { + message_stop.push(message_id); + break; + } const x = await reader?.read(); if (x) { const { done, value } = x; @@ -517,6 +523,16 @@ try { const val = JSON.parse(value?.data || ''); const d = val?.data; + if (message_id != d.message_id) { + message_id = d.message_id; + message_stop = []; + } else { + //message_stop涓煡鎵緈essage_id + const index = message_stop.findIndex(item => item === message_id); + if (index > -1) { + break; + } + } if (typeof d !== 'boolean') { console.info('data:', d); streamStr.value = d.content; @@ -526,15 +542,10 @@ console.warn(e); } if (done) { - console.info('done'); - displayedText.value = ''; - if (isStopChat.value) { - isStopChat.value = false; - setChatDataMeg(chatDataMeg); - } else { - queryAgentSessionDetail(agentObj.id); - EventBus.emit('queryAppUsageList'); - } + console.info("done"); + displayedText.value = ""; + queryAgentSessionDetail(agentObj.id); + EventBus.emit("queryAppUsageList"); break; } } @@ -544,13 +555,9 @@ }; const stopChat = async () => { - // const { code, data } = await stopChatApi(agentObj.id); - // if (code === 200) { - // Message.success("宸插仠姝�"); - // } loading.value = false; chatDis.value = false; - isStopChat.value = true; + isStopChat = true; console.log('stopChat'); console.log(displayedText.value, 'displayedText'); console.log(sessionDetailList.value, 'sessionDetailList'); @@ -572,24 +579,20 @@ .concat(lastArr); console.log(sessionDetailList.value, 'sessionDetailList2'); console.log(chatObj, 'chatObj瀵硅薄'); - chatObj.dsl.messages = chatObj.dsl.messages.concat(lastArr); - Object.assign(chatDataMeg, { - id: chatObj.id, - conversation_id: chatObj.id, - message: sessionDetailList.value, - }); - }; + chatObj.dsl.messages = sessionDetailList.value; - const setChatDataMeg = async (chatData) => { - const { code, data } = await addSessionApi(chatData); + const { code, data } = await updateAgentConversation({ + converson_id: conversation_id.value, + dsl:chatObj.dsl, + }); if (data) { //鍋滄瀹氭椂鍣� clearTimeout(timer!); timer = null; - // displayedText.value = ""; - queryAgentSessionDetail(chatObj.id); } }; + + const handleShiftEnter = (event) => { event.preventDefault(); @@ -639,7 +642,7 @@ watch( () => props.modalObj, (newVal, oldVal) => { - // Object.assign(agentObj, newVal); + Object.assign(agentObj, newVal); //璋冪敤agent鍒濆鍖栨柟娉� if (JSON.stringify(newVal) != '{}') { // initPage(); @@ -661,11 +664,12 @@ .chatItemAnswer { box-sizing: border-box; background: #f1f1f1; - border-radius: 14px; + border-radius: 10px; + padding: 5px; .light { box-sizing: border-box; background: #f1f1f1; - border-radius: 14px; + border-radius: 10px; } } .textItemAnswer { @@ -781,6 +785,28 @@ .icon-user-jpg { border: 1px solid #d9d9d9; } + .prompt { + ul { + margin: 0; + padding: 0; + display: flex; + } + ul > li { + list-style-type: none; + } + .prompt-item { + display: flex; + justify-content: space-between; + background-color: #fff; + cursor: pointer; + border-radius: 8px; + padding: 10px; + border: #e5e5e5; + &:hover { + background-color: #eee; + } + } + } } } .header___lEPyH { -- Gitblit v1.8.0