From 2a2c1177eef03dc2387950c59596704a0390622e Mon Sep 17 00:00:00 2001 From: gerson <1405270578@qq.com> Date: 星期日, 30 六月 2024 17:25:31 +0800 Subject: [PATCH] chat --- src/layout/component/sidebar/waterLeftAside/asideNew.vue | 36 +++++++++++++++++++++++++----------- 1 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/layout/component/sidebar/waterLeftAside/asideNew.vue b/src/layout/component/sidebar/waterLeftAside/asideNew.vue index c2a4fd3..b48ef4e 100644 --- a/src/layout/component/sidebar/waterLeftAside/asideNew.vue +++ b/src/layout/component/sidebar/waterLeftAside/asideNew.vue @@ -35,7 +35,7 @@ @click="roomClick(item)" > <div class="ywicon icon-xiaoxi flex-0 mr-2.5"></div> - <div class="flex-auto text-ellipsis text-nowrap text-sm group-hover:text-[#0084ff]">chat room</div> + <div class="flex-auto text-ellipsis text-nowrap text-sm group-hover:text-[#0084ff]">{{ item.title }}</div> <div class="text-gray-100 flex items-center space-x-2 ml-1"> <div class="ywicon invisible icon-bianji visible group-hover:visible !text-sm"></div> @@ -56,7 +56,8 @@ import { nextTick, onMounted, reactive, ref } from 'vue'; import type { ChatRoomItem } from './types'; import router from '/@/router'; -import { activeRoomId, chatRoomList } from '/@/stores/chatRoom'; +import { CreateHistoryGroup, GetHistoryGroups } from '/@/api/ai/chat'; +import { chatRoomList, activeRoomId } from '/@/stores/chatRoom'; let state = reactive({ searchInput: '', selectDateOption: [ @@ -101,9 +102,13 @@ } }; -const newChatRoomClick = () => { +const newChatRoomClick = async () => { + const res = await CreateHistoryGroup({ + group_title: 'chat room', + }); + const newRoom = { - id: new Date().getTime() + '' + Math.floor(Math.random() * 1000), + id: res.history_group_id, isInitial: true, title: 'chat room', }; @@ -134,13 +139,22 @@ chatRoomRef.value.firstElementChild?.scrollIntoView(); }; -onMounted(() => { - if (router.currentRoute.value.name === 'Home') { - if (!chatRoomList.value || chatRoomList.value.length === 0) { - newChatRoomClick(); - } else { - roomClick(chatRoomList.value[0]); - } +onMounted(async () => { + const res = await GetHistoryGroups(); + + const resData = (res?.groups || []) as any[]; + chatRoomList.value = resData?.map((item) => { + return { + id: item.group_id, + title: item.group_title, + createTime: item.create_time, + isInitial: false, + }; + }); + if (!chatRoomList.value || chatRoomList.value.length === 0) { + newChatRoomClick(); + } else { + roomClick(chatRoomList.value[0]); } }); </script> -- Gitblit v1.9.3