ConversationChatContainer.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <template>
  2. <div class="conversation-chat-container">
  3. <div class="conversation-chat-left">
  4. <DialogAsideLeft />
  5. </div>
  6. <div class="conversation-chat-main" ref="chat_main">
  7. <DialogHeader
  8. class="conversation-chat-header"
  9. :agent_info="CHAT_AGENT_INFOMATION"
  10. :style="{ height: header_height + 'px' }"
  11. />
  12. <div class="conversation-chat-content">
  13. <DialogWelcome v-if="show_welcome" class="conversation-chat-area" :agent_info="CHAT_AGENT_INFOMATION" />
  14. <DialogList
  15. v-if="!show_welcome"
  16. ref="list_scroller"
  17. class="conversation-chat-area"
  18. :height="list_height"
  19. :width="chat_width"
  20. :agent_id="agent_id"
  21. :list="chat_display_list"
  22. :suggestion="chat_suggestion"
  23. @share="handleChatShare"
  24. @submit="handleSuggestSubmit"
  25. />
  26. <DialogInput
  27. ref="dialog_input"
  28. class="conversation-chat-input"
  29. :style="input_style"
  30. :agent_info="CHAT_AGENT_INFOMATION.agent"
  31. :agent_config="CHAT_AGENT_INFOMATION.config"
  32. :disabled="input_disabled"
  33. @sizeChange="handleInputSizeChange"
  34. @submit="handleInputSubmit"
  35. >
  36. <template v-if="show_input_others_opts" v-slot:top>
  37. <DialogInputTop :menu_id="current_menu_id" :agent_info="CHAT_AGENT_INFOMATION" ref="dialog_input_top" />
  38. </template>
  39. </DialogInput>
  40. </div>
  41. <DialogFooter class="conversation-chat-footer" :style="{ height: footer_height + 'px' }" />
  42. </div>
  43. <div class="conversation-chat-right">
  44. <DialogAsideRight />
  45. </div>
  46. </div>
  47. </template>
  48. <script setup>
  49. import { ref, getCurrentInstance, onMounted, onUnmounted, computed, nextTick } from 'vue';
  50. import { Message } from '@arco-design/web-vue';
  51. import { jsonParse, jsonStringify } from '../../utils/utils';
  52. import DialogAsideLeft from '../../modules/conversation-chat/DialogAsideLeft.vue';
  53. import DialogHeader from '../../modules/conversation-chat/DialogHeader.vue';
  54. import DialogWelcome from '../../modules/conversation-chat/DialogWelcome.vue';
  55. import DialogList from '../../modules/conversation-chat/DialogList.vue';
  56. import DialogInput from '../../modules/conversation-chat/DialogInput.vue';
  57. import DialogInputTop from '../../modules/conversation-chat/DialogInputTop.vue';
  58. import DialogFooter from '../../modules/conversation-chat/DialogFooter.vue';
  59. import DialogAsideRight from '../../modules/conversation-chat/DialogAsideRight.vue';
  60. // import { useAllAgentStore } from '../../base/store/use-all-agents';
  61. import getChatAgentInfomation from '../../modules/conversation-board/get-chat-agent-infomation';
  62. import useWebSocketChat from '../../modules/conversation-dialog/use-websocket-chat';
  63. import {
  64. getHistoryLogs,
  65. getDialogChatId,
  66. uploadFiles,
  67. uploadCombineExcelFiles,
  68. uploadFileByAgentInfo
  69. } from '../../modules/conversation-dialog/api-dialog';
  70. import { files2Formdata } from '../../modules/file-preview/files-2-formdata';
  71. import formatDialogSendOptions from '../../modules/conversation-dialog/format-dialog-send-options';
  72. import formatDialogHistory from '../../modules/conversation-dialog/format-dialog-history';
  73. import formatDialogQuestionByClient from '../../modules/conversation-dialog/format-dialog-question-by-client';
  74. import formatDialogAnswerForLoading from '../../modules/conversation-dialog/format-dialog-answer-for-loading';
  75. import formatDialogAnswerForException from '../../modules/conversation-dialog/format-dialog-answer-for-exception';
  76. import formatDialogAnswerFromWebsocketReceiveMessage from '../../modules/conversation-dialog/format-dialog-answer-from-websocket_receive_message';
  77. import useEleSizeV1 from '../../utils/use-ele-size-v1';
  78. import useEleSizeV2 from '../../utils/use-ele-size-v2';
  79. import useInputClear from './use-input-clear';
  80. import useInputGetOptions from './use-input-get-options';
  81. import useScroll2Bottom from './use-scroll-bottom';
  82. /**
  83. * 1. 历史会话进入此页面,展示历史会话内容
  84. * 2. 点击智能体,新建会话
  85. */
  86. const props = defineProps({
  87. /**
  88. * 智能体的ID
  89. * 此参数必须传递
  90. */
  91. agent_id: String,
  92. /**
  93. * 会话ID
  94. * 如果有此参数,则意味着获取该对话的记录内容
  95. */
  96. session_id: String,
  97. chat_type: String
  98. });
  99. // const allAgents = useAllAgentStore();
  100. /**
  101. * 对话使用到的agent信息
  102. * agent属性是由接口返回的数据
  103. * config属性是客户端自定义的数据,针对特定的agent的一些个性化配置,可由此进行配置
  104. * 二者结合,形成对话组件所需要的一些参数
  105. */
  106. const CHAT_AGENT_INFOMATION = ref({
  107. agent: {},
  108. config: {}
  109. });
  110. /**
  111. * input的一些操作方法
  112. */
  113. const inputClearFn1 = useInputClear('dialog_input'); // 主表单清空
  114. const inputClearFn2 = useInputClear('dialog_input_top'); // 顶部附加表单的数据
  115. const getInputTopOptions = useInputGetOptions('dialog_input_top'); // 获取附加表单参数的方法
  116. /**
  117. * 对话区域滚动到底部
  118. */
  119. const scroll2Bottom = useScroll2Bottom('list_scroller');
  120. const scroll2ListBottom = () => {
  121. nextTick(() => {
  122. scroll2Bottom();
  123. });
  124. };
  125. /**
  126. * 整个对话区域的一些尺寸定义
  127. */
  128. const header_height = 30;
  129. const footer_height = 30;
  130. const input_height = ref(100);
  131. /**
  132. * 获取到对话区域的宽度和高度
  133. */
  134. const { width: chat_width, height: chat_height } = useEleSizeV1('chat_main');
  135. /**
  136. * 对话列表区域的高度
  137. */
  138. const list_height = computed(() => {
  139. return chat_height.value - header_height - footer_height - input_height.value - 20;
  140. });
  141. const input_style = computed(() => {
  142. return {
  143. // height: input_height + 'px'
  144. };
  145. });
  146. // ------------------------------------------------------------------
  147. // ------------------------------------------------------------------
  148. // ------------------------------------------------------------------
  149. /**
  150. * 对话数据列表
  151. */
  152. const chat_log_list = ref([]); // 历史对话的数据列表
  153. const chat_new_list = ref([]); // 新对话的数据列表
  154. const chat_suggestion = ref([]); // 对话推荐项目
  155. /**
  156. * 当前新对话的ID
  157. * 当用户有输入后,点击提交,此时创建新对话,新对话的ID为此ID
  158. * 之后用户可以一直使用此ID进行对话。
  159. */
  160. const chat_new_id = ref(null);
  161. /**
  162. * 新对话,客户端的提问数据
  163. * 用以临时保存客户端的提问数据
  164. * 每当用户确认进行提问时,将新提问赋给此值
  165. * 一旦对话消息通过websocket发送到服务器,此值可清空
  166. */
  167. const chat_new_question = ref({});
  168. /**
  169. * 界面展示的对话列表
  170. * 当用户从历史会话进入时,历史会话记录有数据,当用户基于历史会话进行对话时,新会话也有数据,
  171. * 当用户从agent进入时,仅有新会话,没有历史会话
  172. *
  173. * 页面渲染的会话列表是 历史会话 + 新会话数据
  174. */
  175. const chat_display_list = computed(() => {
  176. return [].concat(chat_log_list.value, chat_new_list.value);
  177. });
  178. /**
  179. * 是否禁用输入组件
  180. */
  181. const input_disabled = ref(false);
  182. /**
  183. * 菜单ID编号
  184. * 1 报表合并
  185. * 2 知识问答
  186. * 3 文档智能
  187. * 4 智能问答
  188. * 5 智能数据
  189. * 6 小数绘图
  190. * 7 文档出卷
  191. * 8 出题组卷
  192. * 9 文档报告
  193. */
  194. const current_menu_id = computed(() => {
  195. const agent = CHAT_AGENT_INFOMATION.value.agent;
  196. const menu_id = agent.menuId / 1;
  197. return menu_id;
  198. });
  199. // /**
  200. // * 当前对话的类型
  201. // * 目前已知类型有量类: excel 和 其他类
  202. // * 当类别为excel时,文件上传接口和对话websocket链接都不一样
  203. // */
  204. // const current_chat_type = computed(() => {
  205. // const menu_id = current_menu_id.value;
  206. // const chat_type = menu_id === 1 ? 'excel' : '';
  207. // return chat_type;
  208. // });
  209. /**
  210. * 是否显示欢迎页
  211. * 当用户进入对话页面,还未正式开始对话时
  212. * 对话区域会显示欢迎内容
  213. * 当用户开始对话时,欢迎内容消失,对话列表开始展示
  214. */
  215. const show_welcome = ref(true);
  216. /**
  217. * 是否显示附件参数表单
  218. * 文档报告场景下需要显示此组件
  219. */
  220. const show_input_others_opts = computed(() => {
  221. const menu_id = current_menu_id.value;
  222. /**
  223. * 7 文档出卷
  224. * 9 文档报告
  225. */
  226. if (menu_id === 7 || menu_id === 9) {
  227. return true;
  228. }
  229. return false;
  230. });
  231. /**
  232. * 内容分享操作
  233. * @param chat_id
  234. */
  235. const handleChatShare = (chat_id) => {};
  236. /**
  237. * 在聊天界面点击推荐项
  238. * 继续对话
  239. */
  240. const handleSuggestSubmit = (suggest) => {};
  241. /**
  242. * 处理页面中的错误消息
  243. * @param msg
  244. */
  245. const handleErrorMessage = (msg) => {
  246. Message.error({ content: msg, position: 'top' });
  247. };
  248. // ---------------------------------------------
  249. /**
  250. * 异常处理
  251. * 异常处理过程是一个会话模拟的过程
  252. * 先在界面上显示加载动画,然后紧接着显示错误提示
  253. * 让用户感知到智能体有处理数据的过程
  254. * 所以在异常处理阶段,有一些需要处理的关键点,比如欢迎界面的显示(如果在现实,则需要隐藏,否则对话显示不了)
  255. * @param exceptionInfo
  256. */
  257. const handleChatRequestionException = (exceptionInfo) => {
  258. // 已结束
  259. const answerData = formatDialogAnswerForException(CHAT_AGENT_INFOMATION.value, exceptionInfo);
  260. // 原来的最后一项弹出
  261. chat_new_list.value.pop();
  262. // 添加新的最后一项
  263. chat_new_list.value.push(answerData);
  264. // 对话已结束:文件上传、文本输入区域放开使用
  265. input_disabled.value = false;
  266. // 对话区域滚动到底部
  267. scroll2ListBottom();
  268. };
  269. /**
  270. * 输入区域的尺寸发生了变化
  271. * 整个对话区域的尺寸也需要依据此变化而变化
  272. * @param size
  273. */
  274. const handleInputSizeChange = (size) => {
  275. const input_width = size.width;
  276. // const input_height = size.height;
  277. input_height.value = size.height;
  278. };
  279. /**
  280. * 输入已经确认要提交了
  281. *
  282. * 1. 创建会话 get-chat-id
  283. * 2. 文件上传
  284. * 3. 连接socket,socket 发送文本与文件数据内容
  285. * 4. 接收 socket 返回的数据项
  286. */
  287. const handleInputSubmit = async (options) => {
  288. const ask_text = options.text; // 文本
  289. const ask_files = options.files; // 文件列表
  290. // TODO: 内容检查,如果文本内容不合法,则不允许发送
  291. if (!ask_text) {
  292. handleErrorMessage('请输入文字');
  293. return;
  294. }
  295. // --------------------------------------------
  296. // --------------------------------------------
  297. // --------------------------------------------
  298. // --------------------------------------------
  299. // --------------------------------------------消息发送前的准备工作
  300. // 保存附加参数数据,由于下方有一个 inputClearFn2() 方法的执行
  301. // 会将所有数据清空,故附件参数需要在清理之前保存
  302. const other_options = getInputTopOptions();
  303. /**
  304. * 当新消息发送时
  305. * 意味着新一轮对话的开始
  306. * 此时应该将之前一轮对话的信息进行清空
  307. *
  308. * 整理客户端提问的数据
  309. * 组装Question数据
  310. */
  311. const client_question = formatDialogQuestionByClient(ask_text, ask_files);
  312. // 保存用户的提问信息
  313. // 当消息正式发出后,将提问数据放入列表中
  314. chat_new_question.value = client_question;
  315. // 消息即将发送,记录用户的提问数据
  316. chat_new_list.value.push(chat_new_question.value);
  317. // 客户端依据此数据展示加载中的动画
  318. const loadingMsg = formatDialogAnswerForLoading(CHAT_AGENT_INFOMATION.value);
  319. chat_new_list.value.push(loadingMsg);
  320. /**
  321. * 会话已确认发送
  322. * 隐藏欢迎内容,显示对话内容
  323. */
  324. show_welcome.value = false;
  325. // 清空文本数据和文件数据,避免下一次会话冲突
  326. // 清空表单里的数据
  327. inputClearFn1();
  328. inputClearFn2();
  329. // 清空可能存在的推荐项目
  330. chat_suggestion.value = [];
  331. // 清空已保存的提问数据(提问数据已经推入数组,此处无需继续保存)
  332. chat_new_question.value = null;
  333. // 文件上传、文本输入区域禁用
  334. input_disabled.value = true;
  335. // 对话区域滚动到底部
  336. scroll2ListBottom();
  337. // --------------------------------------------
  338. // --------------------------------------------
  339. // --------------------------------------------
  340. // --------------------------------------------
  341. // --------------------------------------------
  342. const agent_id = props.agent_id;
  343. // 对话分为三个步骤
  344. // 1. 创建会话,如果已经创建,则不需要再次创建
  345. // 2. 上传文件,如果不存在文件,则无需文件上传
  346. // 3. 连接websocket
  347. /**
  348. * 创建会话 get chat id
  349. * 判断对话是否已经创建
  350. * 如果对话已经创建,则使用已经创建的对话
  351. * 否则,创建新对话
  352. */
  353. if (chat_new_id.value === null) {
  354. // 未创建chat,开始创建
  355. try {
  356. const chatResult = await getDialogChatId(agent_id);
  357. if (chatResult.code / 1 === 200) {
  358. // 成功
  359. const res_data = chatResult.data;
  360. chat_new_id.value = res_data.chat_id;
  361. } else {
  362. // 失败
  363. // 处理异常:直接在界面上显示
  364. handleChatRequestionException({
  365. message: `code: ${chatResult.code} message: ${chatResult.msg}`
  366. });
  367. return;
  368. }
  369. } catch (err) {
  370. console.log('err-nfsdnakiuwirea7', err);
  371. // 处理错误
  372. handleChatRequestionException({
  373. message: err.message
  374. });
  375. return;
  376. }
  377. } else {
  378. // 已创建chat,使用已创建的会话ID,进入下一步流程
  379. }
  380. // 文件上传后的信息
  381. let files_response = null;
  382. /**
  383. * 如果存在文件数据,则进行文件上传
  384. */
  385. if (ask_files.length !== 0) {
  386. // 进行文件上传,获取文件信息
  387. const chat_id = chat_new_id.value;
  388. try {
  389. const menu_id = current_menu_id.value;
  390. const uploadResult = await uploadFileByAgentInfo(agent_id, chat_id, ask_files, menu_id);
  391. if (uploadResult.code / 1 === 200) {
  392. // 文件上传成功
  393. files_response = uploadResult.data;
  394. } else {
  395. // 文件上传异常
  396. handleChatRequestionException({
  397. message: `code: ${uploadResult.code} \n\n message: ${uploadResult.msg}`
  398. });
  399. return;
  400. }
  401. } catch (err) {
  402. console.log('err-fhskafhakfjslkfjl', err);
  403. handleChatRequestionException({
  404. message: err.message
  405. });
  406. return;
  407. }
  408. }
  409. /**
  410. * 组装参数
  411. * 组装socket参数: 文本和文件
  412. * 此方法会依据当前使用的agent,组装好传递给websocket的 基础的文本和文件的参数
  413. */
  414. const menu_id = current_menu_id.value;
  415. const msg_obj = formatDialogSendOptions(ask_text, files_response, menu_id);
  416. /**
  417. * 文本和文件的数据已经组装完成
  418. * 在某些情况下,仅有文本和文件还不够,可能还有其他控制参数
  419. * 在这种情况下,可以通过 DialogInputTop 获取到附加参数
  420. * 添加附加参数
  421. * 附加参数应该是一个键值对对象,最终和和已有的文本参数和文件参数合并成一个新的键值对对象发送给websocket
  422. */
  423. // 获取附加表单的数据项目
  424. if (other_options && typeof other_options === 'object') {
  425. for (let key in other_options) {
  426. msg_obj[key] = other_options[key];
  427. }
  428. }
  429. /**
  430. * 所有参数已经正式组装完成,将对象格式转换为字符串
  431. */
  432. const msg_str = jsonStringify(msg_obj);
  433. // 发送websocket消息
  434. handleWSSend(chat_new_id.value, msg_str);
  435. };
  436. /**
  437. * ------------------------------------------------------------
  438. * websocket定义以及初始化
  439. */
  440. const wsTrigger = {
  441. /**
  442. * 当websocket消息回来后
  443. * @param e
  444. */
  445. onMessage: handleWSMessage,
  446. /**
  447. * 当websocket消息出错时
  448. * @param e
  449. */
  450. onError: handleWSError,
  451. /**
  452. * 当websocket消息关闭时
  453. * @param e
  454. */
  455. onClose: handleWSClose
  456. };
  457. /**
  458. * 初始化websocket相关的一些方法
  459. */
  460. const { initWSConnection, sendWSMessage, getWSInstance, closeWSConnect } = useWebSocketChat(wsTrigger);
  461. /**
  462. * 发送websocket消息
  463. * @param chat_id - 对话记录的ID
  464. * @param value
  465. */
  466. function handleWSSend(chat_id, value) {
  467. /**
  468. * -----------------------------------------------------------
  469. * -----------------------------------------------------------
  470. * -----------------------------------------------------------
  471. * websocket消息正式发送,发送步骤:
  472. * 1. 初始化链接
  473. * 2. 发送消息
  474. */
  475. // 初始化websocket连接
  476. const menu_id = current_menu_id.value;
  477. initWSConnection(props.agent_id, chat_id, menu_id);
  478. // 发送socket连接
  479. sendWSMessage(value);
  480. /**
  481. * websocket消息发送流程完成
  482. * ------------------------------------------------------------
  483. * ------------------------------------------------------------
  484. * ------------------------------------------------------------
  485. */
  486. }
  487. /**
  488. * 接收websocket消息
  489. * @param e
  490. */
  491. function handleWSMessage(e) {
  492. const res_data = e.data;
  493. // 获取当前对话中最后一个对话数据
  494. // 最后一个对话数据为当前正在进行的对话
  495. const last_msg = chat_new_list.value[chat_new_list.value.length - 1];
  496. /**
  497. * 整理返回的数据
  498. */
  499. const currentChat = formatDialogAnswerFromWebsocketReceiveMessage(res_data, last_msg, CHAT_AGENT_INFOMATION.value);
  500. const chat_status = currentChat.status;
  501. const chat_message = currentChat.message;
  502. // 处理对话数据
  503. const handleChatData = () => {
  504. const chat_data = currentChat.data; // 对话相关的数据项
  505. // 原来的最后一项弹出
  506. chat_new_list.value.pop();
  507. // 添加新的最后一项
  508. chat_new_list.value.push(chat_data);
  509. // 滚动到底部
  510. scroll2ListBottom();
  511. };
  512. if (chat_status === 0) {
  513. // 未开始: 此状态不存在,无需处理
  514. }
  515. if (chat_status === 1) {
  516. // 此轮对话仍然在进行中
  517. handleChatData();
  518. }
  519. if (chat_status === 2) {
  520. // 此轮对话已结束
  521. handleChatData();
  522. // 对话已结束:检查是否存在推荐数据
  523. const chat_suggest = currentChat.suggest; // 对话相关的推荐数据
  524. if (chat_suggest) {
  525. chat_suggestion.value = chat_suggest;
  526. }
  527. // 对话已结束:文件上传、文本输入区域放开使用
  528. input_disabled.value = false;
  529. }
  530. if (chat_status === 3) {
  531. // 此轮对话出错了
  532. // TODO: 错误处理
  533. // 此轮对话已结束
  534. handleChatData();
  535. // 对话已结束:文件上传、文本输入区域放开使用
  536. input_disabled.value = false;
  537. }
  538. }
  539. /**
  540. * 处理websocket错误
  541. * @param e
  542. */
  543. function handleWSError(e) {
  544. console.log('socket-error-8jfdksagjsfdjaklnfsdajkl', e);
  545. handleChatRequestionException({
  546. message: `对话无法继续:WebSocket Error: ${e.target.url}`
  547. });
  548. }
  549. /**
  550. * 处理websocket关闭事件
  551. * @param e
  552. */
  553. function handleWSClose(e) {}
  554. onMounted(() => {
  555. const agent_id = props.agent_id;
  556. const session_id = props.session_id;
  557. /**
  558. * 根据agent_id 查询到agent的基本信息
  559. * 从而确定agent的相关功能支持,例如:是否需要上传文件,支持上传什么类型的文件、支持上传多少个文件?
  560. * 例如:主题、背景、等等
  561. */
  562. CHAT_AGENT_INFOMATION.value = getChatAgentInfomation(agent_id);
  563. // /**
  564. // * 设置页面标题
  565. // */
  566. // const agent = CHAT_AGENT_INFOMATION.value.agent;
  567. // const agent_name = agent.name;
  568. // document.title = document.title + '-' + agent_name;
  569. // 组件挂载
  570. if (session_id) {
  571. // 有历史记录:获取历史记录内容进行展示
  572. getHistoryLogs(agent_id, session_id)
  573. .then((res) => {
  574. if (res.code / 1 === 200) {
  575. // 成功
  576. const session_list = res.data;
  577. // 将列表数据进行转化
  578. const list = formatDialogHistory(session_list, CHAT_AGENT_INFOMATION.value);
  579. // 如果历史记录不为空
  580. // 则需要展示对话内容
  581. // 此时欢迎内容就不需要展示
  582. if (list.length !== 0) {
  583. show_welcome.value = false;
  584. // 滚动到底部
  585. scroll2ListBottom();
  586. }
  587. chat_log_list.value = list;
  588. } else {
  589. // 异常
  590. // TODO:处理异常
  591. show_welcome.value = false;
  592. // handleChatRequestionException({
  593. // message: res.msg
  594. // });
  595. // 使用消息提示,而非界面错误提示
  596. handleErrorMessage('历史会话异常:' + res.msg);
  597. }
  598. })
  599. .catch((err) => {
  600. console.log('err-mfsjakfjsdkalfjs', err);
  601. show_welcome.value = false;
  602. // handleChatRequestionException({
  603. // message: err.message
  604. // });
  605. handleErrorMessage('历史会话错误:' + err.message);
  606. });
  607. } else {
  608. // 无历史记录:等待创建会话内容(用户开始输入、提交完成),列表区域显示欢迎界面
  609. }
  610. });
  611. // ---------------------------------------------------------
  612. onUnmounted(() => {
  613. // 组件卸载,关闭组件内的websocket连接
  614. closeWSConnect();
  615. });
  616. </script>
  617. <style lang="css" scoped>
  618. .conversation-chat-container {
  619. display: flex;
  620. justify-content: center;
  621. margin-left: auto;
  622. margin-right: auto;
  623. height: 100%;
  624. }
  625. .conversation-chat-left {
  626. width: 25%;
  627. flex-shrink: 0;
  628. }
  629. .conversation-chat-right {
  630. width: 25%;
  631. flex-shrink: 0;
  632. }
  633. .conversation-chat-main {
  634. flex-grow: 1;
  635. height: 100%;
  636. max-width: 960px;
  637. margin-left: auto;
  638. margin-right: auto;
  639. display: flex;
  640. flex-direction: column;
  641. /* background-color: #aaa; */
  642. }
  643. .conversation-chat-content {
  644. flex-grow: 1;
  645. display: flex;
  646. flex-direction: column;
  647. overflow: hidden;
  648. }
  649. .conversation-chat-area {
  650. flex-grow: 1;
  651. overflow: auto;
  652. }
  653. .conversation-chat-input {
  654. /* height: 100px; */
  655. /* background-color: #a67777; */
  656. flex-shrink: 0;
  657. margin-top: 5px;
  658. margin-bottom: 5px;
  659. padding: 5px;
  660. border-radius: 10px;
  661. display: flex;
  662. }
  663. </style>