"新增聊天功能及相关路由和状态管理"

本次提交实现了聊天功能,包括在AppBar中添加了聊天链接,新增了聊天页面,以及聊天状态的管理。具体变更如下:

1. 在`AppBar.vue`中为聊天功能添加了图标和路由链接。
2. 新增`index.vue`文件,用于展示聊天内容。
3. 在`chat.ts`中定义了聊天状态的存储和获取方法。
4. 更新了`typed-router.d.ts`,包含了指向新聊天路由的记录。

这些变更使得应用能够提供聊天功能,为用户提供更丰富的交互方式。
This commit is contained in:
ivamp 2024-08-03 18:59:52 +08:00
parent 4bdb33ba19
commit 38262b11ac
5 changed files with 37 additions and 4 deletions

View File

@ -19,21 +19,21 @@
<v-list-item prepend-icon="mdi-home" rounded="lg" title="首页" to="/" />
<v-list-item
prepend-icon="mdi-home"
prepend-icon="mdi-assistant"
rounded="lg"
title="助理"
to="/assistants"
/>
<v-list-item
prepend-icon="mdi-home"
prepend-icon="mdi-tools"
rounded="lg"
title="工具"
to="/tools"
/>
<v-list-item
prepend-icon="mdi-home"
prepend-icon="mdi-web"
rounded="lg"
title="连通测试"
to="/ping"
@ -46,6 +46,15 @@
title="登录"
to="/auth/login"
/>
<template v-for="chat in chatStore.chats.data" :key="chat.id">
<v-list-item
prepend-icon="mdi-chat"
rounded="lg"
:title="chat?.name"
:to="'/chats/' + chat.id"
/>
</template>
</v-list>
</v-navigation-drawer>
@ -62,9 +71,12 @@
import { useConfigStore } from "@/stores/config";
import { useUserStore } from "@/stores/user";
import { useAppStore } from "@/stores/app";
import { useChatStore } from "@/stores/chat";
const chatStore = useChatStore();
const configStore = useConfigStore();
const userStore = useUserStore();
const appStore = useAppStore();
chatStore.getChats();
</script>

View File

@ -0,0 +1,3 @@
<template>
<div>chats</div>
</template>

View File

16
src/stores/chat.ts Normal file
View File

@ -0,0 +1,16 @@
import { ApiV1ChatsGet200Response } from "@/api";
import { defineStore } from "pinia";
import { api } from "@/plugins/api";
export const useChatStore = defineStore("chats", {
state: () => ({
chats: [] as ApiV1ChatsGet200Response,
}),
actions: {
getChats() {
api.Chat.apiV1ChatsGet().then((response) => {
this.chats = response.data;
});
},
},
});

View File

@ -25,6 +25,8 @@ declare module 'vue-router/auto-routes' {
'/assistants/create': RouteRecordInfo<'/assistants/create', '/assistants/create', Record<never, never>, Record<never, never>>,
'/auth/callback': RouteRecordInfo<'/auth/callback', '/auth/callback', Record<never, never>, Record<never, never>>,
'/auth/login': RouteRecordInfo<'/auth/login', '/auth/login', Record<never, never>, Record<never, never>>,
'/chats/': RouteRecordInfo<'/chats/', '/chats', Record<never, never>, Record<never, never>>,
'/chats/[id]/': RouteRecordInfo<'/chats/[id]/', '/chats/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'/ping/': RouteRecordInfo<'/ping/', '/ping', Record<never, never>, Record<never, never>>,
'/tools/': RouteRecordInfo<'/tools/', '/tools', Record<never, never>, Record<never, never>>,
'/tools/create': RouteRecordInfo<'/tools/create', '/tools/create', Record<never, never>, Record<never, never>>,