DocumentUpload.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script setup>
  2. import { ref } from "vue";
  3. const emit = defineEmits(["ingested"]);
  4. const manualText = ref("");
  5. const file = ref(null);
  6. const loading = ref(false);
  7. const status = ref("");
  8. const error = ref("");
  9. async function onFile(e) {
  10. const f = e.target.files?.[0];
  11. if (!f) return;
  12. file.value = f;
  13. status.value = `Arquivo carregado: ${f.name}`;
  14. }
  15. async function onIngest() {
  16. error.value = "";
  17. status.value = "";
  18. loading.value = true;
  19. try {
  20. const hasManual = Boolean(manualText.value.trim());
  21. if (hasManual) {
  22. emit("ingested", { text: manualText.value.trim(), source: "manual" });
  23. } else if (file.value) {
  24. emit("ingested", { file: file.value, source: "upload" });
  25. }
  26. manualText.value = "";
  27. file.value = null;
  28. status.value = "Enviado para ingestão.";
  29. } catch (e) {
  30. error.value = e?.message || "erro";
  31. } finally {
  32. loading.value = false;
  33. }
  34. }
  35. </script>
  36. <template>
  37. <section class="rounded-2xl border border-gray-300 bg-gray-100 p-4 shadow-sm backdrop-blur-md dark:border-gray-700 dark:bg-secondary/50">
  38. <h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100">Update</h2>
  39. <div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
  40. Envie .txt, .pdf, .docx ou imagens (png/jpg) com manuais/prints para alimentar a base.
  41. </div>
  42. <input
  43. class="mt-3"
  44. type="file"
  45. accept=".txt,.pdf,.docx,.png,.jpg,.jpeg,.webp,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/*,text/plain"
  46. @change="onFile"
  47. />
  48. <textarea
  49. v-model="manualText"
  50. class="mt-3"
  51. rows="6"
  52. placeholder="Ou cole um texto aqui para ingestão..."
  53. />
  54. <button
  55. class="mt-3 rounded-lg border border-primary bg-primary px-4 py-2.5 text-sm font-medium text-primary-foreground transition-colors hover:border-[var(--primary-600)] hover:bg-[var(--primary-600)] disabled:cursor-not-allowed disabled:opacity-50"
  56. :disabled="loading || (!manualText.trim() && !file)"
  57. @click="onIngest"
  58. >
  59. Ingerir
  60. </button>
  61. <div v-if="status" class="mt-2.5 text-sm text-gray-500 dark:text-gray-400">{{ status }}</div>
  62. <div v-if="error" class="mt-2.5 text-sm text-gray-500 dark:text-gray-400">Erro: {{ error }}</div>
  63. </section>
  64. </template>