From 87bce04d7cdf5ca427757071e7cc3b0847b64dfc Mon Sep 17 00:00:00 2001 From: gerson <1405270578@qq.com> Date: 星期一, 01 七月 2024 11:37:25 +0800 Subject: [PATCH] question 传 id --- src/layout/component/sidebar/waterLeftAside/asideNew.vue | 57 ++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/layout/component/sidebar/waterLeftAside/asideNew.vue b/src/layout/component/sidebar/waterLeftAside/asideNew.vue index c2a4fd3..0ac22c9 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, DeleteHistoryGroups, GetHistoryGroups } from '/@/api/ai/chat'; +import { chatRoomList, activeRoomId } from '/@/stores/chatRoom'; let state = reactive({ searchInput: '', selectDateOption: [ @@ -99,11 +100,22 @@ }, }); } + setTimeout(() => { + activeRoomId.value = room.id; + + }, 0); + + + }; -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', }; @@ -112,18 +124,20 @@ } else { chatRoomList.value.unshift(newRoom); } - activeRoomId.value = newRoom.id; - nextTick(() => { - gotoAnswerPage(newRoom); - }); + gotoAnswerPage(newRoom); }; const roomClick = (room: ChatRoomItem) => { - activeRoomId.value = room.id; gotoAnswerPage(room); }; -const confirmDeleteChatRoom = (room: ChatRoomItem) => { +const confirmDeleteChatRoom =async (room: ChatRoomItem) => { + + + const res = await DeleteHistoryGroups({ + history_group_id:room.id + }); + const foundIndex = chatRoomList.value.findIndex((item) => item === room); chatRoomList.value.splice(foundIndex, 1); if (chatRoomList.value.length === 0) { @@ -134,13 +148,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