Files
cz-web/src/views/service/cpns/ChatMessageItem.vue
2026-10-01 17:24:57 +08:00

118 lines
2.5 KiB
Vue

<script setup lang="ts">
import type { ChatMessage } from '@/types/business/service'
import ChatFileCard from './ChatFileCard.vue'
interface Props {
message: ChatMessage
unread?: boolean
}
withDefaults(defineProps<Props>(), { unread: false })
const emit = defineEmits<{ download: [] }>()
</script>
<template>
<div
class="chat-message-item"
:class="`chat-message-item--${message.role}`"
>
<span v-if="message.role === 'assistant'" class="chat-message-item__avatar">服</span>
<div class="chat-message-item__main">
<div class="chat-message-item__bubble">
<span v-if="unread" class="chat-message-item__unread">未读</span>
<ChatFileCard
v-if="message.file"
:file="message.file"
@download="emit('download')"
/>
<template v-else>{{ message.content }}</template>
</div>
<span class="chat-message-item__time text-secondary">{{ message.time }}</span>
</div>
<span v-if="message.role === 'user'" class="chat-message-item__avatar chat-message-item__avatar--user">王</span>
</div>
</template>
<style lang="less" scoped>
.chat-message-item {
.flex(row, flex-start, flex-start);
gap: 9px;
&__avatar {
flex-shrink: 0;
.flex(row, center);
width: 28px;
height: 28px;
border-radius: @radius-round;
background: @primary-strong;
color: @white;
font-size: 12px; // 16 → 12
font-weight: 400;
&--user {
background: @service-user-avatar;
color: @white;
}
}
&__main {
.flex(column, flex-start, flex-start);
gap: 4px;
max-width: 320px;
}
&__bubble {
position: relative;
padding: 9px 12px;
border-radius: 8px;
background: @white;
box-shadow: @shadow-base;
color: @heading-color;
font-size: 11px;
line-height: 1.75;
white-space: pre-wrap;
word-break: break-word;
}
&__bubble:has(.chat-file-card) {
padding: 0;
background: transparent;
box-shadow: none;
}
&__time {
font-size: 11px;
color: @text-color-disabled;
}
&__unread {
position: absolute;
top: 100%;
left: 0;
margin-top: 6px;
padding: 0;
background: transparent;
color: @text-color-disabled;
font-size: 11px;
font-weight: 400;
line-height: 1.3;
}
&--user {
.flex(row, flex-end, flex-start);
.chat-message-item__main {
align-items: flex-end;
}
.chat-message-item__bubble {
background: @primary-strong;
color: @white;
}
}
}
</style>