ChatComposer.vue
1.28 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
<template>
<div class="wrap">
<el-input
v-model="text"
type="textarea"
:autosize="{ minRows: 2, maxRows: 5 }"
placeholder="输入要测试的用户话术,例如:我想退货"
@keydown.enter.exact.prevent="onEnter"
@keydown.enter.shift.exact.stop
/>
<div class="actions">
<el-button type="primary" :loading="sending" :disabled="!canSend" @click="emitSend">
发送
</el-button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
const props = defineProps<{ sending: boolean; modelValue: string }>();
const emit = defineEmits<{
(e: "send", text: string): void;
(e: "update:modelValue", v: string): void;
}>();
const text = computed({
get: () => props.modelValue,
set: (v: string) => emit("update:modelValue", v),
});
const canSend = computed(() => text.value.trim().length > 0 && !props.sending);
function emitSend(): void {
const value = text.value.trim();
if (!value || props.sending) return;
emit("send", value);
emit("update:modelValue", "");
}
function onEnter(): void {
emitSend();
}
</script>
<style scoped>
.wrap {
display: grid;
grid-template-columns: 1fr 92px;
gap: 10px;
align-items: end;
}
.actions {
display: flex;
justify-content: flex-end;
}
</style>