|
@@ -8,9 +8,25 @@
|
|
|
<DialogHeader class="conversation-chat-header" :style="{ height: header_height + 'px' }" />
|
|
<DialogHeader class="conversation-chat-header" :style="{ height: header_height + 'px' }" />
|
|
|
|
|
|
|
|
<div class="conversation-chat-content">
|
|
<div class="conversation-chat-content">
|
|
|
- <DialogList class="conversation-chat-list" :height="list_height" />
|
|
|
|
|
|
|
+ <DialogList
|
|
|
|
|
+ class="conversation-chat-list"
|
|
|
|
|
+ :height="list_height"
|
|
|
|
|
+ :agent_id="agent_id"
|
|
|
|
|
+ :list="chat_log_list"
|
|
|
|
|
+ :suggestion="chat_suggestion"
|
|
|
|
|
+ :show_welcome="show_welcome"
|
|
|
|
|
+ @share="handleChatShare"
|
|
|
|
|
+ @submit="handleSuggestSubmit"
|
|
|
|
|
+ />
|
|
|
|
|
|
|
|
- <DialogInput class="conversation-chat-input" :style="{ height: input_height + 'px' }" />
|
|
|
|
|
|
|
+ <DialogInput
|
|
|
|
|
+ class="conversation-chat-input"
|
|
|
|
|
+ :style="{ height: input_height + 'px' }"
|
|
|
|
|
+ :disabled="input_disabled"
|
|
|
|
|
+ @inputTextChange="handleTextChange"
|
|
|
|
|
+ @inputFileChange="handleFileChange"
|
|
|
|
|
+ @submit="handleInputSubmit"
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<DialogFooter class="conversation-chat-footer" :style="{ height: footer_height + 'px' }" />
|
|
<DialogFooter class="conversation-chat-footer" :style="{ height: footer_height + 'px' }" />
|
|
@@ -34,17 +50,27 @@ import DialogAsideRight from '../../modules/conversation-chat/DialogAsideRight.v
|
|
|
|
|
|
|
|
import useEleSize from '../../utils/use-ele-size';
|
|
import useEleSize from '../../utils/use-ele-size';
|
|
|
|
|
|
|
|
|
|
+import useWebSocketChat from '../../modules/conversation-chat/use-websocket-chat';
|
|
|
|
|
+import { jsonParse, jsonStringify } from '../../utils/utils';
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 1. 历史会话进入此页面,展示历史会话内容
|
|
* 1. 历史会话进入此页面,展示历史会话内容
|
|
|
* 2. 点击智能体,新建会话
|
|
* 2. 点击智能体,新建会话
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 智能体的ID
|
|
|
|
|
+ * 此参数必须传递
|
|
|
|
|
+ */
|
|
|
|
|
+ agent_id: String,
|
|
|
/**
|
|
/**
|
|
|
* 会话ID
|
|
* 会话ID
|
|
|
* 如果有此参数,则意味着获取该对话的记录内容
|
|
* 如果有此参数,则意味着获取该对话的记录内容
|
|
|
*/
|
|
*/
|
|
|
- chat_id: String
|
|
|
|
|
|
|
+ session_id: String,
|
|
|
|
|
+
|
|
|
|
|
+ chat_type: String
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const header_height = 30;
|
|
const header_height = 30;
|
|
@@ -59,6 +85,172 @@ const { width: chat_width, height: chat_height } = useEleSize('chat_main');
|
|
|
const list_height = computed(() => {
|
|
const list_height = computed(() => {
|
|
|
return chat_height.value - header_height - footer_height - input_height;
|
|
return chat_height.value - header_height - footer_height - input_height;
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+// ------------------------------------------------------------------
|
|
|
|
|
+// ------------------------------------------------------------------
|
|
|
|
|
+// ------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 对话数据列表
|
|
|
|
|
+ */
|
|
|
|
|
+const chat_log_list = ref([]);
|
|
|
|
|
+const chat_suggestion = ref({});
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 是否显示欢迎页
|
|
|
|
|
+ * 当用户进入对话页面,还未正式开始对话时
|
|
|
|
|
+ * 对话区域会显示欢迎内容
|
|
|
|
|
+ * 当用户开始对话时,欢迎内容消失,对话列表开始展示
|
|
|
|
|
+ */
|
|
|
|
|
+const show_welcome = ref(false);
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 分享
|
|
|
|
|
+ * @param chat_id
|
|
|
|
|
+ */
|
|
|
|
|
+const handleChatShare = (chat_id) => {};
|
|
|
|
|
+/**
|
|
|
|
|
+ * 在聊天界面点击推荐项
|
|
|
|
|
+ * 继续对话
|
|
|
|
|
+ */
|
|
|
|
|
+const handleSuggestSubmit = (suggest) => {};
|
|
|
|
|
+
|
|
|
|
|
+// ---------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 输入区域数据控制
|
|
|
|
|
+ */
|
|
|
|
|
+const input_text = ref('');
|
|
|
|
|
+const input_files = ref([]);
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 是否禁用输入组件
|
|
|
|
|
+ */
|
|
|
|
|
+const input_disabled = ref(false);
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 输入文本发生了变化
|
|
|
|
|
+ * @param value
|
|
|
|
|
+ */
|
|
|
|
|
+const handleTextChange = (value) => {};
|
|
|
|
|
+/**
|
|
|
|
|
+ * 输入的文件发生了变化
|
|
|
|
|
+ * @param files
|
|
|
|
|
+ */
|
|
|
|
|
+const handleFileChange = (files) => {};
|
|
|
|
|
+/**
|
|
|
|
|
+ * 输入已经确认要提交了
|
|
|
|
|
+ * 1. 文件上传
|
|
|
|
|
+ * 2. 创建会话
|
|
|
|
|
+ * get-chat-id
|
|
|
|
|
+ * 连接socket
|
|
|
|
|
+ * 3. socket 发送文本与文件数据内容
|
|
|
|
|
+ * 4. 接收 socket 返回的数据项
|
|
|
|
|
+ */
|
|
|
|
|
+const handleInputSubmit = () => {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建会话 get chat id
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传文件,获取文件参数
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 组装socket参数
|
|
|
|
|
+ * 发送websocket消息
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ const msg = jsonStringify({
|
|
|
|
|
+ message: '消息内容'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ handleWSSend(msg);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * ------------------------------------------------------------
|
|
|
|
|
+ * websocket定义以及初始化
|
|
|
|
|
+ */
|
|
|
|
|
+const wsTrigger = {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当websocket消息回来后
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+ onMessage: handleWSMessage,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当websocket消息出错时
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+ onError: handleWSError,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 当websocket消息关闭时
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+ onClose: handleWSClose
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 初始化websocket相关的一些方法
|
|
|
|
|
+ */
|
|
|
|
|
+const { initWSConnection, sendWSMessage, getWSInstance, closeWSConnect } = useWebSocketChat(wsTrigger);
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 发送websocket消息
|
|
|
|
|
+ * @param chat_id - 对话记录的ID
|
|
|
|
|
+ * @param value
|
|
|
|
|
+ */
|
|
|
|
|
+function handleWSSend(chat_id, value) {
|
|
|
|
|
+ // 初始化websocket连接
|
|
|
|
|
+ initWSConnection(props.agent_id, chat_id, props.chat_type);
|
|
|
|
|
+ sendWSMessage(value);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 接收websocket消息
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+function handleWSMessage(e) {
|
|
|
|
|
+ const res_data = e.data;
|
|
|
|
|
+ const res_content = jsonParse(res_data);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 类别:
|
|
|
|
|
+ * close
|
|
|
|
|
+ * error
|
|
|
|
|
+ * message
|
|
|
|
|
+ * stream
|
|
|
|
|
+ */
|
|
|
|
|
+ const res_type = res_content.type;
|
|
|
|
|
+ const res_message = res_content.message; // 消息内容
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 处理websocket错误
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+function handleWSError(e) {}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 处理websocket关闭事件
|
|
|
|
|
+ * @param e
|
|
|
|
|
+ */
|
|
|
|
|
+function handleWSClose(e) {}
|
|
|
|
|
+
|
|
|
|
|
+onMounted(() => {
|
|
|
|
|
+ // 组件挂载
|
|
|
|
|
+ if (props.session_id) {
|
|
|
|
|
+ // 有历史记录:获取历史记录内容进行展示
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 无历史记录:等待创建会话内容,列表区域显示欢迎界面
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+// ---------------------------------------------------------
|
|
|
|
|
+onUnmounted(() => {
|
|
|
|
|
+ // 组件卸载,关闭组件内的websocket连接
|
|
|
|
|
+ closeWSConnect();
|
|
|
|
|
+});
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="css" scoped>
|
|
<style lang="css" scoped>
|