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
81 lines (69 loc) · 1.7 KB
/
Copy pathactions-enhanced.vue
File metadata and controls
81 lines (69 loc) · 1.7 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
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { TrSender, UploadButton, VoiceButton } from '@opentiny/tiny-robot'
const content = ref('')
const message = ref('')
let messageTimer: ReturnType<typeof setTimeout> | undefined
const showMessage = (value: string) => {
if (messageTimer) {
clearTimeout(messageTimer)
}
message.value = value
messageTimer = setTimeout(() => {
message.value = ''
messageTimer = undefined
}, 3000)
}
const handleSubmit = (text: string) => {
showMessage(`已提交: ${text}`)
content.value = ''
}
const handleFiles = (files: File[]) => {
showMessage(`已选择 ${files.length} 个文件`)
}
const handleVoiceFinal = (text: string) => {
content.value += text + ' '
}
onBeforeUnmount(() => {
if (messageTimer) {
clearTimeout(messageTimer)
}
})
</script>
<template>
<div class="demo-container">
<tr-sender
v-model="content"
placeholder="输入内容,或使用语音/上传文件..."
mode="multiple"
clearable
@submit="handleSubmit"
>
<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="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;
}
</style>