知识库查询

This commit is contained in:
2025-11-08 10:56:32 +08:00
parent 495e3569e2
commit bdc1bd64f6
4 changed files with 49 additions and 26 deletions

View File

@@ -225,7 +225,7 @@ export const chatApi = {
* @returns Promise<ResultDomain<boolean>>
*/
async deleteConversation(conversationId: string): Promise<ResultDomain<boolean>> {
const response = await api.delete<boolean>(`/ai/chat/conversation/${conversationId}`, {
const response = await api.delete<boolean>(`/ai/chat/conversation/${conversationId}`,{}, {
showLoading: false
});
return response.data;
@@ -249,7 +249,7 @@ export const chatApi = {
* @returns Promise<ResultDomain<AiMessage[]>>
*/
async listMessages(conversationId: string): Promise<ResultDomain<AiMessage>> {
const response = await api.get<AiMessage>(`/ai/chat/conversation/${conversationId}/messages`, {
const response = await api.get<AiMessage>(`/ai/chat/conversation/${conversationId}/messages`, {},{
showLoading: false
});
return response.data;

View File

@@ -136,7 +136,7 @@ export const fileUploadApi = {
* @returns Promise<ResultDomain<AiUploadFile[]>>
*/
async listFilesByMessage(messageId: string): Promise<ResultDomain<AiUploadFile[]>> {
const response = await api.get<AiUploadFile[]>(`/ai/file/message/${messageId}`, {
const response = await api.get<AiUploadFile[]>(`/ai/file/message/${messageId}`, {},{
showLoading: false
});
return response.data;

View File

@@ -460,10 +460,11 @@ async function loadRecentConversations() {
conversations.value = [];
}
// 不自动选中对话,等待用户手动点击
// 如果有对话,自动选中第一个
if (conversations.value.length > 0 && !currentConversation.value) {
await selectConversation(conversations.value[0]);
}
// if (conversations.value.length > 0 && !currentConversation.value) {
// await selectConversation(conversations.value[0]);
// }
}
} catch (error) {
console.error('加载对话历史失败:', error);
@@ -608,10 +609,21 @@ async function loadMessages(conversationId: string) {
const messageList = result.dataList || result.data || [];
messages.value = Array.isArray(messageList) ? messageList : [];
// 加载每条用户消息的关联文件
// 加载每条用户消息的关联文件只有当fileIDs不为空时
for (const message of messages.value) {
if (message.role === 'user' && message.id) {
await loadMessageFiles(message.id);
if (message.role === 'user' && message.id && message.fileIDs) {
// 检查fileIDs是否不为空可能是JSON字符串或数组
let hasFiles = false;
const fileIDs = message.fileIDs;
if (typeof fileIDs === 'string') {
hasFiles = fileIDs.trim() !== '' && fileIDs !== '[]';
} else if (Array.isArray(fileIDs)) {
hasFiles = (fileIDs as any[]).length > 0;
}
if (hasFiles) {
await loadMessageFiles(message.id);
}
}
}
@@ -1691,31 +1703,41 @@ onUnmounted(() => {
}
.message-files {
margin-top: 8px;
margin-top: 12px;
display: flex;
flex-direction: column;
gap: 6px;
gap: 8px;
.message-file-item {
.file-link {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 12px;
background: rgba(255, 255, 255, 0.1);
border-radius: 6px;
gap: 10px;
padding: 10px 14px;
background: rgba(255, 255, 255, 0.15);
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 8px;
text-decoration: none;
color: inherit;
transition: all 0.2s;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
font-size: 13px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
&:hover {
background: rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.25);
border-color: rgba(255, 255, 255, 0.4);
transform: translateX(3px);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
&:active {
transform: translateX(2px);
}
.file-icon {
font-size: 16px;
font-size: 18px;
flex-shrink: 0;
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}
.file-name {
@@ -1723,11 +1745,17 @@ onUnmounted(() => {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: 500;
letter-spacing: 0.01em;
}
.file-size {
opacity: 0.7;
font-size: 12px;
opacity: 0.8;
font-size: 11px;
font-weight: 400;
flex-shrink: 0;
padding-left: 8px;
border-left: 1px solid rgba(255, 255, 255, 0.2);
}
}
}