2025-12-19 04:04:48 +08:00
|
|
|
<template>
|
|
|
|
|
<MessageInputComponent
|
|
|
|
|
ref="inputRef"
|
|
|
|
|
:model-value="modelValue"
|
|
|
|
|
@update:modelValue="updateValue"
|
|
|
|
|
:is-loading="isLoading"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:send-button-disabled="sendButtonDisabled"
|
|
|
|
|
:placeholder="placeholder"
|
2026-02-04 17:05:26 +08:00
|
|
|
:mention="mention"
|
2026-05-21 23:06:33 +08:00
|
|
|
:thread-id="threadId"
|
2025-12-19 04:04:48 +08:00
|
|
|
@send="handleSend"
|
|
|
|
|
@keydown="handleKeyDown"
|
|
|
|
|
>
|
|
|
|
|
<template #top>
|
2026-05-24 00:47:08 +08:00
|
|
|
<div v-if="currentImage || previewAttachments.length" class="input-top-stack">
|
2026-03-29 10:55:00 +08:00
|
|
|
<ImagePreviewComponent
|
2026-05-24 00:47:08 +08:00
|
|
|
v-if="currentImage"
|
2026-03-29 10:55:00 +08:00
|
|
|
:image-data="currentImage"
|
|
|
|
|
@remove="handleImageRemoved"
|
|
|
|
|
class="image-preview-wrapper"
|
|
|
|
|
/>
|
2026-05-24 00:47:08 +08:00
|
|
|
|
|
|
|
|
<div v-if="previewAttachments.length" class="attachment-preview-list">
|
|
|
|
|
<div
|
|
|
|
|
v-for="attachment in previewImageAttachments"
|
|
|
|
|
:key="attachment.fileId"
|
|
|
|
|
class="attachment-preview-image"
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
:src="attachment.previewUrl"
|
|
|
|
|
:alt="attachment.name"
|
|
|
|
|
class="attachment-image-thumb"
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
class="attachment-remove-btn"
|
|
|
|
|
type="button"
|
|
|
|
|
:aria-label="`移除附件 ${attachment.name}`"
|
|
|
|
|
@click.stop="handleAttachmentRemoved(attachment)"
|
|
|
|
|
>
|
|
|
|
|
<X :size="14" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
v-for="attachment in previewFileAttachments"
|
|
|
|
|
:key="attachment.fileId"
|
|
|
|
|
class="attachment-file-card"
|
|
|
|
|
>
|
2026-06-05 01:29:34 +08:00
|
|
|
<div class="attachment-file-icon">
|
|
|
|
|
<FileTypeIcon :name="attachment.name" :size="18" />
|
2026-05-24 00:47:08 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="attachment-file-body">
|
|
|
|
|
<div class="attachment-file-name" :title="attachment.name">{{ attachment.name }}</div>
|
|
|
|
|
<div class="attachment-file-meta">{{ attachment.meta }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
class="attachment-remove-btn"
|
|
|
|
|
type="button"
|
|
|
|
|
:aria-label="`移除附件 ${attachment.name}`"
|
|
|
|
|
@click.stop="handleAttachmentRemoved(attachment)"
|
|
|
|
|
>
|
|
|
|
|
<X :size="14" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-29 10:55:00 +08:00
|
|
|
</div>
|
2025-12-19 04:04:48 +08:00
|
|
|
</template>
|
|
|
|
|
<template #options-left>
|
|
|
|
|
<AttachmentOptionsComponent
|
|
|
|
|
v-if="supportsFileUpload"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
@upload="handleAttachmentUpload"
|
|
|
|
|
@upload-image="handleImageUpload"
|
|
|
|
|
@upload-image-success="handleImageUploadSuccess"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
<template #actions-left>
|
2026-01-24 15:24:25 +08:00
|
|
|
<div class="input-actions-left">
|
2026-05-25 21:02:23 +08:00
|
|
|
<slot name="actions-left-extra"></slot>
|
2026-04-01 03:17:15 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template #actions-right>
|
|
|
|
|
<div class="input-actions-right">
|
2026-05-25 21:02:23 +08:00
|
|
|
<slot name="actions-right-extra"></slot>
|
2026-01-24 15:24:25 +08:00
|
|
|
</div>
|
2025-12-19 04:04:48 +08:00
|
|
|
</template>
|
|
|
|
|
</MessageInputComponent>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-05-29 22:19:58 +08:00
|
|
|
import { computed, ref } from 'vue'
|
2026-01-15 06:01:34 +08:00
|
|
|
import MessageInputComponent from '@/components/MessageInputComponent.vue'
|
|
|
|
|
import ImagePreviewComponent from '@/components/ImagePreviewComponent.vue'
|
|
|
|
|
import AttachmentOptionsComponent from '@/components/AttachmentOptionsComponent.vue'
|
2026-05-29 22:19:58 +08:00
|
|
|
import { X } from 'lucide-vue-next'
|
2026-05-24 00:47:08 +08:00
|
|
|
import { normalizeAttachmentPreviews } from '@/utils/file_utils'
|
2026-06-05 01:29:34 +08:00
|
|
|
import FileTypeIcon from '@/components/common/FileTypeIcon.vue'
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-03-24 21:42:37 +08:00
|
|
|
const props = defineProps({
|
2025-12-19 04:04:48 +08:00
|
|
|
modelValue: { type: String, default: '' },
|
|
|
|
|
isLoading: { type: Boolean, default: false },
|
|
|
|
|
disabled: { type: Boolean, default: false },
|
|
|
|
|
sendButtonDisabled: { type: Boolean, default: false },
|
2026-03-20 17:51:12 +08:00
|
|
|
mention: { type: Object, default: () => null },
|
2026-05-21 23:06:33 +08:00
|
|
|
threadId: { type: String, default: '' },
|
2025-12-19 04:04:48 +08:00
|
|
|
supportsFileUpload: { type: Boolean, default: false },
|
2026-05-24 00:47:08 +08:00
|
|
|
attachments: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
2026-04-01 03:17:15 +08:00
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-05-24 00:47:08 +08:00
|
|
|
const emit = defineEmits([
|
|
|
|
|
'update:modelValue',
|
|
|
|
|
'send',
|
|
|
|
|
'keydown',
|
|
|
|
|
'upload-attachment',
|
|
|
|
|
'remove-attachment'
|
|
|
|
|
])
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
const inputRef = ref(null)
|
|
|
|
|
const currentImage = ref(null)
|
2026-03-26 12:13:51 +08:00
|
|
|
const placeholder = '问点什么?使用 @ 可以提及哦~'
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-05-24 00:47:08 +08:00
|
|
|
const previewAttachments = computed(() => normalizeAttachmentPreviews(props.attachments))
|
|
|
|
|
const previewImageAttachments = computed(() =>
|
|
|
|
|
previewAttachments.value.filter((attachment) => attachment.isImage && attachment.previewUrl)
|
|
|
|
|
)
|
|
|
|
|
const previewFileAttachments = computed(() =>
|
|
|
|
|
previewAttachments.value.filter((attachment) => !attachment.isImage || !attachment.previewUrl)
|
|
|
|
|
)
|
2026-04-01 03:17:15 +08:00
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
const updateValue = (val) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
emit('update:modelValue', val)
|
|
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-05-27 18:22:29 +08:00
|
|
|
const handleAttachmentUpload = (files = []) => {
|
2026-03-20 17:51:12 +08:00
|
|
|
emit('upload-attachment', files)
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
const handleImageUpload = (imageData) => {
|
|
|
|
|
if (imageData && imageData.success) {
|
|
|
|
|
currentImage.value = imageData
|
2025-12-19 04:04:48 +08:00
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
2026-01-24 15:24:25 +08:00
|
|
|
const handleImageUploadSuccess = () => {
|
|
|
|
|
if (inputRef.value) {
|
|
|
|
|
inputRef.value.closeOptions()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleImageRemoved = () => {
|
|
|
|
|
currentImage.value = null
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 00:47:08 +08:00
|
|
|
const handleAttachmentRemoved = (attachment) => {
|
|
|
|
|
emit('remove-attachment', attachment.raw)
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
const handleSend = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
emit('send', { image: currentImage.value })
|
|
|
|
|
currentImage.value = null
|
|
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
|
|
|
const handleKeyDown = (e) => {
|
2026-03-24 21:42:37 +08:00
|
|
|
if (props.sendButtonDisabled) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 04:04:48 +08:00
|
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
2026-01-15 06:01:34 +08:00
|
|
|
e.preventDefault()
|
|
|
|
|
handleSend()
|
2025-12-19 04:04:48 +08:00
|
|
|
} else {
|
2026-01-15 06:01:34 +08:00
|
|
|
emit('keydown', e)
|
2025-12-19 04:04:48 +08:00
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-19 04:04:48 +08:00
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
focus: () => inputRef.value?.focus(),
|
|
|
|
|
closeOptions: () => inputRef.value?.closeOptions()
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-19 04:04:48 +08:00
|
|
|
</script>
|
2026-01-24 15:24:25 +08:00
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.input-actions-left {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
2026-04-01 03:17:15 +08:00
|
|
|
flex-wrap: wrap;
|
2026-01-24 15:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-20 03:21:52 +08:00
|
|
|
.input-actions-right {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-right: 8px;
|
2026-04-01 16:55:29 +08:00
|
|
|
gap: 2px;
|
2026-03-20 03:21:52 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 10:55:00 +08:00
|
|
|
.input-top-stack {
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 00:47:08 +08:00
|
|
|
.attachment-preview-list {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-preview-image {
|
|
|
|
|
position: relative;
|
|
|
|
|
width: 80px;
|
|
|
|
|
height: 80px;
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
border: 1px solid var(--gray-150);
|
|
|
|
|
background: var(--gray-25);
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-image-thumb {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
object-fit: cover;
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-file-card {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
width: 220px;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
padding: 10px 34px 10px 12px;
|
|
|
|
|
border: 1px solid var(--gray-150);
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
background: var(--gray-0);
|
|
|
|
|
box-shadow: 0 1px 4px var(--shadow-0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-file-icon {
|
|
|
|
|
width: 40px;
|
|
|
|
|
height: 40px;
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
color: var(--main-700);
|
|
|
|
|
background: var(--main-30);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-file-body {
|
|
|
|
|
min-width: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-file-name {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
line-height: 1.35;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-file-meta {
|
|
|
|
|
margin-top: 2px;
|
|
|
|
|
color: var(--gray-500);
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 1.3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.attachment-remove-btn {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 6px;
|
|
|
|
|
right: 6px;
|
|
|
|
|
width: 24px;
|
|
|
|
|
height: 24px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
padding: 0;
|
|
|
|
|
color: var(--gray-0);
|
|
|
|
|
background: var(--gray-900);
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition:
|
|
|
|
|
background-color 0.15s ease,
|
|
|
|
|
transform 0.15s ease;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background: var(--gray-700);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
|
transform: scale(0.96);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 03:21:52 +08:00
|
|
|
// 输入框操作按钮通用样式(穿透到 slot 内容)
|
|
|
|
|
:deep(.input-action-btn) {
|
2026-01-24 15:24:25 +08:00
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 6px;
|
2026-03-27 01:15:42 +08:00
|
|
|
padding: 6px 8px;
|
2026-05-25 21:02:23 +08:00
|
|
|
height: 30px;
|
2026-01-24 15:24:25 +08:00
|
|
|
border-radius: 8px;
|
2026-04-18 16:22:59 +08:00
|
|
|
font-size: 13px;
|
2026-01-24 15:24:25 +08:00
|
|
|
color: var(--gray-600);
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
user-select: none;
|
|
|
|
|
background: transparent;
|
|
|
|
|
border: none;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2026-03-20 03:21:52 +08:00
|
|
|
color: var(--gray-900);
|
|
|
|
|
background: var(--gray-50);
|
2026-01-24 15:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.active {
|
2026-03-20 03:21:52 +08:00
|
|
|
color: var(--gray-900);
|
|
|
|
|
background: var(--gray-100);
|
2026-01-24 15:24:25 +08:00
|
|
|
font-weight: 500;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.disabled {
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
span {
|
|
|
|
|
line-height: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-20 03:21:52 +08:00
|
|
|
|
|
|
|
|
// slot 内容的 hide-text 响应式样式
|
|
|
|
|
:deep(.hide-text) {
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-29 10:55:00 +08:00
|
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
.input-top-stack {
|
|
|
|
|
gap: 8px;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
2026-04-01 03:17:15 +08:00
|
|
|
|
2026-05-24 00:47:08 +08:00
|
|
|
.attachment-file-card {
|
|
|
|
|
width: min(220px, 100%);
|
|
|
|
|
}
|
2026-03-29 10:55:00 +08:00
|
|
|
}
|
2026-01-24 15:24:25 +08:00
|
|
|
</style>
|