Files
lanecarford_front/src/views/asistant/components/NoticeList.vue

69 lines
1.3 KiB
Vue
Raw Normal View History

2025-10-14 16:42:09 +08:00
<template>
<div class="chat-list" ref="chatListRef">
<div class="chat-message-item" v-for="message in list" :key="message.id">
2025-10-24 17:37:15 +08:00
<NoticeItem :value="message" />
2025-10-14 16:42:09 +08:00
</div>
</div>
</template>
<script setup lang="ts">
import NoticeItem from './NoticeItem.vue'
import GenerateLoading from './GenerateLoading.vue'
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
2025-10-14 16:42:09 +08:00
// 定义消息类型
interface ChatMessage {
id: string
content: string
userId: string
time: string
thumb: string
}
const props = defineProps<{
list: ChatMessage[]
}>()
2025-10-14 16:42:09 +08:00
const emits = defineEmits(['send-message'])
2025-10-14 16:42:09 +08:00
const chatListRef = ref<HTMLElement>()
2025-10-14 16:42:09 +08:00
// 自动滚动到底部
const scrollToBottom = (): void => {
if (chatListRef.value) {
chatListRef.value.scrollTo({
top: chatListRef.value.scrollHeight,
behavior: 'smooth'
})
2025-10-14 16:42:09 +08:00
}
}
// 监听消息列表变化,自动滚动到底部
watch(
() => props.list,
async () => {
await nextTick()
scrollToBottom()
},
{ deep: true }
)
2025-10-14 16:42:09 +08:00
const handleSendMessage = (message: string): void => {
console.log('list发送消息:', message)
emits('send-message', message)
2025-10-14 16:42:09 +08:00
}
</script>
<style lang="less" scoped>
.chat-list {
padding: 16px;
background-color: #fff;
height: 100%;
overflow-y: auto;
flex: 1;
}
.chat-message-item {
margin-bottom: 4.84rem;
}
</style>