This commit is contained in:
XIE7654
2025-07-18 10:39:05 +08:00
parent 66d5971570
commit aef25112f6
16 changed files with 83 additions and 74 deletions

View File

@@ -5,6 +5,16 @@ export async function getConversations() {
return await res.json();
}
export async function createConversation() {
const response = await fetchWithAuth('/chat/api/v1/conversations', {
method: 'POST',
});
if (!response.ok) {
throw new Error('创建对话失败');
}
return await response.json();
}
export async function getMessages(conversationId: number) {
const res = await fetchWithAuth(
`/chat/api/v1/messages?conversation_id=${conversationId}`,

View File

@@ -1,6 +1,6 @@
{
"title": "AI Management",
"ai_api_key": {
"api_key": {
"title": "KEY Management",
"name": "KEY Management"
},

View File

@@ -1,6 +1,6 @@
{
"title": "AI大模型",
"ai_api_key": {
"api_key": {
"title": "API 密钥",
"name": "API 密钥"
},

View File

@@ -133,7 +133,7 @@ function refreshGrid() {
v-permission="'ai:ai_api_key:create'"
>
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', [$t('ai.ai_api_key.name')]) }}
{{ $t('ui.actionTitle.create', [$t('ai.api_key.name')]) }}
</Button>
</template>
</Grid>

View File

@@ -20,8 +20,8 @@ const formModel = new AiAIApiKeyModel();
const formData = ref<AiAIApiKeyApi.AiAIApiKey>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', [$t('ai.ai_api_key.name')])
: $t('ui.actionTitle.create', [$t('ai.ai_api_key.name')]);
? $t('ui.actionTitle.edit', [$t('ai.api_key.name')])
: $t('ui.actionTitle.create', [$t('ai.api_key.name')]);
});
const [Form, formApi] = useVbenForm({

View File

@@ -14,16 +14,21 @@ import {
Select,
} from 'ant-design-vue';
import { fetchAIStream, getConversations, getMessages } from '#/api/ai/chat';
import {
createConversation,
fetchAIStream,
getConversations,
getMessages,
} from '#/api/ai/chat';
interface Message {
id: null | number;
id: number;
type: 'assistant' | 'user';
content: string;
}
interface ChatItem {
id: null | number;
id: number;
title: string;
lastMessage: string;
}
@@ -60,14 +65,13 @@ async function selectChat(id: number) {
nextTick(scrollToBottom);
}
function handleNewChat() {
const newId = null;
chatList.value.unshift({
id: newId,
title: `新对话${chatList.value.length + 1}`,
lastMessage: '',
});
selectedChatId.value = newId;
async function handleNewChat() {
// 调用后端新建对话
const { data } = await createConversation();
// 刷新对话列表
await fetchConversations();
// 选中新建的对话
selectedChatId.value = data;
messages.value = [];
nextTick(scrollToBottom);
}
@@ -195,7 +199,7 @@ onMounted(() => {
/>
</div>
</div>
<div class="chat-messages" style="height: 100%;" ref="messagesRef">
<div class="chat-messages" style="height: 100%" ref="messagesRef">
<div
v-for="msg in messages"
:key="msg.id"