forked from opentiny/tiny-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions-enhanced.vue
More file actions
96 lines (83 loc) · 2.3 KB
/
Copy pathactions-enhanced.vue
File metadata and controls
96 lines (83 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<script setup lang="ts">
import { ref } from 'vue'
import { TrSender, UploadButton, VoiceButton } from '@opentiny/tiny-robot'
import { Tag as TinyTag } from '@opentiny/vue'
const content = ref('')
const message = ref('')
const selectedFiles = ref<File[]>([])
const handleSubmit = (text: string) => {
const fileNames = selectedFiles.value.map((file) => file.name).join(', ')
message.value = fileNames ? `已提交: ${text || '(无文本)'},附件: ${fileNames}` : `已提交: ${text}`
content.value = ''
selectedFiles.value = []
setTimeout(() => (message.value = ''), 3000)
}
const handleFiles = (files: File[]) => {
selectedFiles.value = [...selectedFiles.value, ...files]
}
const handleClear = () => {
selectedFiles.value = []
}
const removeFile = (index: number) => {
selectedFiles.value = selectedFiles.value.filter((_, fileIndex) => fileIndex !== index)
}
const handleVoiceFinal = (text: string) => {
content.value += text + ' '
}
</script>
<template>
<div class="demo-container">
<tr-sender
v-model="content"
placeholder="输入内容,或使用语音/上传文件..."
mode="multiple"
:has-external-content="selectedFiles.length > 0"
clearable
@submit="handleSubmit"
@clear="handleClear"
>
<template #footer-right>
<!-- 上传按钮 -->
<UploadButton
accept="image/*"
:multiple="true"
tooltip="上传图片"
tooltip-placement="top"
@select="handleFiles"
/>
<!-- 语音按钮 -->
<VoiceButton tooltip="语音输入" tooltip-placement="top" @speech-final="handleVoiceFinal" />
</template>
</tr-sender>
<div v-if="selectedFiles.length" class="file-list">
<tiny-tag
v-for="(file, index) in selectedFiles"
:key="`${file.name}-${file.lastModified}-${index}`"
:max-width="240"
closable
@close="removeFile(index)"
>
{{ file.name }}
</tiny-tag>
</div>
<div v-if="message" class="message">{{ message }}</div>
</div>
</template>
<style scoped>
.demo-container {
padding: 20px;
}
.message {
margin-top: 15px;
padding: 10px;
background: #e7f3ff;
border-radius: 6px;
color: #1476ff;
}
.file-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 12px;
}
</style>