|
@@ -193,11 +193,17 @@ const chat_new_list = ref([]); // 新对话的数据列表
|
|
|
const chat_suggestion = ref([]); // 对话推荐项目
|
|
const chat_suggestion = ref([]); // 对话推荐项目
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 当前新对话的ID
|
|
|
|
|
|
|
+ * 当前对话使用的ID
|
|
|
* 当用户有输入后,点击提交,此时创建新对话,新对话的ID为此ID
|
|
* 当用户有输入后,点击提交,此时创建新对话,新对话的ID为此ID
|
|
|
* 之后用户可以一直使用此ID进行对话。
|
|
* 之后用户可以一直使用此ID进行对话。
|
|
|
*/
|
|
*/
|
|
|
-const chat_new_id = ref(null);
|
|
|
|
|
|
|
+const chat_round_id = ref(null);
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 对话发起的次数记录
|
|
|
|
|
+ * 用户每发起一次会话,此值会加1
|
|
|
|
|
+ */
|
|
|
|
|
+const chat_round_sent_count = ref(0);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 新对话,客户端的提问数据
|
|
* 新对话,客户端的提问数据
|
|
@@ -292,6 +298,8 @@ const enable_text_input = computed(() => {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 对话文本是否必须
|
|
* 对话文本是否必须
|
|
|
|
|
+ * 此值如果为 true,则在发起对话之前,会进行 文本的存在性检查
|
|
|
|
|
+ * 此值如果为 false,则在发起对话之前,不会进行 文件存在性检查
|
|
|
*/
|
|
*/
|
|
|
const is_chat_text_required = computed(() => {
|
|
const is_chat_text_required = computed(() => {
|
|
|
const is_enable = enable_text_input.value;
|
|
const is_enable = enable_text_input.value;
|
|
@@ -348,7 +356,9 @@ const enable_file_upload = computed(() => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 对话文件是否必须
|
|
|
|
|
|
|
+ * 对话文件是否必须上传
|
|
|
|
|
+ * 此值如果返回 true,则 在对话时,会进行文件检查
|
|
|
|
|
+ * 此值如果返回 false,则 在对话时,不会检查文件的存在性
|
|
|
*/
|
|
*/
|
|
|
const is_chat_file_required = computed(() => {
|
|
const is_chat_file_required = computed(() => {
|
|
|
const is_enable = enable_file_upload.value;
|
|
const is_enable = enable_file_upload.value;
|
|
@@ -360,17 +370,26 @@ const is_chat_file_required = computed(() => {
|
|
|
|
|
|
|
|
// 报表合并: 文件必须
|
|
// 报表合并: 文件必须
|
|
|
if (menu_id === 1) {
|
|
if (menu_id === 1) {
|
|
|
- return true;
|
|
|
|
|
|
|
+ // 当第一次会话时,要求必须上传文件
|
|
|
|
|
+ // 非第一次,不做要求
|
|
|
|
|
+ if (chat_round_sent_count.value === 0) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 文档出卷:文件必须上传
|
|
// 文档出卷:文件必须上传
|
|
|
if (menu_id === 7) {
|
|
if (menu_id === 7) {
|
|
|
- return true;
|
|
|
|
|
|
|
+ // 当第一次对话时,必须上传文件,
|
|
|
|
|
+ // 非第一次,不做要求
|
|
|
|
|
+ if (chat_round_sent_count.value === 0) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
return false;
|
|
|
});
|
|
});
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 此值在 enable_file_upload === true 的前提下有效
|
|
|
* 表单区域:文件上传允许的文件类型
|
|
* 表单区域:文件上传允许的文件类型
|
|
|
* 对应表单参数的 accept
|
|
* 对应表单参数的 accept
|
|
|
*/
|
|
*/
|
|
@@ -409,6 +428,8 @@ const file_accept = computed(() => {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 答案可用的操作按钮
|
|
* 答案可用的操作按钮
|
|
|
|
|
+ * 可用的值有 [] 或者 ['copy']
|
|
|
|
|
+ * 后续可能有新值添加
|
|
|
*/
|
|
*/
|
|
|
const answer_action_list = computed(() => {
|
|
const answer_action_list = computed(() => {
|
|
|
const menu_id = current_menu_id.value;
|
|
const menu_id = current_menu_id.value;
|
|
@@ -482,7 +503,7 @@ const handleInputSizeChange = (size) => {
|
|
|
* 输入已经确认要提交了
|
|
* 输入已经确认要提交了
|
|
|
*
|
|
*
|
|
|
* 1. 创建会话 get-chat-id
|
|
* 1. 创建会话 get-chat-id
|
|
|
- * 2. 文件上传
|
|
|
|
|
|
|
+ * 2. 文件上传 如果有文件,则需要文件上传,没有文件,则不需要文件上传
|
|
|
* 3. 连接socket,socket 发送文本与文件数据内容
|
|
* 3. 连接socket,socket 发送文本与文件数据内容
|
|
|
* 4. 接收 socket 返回的数据项
|
|
* 4. 接收 socket 返回的数据项
|
|
|
*/
|
|
*/
|
|
@@ -580,7 +601,7 @@ const handleInputSubmit = async (options) => {
|
|
|
* 如果对话已经创建,则使用已经创建的对话
|
|
* 如果对话已经创建,则使用已经创建的对话
|
|
|
* 否则,创建新对话
|
|
* 否则,创建新对话
|
|
|
*/
|
|
*/
|
|
|
- if (chat_new_id.value === null) {
|
|
|
|
|
|
|
+ if (chat_round_id.value === null) {
|
|
|
// 未创建chat,开始创建
|
|
// 未创建chat,开始创建
|
|
|
try {
|
|
try {
|
|
|
const chatResult = await getDialogChatId(agent_id);
|
|
const chatResult = await getDialogChatId(agent_id);
|
|
@@ -589,7 +610,7 @@ const handleInputSubmit = async (options) => {
|
|
|
// 成功
|
|
// 成功
|
|
|
const res_data = chatResult.data;
|
|
const res_data = chatResult.data;
|
|
|
|
|
|
|
|
- chat_new_id.value = res_data.chat_id;
|
|
|
|
|
|
|
+ chat_round_id.value = res_data.chat_id;
|
|
|
} else {
|
|
} else {
|
|
|
// 失败
|
|
// 失败
|
|
|
// 处理异常:直接在界面上显示
|
|
// 处理异常:直接在界面上显示
|
|
@@ -620,7 +641,7 @@ const handleInputSubmit = async (options) => {
|
|
|
*/
|
|
*/
|
|
|
if (file_total !== 0) {
|
|
if (file_total !== 0) {
|
|
|
// 进行文件上传,获取文件信息
|
|
// 进行文件上传,获取文件信息
|
|
|
- const chat_id = chat_new_id.value;
|
|
|
|
|
|
|
+ const chat_id = chat_round_id.value;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const menu_id = current_menu_id.value;
|
|
const menu_id = current_menu_id.value;
|
|
@@ -675,7 +696,7 @@ const handleInputSubmit = async (options) => {
|
|
|
*/
|
|
*/
|
|
|
const msg_str = jsonStringify(msg_obj);
|
|
const msg_str = jsonStringify(msg_obj);
|
|
|
// 发送websocket消息
|
|
// 发送websocket消息
|
|
|
- handleWSSend(chat_new_id.value, msg_str);
|
|
|
|
|
|
|
+ handleWSSend(chat_round_id.value, msg_str);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -725,6 +746,8 @@ function handleWSSend(chat_id, value) {
|
|
|
initWSConnection(props.agent_id, chat_id, menu_id);
|
|
initWSConnection(props.agent_id, chat_id, menu_id);
|
|
|
// 发送socket连接
|
|
// 发送socket连接
|
|
|
sendWSMessage(value);
|
|
sendWSMessage(value);
|
|
|
|
|
+ // 统计会话发起的次数
|
|
|
|
|
+ chat_round_sent_count.value = chat_round_sent_count.value + 1;
|
|
|
/**
|
|
/**
|
|
|
* websocket消息发送流程完成
|
|
* websocket消息发送流程完成
|
|
|
* ------------------------------------------------------------
|
|
* ------------------------------------------------------------
|