【增加】AI 对话删除,重置 Chat 聊天

This commit is contained in:
cherishsince 2024-05-16 23:21:31 +08:00
parent 934d5e7ca8
commit 222a841226

View File

@ -1,8 +1,11 @@
<template>
<el-container class="ai-layout">
<!-- 左侧会话列表 -->
<Conversation @onConversationClick="handleConversationClick"
@onConversationClear="handlerConversationClear" />
<Conversation :active-id="activeConversationId"
@onConversationClick="handleConversationClick"
@onConversationClear="handlerConversationClear"
@onConversationDelete="handlerConversationDelete"
/>
<!-- 右侧会话详情 -->
<el-container class="detail-container">
<!-- 右顶部 TODO 芋艿右对齐 -->
@ -30,62 +33,8 @@
<!-- main -->
<el-main class="main-container">
<div class="message-container" ref="messageContainer">
<div class="chat-list" v-for="(item, index) in list" :key="index">
<!-- 靠左 message -->
<!-- TODO 芋艿类型判断 -->
<div class="left-message message-item" v-if="item.type === 'system'">
<div class="avatar">
<el-avatar
src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
/>
</div>
<div class="message">
<div>
<el-text class="time">{{ formatDate(item.createTime) }}</el-text>
</div>
<div class="left-text-container" ref="markdownViewRef">
<MarkdownView class="left-text" :content="item.content" />
</div>
<div class="left-btns">
<div class="btn-cus" @click="noCopy(item.content)">
<img class="btn-image" src="../../../assets/ai/copy.svg"/>
<el-text class="btn-cus-text">复制</el-text>
</div>
<div class="btn-cus" style="margin-left: 20px" @click="onDelete(item.id)">
<img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px"/>
<el-text class="btn-cus-text">删除</el-text>
</div>
</div>
</div>
</div>
<!-- 靠右 message -->
<div class="right-message message-item" v-if="item.type === 'user'">
<div class="avatar">
<el-avatar
src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
/>
</div>
<div class="message">
<div>
<el-text class="time">{{ formatDate(item.createTime) }}</el-text>
</div>
<div class="right-text-container">
<div class="right-text">{{ item.content }}</div>
</div>
<div class="right-btns">
<div class="btn-cus" @click="noCopy(item.content)">
<img class="btn-image" src="@/assets/ai/copy.svg"/>
<el-text class="btn-cus-text">复制</el-text>
</div>
<div class="btn-cus" style="margin-left: 20px" @click="onDelete(item.id)">
<img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px"/>
<el-text class="btn-cus-text">删除</el-text>
</div>
</div>
</div>
</div>
</div>
<div class="message-container" >
<Message ref="messageRef" :list="list" />
</div>
</el-main>
<el-footer class="footer-container">
@ -135,8 +84,9 @@
<script setup lang="ts">
import MarkdownView from '@/components/MarkdownView/index.vue'
import Conversation from './Conversation.vue'
import Message from './Message.vue'
import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message'
import {ChatConversationVO} from '@/api/ai/chat/conversation'
import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
import {formatDate} from '@/utils/formatTime'
import {useClipboard} from '@vueuse/core'
import ChatConversationUpdateForm from "@/views/ai/chat/components/ChatConversationUpdateForm.vue";
@ -146,7 +96,7 @@ const message = useMessage() // 消息弹窗
const {copy} = useClipboard() // copy
// ref
const activeConversationId = ref<number | null>(null) //
const activeConversationId = ref<string | null>(null) //
const activeConversation = ref<ChatConversationVO | null>(null) // Conversation
const conversationInProgress = ref(false) //
const conversationInAbortController = ref<any>() // abort ( stream )
@ -155,6 +105,7 @@ const prompt = ref<string>() // prompt
// ()
const messageContainer: any = ref(null)
const messageRef = ref()
const isScrolling = ref(false) //
const isComposing = ref(false) //
@ -164,14 +115,14 @@ const list = ref<ChatMessageVO[]>([]) // 列表的数据
// ============ ==============
function scrollToBottom() {
nextTick(() => {
//使nexttickdom
console.log('isScrolling.value', isScrolling.value)
if (!isScrolling.value) {
messageContainer.value.scrollTop =
messageContainer.value.scrollHeight - messageContainer.value.offsetHeight
}
})
// nextTick(() => {
// //使nexttickdom
// console.log('isScrolling.value', isScrolling.value)
// if (!isScrolling.value) {
// messageContainer.value.scrollTop =
// messageContainer.value.scrollHeight - messageContainer.value.offsetHeight
// }
// })
}
function handleScroll() {
@ -179,6 +130,7 @@ function handleScroll() {
const scrollTop = scrollContainer.scrollTop
const scrollHeight = scrollContainer.scrollHeight
const offsetHeight = scrollContainer.offsetHeight
console.log('scrollTop', scrollTop)
if ((scrollTop + offsetHeight) < (scrollHeight - 50)) {
//
isScrolling.value = true
@ -338,7 +290,8 @@ const getMessageList = async () => {
list.value = await ChatMessageApi.messageList(activeConversationId.value)
//
await nextTick(() => {
scrollToBottom()
//
messageRef.value.scrollToBottom(true)
})
} finally {
}
@ -384,6 +337,8 @@ const handlerTitleSuccess = async () => {
* 对话 - 点击
*/
const handleConversationClick = async (conversation: ChatConversationVO) => {
//
isScrolling.value = false
// id
activeConversationId.value = conversation.id
activeConversation.value = conversation
@ -400,12 +355,32 @@ const handlerConversationClear = async ()=> {
list.value = []
}
/**
* 对话 - 删除
*/
const handlerConversationDelete = async (delConversation: ChatConversationVO) => {
//
if (activeConversationId.value === delConversation.id) {
await handlerConversationClear()
}
}
/**
* 对话 - 获取
*/
const getConversation = async (id: string) => {
const conversation: ChatConversationVO = await ChatConversationApi.getChatConversationMy(id)
return conversation
}
/** 初始化 **/
onMounted(async () => {
// TODO conversationId
// if (route.query.conversationId) {
// conversationId.value = route.query.conversationId as number
// }
if (route.query.conversationId) {
const id = route.query.conversationId as string
activeConversationId.value = id
activeConversation.value = await getConversation(id) as ChatConversationVO
}
//
// await getChatConversationList()
//
@ -415,18 +390,18 @@ onMounted(async () => {
// scrollToBottom();
// await nextTick
//
messageContainer.value.addEventListener('scroll', handleScroll)
// messageContainer.value.addEventListener('scroll', handleScroll)
// copy
messageContainer.value.addEventListener('click', (e: any) => {
console.log(e)
if (e.target.id === 'copy') {
copy(e.target?.dataset?.copy)
ElMessage({
message: '复制成功!',
type: 'success'
})
}
})
// messageContainer.value.addEventListener('click', (e: any) => {
// console.log(e)
// if (e.target.id === 'copy') {
// copy(e.target?.dataset?.copy)
// ElMessage({
// message: '!',
// type: 'success'
// })
// }
// })
})
</script>