ChatComposer.vue 1.28 KB
<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>